|
|
@ -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,29 +304,43 @@ 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) => { |
|
|
|
|
|
|
|
bases.value.set(base.id!, { ...base, order: i + 1 }) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return { |
|
|
|
// Check if basesArray contains null or duplicate order
|
|
|
|
id: base.id, |
|
|
|
for (const base of basesArray) { |
|
|
|
order: i + 1, |
|
|
|
if (base.order === null || baseOrderSet.has(base.order)) { |
|
|
|
} |
|
|
|
hasNullOrDuplicates = true |
|
|
|
}) |
|
|
|
break |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
baseOrderSet.add(base.order) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!hasNullOrDuplicates) return |
|
|
|
|
|
|
|
|
|
|
|
if (basesWithNullOrder.length) { |
|
|
|
// update the local state and return updated bases payload
|
|
|
|
|
|
|
|
let updatedBasesOrder = basesArray.map((base, i) => { |
|
|
|
|
|
|
|
bases.value.set(base.id!, { ...base, order: i + 1 }) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return { |
|
|
|
|
|
|
|
id: base.id, |
|
|
|
|
|
|
|
order: i + 1, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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)) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|