Browse Source

feat(nc-gui): revise groupingFieldColumn & stack_meta logic

pull/3818/head
Wing-Kam Wong 2 years ago
parent
commit
71739ec525
  1. 39
      packages/nc-gui/composables/useKanbanViewData.ts

39
packages/nc-gui/composables/useKanbanViewData.ts

@ -35,6 +35,7 @@ export function useKanbanViewData(
// } // }
const formattedData = useState<Record<string, Row[]>>('KanbanFormattedData', () => ({})) const formattedData = useState<Record<string, Row[]>>('KanbanFormattedData', () => ({}))
const groupingField = useState<string>('KanbanGroupingField', () => '') const groupingField = useState<string>('KanbanGroupingField', () => '')
const groupingFieldColumn = useState<Record<string, any>>('KanbanGroupingFieldColumn', () => ({}))
const formatData = (list: Record<string, any>[]) => const formatData = (list: Record<string, any>[]) =>
list.map((row) => ({ list.map((row) => ({
@ -56,26 +57,19 @@ export function useKanbanViewData(
const stackMetaObj = JSON.parse(stack_meta as string) || {} const stackMetaObj = JSON.parse(stack_meta as string) || {}
if (stack_meta && grp_column_id && stackMetaObj[grp_column_id]) { // build stack meta
// the target stack meta exists, use it directly groupingFieldColOptions.value = [
groupingFieldColOptions.value = stackMetaObj[grp_column_id] ...(groupingFieldColumn.value?.colOptions?.options ?? []),
} else { // enrich uncategorized stack
// retrieve the grouping field column { id: 'uncategorized', title: 'Uncategorized', order: 0, color: enumColor.light[2] },
const groupingFieldColumn = meta?.value?.columns?.filter((f) => f.title === groupingField.value)[0] as Record<string, any> ].sort((a: Record<string, any>, b: Record<string, any>) => a.order - b.order)
// build stack meta
groupingFieldColOptions.value = [ // if grouping column id is present, add the grouping field column options to stackMetaObj
...(groupingFieldColumn?.colOptions?.options ?? []), if (grp_column_id) {
// enrich uncategorized stack stackMetaObj[grp_column_id] = groupingFieldColOptions.value
{ id: 'uncategorized', title: 'Uncategorized', order: 0, color: enumColor.light[2] }, await updateKanbanMeta({
].sort((a: Record<string, any>, b: Record<string, any>) => a.order - b.order) stack_meta: stackMetaObj,
})
// if grouping column id is present, add the grouping field column options to stackMetaObj
if (grp_column_id) {
stackMetaObj[grp_column_id] = groupingFieldColOptions.value
await updateKanbanMeta({
stack_meta: stackMetaObj,
})
}
} }
await Promise.all( await Promise.all(
@ -99,8 +93,8 @@ export function useKanbanViewData(
if (!viewMeta?.value?.id) return if (!viewMeta?.value?.id) return
kanbanMetaData.value = await $api.dbView.kanbanRead(viewMeta.value.id) kanbanMetaData.value = await $api.dbView.kanbanRead(viewMeta.value.id)
// set groupingField // set groupingField
const groupingFieldCol = meta?.value?.columns?.filter((f) => f.id === kanbanMetaData?.value?.grp_column_id)[0] groupingFieldColumn.value = meta?.value?.columns?.filter((f) => f.id === kanbanMetaData?.value?.grp_column_id)[0] || {}
groupingField.value = groupingFieldCol?.title as string groupingField.value = groupingFieldColumn.value?.title as string
} }
async function updateKanbanMeta(updateObj: Partial<KanbanType>) { async function updateKanbanMeta(updateObj: Partial<KanbanType>) {
@ -206,6 +200,7 @@ export function useKanbanViewData(
formattedData, formattedData,
groupingField, groupingField,
groupingFieldColOptions, groupingFieldColOptions,
groupingFieldColumn,
updateOrSaveRow, updateOrSaveRow,
addEmptyRow, addEmptyRow,
} }

Loading…
Cancel
Save