Skip to content

Commit

Permalink
Merge pull request #5659 from owncloud/feat/refresh-list
Browse files Browse the repository at this point in the history
[full-ci] feat: refresh list on breadcrumb click
  • Loading branch information
kulmann authored Aug 17, 2021
2 parents e34e7f9 + b979ff8 commit 4e410bb
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 6 deletions.
6 changes: 6 additions & 0 deletions changelog/unreleased/enhancement-refresh-list-via-breadcrumbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Enhancement: refresh files list via breadcrumbs

In the personal and public files lists we've added a click handler to the last breadcrumb item representing the current folder that reloads the files list.

https://github.com/owncloud/web/issues/2018
https://github.com/owncloud/web/pull/5659
20 changes: 18 additions & 2 deletions packages/web-app-files/src/components/AppBar/AppBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<oc-breadcrumb
v-if="showBreadcrumb"
id="files-breadcrumb"
data-testid="files-breadcrumbs"
class="oc-p-s"
:items="breadcrumbs"
/>
Expand Down Expand Up @@ -115,6 +116,7 @@ import MixinFileActions, { EDITOR_MODE_CREATE } from '../../mixins/fileActions'
import MixinRoutes from '../../mixins/routes'
import MixinScrollToResource from '../../mixins/filesListScrolling'
import { buildResource } from '../../helpers/resources'
import { bus } from 'web-pkg/src/instance'
import BatchActions from './SelectedResources/BatchActions.vue'
import FileDrop from './Upload/FileDrop.vue'
Expand Down Expand Up @@ -221,9 +223,13 @@ export default {
baseUrl = '/files/list/all/'
pathItems.push('/') // as of now we need to add the url encoded root path `/`, otherwise we'll land in the configured homeFolder
breadcrumbs.push({
text: this.$gettext('All files'),
to: baseUrl + encodeURIComponent(pathUtil.join(...pathItems))
text: this.$gettext('All files')
})
pathSegments.length < 1
? (breadcrumbs[0].onClick = () =>
bus.emit('app.files.list.load', this.$route.params.item))
: (breadcrumbs[0].to = baseUrl + encodeURIComponent(pathUtil.join(...pathItems)))
} else {
baseUrl = '/files/public/list/'
pathItems.push(pathSegments.splice(0, 1)[0])
Expand All @@ -236,6 +242,16 @@ export default {
for (let i = 0; i < pathSegments.length; i++) {
pathItems.push(pathSegments[i])
const to = baseUrl + encodeURIComponent(pathUtil.join(...pathItems))
if (i === pathSegments.length - 1) {
breadcrumbs.push({
text: pathSegments[i],
onClick: () => bus.emit('app.files.list.load', this.$route.params.item)
})
continue
}
breadcrumbs.push({
text: pathSegments[i],
to: i + 1 === pathSegments.length ? null : to
Expand Down
9 changes: 7 additions & 2 deletions packages/web-app-files/src/views/Personal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ import MixinMountSideBar from '../mixins/sidebar/mountSideBar'
import { buildResource } from '../helpers/resources'
import { VisibilityObserver } from 'web-pkg/src/observer'
import { ImageDimension, ImageType } from '../constants'
import { bus } from 'web-pkg/src/instance'
import QuickActions from '../components/FilesList/QuickActions.vue'
import ListLoader from '../components/FilesList/ListLoader.vue'
Expand Down Expand Up @@ -191,6 +192,10 @@ export default {
mounted() {
this.adjustTableHeaderPosition()
bus.on('app.files.list.load', path => {
this.loadResources(this.$route.params.item === path, path)
})
},
beforeDestroy() {
Expand Down Expand Up @@ -226,13 +231,13 @@ export default {
visibilityObserver.observe(component.$el, { onEnter: debounced, onExit: debounced.cancel })
},
async loadResources(sameRoute) {
async loadResources(sameRoute, path = null) {
this.loading = true
this.CLEAR_CURRENT_FILES_LIST()
try {
let resources = await this.$client.files.list(
this.$route.params.item,
path || this.$route.params.item,
1,
DavProperties.Default
)
Expand Down
12 changes: 10 additions & 2 deletions packages/web-app-files/src/views/PublicFiles.vue
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ import { VisibilityObserver } from 'web-pkg/src/observer'
import { ImageDimension, ImageType } from '../constants'
import debounce from 'lodash-es/debounce'
import { buildResource } from '../helpers/resources'
import { bus } from 'web-pkg/src/instance'
import ListLoader from '../components/FilesList/ListLoader.vue'
import NoContentMessage from '../components/FilesList/NoContentMessage.vue'
Expand Down Expand Up @@ -162,6 +163,13 @@ export default {
beforeDestroy() {
visibilityObserver.disconnect()
},
created() {
bus.on('app.files.list.load', path => {
this.loadResources(this.$route.params.item === path, path)
})
},
methods: {
...mapActions('Files', ['loadPreview']),
...mapMutations('Files', [
Expand Down Expand Up @@ -189,13 +197,13 @@ export default {
visibilityObserver.observe(component.$el, { onEnter: debounced, onExit: debounced.cancel })
},
async loadResources(sameRoute) {
async loadResources(sameRoute, path = null) {
this.loading = true
this.CLEAR_CURRENT_FILES_LIST()
try {
let resources = await this.$client.publicFiles.list(
this.$route.params.item,
path || this.$route.params.item,
this.publicLinkPassword,
DavProperties.PublicLink
)
Expand Down
55 changes: 55 additions & 0 deletions packages/web-app-files/tests/integration/specs/appBar.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import '@testing-library/jest-dom'
import { render, waitFor, fireEvent } from '@testing-library/vue'
import { config } from '@vue/test-utils'

import StoreFiles from '@files/src/store'
import Store from '@runtime/src/store'
import { bus } from '@pkg/src/instance'

import AppBar from '@files/src/components/AppBar/AppBar.vue'

const store = {
...Store,
modules: {
...Store.modules,
user: {
...Store.modules.user,
state: {
...Store.modules.user.state,
id: 'alice'
}
},
Files: {
...StoreFiles
}
}
}

describe('AppBar contains set of actions and informations', () => {
describe('when breadcrumbs are visible', () => {
beforeEach(() => {
config.mocks.publicPage = () => false

bus.emit = jest.fn(path => path)
})

test('user can refresh files list by clicking on last breadcrumb item', async () => {
render(
AppBar,
{
store,
routes: [{ name: 'files-personal', path: '/files/list/personal/:item?/:page?' }]
},
(vue, store, router) => {
vue.directive('translate', () => {})
router.push({ name: 'files-personal', params: { item: '/documents' } })
}
)
const item = document.querySelector('[data-testid="files-breadcrumbs"] .oc-button')

await waitFor(() => expect(item).toBeVisible())
await fireEvent.click(item)
expect(bus.emit).toHaveBeenCalledWith('app.files.list.load', '/documents')
})
})
})

0 comments on commit 4e410bb

Please sign in to comment.