Browse Source

fix(nc-gui): handle duplicate base order case and use permission `baseReorder` instead of `baseMove`

pull/7528/head
Ramesh Mane 11 months ago
parent
commit
02fad3630b
  1. 2
      packages/nc-gui/components/dashboard/TreeView/index.vue
  2. 1
      packages/nc-gui/lib/acl.ts
  3. 32
      packages/nc-gui/store/bases.ts

2
packages/nc-gui/components/dashboard/TreeView/index.vue

@ -258,7 +258,7 @@ watch(
<div v-if="basesList?.length"> <div v-if="basesList?.length">
<Draggable <Draggable
:model-value="basesList" :model-value="basesList"
:disabled="!isUIAllowed('baseMove') || basesList?.length < 2" :disabled="!isUIAllowed('baseReorder') || basesList?.length < 2"
item-key="id" item-key="id"
handle=".base-title-node" handle=".base-title-node"
ghost-class="ghost" ghost-class="ghost"

1
packages/nc-gui/lib/acl.ts

@ -30,6 +30,7 @@ const rolePermissions = {
tableRename: true, tableRename: true,
tableDelete: true, tableDelete: true,
viewCreateOrEdit: true, viewCreateOrEdit: true,
baseReorder: true,
}, },
}, },
[OrgUserRoles.VIEWER]: { [OrgUserRoles.VIEWER]: {

32
packages/nc-gui/store/bases.ts

@ -153,7 +153,7 @@ export const useBases = defineStore('basesStore', () => {
return acc return acc
}, new Map()) }, new Map())
await updateNullBaseOrder() await updateIfBaseOrderIsNullOrDuplicate()
} catch (e) { } catch (e) {
console.error(e) console.error(e)
message.error(e.message) message.error(e.message)
@ -304,15 +304,27 @@ export const useBases = defineStore('basesStore', () => {
await navigateTo(`/nc/${baseId}`) await navigateTo(`/nc/${baseId}`)
} }
async function updateNullBaseOrder() { async function updateIfBaseOrderIsNullOrDuplicate() {
if (!isUIAllowed('baseMove')) return if (!isUIAllowed('baseReorder')) return
const basesArray = Array.from(bases.value.values()) const basesArray = Array.from(bases.value.values())
// Filter bases with null orders, update the local state and return updated bases payload let baseOrderSet = new Set()
const basesWithNullOrder = basesArray let hasNullOrDuplicates = false
.filter((base) => base.order === null)
.map((base, i) => { // Check if basesArray contains null or duplicate order
for (const base of basesArray) {
if (base.order === null || baseOrderSet.has(base.order)) {
hasNullOrDuplicates = true
break
}
baseOrderSet.add(base.order)
}
if (!hasNullOrDuplicates) return
// update the local state and return updated bases payload
let updatedBasesOrder = basesArray.map((base, i) => {
bases.value.set(base.id!, { ...base, order: i + 1 }) bases.value.set(base.id!, { ...base, order: i + 1 })
return { return {
@ -321,12 +333,14 @@ export const useBases = defineStore('basesStore', () => {
} }
}) })
if (basesWithNullOrder.length) { try {
await Promise.all( await Promise.all(
basesWithNullOrder.map(async (base) => { updatedBasesOrder.map(async (base) => {
await api.base.update(base.id!, { order: base.order }) await api.base.update(base.id!, { order: base.order })
}), }),
) )
} catch (e: any) {
message.error(await extractSdkResponseErrorMsg(e))
} }
} }

Loading…
Cancel
Save