Skip to content

Commit ff23b69

Browse files
committed
fix(files): keep reactivity when destructuring the store in grid view
FileEntryGrid destructured useActiveStore() directly, so activeFolder, activeNode and activeView were plain snapshots taken when the entry was first rendered. Opening a file from grid view therefore handed the file actions a stale folder, and the viewer navigated the list to whichever folder happened to be active back then: from a nested folder this drops you at the root, or a level or two above, with the file open on top. Same fix as #59942, which covered FileEntry but left its grid counterpart behind despite the "keep in sync with FileEntry.vue" note above it. Signed-off-by: ELHart05 <o.allaoua@esi-sba.dz>
1 parent 319c8f1 commit ff23b69

2 files changed

Lines changed: 74 additions & 1 deletion

File tree

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*!
2+
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
3+
* SPDX-License-Identifier: AGPL-3.0-or-later
4+
*/
5+
6+
import { File, Folder, Permission } from '@nextcloud/files'
7+
import { createTestingPinia } from '@pinia/testing'
8+
import { shallowMount } from '@vue/test-utils'
9+
import { beforeEach, describe, expect, test, vi } from 'vitest'
10+
import { nextTick } from 'vue'
11+
import FileEntryGrid from './FileEntryGrid.vue'
12+
import router from '../router/router.ts'
13+
import { useActiveStore } from '../store/active.ts'
14+
15+
// useFileListWidth builds its ResizeObserver while the module is evaluated, so
16+
// the stub has to exist before the import chain runs. jsdom-testing-mocks sets
17+
// its observer up from a hook, which is already too late here.
18+
vi.hoisted(() => {
19+
globalThis.ResizeObserver = class {
20+
21+
observe() {}
22+
unobserve() {}
23+
disconnect() {}
24+
25+
}
26+
})
27+
28+
vi.mock('@nextcloud/auth')
29+
30+
const source = new File({
31+
id: 42,
32+
source: 'http://nextcloud.local/remote.php/dav/files/test/Deep/Nested/report.pdf',
33+
root: '/files/test',
34+
owner: 'test',
35+
mime: 'application/pdf',
36+
permissions: Permission.READ,
37+
})
38+
39+
const nestedFolder = new Folder({
40+
id: 41,
41+
source: 'http://nextcloud.local/remote.php/dav/files/test/Deep/Nested',
42+
root: '/files/test',
43+
owner: 'test',
44+
permissions: Permission.READ,
45+
})
46+
47+
describe('FileEntryGrid.vue', () => {
48+
beforeEach(async () => {
49+
await router.replace({ name: 'filelist', params: { view: 'files' } })
50+
})
51+
52+
// The grid entry hands its `activeFolder` to the file actions, so a stale copy
53+
// makes opening a file navigate to whichever folder was active when the entry
54+
// was first rendered rather than the one the file lives in.
55+
test('follows the active folder after navigating', async () => {
56+
const wrapper = shallowMount(FileEntryGrid, {
57+
propsData: { source, nodes: [source] },
58+
mocks: { t: (_: string, text: string) => text },
59+
router,
60+
pinia: createTestingPinia({ createSpy: vi.fn }),
61+
})
62+
const activeStore = useActiveStore()
63+
64+
expect(wrapper.vm.activeFolder).not.toBe(nestedFolder)
65+
66+
activeStore.activeFolder = nestedFolder
67+
await nextTick()
68+
69+
expect(wrapper.vm.activeFolder).toBe(nestedFolder)
70+
})
71+
})

apps/files/src/components/FileEntryGrid.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
</template>
7272

7373
<script lang="ts">
74+
import { storeToRefs } from 'pinia'
7475
import { defineComponent } from 'vue'
7576
import NcDateTime from '@nextcloud/vue/components/NcDateTime'
7677
import FileEntryActions from './FileEntry/FileEntryActions.vue'
@@ -117,11 +118,12 @@ export default defineComponent({
117118
fileId: currentRouteFileId,
118119
} = useRouteParameters()
119120
121+
const activeStore = useActiveStore()
120122
const {
121123
activeFolder,
122124
activeNode,
123125
activeView,
124-
} = useActiveStore()
126+
} = storeToRefs(activeStore)
125127
126128
const actions = useFileActions()
127129

0 commit comments

Comments
 (0)