From 292998384dc0428cd9b7c7f9a8cdab089d3b44b3 Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Sun, 11 Sep 2022 12:53:44 +0800 Subject: [PATCH] feat(nc-gui): add addEmptyRow & use useState for formattedData in useKanbanViewData --- .../nc-gui/composables/useKanbanViewData.ts | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/packages/nc-gui/composables/useKanbanViewData.ts b/packages/nc-gui/composables/useKanbanViewData.ts index 9b70b25af0..18a2aaad72 100644 --- a/packages/nc-gui/composables/useKanbanViewData.ts +++ b/packages/nc-gui/composables/useKanbanViewData.ts @@ -1,10 +1,9 @@ import type { ComputedRef, Ref } from 'vue' -import type { Api, KanbanType, TableType, ViewType } from 'nocodb-sdk' +import type { Api, ColumnType, KanbanType, TableType, ViewType } from 'nocodb-sdk' import { useI18n } from 'vue-i18n' +import { message } from 'ant-design-vue' import type { Row } from '~/composables/useViewData' import { useNuxtApp } from '#app' -import { message } from 'ant-design-vue' -import { ColumnType } from 'nocodb-sdk' export function useKanbanViewData( meta: Ref | ComputedRef | undefined, @@ -32,7 +31,7 @@ export function useKanbanViewData( // ... // ], // } - const formattedData = ref>({}) + const formattedData = useState>('formattedKanbanData', () => ({})) // TODO: retrieve from meta const groupingField = 'singleSelect2' @@ -79,7 +78,7 @@ export function useKanbanViewData( kanbanMetaData.value = await $api.dbView.kanbanRead(viewMeta.value.id) } - async function insertRow(row: Record, rowIndex = formattedData.value['uncatgorized']?.length) { + async function insertRow(row: Record, rowIndex = formattedData.value.uncatgorized?.length) { try { const insertObj = meta?.value?.columns?.reduce((o: any, col) => { if (!col.ai && row?.[col.title as string] !== null) { @@ -96,7 +95,7 @@ export function useKanbanViewData( insertObj, ) - formattedData.value['uncatgorized']?.splice(rowIndex ?? 0, 1, { + formattedData.value.uncatgorized?.splice(rowIndex ?? 0, 1, { row: insertedData, rowMeta: {}, oldRow: { ...insertedData }, @@ -153,8 +152,14 @@ export function useKanbanViewData( } } - function addEmptyRow(addAfter?: number) { - // TODO: implement + function addEmptyRow(addAfter = formattedData.value.Uncategorized?.length) { + formattedData.value.Uncategorized.splice(addAfter, 0, { + row: {}, + oldRow: {}, + rowMeta: { new: true }, + }) + + return formattedData.value.Uncategorized[addAfter] } return {