Skip to content

Commit 58e1427

Browse files
authored
Merge pull request #53824 from nextcloud/fix/FileList-render
2 parents a7d6f5f + 47b2a96 commit 58e1427

30 files changed

+276
-200
lines changed

apps/files/src/components/FilesListHeader.vue

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
import type { Folder, Header, View } from '@nextcloud/files'
1313
import type { PropType } from 'vue'
1414
15+
import logger from '../logger.ts'
16+
1517
/**
1618
* This component is used to render custom
1719
* elements provided by an API. Vue doesn't allow
@@ -51,8 +53,12 @@ export default {
5153
},
5254
},
5355
mounted() {
54-
console.debug('Mounted', this.header.id)
56+
logger.debug(`Mounted ${this.header.id} FilesListHeader`, { header: this.header })
5557
this.header.render(this.$refs.mount as HTMLElement, this.currentFolder, this.currentView)
5658
},
59+
60+
destroyed() {
61+
logger.debug(`Destroyed ${this.header.id} FilesListHeader`, { header: this.header })
62+
},
5763
}
5864
</script>

apps/files/src/components/FilesListVirtual.vue

Lines changed: 75 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@
4848
:nodes="nodes" />
4949
</template>
5050

51+
<!-- Body replacement if no files are available -->
52+
<template #empty>
53+
<slot name="empty" />
54+
</template>
55+
5156
<!-- Tfoot-->
5257
<template #footer>
5358
<FilesListTableFooter :current-view="currentView"
@@ -65,7 +70,6 @@
6570
import type { UserConfig } from '../types'
6671
import type { Node as NcNode } from '@nextcloud/files'
6772
import type { ComponentPublicInstance, PropType } from 'vue'
68-
import type { Location } from 'vue-router'
6973
7074
import { Folder, Permission, View, getFileActions, FileType } from '@nextcloud/files'
7175
import { showError } from '@nextcloud/dialogs'
@@ -81,6 +85,7 @@ import { useFileListWidth } from '../composables/useFileListWidth.ts'
8185
import { useRouteParameters } from '../composables/useRouteParameters.ts'
8286
import { useSelectionStore } from '../store/selection.js'
8387
import { useUserConfigStore } from '../store/userconfig.ts'
88+
import logger from '../logger.ts'
8489
8590
import FileEntry from './FileEntry.vue'
8691
import FileEntryGrid from './FileEntryGrid.vue'
@@ -90,7 +95,6 @@ import FilesListTableFooter from './FilesListTableFooter.vue'
9095
import FilesListTableHeader from './FilesListTableHeader.vue'
9196
import FilesListTableHeaderActions from './FilesListTableHeaderActions.vue'
9297
import VirtualList from './VirtualList.vue'
93-
import logger from '../logger.ts'
9498
9599
export default defineComponent({
96100
name: 'FilesListVirtual',
@@ -152,7 +156,6 @@ export default defineComponent({
152156
FileEntry,
153157
FileEntryGrid,
154158
scrollToIndex: 0,
155-
openFileId: null as number|null,
156159
}
157160
},
158161
@@ -217,39 +220,26 @@ export default defineComponent({
217220
isNoneSelected() {
218221
return this.selectedNodes.length === 0
219222
},
223+
224+
isEmpty() {
225+
return this.nodes.length === 0
226+
},
220227
},
221228
222229
watch: {
223-
fileId: {
224-
handler(fileId) {
225-
this.scrollToFile(fileId, false)
226-
},
227-
immediate: true,
230+
// If nodes gets populated and we have a fileId,
231+
// an openFile or openDetails, we fire the appropriate actions.
232+
isEmpty() {
233+
this.handleOpenQueries()
228234
},
229-
230-
openFile: {
231-
handler(openFile) {
232-
if (!openFile || !this.fileId) {
233-
return
234-
}
235-
236-
this.handleOpenFile(this.fileId)
237-
},
238-
immediate: true,
235+
fileId() {
236+
this.handleOpenQueries()
239237
},
240-
241-
openDetails: {
242-
handler(openDetails) {
243-
// wait for scrolling and updating the actions to settle
244-
this.$nextTick(() => {
245-
if (!openDetails || !this.fileId) {
246-
return
247-
}
248-
249-
this.openSidebarForFile(this.fileId)
250-
})
251-
},
252-
immediate: true,
238+
openFile() {
239+
this.handleOpenQueries()
240+
},
241+
openDetails() {
242+
this.handleOpenQueries()
253243
},
254244
},
255245
@@ -279,6 +269,33 @@ export default defineComponent({
279269
},
280270
281271
methods: {
272+
handleOpenQueries() {
273+
// If the list is empty, or we don't have a fileId,
274+
// there's nothing to be done.
275+
if (this.isEmpty || !this.fileId) {
276+
return
277+
}
278+
279+
logger.debug('FilesListVirtual: checking for requested fileId, openFile or openDetails', {
280+
nodes: this.nodes,
281+
fileId: this.fileId,
282+
openFile: this.openFile,
283+
openDetails: this.openDetails,
284+
})
285+
286+
if (this.openFile) {
287+
this.handleOpenFile(this.fileId)
288+
}
289+
290+
if (this.openDetails) {
291+
this.openSidebarForFile(this.fileId)
292+
}
293+
294+
if (this.fileId) {
295+
this.scrollToFile(this.fileId, false)
296+
}
297+
},
298+
282299
openSidebarForFile(fileId) {
283300
// Open the sidebar for the given URL fileid
284301
// iif we just loaded the app.
@@ -288,7 +305,7 @@ export default defineComponent({
288305
sidebarAction.exec(node, this.currentView, this.currentFolder.path)
289306
return
290307
}
291-
logger.error(`Failed to open sidebar on file ${fileId}, file isn't cached yet !`, { fileId, node })
308+
logger.warn(`Failed to open sidebar on file ${fileId}, file isn't cached yet !`, { fileId, node })
292309
},
293310
294311
scrollToFile(fileId: number|null, warn = true) {
@@ -304,6 +321,7 @@ export default defineComponent({
304321
}
305322
306323
this.scrollToIndex = Math.max(0, index)
324+
logger.debug('Scrolling to file ' + fileId, { fileId, index })
307325
}
308326
},
309327
@@ -368,15 +386,13 @@ export default defineComponent({
368386
}
369387
// The file is either a folder or has no default action other than downloading
370388
// in this case we need to open the details instead and remove the route from the history
371-
const query = this.$route.query
372-
delete query.openfile
373-
query.opendetails = ''
374-
375389
logger.debug('Ignore `openfile` query and replacing with `opendetails` for ' + node.path, { node })
376-
await this.$router.replace({
377-
...(this.$route as Location),
378-
query,
379-
})
390+
window.OCP.Files.Router.goToRoute(
391+
null,
392+
this.$route.params,
393+
{ ...this.$route.query, openfile: undefined, opendetails: '' },
394+
true, // silent update of the URL
395+
)
380396
},
381397
382398
onDragOver(event: DragEvent) {
@@ -474,6 +490,8 @@ export default defineComponent({
474490
--icon-preview-size: 32px;
475491
476492
--fixed-block-start-position: var(--default-clickable-area);
493+
display: flex;
494+
flex-direction: column;
477495
overflow: auto;
478496
height: 100%;
479497
will-change: scroll-position;
@@ -521,6 +539,13 @@ export default defineComponent({
521539
// Hide the table header below the overlay
522540
margin-block-start: calc(-1 * var(--row-height));
523541
}
542+
543+
// Visually hide the table when there are no files
544+
&--hidden {
545+
visibility: hidden;
546+
z-index: -1;
547+
opacity: 0;
548+
}
524549
}
525550
526551
.files-list__filters {
@@ -570,6 +595,16 @@ export default defineComponent({
570595
top: var(--fixed-block-start-position);
571596
}
572597
598+
// Empty content
599+
.files-list__empty {
600+
display: flex;
601+
flex-direction: column;
602+
align-items: center;
603+
justify-content: center;
604+
width: 100%;
605+
height: 100%;
606+
}
607+
573608
tr {
574609
position: relative;
575610
display: flex;

apps/files/src/components/VirtualList.vue

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,18 @@
2020
<slot name="header-overlay" />
2121
</div>
2222

23-
<table class="files-list__table" :class="{ 'files-list__table--with-thead-overlay': !!$scopedSlots['header-overlay'] }">
23+
<div v-if="dataSources.length === 0"
24+
class="files-list__empty">
25+
<slot name="empty" />
26+
</div>
27+
28+
<table :aria-hidden="dataSources.length === 0"
29+
:inert="dataSources.length === 0"
30+
class="files-list__table"
31+
:class="{
32+
'files-list__table--with-thead-overlay': !!$scopedSlots['header-overlay'],
33+
'files-list__table--hidden': dataSources.length === 0,
34+
}">
2435
<!-- Accessibility table caption for screen readers -->
2536
<caption v-if="caption" class="hidden-visually">
2637
{{ caption }}
@@ -309,7 +320,7 @@ export default defineComponent({
309320
310321
methods: {
311322
scrollTo(index: number) {
312-
if (!this.$el) {
323+
if (!this.$el || this.index === index) {
313324
return
314325
}
315326

0 commit comments

Comments
 (0)