Skip to content

Commit 1c3ec2a

Browse files
committed
fix(files): sort not working after changing views
Signed-off-by: Richard Steinmetz <richard@steinmetz.cloud>
1 parent 40dd2a9 commit 1c3ec2a

File tree

6 files changed

+87
-10
lines changed

6 files changed

+87
-10
lines changed

apps/files/src/main.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import router from './router/router'
1515
import RouterService from './services/RouterService'
1616
import SettingsModel from './models/Setting.js'
1717
import SettingsService from './services/Settings.js'
18+
import type { ProxiedNavigation } from './vue'
1819

1920
__webpack_nonce__ = getCSPNonce()
2021

@@ -44,9 +45,19 @@ Vue.use(PiniaVuePlugin)
4445
// Init HotKeys AFTER pinia is set up
4546
registerHotkeys()
4647

47-
// Init Navigation Service
48-
// This only works with Vue 2 - with Vue 3 this will not modify the source but return just a observer
49-
const Navigation = Vue.observable(getNavigation())
48+
// Init Navigation Service (turn getNavigation() into a *read-only* observable object)
49+
const Navigation = Vue.observable<ProxiedNavigation>({
50+
active: null,
51+
views: [],
52+
})
53+
const actualNavigation = getNavigation()
54+
actualNavigation.addEventListener('update', () => {
55+
Vue.set(Navigation, 'views', actualNavigation.views)
56+
Vue.set(Navigation, 'active', actualNavigation.active)
57+
})
58+
actualNavigation.addEventListener('updateActive', () => {
59+
Vue.set(Navigation, 'active', actualNavigation.active)
60+
})
5061
Vue.prototype.$navigation = Navigation
5162

5263
// Init Files App Settings Service

apps/files/src/views/Navigation.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
</template>
4040

4141
<script lang="ts">
42-
import type { View } from '@nextcloud/files'
42+
import { getNavigation, type View } from '@nextcloud/files'
4343
import type { ViewConfig } from '../types.ts'
4444
4545
import { defineComponent } from 'vue'
@@ -179,7 +179,7 @@ export default defineComponent({
179179
showView(view: View) {
180180
// Closing any opened sidebar
181181
window.OCA?.Files?.Sidebar?.close?.()
182-
this.$navigation.setActive(view)
182+
getNavigation().setActive(view)
183183
emit('files:navigation:changed', view)
184184
},
185185

apps/files/src/vue.d.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,15 @@
22
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
33
* SPDX-License-Identifier: AGPL-3.0-or-later
44
*/
5-
import type { Navigation } from '@nextcloud/files'
5+
import type { View } from '@nextcloud/files'
6+
7+
export interface ProxiedNavigation {
8+
get active(): View | null,
9+
get views(): View[],
10+
}
611

712
declare module 'vue/types/vue' {
813
interface Vue {
9-
$navigation: Navigation
14+
$navigation: ProxiedNavigation,
1015
}
1116
}

cypress/e2e/files/files-sorting.cy.ts

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,4 +267,65 @@ describe('Files: Sorting the file list', { testIsolation: true }, () => {
267267
}
268268
})
269269
})
270+
271+
it('Sorting works after switching view twice', () => {
272+
cy.uploadContent(currentUser, new Blob(), 'text/plain', '/1 tiny.txt')
273+
.uploadContent(currentUser, new Blob(['a'.repeat(1024)]), 'text/plain', '/z big.txt')
274+
.uploadContent(currentUser, new Blob(['a'.repeat(512)]), 'text/plain', '/a medium.txt')
275+
.mkdir(currentUser, '/folder')
276+
cy.login(currentUser)
277+
cy.visit('/apps/files')
278+
279+
// click sort button twice
280+
cy.get('th').contains('button', 'Size').click()
281+
cy.get('th').contains('button', 'Size').click()
282+
283+
// switch to personal and click sort button twice again
284+
cy.get('[data-cy-files-navigation-item="personal"]').click()
285+
cy.get('th').contains('button', 'Size').click()
286+
cy.get('th').contains('button', 'Size').click()
287+
288+
// switch back to files view and do actual assertions
289+
cy.get('[data-cy-files-navigation-item="files"]').click()
290+
291+
// click sort button
292+
cy.get('th').contains('button', 'Size').click()
293+
// sorting is set
294+
cy.contains('th', 'Size').should('have.attr', 'aria-sort', 'ascending')
295+
// Files are sorted
296+
cy.get('[data-cy-files-list-row]').each(($row, index) => {
297+
switch (index) {
298+
case 0: expect($row.attr('data-cy-files-list-row-name')).to.eq('folder')
299+
break
300+
case 1: expect($row.attr('data-cy-files-list-row-name')).to.eq('1 tiny.txt')
301+
break
302+
case 2: expect($row.attr('data-cy-files-list-row-name')).to.eq('welcome.txt')
303+
break
304+
case 3: expect($row.attr('data-cy-files-list-row-name')).to.eq('a medium.txt')
305+
break
306+
case 4: expect($row.attr('data-cy-files-list-row-name')).to.eq('z big.txt')
307+
break
308+
}
309+
})
310+
311+
// click sort button
312+
cy.get('th').contains('button', 'Size').click()
313+
// sorting is set
314+
cy.contains('th', 'Size').should('have.attr', 'aria-sort', 'descending')
315+
// Files are sorted
316+
cy.get('[data-cy-files-list-row]').each(($row, index) => {
317+
switch (index) {
318+
case 0: expect($row.attr('data-cy-files-list-row-name')).to.eq('folder')
319+
break
320+
case 1: expect($row.attr('data-cy-files-list-row-name')).to.eq('z big.txt')
321+
break
322+
case 2: expect($row.attr('data-cy-files-list-row-name')).to.eq('a medium.txt')
323+
break
324+
case 3: expect($row.attr('data-cy-files-list-row-name')).to.eq('welcome.txt')
325+
break
326+
case 4: expect($row.attr('data-cy-files-list-row-name')).to.eq('1 tiny.txt')
327+
break
328+
}
329+
})
330+
})
270331
})

dist/files-main.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/files-main.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)