Skip to content

Commit

Permalink
feat: emit location select on folder load
Browse files Browse the repository at this point in the history
  • Loading branch information
LukasHirt committed Jun 18, 2021
1 parent 428035e commit 071b1aa
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
6 changes: 6 additions & 0 deletions changelog/unreleased/enhancement-emit-location
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Enhancement: Emit update on location change

If a new folder in Location picker is loaded, emit it in the `update` event so that in case of hidden select button, consuming app can still receive the location.

https://github.com/owncloud/file-picker/issues/71
https://github.com/owncloud/file-picker/pull/72
2 changes: 1 addition & 1 deletion docs/component-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ geekdocFilePath: component-reference.md
## Events
| Event | Arguments | Description |
| :---- | :-------- | :---------- |
| `update` | Resources array | Emitted when any resource or location is selected or deselected |
| `update` | Resources array | Emitted when any resource is selected or deselected or if a folder has been loaded in location picker |
| `select` | Resources array | Emitted when the select button is clicked |
| `cancel` | Native click event object | Emitted when the cancel button is clicked |
7 changes: 7 additions & 0 deletions src/components/FilePicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,23 @@ export default {
methods: {
loadFolder(path) {
this.state = 'loading'
this.$client.files
.list(decodeURIComponent(path), 1, this.davProperties)
.then((resources) => {
resources = resources.map((resource) => buildResource(resource))
this.resources = resources.splice(1)
this.currentFolder = resources[0]
if (this.isLocationPicker) {
this.$emit('update', this.currentFolder)
}
this.state = 'loaded'
})
.catch((error) => {
console.error(error)
this.state = 'failed'
})
},
Expand Down
18 changes: 18 additions & 0 deletions tests/integration/specs/filePicker.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,24 @@ describe('Users can select location from within the file picker', () => {
expectedFolder.fileInfo['{http://owncloud.org/ns}fileid']
)
})

test('Developers can get location from update event when folder is loaded', async () => {
const { getByTestId, emitted, getByText } = render(FilePicker, {
props: {
variation: 'location',
},
})

await waitFor(() => expect(getByTestId('list-resources-table')).toBeVisible())

expect(emitted().update[emitted().update.length - 1][0].id).toEqual('144055')

await fireEvent.click(getByText('Photos'))

await waitFor(() => expect(getByText('Teotihuacan')).toBeVisible())

expect(emitted().update[emitted().update.length - 1][0].id).toEqual('144228')
})
})

describe('Users can select resources from within the file picker', () => {
Expand Down

0 comments on commit 071b1aa

Please sign in to comment.