Skip to content

Commit 1653d22

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

File tree

9 files changed

+77
-39
lines changed

9 files changed

+77
-39
lines changed

apps/files/src/components/BreadCrumbs.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ export default defineComponent({
155155
},
156156
getDirDisplayName(path: string): string {
157157
if (path === '/') {
158-
return this.$navigation?.active?.name || t('files', 'Home')
158+
return this.currentView?.name || t('files', 'Home')
159159
}
160160
161161
const source = this.getFileSourceFromPath(path)

apps/files/src/main.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
* SPDX-License-Identifier: AGPL-3.0-or-later
44
*/
55
import { getCSPNonce } from '@nextcloud/auth'
6-
import { getNavigation } from '@nextcloud/files'
76
import { PiniaVuePlugin } from 'pinia'
87
import Vue from 'vue'
98

@@ -36,11 +35,6 @@ Object.assign(window.OCP.Files, { Router })
3635
// Init Pinia store
3736
Vue.use(PiniaVuePlugin)
3837

39-
// Init Navigation Service
40-
// This only works with Vue 2 - with Vue 3 this will not modify the source but return just a observer
41-
const Navigation = Vue.observable(getNavigation())
42-
Vue.prototype.$navigation = Navigation
43-
4438
// Init Files App Settings Service
4539
const Settings = new SettingsService()
4640
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
@@ -6,16 +6,20 @@ import Vue from 'vue'
66

77
import { mapState } from 'pinia'
88
import { useViewConfigStore } from '../store/viewConfig'
9-
import { Navigation, View } from '@nextcloud/files'
9+
import { useNavigation } from '../composables/useNavigation'
1010

1111
export default Vue.extend({
12+
setup() {
13+
const { currentView } = useNavigation()
14+
15+
return {
16+
currentView,
17+
}
18+
},
19+
1220
computed: {
1321
...mapState(useViewConfigStore, ['getConfig', 'setSortingBy', 'toggleSortingDirection']),
1422

15-
currentView(): View {
16-
return (this.$navigation as Navigation).active as View
17-
},
18-
1923
/**
2024
* Get the sorting mode for the current view
2125
*/

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

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

13-
import Vue from 'vue'
1413
import router from '../router/router'
1514

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

3130
describe('Navigation renders', () => {
32-
let Navigation: Navigation
33-
3431
before(() => {
3532
delete window._nc_navigation
36-
Navigation = getNavigation()
37-
Vue.prototype.$navigation = Navigation
3833

3934
cy.mockInitialState('files', 'storageStats', {
4035
used: 1000 * 1000 * 1000,
@@ -66,7 +61,6 @@ describe('Navigation API', () => {
6661
delete window._nc_navigation
6762
Navigation = getNavigation()
6863

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

@@ -158,12 +152,8 @@ describe('Navigation API', () => {
158152
})
159153

160154
describe('Quota rendering', () => {
161-
let Navigation: Navigation
162-
163155
before(() => {
164156
delete window._nc_navigation
165-
Navigation = getNavigation()
166-
Vue.prototype.$navigation = Navigation
167157
})
168158

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

apps/files/src/views/Navigation.vue

Lines changed: 3 additions & 3 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'
@@ -164,7 +164,7 @@ export default defineComponent({
164164
// eslint-disable-next-line @typescript-eslint/no-unused-vars
165165
.filter(([viewId, config]) => config.expanded === true)
166166
// eslint-disable-next-line @typescript-eslint/no-unused-vars
167-
.map(([viewId, config]) => this.$navigation.views.find(view => view.id === viewId))
167+
.map(([viewId, config]) => this.views.find(view => view.id === viewId))
168168
.filter(Boolean) // Only registered views
169169
.filter(view => view.loadChildViews && !view.loaded)
170170
for (const view of viewsToLoad) {
@@ -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: 0 additions & 11 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
@@ -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)