From cd19f131b04a8c6fd48625fa832356f660153162 Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Fri, 7 Oct 2022 14:12:03 +0800 Subject: [PATCH] fix(nc-gui): duplicate openNewRecordFormHook handler attached & disable add new record in locked view --- .../nc-gui/components/smartsheet/Kanban.vue | 34 +++++++++++++++---- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/packages/nc-gui/components/smartsheet/Kanban.vue b/packages/nc-gui/components/smartsheet/Kanban.vue index 38f9fdeff6..70cdcbffec 100644 --- a/packages/nc-gui/components/smartsheet/Kanban.vue +++ b/packages/nc-gui/components/smartsheet/Kanban.vue @@ -15,6 +15,7 @@ import { ReadonlyInj, inject, onBeforeMount, + onBeforeUnmount, provide, useKanbanViewStoreOrThrow, } from '#imports' @@ -88,6 +89,8 @@ const fields = inject(FieldsInj, ref([])) const kanbanContainerRef = ref() +const selectedStackTitle = ref('') + const isRowEmpty = (record: any, col: any) => { const val = record.row[col.title] if (!val) return true @@ -122,6 +125,7 @@ const expandForm = (row: RowType, state?: Record) => { } const _contextMenu = ref(false) + const contextMenu = computed({ get: () => _contextMenu.value, set: (val) => { @@ -227,23 +231,29 @@ const handleCollapseStack = async (stackIdx: number) => { } } -openNewRecordFormHook?.on(async (stackTitle) => { +const openNewRecordFormHookHandler = async () => { const newRow = await addEmptyRow() // preset the grouping field value newRow.row = { - [groupingField.value]: stackTitle, + [groupingField.value]: selectedStackTitle.value, } // increase total count by 1 countByStack.value.set(null, countByStack.value.get(null)! + 1) // open the expanded form expandForm(newRow) -}) +} + +openNewRecordFormHook?.on(openNewRecordFormHookHandler) onBeforeMount(async () => { await loadKanbanMeta() await loadKanbanData() }) +// remove openNewRecordFormHookHandler before unmounting +// so that it won't be triggered multiple times +onBeforeUnmount(() => openNewRecordFormHook.off(openNewRecordFormHookHandler)) + // reset context menu target on hide watch(contextMenu, () => { if (!contextMenu.value) { @@ -325,9 +335,14 @@ watch(view, async (nextView) => {