Browse Source

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

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

15
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,15 +57,9 @@ 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]) {
// the target stack meta exists, use it directly
groupingFieldColOptions.value = stackMetaObj[grp_column_id]
} else {
// retrieve the grouping field column
const groupingFieldColumn = meta?.value?.columns?.filter((f) => f.title === groupingField.value)[0] as Record<string, any>
// build stack meta // build stack meta
groupingFieldColOptions.value = [ groupingFieldColOptions.value = [
...(groupingFieldColumn?.colOptions?.options ?? []), ...(groupingFieldColumn.value?.colOptions?.options ?? []),
// enrich uncategorized stack // enrich uncategorized stack
{ id: 'uncategorized', title: 'Uncategorized', order: 0, color: enumColor.light[2] }, { id: 'uncategorized', title: 'Uncategorized', order: 0, color: enumColor.light[2] },
].sort((a: Record<string, any>, b: Record<string, any>) => a.order - b.order) ].sort((a: Record<string, any>, b: Record<string, any>) => a.order - b.order)
@ -76,7 +71,6 @@ export function useKanbanViewData(
stack_meta: stackMetaObj, stack_meta: stackMetaObj,
}) })
} }
}
await Promise.all( await Promise.all(
groupingFieldColOptions.value.map(async (option) => { groupingFieldColOptions.value.map(async (option) => {
@ -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