|
|
@ -154,16 +154,28 @@ export function useKanbanViewData( |
|
|
|
|
|
|
|
|
|
|
|
// handle deleted options
|
|
|
|
// handle deleted options
|
|
|
|
const columnOptionIds = (groupingFieldColumn.value?.colOptions as SelectOptionsType)?.options.map(({ id }) => id) |
|
|
|
const columnOptionIds = (groupingFieldColumn.value?.colOptions as SelectOptionsType)?.options.map(({ id }) => id) |
|
|
|
stackMetaObj.value[grp_column_id] |
|
|
|
const cols = stackMetaObj.value[grp_column_id].filter(({ id }) => id !== 'uncategorized' && !columnOptionIds.includes(id)) |
|
|
|
.filter(({ id }) => id !== 'uncategorized' && !columnOptionIds.includes(id)) |
|
|
|
for (const col of cols) { |
|
|
|
.forEach(({ id }) => { |
|
|
|
const idx = stackMetaObj.value[grp_column_id].map((ele: Record<string, any>) => ele.id).indexOf(col.id) |
|
|
|
const idx = stackMetaObj.value[grp_column_id].map((ele: Record<string, any>) => ele.id).indexOf(id) |
|
|
|
if (idx !== -1) { |
|
|
|
if (idx !== -1) { |
|
|
|
stackMetaObj.value[grp_column_id].splice(idx, 1) |
|
|
|
deleteStack(stackMetaObj.value[grp_column_id][idx].title!) |
|
|
|
// there are two cases
|
|
|
|
stackMetaObj.value[grp_column_id].splice(idx, 1) |
|
|
|
// 1. delete option from Add / Edit Stack in kanban view
|
|
|
|
|
|
|
|
// 2. delete option from grid view, then switch to kanban view
|
|
|
|
|
|
|
|
// for the second case, formattedData.value and countByStack.value would be empty at this moment
|
|
|
|
|
|
|
|
// however, the data will be correct after rendering
|
|
|
|
|
|
|
|
if (Object.keys(formattedData.value).length && Object.keys(countByStack.value).length) { |
|
|
|
|
|
|
|
// for the first case, no reload is executed.
|
|
|
|
|
|
|
|
// hence, we set groupingField to null for all records under the target stack
|
|
|
|
|
|
|
|
await bulkUpdateGroupingFieldValue(col.title!, true) |
|
|
|
|
|
|
|
// merge the to-be-deleted stack to uncategorized stack
|
|
|
|
|
|
|
|
formattedData.value.uncategorized = [...formattedData.value.uncategorized, ...formattedData.value[col.title!]] |
|
|
|
|
|
|
|
// update the record count
|
|
|
|
|
|
|
|
countByStack.value.uncategorized += countByStack.value[col.title!] |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
isChanged = true |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
groupingFieldColOptions.value = stackMetaObj.value[grp_column_id] |
|
|
|
groupingFieldColOptions.value = stackMetaObj.value[grp_column_id] |
|
|
|
|
|
|
|
|
|
|
|
if (isChanged) { |
|
|
|
if (isChanged) { |
|
|
@ -295,33 +307,50 @@ export function useKanbanViewData( |
|
|
|
where: `(${groupingField.value},eq,${stackTitle})`, |
|
|
|
where: `(${groupingField.value},eq,${stackTitle})`, |
|
|
|
}, |
|
|
|
}, |
|
|
|
) |
|
|
|
) |
|
|
|
// update to groupingField value to target value
|
|
|
|
if (stackTitle in formattedData.value) { |
|
|
|
formattedData.value[stackTitle] = formattedData.value[stackTitle].map((o) => ({ |
|
|
|
// update to groupingField value to target value
|
|
|
|
...o, |
|
|
|
formattedData.value[stackTitle] = formattedData.value[stackTitle].map((o) => ({ |
|
|
|
row: { |
|
|
|
...o, |
|
|
|
...o.row, |
|
|
|
row: { |
|
|
|
[groupingField.value]: groupingFieldVal, |
|
|
|
...o.row, |
|
|
|
}, |
|
|
|
[groupingField.value]: groupingFieldVal, |
|
|
|
oldRow: { |
|
|
|
}, |
|
|
|
...o.oldRow, |
|
|
|
oldRow: { |
|
|
|
[groupingField.value]: o.row[groupingField.value], |
|
|
|
...o.oldRow, |
|
|
|
}, |
|
|
|
[groupingField.value]: o.row[groupingField.value], |
|
|
|
})) |
|
|
|
}, |
|
|
|
|
|
|
|
})) |
|
|
|
|
|
|
|
} |
|
|
|
} catch (e: any) { |
|
|
|
} catch (e: any) { |
|
|
|
message.error(await extractSdkResponseErrorMsg(e)) |
|
|
|
message.error(await extractSdkResponseErrorMsg(e)) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async function deleteStack(stackTitle: string) { |
|
|
|
async function deleteStack(stackTitle: string, stackIdx: number) { |
|
|
|
|
|
|
|
if (!viewMeta?.value?.id || !groupingFieldColumn.value) return |
|
|
|
try { |
|
|
|
try { |
|
|
|
// set groupingField to null for all records under the target stack
|
|
|
|
// set groupingField to null for all records under the target stack
|
|
|
|
await bulkUpdateGroupingFieldValue(stackTitle, true) |
|
|
|
await bulkUpdateGroupingFieldValue(stackTitle, true) |
|
|
|
// merge the 'deleted' stack to uncategorized stack
|
|
|
|
// merge the to-be-deleted stack to uncategorized stack
|
|
|
|
formattedData.value.uncategorized = [...formattedData.value.uncategorized, ...formattedData.value[stackTitle]] |
|
|
|
formattedData.value.uncategorized = [...formattedData.value.uncategorized, ...formattedData.value[stackTitle]] |
|
|
|
countByStack.value.uncategorized += countByStack.value[stackTitle] |
|
|
|
countByStack.value.uncategorized += countByStack.value[stackTitle] |
|
|
|
// clear the 'deleted' stack
|
|
|
|
// clear state for the to-be-deleted stack
|
|
|
|
formattedData.value[stackTitle] = [] |
|
|
|
delete formattedData.value[stackTitle] |
|
|
|
countByStack.value[stackTitle] = 0 |
|
|
|
delete countByStack.value[stackTitle] |
|
|
|
|
|
|
|
// delete the stack, i.e. grouping field value
|
|
|
|
|
|
|
|
const newOptions = (groupingFieldColumn.value.colOptions as SelectOptionsType).options.filter((o) => o.title !== stackTitle) |
|
|
|
|
|
|
|
;(groupingFieldColumn.value.colOptions as SelectOptionsType).options = newOptions |
|
|
|
|
|
|
|
await api.dbTableColumn.update(groupingFieldColumn.value.id!, { |
|
|
|
|
|
|
|
...groupingFieldColumn.value, |
|
|
|
|
|
|
|
colOptions: { |
|
|
|
|
|
|
|
options: newOptions, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
} as any) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// update kanban stack meta
|
|
|
|
|
|
|
|
stackMetaObj.value[kanbanMetaData.value.grp_column_id!].splice(stackIdx, 1) |
|
|
|
|
|
|
|
groupingFieldColOptions.value.splice(stackIdx, 1) |
|
|
|
|
|
|
|
await updateKanbanStackMeta() |
|
|
|
} catch (e: any) { |
|
|
|
} catch (e: any) { |
|
|
|
message.error(await extractSdkResponseErrorMsg(e)) |
|
|
|
message.error(await extractSdkResponseErrorMsg(e)) |
|
|
|
} |
|
|
|
} |
|
|
|