Skip to content

Commit

Permalink
fix(files): sort not working after changing views
Browse files Browse the repository at this point in the history
Signed-off-by: Richard Steinmetz <[email protected]>
  • Loading branch information
st3iny committed Jan 15, 2025
1 parent 47eedf9 commit b97a3d2
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 32 deletions.
2 changes: 1 addition & 1 deletion apps/files/src/components/BreadCrumbs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export default defineComponent({
},
getDirDisplayName(path: string): string {
if (path === '/') {
return this.$navigation?.active?.name || t('files', 'Home')
return this.currentView?.name || t('files', 'Home')
}

const source = this.getFileSourceFromPath(path)
Expand Down
6 changes: 1 addition & 5 deletions apps/files/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import router from './router/router'
import RouterService from './services/RouterService'
import SettingsModel from './models/Setting.js'
import SettingsService from './services/Settings.js'
import type { ProxiedNavigation } from './vue'

Check failure on line 18 in apps/files/src/main.ts

View workflow job for this annotation

GitHub Actions / NPM lint

'ProxiedNavigation' is defined but never used

__webpack_nonce__ = getCSPNonce()

Expand Down Expand Up @@ -44,11 +45,6 @@ Vue.use(PiniaVuePlugin)
// Init HotKeys AFTER pinia is set up
registerHotkeys()

// Init Navigation Service
// This only works with Vue 2 - with Vue 3 this will not modify the source but return just a observer
const Navigation = Vue.observable(getNavigation())
Vue.prototype.$navigation = Navigation

// Init Files App Settings Service
const Settings = new SettingsService()
Object.assign(window.OCA.Files, { Settings })
Expand Down
13 changes: 9 additions & 4 deletions apps/files/src/mixins/filesSorting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,20 @@ import Vue from 'vue'
import { mapState } from 'pinia'
import { useViewConfigStore } from '../store/viewConfig'
import { Navigation, View } from '@nextcloud/files'

Check failure on line 9 in apps/files/src/mixins/filesSorting.ts

View workflow job for this annotation

GitHub Actions / NPM lint

'Navigation' is defined but never used

Check failure on line 9 in apps/files/src/mixins/filesSorting.ts

View workflow job for this annotation

GitHub Actions / NPM lint

'View' is defined but never used
import { useNavigation } from '../composables/useNavigation'

export default Vue.extend({
setup() {
const { currentView } = useNavigation()

return {
currentView,
}
},

computed: {
...mapState(useViewConfigStore, ['getConfig', 'setSortingBy', 'toggleSortingDirection']),

currentView(): View {
return (this.$navigation as Navigation).active as View
},

/**
* Get the sorting mode for the current view
*/
Expand Down
5 changes: 0 additions & 5 deletions apps/files/src/views/Navigation.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ describe('Navigation renders', () => {

before(() => {
delete window._nc_navigation
Navigation = getNavigation()
Vue.prototype.$navigation = Navigation

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

before(async () => {
delete window._nc_navigation
Navigation = getNavigation()

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

before(() => {
delete window._nc_navigation
Navigation = getNavigation()
Vue.prototype.$navigation = Navigation
})

afterEach(() => cy.unmockInitialState())
Expand Down
6 changes: 3 additions & 3 deletions apps/files/src/views/Navigation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
</template>

<script lang="ts">
import type { View } from '@nextcloud/files'
import { getNavigation, type View } from '@nextcloud/files'
import type { ViewConfig } from '../types.ts'

import { defineComponent } from 'vue'
Expand Down Expand Up @@ -164,7 +164,7 @@ export default defineComponent({
// eslint-disable-next-line @typescript-eslint/no-unused-vars
.filter(([viewId, config]) => config.expanded === true)
// eslint-disable-next-line @typescript-eslint/no-unused-vars
.map(([viewId, config]) => this.$navigation.views.find(view => view.id === viewId))
.map(([viewId, config]) => this.views.find(view => view.id === viewId))
.filter(Boolean) // Only registered views
.filter(view => view.loadChildViews && !view.loaded)
for (const view of viewsToLoad) {
Expand All @@ -179,7 +179,7 @@ export default defineComponent({
showView(view: View) {
// Closing any opened sidebar
window.OCA?.Files?.Sidebar?.close?.()
this.$navigation.setActive(view)
getNavigation().setActive(view)
emit('files:navigation:changed', view)
},

Expand Down
11 changes: 0 additions & 11 deletions apps/files/src/vue.d.ts

This file was deleted.

61 changes: 61 additions & 0 deletions cypress/e2e/files/files-sorting.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,4 +267,65 @@ describe('Files: Sorting the file list', { testIsolation: true }, () => {
}
})
})

it('Sorting works after switching view twice', () => {
cy.uploadContent(currentUser, new Blob(), 'text/plain', '/1 tiny.txt')
.uploadContent(currentUser, new Blob(['a'.repeat(1024)]), 'text/plain', '/z big.txt')
.uploadContent(currentUser, new Blob(['a'.repeat(512)]), 'text/plain', '/a medium.txt')
.mkdir(currentUser, '/folder')
cy.login(currentUser)
cy.visit('/apps/files')

// click sort button twice
cy.get('th').contains('button', 'Size').click()
cy.get('th').contains('button', 'Size').click()

// switch to personal and click sort button twice again
cy.get('[data-cy-files-navigation-item="personal"]').click()
cy.get('th').contains('button', 'Size').click()
cy.get('th').contains('button', 'Size').click()

// switch back to files view and do actual assertions
cy.get('[data-cy-files-navigation-item="files"]').click()

// click sort button
cy.get('th').contains('button', 'Size').click()
// sorting is set
cy.contains('th', 'Size').should('have.attr', 'aria-sort', 'ascending')
// Files are sorted
cy.get('[data-cy-files-list-row]').each(($row, index) => {
switch (index) {
case 0: expect($row.attr('data-cy-files-list-row-name')).to.eq('folder')
break
case 1: expect($row.attr('data-cy-files-list-row-name')).to.eq('1 tiny.txt')
break
case 2: expect($row.attr('data-cy-files-list-row-name')).to.eq('welcome.txt')
break
case 3: expect($row.attr('data-cy-files-list-row-name')).to.eq('a medium.txt')
break
case 4: expect($row.attr('data-cy-files-list-row-name')).to.eq('z big.txt')
break
}
})

// click sort button
cy.get('th').contains('button', 'Size').click()
// sorting is set
cy.contains('th', 'Size').should('have.attr', 'aria-sort', 'descending')
// Files are sorted
cy.get('[data-cy-files-list-row]').each(($row, index) => {
switch (index) {
case 0: expect($row.attr('data-cy-files-list-row-name')).to.eq('folder')
break
case 1: expect($row.attr('data-cy-files-list-row-name')).to.eq('z big.txt')
break
case 2: expect($row.attr('data-cy-files-list-row-name')).to.eq('a medium.txt')
break
case 3: expect($row.attr('data-cy-files-list-row-name')).to.eq('welcome.txt')
break
case 4: expect($row.attr('data-cy-files-list-row-name')).to.eq('1 tiny.txt')
break
}
})
})
})
4 changes: 2 additions & 2 deletions dist/files-main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/files-main.js.map

Large diffs are not rendered by default.

0 comments on commit b97a3d2

Please sign in to comment.