Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reload file list after last share removal #7748

Merged
merged 1 commit into from
Oct 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Bugfix: Reload file list after last share removal

We've fixed a bug where the file list would not update after removing the last share or link. Also, we now prevent the shares tree from being loaded again if the removed share was not the last one.

https://github.com/owncloud/web/pull/7748
48 changes: 28 additions & 20 deletions packages/web-app-files/src/components/SideBar/Shares/FileLinks.vue
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
<script lang="ts">
import { defineComponent, PropType, unref } from '@vue/composition-api'
import { DateTime } from 'luxon'
import { mapGetters, mapActions, mapState } from 'vuex'
import { mapGetters, mapActions, mapState, mapMutations } from 'vuex'
import {
useStore,
useCapabilitySpacesEnabled,
Expand All @@ -135,6 +135,7 @@ import { useGraphClient } from 'web-client/src/composables'
import CreateQuickLink from './Links/CreateQuickLink.vue'
import { getLocaleFromLanguage } from 'web-pkg/src/helpers'
import { SpaceResource } from 'web-client/src/helpers'
import { isLocationSharesActive } from '../../../router'

export default defineComponent({
name: 'FileLinks',
Expand Down Expand Up @@ -371,6 +372,7 @@ export default defineComponent({
methods: {
...mapActions('Files', ['addLink', 'updateLink', 'removeLink']),
...mapActions(['showMessage', 'createModal', 'hideModal']),
...mapMutations('Files', ['REMOVE_FILES']),

toggleLinkListCollapsed() {
this.linkListCollapsed = !this.linkListCollapsed
Expand Down Expand Up @@ -565,26 +567,32 @@ export default defineComponent({
if (this.hasShareJail && path === '/') {
path = `/${resource.name}`
}
// removeLink currently fetches all shares from the backend in order to reload the shares indicators
// TODO: Check if to-removed link is last link share and only reload if it's the last link
await this.removeLink({
client,
share,
path,
storageId: resource.fileId
})
.then(
this.showMessage({
title: this.$gettext('Link was deleted successfully')
})
)
.catch((e) => {
console.error(e)
this.showMessage({
title: this.$gettext('Failed to delete link'),
status: 'danger'
})

const lastLinkId =
this.currentFileOutgoingLinks.length === 1 ? this.currentFileOutgoingLinks[0].id : undefined

try {
await this.removeLink({
client,
share,
path,
storageId: resource.fileId,
loadIndicators: !!lastLinkId
})
this.showMessage({
title: this.$gettext('Link was deleted successfully')
})

if (lastLinkId && isLocationSharesActive(this.$router, 'files-shares-via-link')) {
this.REMOVE_FILES([{ id: lastLinkId }])
}
} catch (e) {
console.error(e)
this.showMessage({
title: this.$gettext('Failed to delete link'),
status: 'danger'
})
}
}
}
})
Expand Down
52 changes: 32 additions & 20 deletions packages/web-app-files/src/components/SideBar/Shares/FileShares.vue
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@
</template>

<script lang="ts">
import { mapGetters, mapActions, mapState } from 'vuex'
import { mapGetters, mapActions, mapState, mapMutations } from 'vuex'
import {
useStore,
useCapabilityProjectSpacesEnabled,
useCapabilityShareJailEnabled,
useCapabilityFilesSharingResharing
} from 'web-pkg/src/composables'
import { createLocationSpaces } from '../../../router'
import { createLocationSpaces, isLocationSharesActive } from '../../../router'
import { textUtils } from '../../../helpers/textUtils'
import { getParentPaths } from '../../../helpers/path'
import { ShareTypes } from 'web-client/src/helpers/share'
Expand Down Expand Up @@ -240,6 +240,8 @@ export default defineComponent({
methods: {
...mapActions('Files', ['deleteShare']),
...mapActions(['createModal', 'hideModal', 'showMessage']),
...mapMutations('Files', ['REMOVE_FILES']),

toggleShareesListCollapsed() {
this.sharesListCollapsed = !this.sharesListCollapsed
},
Expand Down Expand Up @@ -288,31 +290,41 @@ export default defineComponent({
this.createModal(modal)
},

$_ocCollaborators_deleteShare(share) {
async $_ocCollaborators_deleteShare(share) {
let path = this.highlightedFile.path
// sharing a share root from the share jail -> use resource name as path
if (this.hasShareJail && path === '/') {
path = `/${this.highlightedFile.name}`
}
this.deleteShare({
client: this.$client,
share: share,
path,
storageId: this.highlightedFile.fileId
})
.then(() => {
this.hideModal()
this.showMessage({
title: this.$gettext('Share was removed successfully')
})

const lastShareId =
this.currentFileOutgoingCollaborators.length === 1
? this.currentFileOutgoingCollaborators[0].id
: undefined

try {
await this.deleteShare({
client: this.$client,
share: share,
path,
storageId: this.highlightedFile.fileId,
loadIndicators: !!lastShareId
})
.catch((error) => {
console.error(error)
this.showMessage({
title: this.$gettext('Failed to remove share'),
status: 'danger'
})

this.hideModal()
this.showMessage({
title: this.$gettext('Share was removed successfully')
})
if (lastShareId && isLocationSharesActive(this.$router, 'files-shares-with-others')) {
this.REMOVE_FILES([{ id: lastShareId }])
}
} catch (error) {
console.error(error)
this.showMessage({
title: this.$gettext('Failed to remove share'),
status: 'danger'
})
}
},
getSharedParentRoute(parentShare) {
if (!parentShare.indirect) {
Expand Down
16 changes: 11 additions & 5 deletions packages/web-app-files/src/store/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,11 +304,14 @@ export default {
)
})
},
deleteShare(context, { client, share, path, storageId }) {
deleteShare(context, { client, share, path, storageId, loadIndicators = false }) {
return client.shares.deleteShare(share.id, {} as any).then(() => {
context.commit('CURRENT_FILE_OUTGOING_SHARES_REMOVE', share)
context.dispatch('updateCurrentFileShareTypes')
context.dispatch('loadIndicators', { client, currentFolder: path, storageId })

if (loadIndicators) {
context.dispatch('loadIndicators', { client, currentFolder: path, storageId })
}
})
},
/**
Expand Down Expand Up @@ -455,11 +458,14 @@ export default {
})
})
},
removeLink(context, { share, client, path, storageId }) {
client.shares.deleteShare(share.id).then(() => {
removeLink(context, { share, client, path, storageId, loadIndicators = false }) {
return client.shares.deleteShare(share.id).then(() => {
context.commit('CURRENT_FILE_OUTGOING_SHARES_REMOVE', share)
context.dispatch('updateCurrentFileShareTypes')
context.dispatch('loadIndicators', { client, currentFolder: path, storageId })

if (loadIndicators) {
context.dispatch('loadIndicators', { client, currentFolder: path, storageId })
}
})
},

Expand Down