Browse Source

feat(nc-gui): loadKanbanData

pull/3818/head
Wing-Kam Wong 2 years ago
parent
commit
9cdfa1879b
  1. 86
      packages/nc-gui/composables/useKanbanViewData.ts

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

@ -16,51 +16,60 @@ export function useKanbanViewData(
const { $api, $e } = useNuxtApp() const { $api, $e } = useNuxtApp()
const { sorts, nestedFilters } = useSmartsheetStoreOrThrow() const { sorts, nestedFilters } = useSmartsheetStoreOrThrow()
const { isUIAllowed } = useUIPermission() const { isUIAllowed } = useUIPermission()
const groupingFieldColOptions = ref<Record<string, any>[]>([])
const kanbanMetaData = ref<KanbanType>() const kanbanMetaData = ref<KanbanType>()
const formattedData = ref<Record<string, Row[]>>() // {
// [val1] : [
// {row: {...}, oldRow: {...}, rowMeta: {...}},
// {row: {...}, oldRow: {...}, rowMeta: {...}},
// ...
// ],
// [val2] : [
// {row: {...}, oldRow: {...}, rowMeta: {...}},
// {row: {...}, oldRow: {...}, rowMeta: {...}},
// ...
// ],
// }
const formattedData = ref<Record<string, Row[]>>({})
// TODO: retrieve from meta
const groupingField = 'singleSelect2'
const formatData = (list: Record<string, any>[]) => { const formatData = (list: Record<string, any>[]) =>
const groupingField = 'singleSelect2' list.map((row) => ({
row: { ...row },
oldRow: { ...row },
rowMeta: {},
}))
async function loadKanbanData(params: Parameters<Api<any>['dbViewRow']['list']>[4] = {}) {
// each stack only loads 25 records -> scroll to load more (to be integrated with infinite scroll)
// TODO: integrate with infinite scroll
// TODO: handle share view case
if ((!project?.value?.id || !meta?.value?.id || !viewMeta?.value?.id) && !isPublic.value) return
// grouping field column options
const groupingFieldColumn = meta?.value?.columns?.filter((f) => f.title === groupingField)[0] as Record<string, any> const groupingFieldColumn = meta?.value?.columns?.filter((f) => f.title === groupingField)[0] as Record<string, any>
// TODO: sort by kanban meta groupingFieldColOptions.value = [
const groupingFieldColumnOptions = [
...(groupingFieldColumn?.colOptions?.options ?? []), ...(groupingFieldColumn?.colOptions?.options ?? []),
{ title: 'Uncategorized', order: 0 }, { id: 'uncategorized', title: 'Uncategorized', order: 0 },
].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)
const initialAcc = groupingFieldColumnOptions.reduce((acc: any, obj: any) => {
if (!acc[obj.title]) { await Promise.all(
acc[obj.title] = [] groupingFieldColOptions.value.map(async (option) => {
} let where = `(${groupingField},eq,${option.title})`
return acc if (option.title === 'Uncategorized') {
}, {}) where = `(${groupingField},is,null)`
return {
meta: groupingFieldColumnOptions,
data: list.reduce((acc: any, obj: any) => {
// TODO: grouping field
const key = obj[groupingField] === null ? 'Uncategorized' : obj[groupingField]
if (!acc[key]) {
acc[key] = []
} }
acc[key].push({ const response = await api.dbViewRow.list('noco', project.value.id!, meta!.value.id!, viewMeta!.value.id, {
row: { ...obj }, ...params,
oldRow: { ...obj }, ...(isUIAllowed('sortSync') ? {} : { sortArrJson: JSON.stringify(sorts.value) }),
rowMeta: {}, ...(isUIAllowed('filterSync') ? {} : { filterArrJson: JSON.stringify(nestedFilters.value) }),
where,
}) })
return acc
}, initialAcc),
}
}
async function loadKanbanData(params: Parameters<Api<any>['dbViewRow']['list']>[4] = {}) { formattedData.value[option.id] = formatData(response.list)
if ((!project?.value?.id || !meta?.value?.id || !viewMeta?.value?.id) && !isPublic.value) return }),
// TODO: handle share view case )
const response = await api.dbViewRow.list('noco', project.value.id!, meta!.value.id!, viewMeta!.value.id, {
...params,
...(isUIAllowed('sortSync') ? {} : { sortArrJson: JSON.stringify(sorts.value) }),
...(isUIAllowed('filterSync') ? {} : { filterArrJson: JSON.stringify(nestedFilters.value) }),
where: where?.value,
})
formattedData.value = formatData(response.list)
} }
async function loadKanbanMeta() { async function loadKanbanMeta() {
@ -80,7 +89,8 @@ export function useKanbanViewData(
loadKanbanData, loadKanbanData,
loadKanbanMeta, loadKanbanMeta,
kanbanMetaData, kanbanMetaData,
formatData, formattedData,
groupingFieldColOptions,
updateOrSaveRow, updateOrSaveRow,
addEmptyRow, addEmptyRow,
} }

Loading…
Cancel
Save