Skip to content

Commit

Permalink
Introduce UPSERT_RESOURCE to files mutations
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalwengerter committed May 20, 2021
1 parent e229c60 commit 6580cc8
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 20 deletions.
7 changes: 7 additions & 0 deletions changelog/unreleased/bugfix-upsert-resource-in-filestable
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Bugfix: Upsert resource in filestable

When uploading an already existing resource in the filestable, we sometimes displayed both
files in the filestable until the page got refreshed. We now check when uploading a file if
it exists in the filestable and replace it there if that is the case.

https://github.com/owncloud/web/pull/5130
8 changes: 4 additions & 4 deletions packages/web-app-files/src/components/AppBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ export default {
'loadIndicators'
]),
...mapActions(['openFile', 'showMessage', 'createModal', 'setModalInputErrorMessage']),
...mapMutations('Files', ['PUSH_NEW_RESOURCE']),
...mapMutations('Files', ['UPSERT_RESOURCE']),
...mapMutations(['SET_QUOTA']),
showCreateResourceModal(isFolder = true, ext = 'txt', openAction = null) {
Expand Down Expand Up @@ -313,7 +313,7 @@ export default {
}
resource = buildResource(resource)
this.PUSH_NEW_RESOURCE(resource)
this.UPSERT_RESOURCE(resource)
this.hideModal()
if (this.isPersonalRoute) {
Expand Down Expand Up @@ -405,7 +405,7 @@ export default {
resource = buildResource(resource)
this.PUSH_NEW_RESOURCE(resource)
this.UPSERT_RESOURCE(resource)
this.hideModal()
if (this.isPersonalRoute) {
Expand Down Expand Up @@ -481,7 +481,7 @@ export default {
)
resource = buildResource(resource)
this.PUSH_NEW_RESOURCE(resource)
this.UPSERT_RESOURCE(resource)
if (this.isPersonalRoute) {
await this.loadIndicators({
Expand Down
4 changes: 2 additions & 2 deletions packages/web-app-files/src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ export default {
}

resource.preview = previewUrl
commit('UPDATE_RESOURCE', resource)
commit('UPSERT_RESOURCE', resource)

continue
} catch (ignored) {}
Expand All @@ -570,7 +570,7 @@ export default {
const previewUrl = davUrl + encodePath(resource.path) + '?' + queryString.stringify(query)
try {
resource.preview = await mediaSource(previewUrl, 'url')
commit('UPDATE_RESOURCE', resource)
commit('UPSERT_RESOURCE', resource)
} catch (ignored) {}
}
}
Expand Down
12 changes: 4 additions & 8 deletions packages/web-app-files/src/store/mutations.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,23 +302,19 @@ export default {
state.files = files
},

PUSH_NEW_RESOURCE(state, resource) {
const files = [...state.files]
files.push(resource)
state.files = files
},

SELECT_RESOURCES(state, resources) {
state.selected = resources
},

UPDATE_RESOURCE(state, resource) {
UPSERT_RESOURCE(state, resource) {
const files = [...state.files]
const index = files.findIndex(r => r.id === resource.id)

if (index > -1) {
files.splice(index, 1, resource)
state.files = files
} else {
files.push(resource)
}
state.files = files
}
}
6 changes: 3 additions & 3 deletions packages/web-app-files/src/views/SharedWithMe.vue
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export default {
'LOAD_FILES',
'SELECT_RESOURCES',
'CLEAR_CURRENT_FILES_LIST',
'UPDATE_RESOURCE'
'UPSERT_RESOURCE'
]),
...mapMutations(['SET_QUOTA']),
Expand Down Expand Up @@ -192,7 +192,7 @@ export default {
this.configuration.server,
this.getToken,
this.$client,
this.UPDATE_RESOURCE
this.UPSERT_RESOURCE
)
this.LOAD_FILES({ currentFolder: rootFolder, files: resources })
Expand Down Expand Up @@ -263,7 +263,7 @@ export default {
this.configuration.server,
this.getToken
)
this.UPDATE_RESOURCE(sharedResource)
this.UPSERT_RESOURCE(sharedResource)
}
} catch (error) {
this.showMessage({
Expand Down
4 changes: 2 additions & 2 deletions packages/web-app-files/src/views/SharedWithOthers.vue
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export default {
'LOAD_FILES',
'SELECT_RESOURCES',
'CLEAR_CURRENT_FILES_LIST',
'UPDATE_RESOURCE'
'UPSERT_RESOURCE'
]),
...mapMutations(['SET_QUOTA']),
Expand Down Expand Up @@ -165,7 +165,7 @@ export default {
this.configuration.server,
this.getToken,
this.$client,
this.UPDATE_RESOURCE
this.UPSERT_RESOURCE
)
this.LOAD_FILES({ currentFolder: rootFolder, files: resources })
Expand Down
2 changes: 1 addition & 1 deletion packages/web-app-files/tests/views/SharedWithMe.setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const store = createStore(Vuex.Store, {
highlightedFile: () => null
},
mutations: {
UPDATE_RESOURCE: (state, resource) => {
UPSERT_RESOURCE: (state, resource) => {
state.resource = resource
}
},
Expand Down

0 comments on commit 6580cc8

Please sign in to comment.