Skip to content

Commit b97a3d2

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

File tree

9 files changed

+78
-32
lines changed

9 files changed

+78
-32
lines changed

apps/files/src/components/BreadCrumbs.vue

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

apps/files/src/main.ts

Lines changed: 1 addition & 5 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,11 +45,6 @@ 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())
50-
Vue.prototype.$navigation = Navigation
51-
5248
// Init Files App Settings Service
5349
const Settings = new SettingsService()
5450
Object.assign(window.OCA.Files, { Settings })

apps/files/src/mixins/filesSorting.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,20 @@ import Vue from 'vue'
77
import { mapState } from 'pinia'
88
import { useViewConfigStore } from '../store/viewConfig'
99
import { Navigation, View } from '@nextcloud/files'
10+
import { useNavigation } from '../composables/useNavigation'
1011

1112
export default Vue.extend({
13+
setup() {
14+
const { currentView } = useNavigation()
15+
16+
return {
17+
currentView,
18+
}
19+
},
20+
1221
computed: {
1322
...mapState(useViewConfigStore, ['getConfig', 'setSortingBy', 'toggleSortingDirection']),
1423

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

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ describe('Navigation renders', () => {
3333

3434
before(() => {
3535
delete window._nc_navigation
36-
Navigation = getNavigation()
37-
Vue.prototype.$navigation = Navigation
3836

3937
cy.mockInitialState('files', 'storageStats', {
4038
used: 1000 * 1000 * 1000,
@@ -64,7 +62,6 @@ describe('Navigation API', () => {
6462

6563
before(async () => {
6664
delete window._nc_navigation
67-
Navigation = getNavigation()
6865

6966
Vue.prototype.$navigation = Navigation
7067
await router.replace({ name: 'filelist', params: { view: 'files' } })
@@ -162,8 +159,6 @@ describe('Quota rendering', () => {
162159

163160
before(() => {
164161
delete window._nc_navigation
165-
Navigation = getNavigation()
166-
Vue.prototype.$navigation = Navigation
167162
})
168163

169164
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)