|
|
@ -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)) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|