Skip to content

Commit 7093472

Browse files
Merge pull request #45251 from nextcloud/fix/files-source-no-fileid
fix(files): do not rely on unique fileid
2 parents 6ec6c1f + 51791e5 commit 7093472

16 files changed

Lines changed: 139 additions & 90 deletions

apps/files/src/components/BreadCrumbs.vue

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ import { useSelectionStore } from '../store/selection.ts'
5454
import { useUploaderStore } from '../store/uploader.ts'
5555
import filesListWidthMixin from '../mixins/filesListWidth.ts'
5656
import logger from '../logger'
57+
import type { FileSource } from '../types.ts'
5758
5859
export default defineComponent({
5960
name: 'BreadCrumbs',
@@ -106,8 +107,9 @@ export default defineComponent({
106107
107108
sections() {
108109
return this.dirs.map((dir: string, index: number) => {
109-
const fileid = this.getFileIdFromPath(dir)
110-
const to = { ...this.$route, params: { fileid }, query: { dir } }
110+
const source = this.getFileSourceFromPath(dir)
111+
const node: Node | undefined = source ? this.getNodeFromSource(source) : undefined
112+
const to = { ...this.$route, params: { node: node?.fileid }, query: { dir } }
111113
return {
112114
dir,
113115
exact: true,
@@ -136,28 +138,28 @@ export default defineComponent({
136138
},
137139
138140
selectedFiles() {
139-
return this.selectionStore.selected
141+
return this.selectionStore.selected as FileSource[]
140142
},
141143
142144
draggingFiles() {
143-
return this.draggingStore.dragging
145+
return this.draggingStore.dragging as FileSource[]
144146
},
145147
},
146148
147149
methods: {
148-
getNodeFromId(id: number): Node | undefined {
149-
return this.filesStore.getNode(id)
150+
getNodeFromSource(source: FileSource): Node | undefined {
151+
return this.filesStore.getNode(source)
150152
},
151-
getFileIdFromPath(path: string): number | undefined {
153+
getFileSourceFromPath(path: string): FileSource | undefined {
152154
return this.pathsStore.getPath(this.currentView?.id, path)
153155
},
154156
getDirDisplayName(path: string): string {
155157
if (path === '/') {
156158
return this.$navigation?.active?.name || t('files', 'Home')
157159
}
158160
159-
const fileId: number | undefined = this.getFileIdFromPath(path)
160-
const node: Node | undefined = (fileId) ? this.getNodeFromId(fileId) : undefined
161+
const source: FileSource | undefined = this.getFileSourceFromPath(path)
162+
const node: Node | undefined = source ? this.getNodeFromSource(source) : undefined
161163
return node?.attributes?.displayName || basename(path)
162164
},
163165
@@ -227,12 +229,12 @@ export default defineComponent({
227229
}
228230
229231
// Else we're moving/copying files
230-
const nodes = selection.map(fileid => this.filesStore.getNode(fileid)) as Node[]
232+
const nodes = selection.map(source => this.filesStore.getNode(source)) as Node[]
231233
await onDropInternalFiles(nodes, folder, contents.contents, isCopy)
232234
233235
// Reset selection after we dropped the files
234236
// if the dropped files are within the selection
235-
if (selection.some(fileid => this.selectedFiles.includes(fileid))) {
237+
if (selection.some(source => this.selectedFiles.includes(source))) {
236238
logger.debug('Dropped selection, resetting select store...')
237239
this.selectionStore.reset()
238240
}

apps/files/src/components/FileEntry/FileEntryCheckbox.vue

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import NcLoadingIcon from '@nextcloud/vue/dist/Components/NcLoadingIcon.js'
2424
import { useKeyboardStore } from '../../store/keyboard.ts'
2525
import { useSelectionStore } from '../../store/selection.ts'
2626
import logger from '../../logger.js'
27+
import type { FileSource } from '../../types.ts'
2728
2829
export default defineComponent({
2930
name: 'FileEntryCheckbox',
@@ -66,10 +67,10 @@ export default defineComponent({
6667
return this.selectionStore.selected
6768
},
6869
isSelected() {
69-
return this.selectedFiles.includes(this.fileid)
70+
return this.selectedFiles.includes(this.source.source)
7071
},
7172
index() {
72-
return this.nodes.findIndex((node: Node) => node.fileid === this.fileid)
73+
return this.nodes.findIndex((node: Node) => node.source === this.source.source)
7374
},
7475
isFile() {
7576
return this.source.type === FileType.File
@@ -88,20 +89,20 @@ export default defineComponent({
8889
8990
// Get the last selected and select all files in between
9091
if (this.keyboardStore?.shiftKey && lastSelectedIndex !== null) {
91-
const isAlreadySelected = this.selectedFiles.includes(this.fileid)
92+
const isAlreadySelected = this.selectedFiles.includes(this.source.source)
9293
9394
const start = Math.min(newSelectedIndex, lastSelectedIndex)
9495
const end = Math.max(lastSelectedIndex, newSelectedIndex)
9596
9697
const lastSelection = this.selectionStore.lastSelection
9798
const filesToSelect = this.nodes
98-
.map(file => file.fileid)
99+
.map(file => file.source)
99100
.slice(start, end + 1)
100-
.filter(Boolean) as number[]
101+
.filter(Boolean) as FileSource[]
101102
102103
// If already selected, update the new selection _without_ the current file
103104
const selection = [...lastSelection, ...filesToSelect]
104-
.filter(fileid => !isAlreadySelected || fileid !== this.fileid)
105+
.filter(source => !isAlreadySelected || source !== this.source.source)
105106
106107
logger.debug('Shift key pressed, selecting all files in between', { start, end, filesToSelect, isAlreadySelected })
107108
// Keep previous lastSelectedIndex to be use for further shift selections
@@ -110,8 +111,8 @@ export default defineComponent({
110111
}
111112
112113
const selection = selected
113-
? [...this.selectedFiles, this.fileid]
114-
: this.selectedFiles.filter(fileid => fileid !== this.fileid)
114+
? [...this.selectedFiles, this.source.source]
115+
: this.selectedFiles.filter(source => source !== this.source.source)
115116
116117
logger.debug('Updating selection', { selection })
117118
this.selectionStore.set(selection)

apps/files/src/components/FileEntryMixin.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55

66
import type { ComponentPublicInstance, PropType } from 'vue'
7+
import type { FileSource } from '../types.ts'
78

89
import { showError } from '@nextcloud/dialogs'
910
import { FileType, Permission, Folder, File as NcFile, NodeStatus, Node, View } from '@nextcloud/files'
@@ -85,13 +86,13 @@ export default defineComponent({
8586
},
8687

8788
draggingFiles() {
88-
return this.draggingStore.dragging
89+
return this.draggingStore.dragging as FileSource[]
8990
},
9091
selectedFiles() {
91-
return this.selectionStore.selected
92+
return this.selectionStore.selected as FileSource[]
9293
},
9394
isSelected() {
94-
return this.fileid && this.selectedFiles.includes(this.fileid)
95+
return this.selectedFiles.includes(this.source.source)
9596
},
9697

9798
isRenaming() {
@@ -116,7 +117,7 @@ export default defineComponent({
116117

117118
// If we're dragging a selection, we need to check all files
118119
if (this.selectedFiles.length > 0) {
119-
const nodes = this.selectedFiles.map(fileid => this.filesStore.getNode(fileid)) as Node[]
120+
const nodes = this.selectedFiles.map(source => this.filesStore.getNode(source)) as Node[]
120121
return nodes.every(canDrag)
121122
}
122123
return canDrag(this.source)
@@ -128,7 +129,7 @@ export default defineComponent({
128129
}
129130

130131
// If the current folder is also being dragged, we can't drop it on itself
131-
if (this.fileid && this.draggingFiles.includes(this.fileid)) {
132+
if (this.draggingFiles.includes(this.source.source)) {
132133
return false
133134
}
134135

@@ -269,14 +270,14 @@ export default defineComponent({
269270

270271
// Dragging set of files, if we're dragging a file
271272
// that is already selected, we use the entire selection
272-
if (this.selectedFiles.includes(this.fileid)) {
273+
if (this.selectedFiles.includes(this.source.source)) {
273274
this.draggingStore.set(this.selectedFiles)
274275
} else {
275-
this.draggingStore.set([this.fileid])
276+
this.draggingStore.set([this.source.source])
276277
}
277278

278279
const nodes = this.draggingStore.dragging
279-
.map(fileid => this.filesStore.getNode(fileid)) as Node[]
280+
.map(source => this.filesStore.getNode(source)) as Node[]
280281

281282
const image = await getDragAndDropPreview(nodes)
282283
event.dataTransfer?.setDragImage(image, -10, -10)
@@ -330,12 +331,12 @@ export default defineComponent({
330331
}
331332

332333
// Else we're moving/copying files
333-
const nodes = selection.map(fileid => this.filesStore.getNode(fileid)) as Node[]
334+
const nodes = selection.map(source => this.filesStore.getNode(source)) as Node[]
334335
await onDropInternalFiles(nodes, folder, contents.contents, isCopy)
335336

336337
// Reset selection after we dropped the files
337338
// if the dropped files are within the selection
338-
if (selection.some(fileid => this.selectedFiles.includes(fileid))) {
339+
if (selection.some(source => this.selectedFiles.includes(source))) {
339340
logger.debug('Dropped selection, resetting select store...')
340341
this.selectionStore.reset()
341342
}

apps/files/src/components/FilesListTableHeader.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ import FilesListTableHeaderButton from './FilesListTableHeaderButton.vue'
6464
import filesSortingMixin from '../mixins/filesSorting.ts'
6565
import logger from '../logger.js'
6666
import type { Node } from '@nextcloud/files'
67+
import type { FileSource } from '../types.ts'
6768
6869
export default defineComponent({
6970
name: 'FilesListTableHeader',
@@ -169,7 +170,7 @@ export default defineComponent({
169170
170171
onToggleAll(selected) {
171172
if (selected) {
172-
const selection = this.nodes.map(node => node.fileid).filter(Boolean) as number[]
173+
const selection = this.nodes.map(node => node.source).filter(Boolean) as FileSource[]
173174
logger.debug('Added all nodes to selection', { selection })
174175
this.selectionStore.setLastIndex(null)
175176
this.selectionStore.set(selection)

apps/files/src/components/FilesListTableHeaderActions.vue

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import { useFilesStore } from '../store/files.ts'
3939
import { useSelectionStore } from '../store/selection.ts'
4040
import filesListWidthMixin from '../mixins/filesListWidth.ts'
4141
import logger from '../logger.js'
42-
import type { FileId } from '../types'
42+
import type { FileSource } from '../types'
4343
4444
// The registered actions list
4545
const actions = getFileActions()
@@ -64,7 +64,7 @@ export default defineComponent({
6464
required: true,
6565
},
6666
selectedNodes: {
67-
type: Array as PropType<FileId[]>,
67+
type: Array as PropType<FileSource[]>,
6868
default: () => ([]),
6969
},
7070
},
@@ -100,7 +100,7 @@ export default defineComponent({
100100
101101
nodes() {
102102
return this.selectedNodes
103-
.map(fileid => this.getNode(fileid))
103+
.map(source => this.getNode(source))
104104
.filter(Boolean) as Node[]
105105
},
106106
@@ -144,7 +144,7 @@ export default defineComponent({
144144
145145
async onActionClick(action) {
146146
const displayName = action.displayName(this.nodes, this.currentView)
147-
const selectionIds = this.selectedNodes
147+
const selectionSources = this.selectedNodes
148148
try {
149149
// Set loading markers
150150
this.loading = action.id
@@ -165,9 +165,9 @@ export default defineComponent({
165165
// Handle potential failures
166166
if (results.some(result => result === false)) {
167167
// Remove the failed ids from the selection
168-
const failedIds = selectionIds
169-
.filter((fileid, index) => results[index] === false)
170-
this.selectionStore.set(failedIds)
168+
const failedSources = selectionSources
169+
.filter((source, index) => results[index] === false)
170+
this.selectionStore.set(failedSources)
171171
172172
if (results.some(result => result === null)) {
173173
// If some actions returned null, we assume that the dev

apps/files/src/store/dragging.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55
import { defineStore } from 'pinia'
66
import Vue from 'vue'
7-
import type { FileId, DragAndDropStore } from '../types'
7+
import type { DragAndDropStore, FileSource } from '../types'
88

99
export const useDragAndDropStore = defineStore('dragging', {
1010
state: () => ({
@@ -15,7 +15,7 @@ export const useDragAndDropStore = defineStore('dragging', {
1515
/**
1616
* Set the selection of fileIds
1717
*/
18-
set(selection = [] as FileId[]) {
18+
set(selection = [] as FileSource[]) {
1919
Vue.set(this, 'dragging', selection)
2020
},
2121

0 commit comments

Comments
 (0)