Skip to content

Commit

Permalink
Fix storageId usage in sidebar panels of files app
Browse files Browse the repository at this point in the history
  • Loading branch information
kulmann committed Jun 9, 2022
1 parent c0c8f65 commit 2bb5003
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 93 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@
</div>
</template>
<script lang="ts">
import { computed, defineComponent, ref } from '@vue/composition-api'
import { computed, defineComponent, ref, unref } from '@vue/composition-api'
import Mixins from '../../../mixins'
import MixinResources from '../../../mixins/resources'
import { mapActions, mapGetters } from 'vuex'
Expand All @@ -150,7 +150,7 @@ import upperFirst from 'lodash-es/upperFirst'
import path from 'path'
import { createLocationSpaces, isAuthenticatedRoute, isLocationSpacesActive } from '../../../router'
import { ShareTypes } from '../../../helpers/share'
import { useRoute, useRouter } from 'web-pkg/src/composables'
import { useRouteParam, useRouter } from 'web-pkg/src/composables'
import { getIndicators } from '../../../helpers/statusIndicators'
import copyToClipboard from 'copy-to-clipboard'
import { encodePath } from 'web-pkg/src/utils'
Expand All @@ -163,23 +163,24 @@ export default defineComponent({
setup() {
const sharedParentDir = ref('')
const router = useRouter()
const route = useRoute()
const currentStorageId = useRouteParam('storageId')
const sharedParentRoute = computed(() => {
if (isLocationSpacesActive(router, 'files-spaces-project')) {
return createLocationSpaces('files-spaces-project', {
params: { storageId: route.value.params.storageId, item: sharedParentDir.value }
params: { storageId: unref(currentStorageId), item: unref(sharedParentDir) }
})
}
return createLocationSpaces('files-spaces-personal', {
params: { item: sharedParentDir.value }
params: { item: unref(sharedParentDir) }
})
})
return {
sharedParentDir,
sharedParentRoute
sharedParentRoute,
currentStorageId
}
},
Expand Down Expand Up @@ -392,7 +393,7 @@ export default defineComponent({
client: this.$client,
path: this.file.path,
$gettext: this.$gettext,
storageId: this.$route.params.storageId
...(this.currentStorageId && { storageId: this.currentStorageId })
})
this.shareIndicators = getIndicators(this.file, this.sharesTree)
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ export default {
return this.$gettext('Invite')
},
currentStorageId() {
return this.$route.params.storageId
},
resourceIsSpace() {
return this.highlightedFile.type === 'space'
},
Expand Down Expand Up @@ -326,8 +329,8 @@ export default {
let storageId
if (this.resourceIsSpace) {
storageId = this.highlightedFile.id
} else if (this.$route.params.storageId) {
storageId = this.$route.params.storageId
} else if (this.currentStorageId) {
storageId = this.currentStorageId
}
this.addShare({
Expand Down
21 changes: 15 additions & 6 deletions packages/web-app-files/src/components/SideBar/Shares/FileLinks.vue
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,11 @@ export default defineComponent({
const linkListCollapsed = !store.getters.configuration.options.sidebar.shares.showAllOnLoad
return { graphClient, hasSpaces: useCapabilitySpacesEnabled(), linkListCollapsed }
return {
graphClient,
hasSpaces: useCapabilitySpacesEnabled(),
linkListCollapsed
}
},
data() {
return {
Expand Down Expand Up @@ -346,14 +350,14 @@ export default defineComponent({
graphClient: this.graphClient,
path: this.highlightedFile.path,
$gettext: this.$gettext,
storageId: this.currentStorageId,
...(this.currentStorageId && { storageId: this.currentStorageId }),
resource: this.highlightedFile
})
this.loadSharesTree({
client: this.$client,
path: this.highlightedFile.path === '' ? '/' : dirname(this.highlightedFile.path),
$gettext: this.$gettext,
storageId: this.currentStorageId
...(this.currentStorageId && { storageId: this.currentStorageId })
})
},
Expand Down Expand Up @@ -425,6 +429,7 @@ export default defineComponent({
quicklink: link.quicklink,
name: link.name,
...(this.currentStorageId && {
storageId: this.currentStorageId,
spaceRef: `${this.currentStorageId}${this.highlightedFile.path}`
})
}
Expand All @@ -437,8 +442,7 @@ export default defineComponent({
path: this.highlightedFile.path,
client: this.$client,
$gettext: this.$gettext,
params,
storageId: this.currentStorageId
params
}).catch(showError)
this.currentView = VIEW_SHOW
Expand Down Expand Up @@ -495,7 +499,12 @@ export default defineComponent({
this.hideModal()
// 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, resource, storageId: this.currentStorageId })
await this.removeLink({
client,
share,
resource,
...(this.currentStorageId && { storageId: this.currentStorageId })
})
.then(
this.showMessage({
title: this.$gettext('Link was deleted successfully')
Expand Down
95 changes: 49 additions & 46 deletions packages/web-app-files/src/components/SideBar/Shares/FileShares.vue
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,18 @@
import { dirname } from 'path'
import { useTask } from 'vue-concurrency'
import { mapGetters, mapActions, mapState } from 'vuex'
import { watch, computed } from '@vue/composition-api'
import { useStore, useDebouncedRef } from 'web-pkg/src/composables'
import { watch, computed, ref, unref } from '@vue/composition-api'
import {
useStore,
useDebouncedRef,
useRouteParam,
useCapabilityProjectSpacesEnabled
} from 'web-pkg/src/composables'
import { clientService } from 'web-pkg/src/services'
import { createLocationSpaces, isLocationSpacesActive } from '../../../router'
import { textUtils } from '../../../helpers/textUtils'
import { getParentPaths } from '../../../helpers/path'
import { buildSpace, buildSpaceShare } from '../../../helpers/resources'
import { buildSpaceShare } from '../../../helpers/resources'
import { ShareTypes } from '../../../helpers/share'
import { sortSpaceMembers } from '../../../helpers/space'
import InviteCollaboratorForm from './Collaborators/InviteCollaborator/InviteCollaboratorForm.vue'
Expand All @@ -97,53 +102,55 @@ export default {
sharesTreeLoading.value
})
const currentSpace = ref(null)
const spaceMembers = ref([])
const currentStorageId = useRouteParam('storageId')
watch(
currentStorageId,
(storageId) => {
currentSpace.value = store.state.Files.spaces?.find((space) => space.id === storageId)
},
{ immediate: true }
)
const isCurrentSpaceTypeProject = computed(() => unref(currentSpace)?.driveType === 'project')
const graphClient = clientService.graphAuthenticated(
store.getters.configuration.server,
store.getters.getToken
)
const loadSpaceTask = useTask(function* (signal, ref, storageId) {
const graphResponse = yield graphClient.drives.getDrive(storageId)
if (!graphResponse.data) {
return
}
ref.currentSpace = buildSpace(graphResponse.data)
})
const loadSpaceMembersTask = useTask(function* (signal, ref) {
const promises = []
const spaceShares = []
for (const role of Object.keys(ref.currentSpace.spaceRoles)) {
for (const userId of ref.currentSpace.spaceRoles[role]) {
console.log('roles', unref(currentSpace).spaceRoles)
for (const role of Object.keys(unref(currentSpace).spaceRoles)) {
for (const userId of unref(currentSpace).spaceRoles[role]) {
promises.push(
graphClient.users.getUser(userId).then((resolved) => {
spaceShares.push(buildSpaceShare({ ...resolved.data, role }, ref.currentSpace.id))
spaceShares.push(buildSpaceShare({ ...resolved.data, role }, unref(currentSpace).id))
console.log(spaceShares)
})
)
}
}
yield Promise.all(promises).then(() => {
ref.spaceMembers = sortSpaceMembers(spaceShares)
spaceMembers.value = sortSpaceMembers(spaceShares)
})
})
const sharesListCollapsed = !store.getters.configuration.options.sidebar.shares.showAllOnLoad
return {
loadSpaceTask,
currentStorageId,
currentSpace,
spaceMembers,
isCurrentSpaceTypeProject,
loadSpaceMembersTask,
sharesListCollapsed,
sharesLoading
}
},
data() {
return {
currentSpace: null,
spaceMembers: []
sharesLoading,
hasProjectSpaces: useCapabilityProjectSpacesEnabled()
}
},
computed: {
Expand Down Expand Up @@ -279,11 +286,12 @@ export default {
return null
},
currentUserIsMemberOfSpace() {
return this.currentSpace?.spaceMemberIds.includes(this.user.uuid)
return this.currentSpace?.spaceMemberIds?.includes(this.user.uuid)
},
showSpaceMembers() {
return (
this.currentSpace &&
this.isCurrentSpaceTypeProject &&
this.highlightedFile.type !== 'space' &&
this.currentUserIsMemberOfSpace
)
Expand All @@ -299,13 +307,9 @@ export default {
immediate: true
}
},
async mounted() {
if (this.$route.params.storageId) {
await this.loadSpaceTask.perform(this, this.$route.params.storageId)
if (this.showSpaceMembers) {
this.loadSpaceMembersTask.perform(this)
}
mounted() {
if (this.showSpaceMembers) {
this.loadSpaceMembersTask.perform()
}
},
methods: {
Expand Down Expand Up @@ -369,7 +373,7 @@ export default {
client: this.$client,
share: share,
resource: this.highlightedFile,
storageId: this.$route.params.storageId
...(this.currentStorageId && { storageId: this.currentStorageId })
})
.then(() => {
this.hideModal()
Expand All @@ -386,23 +390,22 @@ export default {
})
},
$_reloadShares() {
this.loadCurrentFileOutgoingShares({
const requestParams = {
client: this.$client,
path: this.highlightedFile.path,
$gettext: this.$gettext,
storageId: this.$route.params.storageId
...(this.currentStorageId && { storageId: this.currentStorageId })
}
this.loadCurrentFileOutgoingShares({
...requestParams,
path: this.highlightedFile.path
})
this.loadIncomingShares({
client: this.$client,
path: this.highlightedFile.path,
$gettext: this.$gettext,
storageId: this.$route.params.storageId
...requestParams,
path: this.highlightedFile.path
})
this.loadSharesTree({
client: this.$client,
path: dirname(this.highlightedFile.path),
$gettext: this.$gettext,
storageId: this.$route.params.storageId
...requestParams,
path: dirname(this.highlightedFile.path)
})
},
getSharedParentRoute(parentShare) {
Expand All @@ -413,7 +416,7 @@ export default {
if (this.sharesTree[parentShare.path]) {
if (isLocationSpacesActive(this.$router, 'files-spaces-project')) {
return createLocationSpaces('files-spaces-project', {
params: { storageId: this.$route.params.storageId, item: parentShare.path }
params: { storageId: this.currentStorageId, item: parentShare.path }
})
}
Expand Down
Loading

0 comments on commit 2bb5003

Please sign in to comment.