From 7048ef345fe8c8550fb97fcbfb1b215dd17a0e19 Mon Sep 17 00:00:00 2001 From: HangLe Date: Thu, 24 Nov 2022 15:08:38 +0200 Subject: [PATCH 1/5] Fix for data table's disabled options --- .../src/common/globalFunctions.js | 13 ++++ .../src/components/ContainerTable.vue | 63 ++++++++++--------- .../src/components/Containers.vue | 5 +- .../src/components/ObjectTable.vue | 7 ++- 4 files changed, 53 insertions(+), 35 deletions(-) diff --git a/swift_browser_ui_frontend/src/common/globalFunctions.js b/swift_browser_ui_frontend/src/common/globalFunctions.js index e25dd90b8..ef3e49fa4 100644 --- a/swift_browser_ui_frontend/src/common/globalFunctions.js +++ b/swift_browser_ui_frontend/src/common/globalFunctions.js @@ -53,5 +53,18 @@ export async function getSharedContainers (projectId) { : []; } +export async function getAccessDetails ( + projectId, + folderName, + sourceProjectId) +{ + return store.state.client + ? await store.state.client.getAccessDetails( + projectId, + folderName, + sourceProjectId) + : []; +} + diff --git a/swift_browser_ui_frontend/src/components/ContainerTable.vue b/swift_browser_ui_frontend/src/components/ContainerTable.vue index 8ebfe6a2d..20137f22a 100644 --- a/swift_browser_ui_frontend/src/components/ContainerTable.vue +++ b/swift_browser_ui_frontend/src/components/ContainerTable.vue @@ -27,6 +27,7 @@ import { toggleCreateFolderModal, getSharingContainers, getSharedContainers, + getAccessDetails, toggleCopyFolderModal, } from "@/common/globalFunctions"; import {swiftDeleteContainer} from "@/common/api"; @@ -139,7 +140,18 @@ export default { return ""; }; - this.containers = this.conts.slice(offset, offset + limit).reduce(( + // Map the 'accessRights' to the container if it's a shared container + const mappedContainers = await Promise.all(this.conts.map(async(cont) => { + const sharedDetails = cont.owner ? await getAccessDetails( + this.$route.params.project, + cont.container, + cont.owner) : null; + const accessRights = sharedDetails ? sharedDetails.access : null; + return sharedDetails && accessRights ? + {...cont, accessRights} : {...cont}; + })); + + this.containers = mappedContainers.slice(offset, offset + limit).reduce(( items, item, ) => { @@ -230,35 +242,24 @@ export default { }, }, // Share button is disabled for Shared (with you) Folders - item.owner ? - { - value: null, - component: { - tag: "c-button", - params: { - text: true, - size: "small", - disabled: true, - }, - }, - } : - { - value: this.$t("message.share.share"), - component: { - tag: "c-button", - params: { - text: true, - size: "small", - title: this.$t("message.share.share"), - path: mdiShareVariantOutline, - onClick: (item) => { - this.$store.commit("toggleShareModal", true); - this.$store.commit( - "setFolderName", item.data.name.value); - }, + { + value: this.$t("message.share.share"), + component: { + tag: "c-button", + params: { + text: true, + size: "small", + title: this.$t("message.share.share"), + path: mdiShareVariantOutline, + onClick: (item) => { + this.$store.commit("toggleShareModal", true); + this.$store.commit( + "setFolderName", item.data.name.value); }, + disabled: item.owner, }, }, + }, { value: null, component: { @@ -267,7 +268,7 @@ export default { items: [ { name: this.$t("message.copy"), - action: item.owner + action: item.owner ? () => toggleCopyFolderModal(item.name, item.owner) : () => toggleCopyFolderModal(item.name), disabled: !item.bytes ? true : false, @@ -281,10 +282,12 @@ export default { action: () => this.confirmDelete( item.name, item.count, ), + disabled: item.owner && item.accessRights.length > 1, }, ], customTrigger: { value: this.$t("message.options"), + disabled: true, component: { tag: "c-button", params: { @@ -292,11 +295,11 @@ export default { path: mdiDotsHorizontal, title: "Menu with custom trigger", size: "small", + disabled: item.owner + && item.accessRights.length === 1, }, }, }, - path: mdiDotsHorizontal, - }, }, }, diff --git a/swift_browser_ui_frontend/src/components/Containers.vue b/swift_browser_ui_frontend/src/components/Containers.vue index 46879890a..629c85d62 100644 --- a/swift_browser_ui_frontend/src/components/Containers.vue +++ b/swift_browser_ui_frontend/src/components/Containers.vue @@ -94,9 +94,8 @@ export default { }); } else if (this.$route.name === "SharedTo") { - this.renderingContainers = this.containers.filter(cont => - cont.owner, - ); + this.renderingContainers = this.containers ? + this.containers.filter(cont => cont.owner) : []; } else { this.renderingContainers = this.containers; } diff --git a/swift_browser_ui_frontend/src/components/ObjectTable.vue b/swift_browser_ui_frontend/src/components/ObjectTable.vue index 924c5d5d8..a0687e607 100644 --- a/swift_browser_ui_frontend/src/components/ObjectTable.vue +++ b/swift_browser_ui_frontend/src/components/ObjectTable.vue @@ -114,7 +114,10 @@