Skip to content

Commit e70b6fc

Browse files
authored
Merge pull request #50283 from nextcloud/backport/50161/stable29
[stable29] fix(files): sort not working after changing views
2 parents 2573784 + f0dfc9c commit e70b6fc

File tree

10 files changed

+79
-38
lines changed

10 files changed

+79
-38
lines changed

apps/files/src/components/BreadCrumbs.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ export default defineComponent({
172172
},
173173
getDirDisplayName(path: string): string {
174174
if (path === '/') {
175-
return this.$navigation?.active?.name || t('files', 'Home')
175+
return this.currentView?.name || t('files', 'Home')
176176
}
177177
178178
const source = this.getFileSourceFromPath(path)

apps/files/src/components/FilesListTableFooter.vue

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ import Vue from 'vue'
6565
import { useFilesStore } from '../store/files.ts'
6666
import { usePathsStore } from '../store/paths.ts'
6767
import { useRouteParameters } from '../composables/useRouteParameters.ts'
68+
import { useNavigation } from '../composables/useNavigation'
6869
6970
export default Vue.extend({
7071
name: 'FilesListTableFooter',
@@ -99,19 +100,17 @@ export default Vue.extend({
99100
const pathsStore = usePathsStore()
100101
const filesStore = useFilesStore()
101102
const { directory } = useRouteParameters()
103+
const { currentView } = useNavigation()
102104
103105
return {
104106
filesStore,
105107
pathsStore,
106108
directory,
109+
currentView,
107110
}
108111
},
109112
110113
computed: {
111-
currentView() {
112-
return this.$navigation.active
113-
},
114-
115114
currentFolder() {
116115
if (!this.currentView?.id) {
117116
return

apps/files/src/main.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { PiniaVuePlugin } from 'pinia'
2-
import { getNavigation } from '@nextcloud/files'
32
import { getRequestToken } from '@nextcloud/auth'
43
import Vue from 'vue'
54

@@ -32,11 +31,6 @@ Object.assign(window.OCP.Files, { Router })
3231
// Init Pinia store
3332
Vue.use(PiniaVuePlugin)
3433

35-
// Init Navigation Service
36-
// This only works with Vue 2 - with Vue 3 this will not modify the source but return just a oberserver
37-
const Navigation = Vue.observable(getNavigation())
38-
Vue.prototype.$navigation = Navigation
39-
4034
// Init Files App Settings Service
4135
const Settings = new SettingsService()
4236
Object.assign(window.OCA.Files, { Settings })

apps/files/src/mixins/filesSorting.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,20 @@ import Vue from 'vue'
2323

2424
import { mapState } from 'pinia'
2525
import { useViewConfigStore } from '../store/viewConfig'
26-
import { Navigation, View } from '@nextcloud/files'
26+
import { useNavigation } from '../composables/useNavigation'
2727

2828
export default Vue.extend({
29+
setup() {
30+
const { currentView } = useNavigation()
31+
32+
return {
33+
currentView,
34+
}
35+
},
36+
2937
computed: {
3038
...mapState(useViewConfigStore, ['getConfig', 'setSortingBy', 'toggleSortingDirection']),
3139

32-
currentView(): View {
33-
return (this.$navigation as Navigation).active as View
34-
},
35-
3640
/**
3741
* Get the sorting mode for the current view
3842
*/

apps/files/src/views/Navigation.cy.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import NavigationView from './Navigation.vue'
1111
import { useViewConfigStore } from '../store/viewConfig'
1212
import { Folder, View, getNavigation } from '@nextcloud/files'
1313

14-
import Vue from 'vue'
1514
import router from '../router/router'
1615

1716
const resetNavigation = () => {
@@ -30,12 +29,8 @@ const createView = (id: string, name: string, parent?: string) => new View({
3029
})
3130

3231
describe('Navigation renders', () => {
33-
let Navigation: Navigation
34-
3532
before(() => {
3633
delete window._nc_navigation
37-
Navigation = getNavigation()
38-
Vue.prototype.$navigation = Navigation
3934

4035
cy.mockInitialState('files', 'storageStats', {
4136
used: 1000 * 1000 * 1000,
@@ -67,7 +62,6 @@ describe('Navigation API', () => {
6762
delete window._nc_navigation
6863
Navigation = getNavigation()
6964

70-
Vue.prototype.$navigation = Navigation
7165
await router.replace({ name: 'filelist', params: { view: 'files' } })
7266
})
7367

@@ -159,12 +153,8 @@ describe('Navigation API', () => {
159153
})
160154

161155
describe('Quota rendering', () => {
162-
let Navigation: Navigation
163-
164156
before(() => {
165157
delete window._nc_navigation
166-
Navigation = getNavigation()
167-
Vue.prototype.$navigation = Navigation
168158
})
169159

170160
afterEach(() => cy.unmockInitialState())

apps/files/src/views/Navigation.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
</template>
7676

7777
<script lang="ts">
78-
import type { View } from '@nextcloud/files'
78+
import { getNavigation, type View } from '@nextcloud/files'
7979
8080
import { emit } from '@nextcloud/event-bus'
8181
import { translate as t } from '@nextcloud/l10n'
@@ -196,7 +196,7 @@ export default defineComponent({
196196
showView(view: View) {
197197
// Closing any opened sidebar
198198
window.OCA?.Files?.Sidebar?.close?.()
199-
this.$navigation.setActive(view)
199+
getNavigation().setActive(view)
200200
emit('files:navigation:changed', view)
201201
},
202202

apps/files/src/vue.d.ts

Lines changed: 0 additions & 7 deletions
This file was deleted.

cypress/e2e/files/files_sorting.cy.ts

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,4 +284,65 @@ describe('Files: Sorting the file list', { testIsolation: true }, () => {
284284
}
285285
})
286286
})
287+
288+
it('Sorting works after switching view twice', () => {
289+
cy.uploadContent(currentUser, new Blob(), 'text/plain', '/1 tiny.txt')
290+
.uploadContent(currentUser, new Blob(['a'.repeat(1024)]), 'text/plain', '/z big.txt')
291+
.uploadContent(currentUser, new Blob(['a'.repeat(512)]), 'text/plain', '/a medium.txt')
292+
.mkdir(currentUser, '/folder')
293+
cy.login(currentUser)
294+
cy.visit('/apps/files')
295+
296+
// click sort button twice
297+
cy.get('th').contains('button', 'Size').click()
298+
cy.get('th').contains('button', 'Size').click()
299+
300+
// switch to personal and click sort button twice again
301+
cy.get('[data-cy-files-navigation-item="personal"]').click()
302+
cy.get('th').contains('button', 'Size').click()
303+
cy.get('th').contains('button', 'Size').click()
304+
305+
// switch back to files view and do actual assertions
306+
cy.get('[data-cy-files-navigation-item="files"]').click()
307+
308+
// click sort button
309+
cy.get('th').contains('button', 'Size').click()
310+
// sorting is set
311+
cy.contains('th', 'Size').should('have.attr', 'aria-sort', 'ascending')
312+
// Files are sorted
313+
cy.get('[data-cy-files-list-row]').each(($row, index) => {
314+
switch (index) {
315+
case 0: expect($row.attr('data-cy-files-list-row-name')).to.eq('folder')
316+
break
317+
case 1: expect($row.attr('data-cy-files-list-row-name')).to.eq('1 tiny.txt')
318+
break
319+
case 2: expect($row.attr('data-cy-files-list-row-name')).to.eq('welcome.txt')
320+
break
321+
case 3: expect($row.attr('data-cy-files-list-row-name')).to.eq('a medium.txt')
322+
break
323+
case 4: expect($row.attr('data-cy-files-list-row-name')).to.eq('z big.txt')
324+
break
325+
}
326+
})
327+
328+
// click sort button
329+
cy.get('th').contains('button', 'Size').click()
330+
// sorting is set
331+
cy.contains('th', 'Size').should('have.attr', 'aria-sort', 'descending')
332+
// Files are sorted
333+
cy.get('[data-cy-files-list-row]').each(($row, index) => {
334+
switch (index) {
335+
case 0: expect($row.attr('data-cy-files-list-row-name')).to.eq('folder')
336+
break
337+
case 1: expect($row.attr('data-cy-files-list-row-name')).to.eq('z big.txt')
338+
break
339+
case 2: expect($row.attr('data-cy-files-list-row-name')).to.eq('a medium.txt')
340+
break
341+
case 3: expect($row.attr('data-cy-files-list-row-name')).to.eq('welcome.txt')
342+
break
343+
case 4: expect($row.attr('data-cy-files-list-row-name')).to.eq('1 tiny.txt')
344+
break
345+
}
346+
})
347+
})
287348
})

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)