diff --git a/packages/nc-gui-v2/components/smartsheet/Grid.vue b/packages/nc-gui-v2/components/smartsheet/Grid.vue index a496f32207..a56ed469fb 100644 --- a/packages/nc-gui-v2/components/smartsheet/Grid.vue +++ b/packages/nc-gui-v2/components/smartsheet/Grid.vue @@ -45,6 +45,7 @@ const readOnly = inject(ReadonlyInj, false) const isLocked = inject(IsLockedInj, false) const reloadViewDataHook = inject(ReloadViewDataHookInj) +const openNewRecordFormHook = inject(OpenNewRecordFormHookInj) const { isUIAllowed } = useUIPermission() @@ -87,6 +88,7 @@ const { deleteSelectedRows, selectedAllRecords, loadAggCommentsCount, + removeLastEmptyRow, } = useViewData(meta, view as any, xWhere) const { loadGridViewColumns, updateWidth, resizingColWidth, resizingCol } = useGridViewColumnWidth(view as any) @@ -107,6 +109,17 @@ reloadViewDataHook?.on(async () => { loadAggCommentsCount() }) +const expandForm = (row: Row, state?: Record) => { + expandedFormRow.value = row + expandedFormRowState.value = state + expandedFormDlg.value = true +} + +openNewRecordFormHook?.on(async () => { + const newRow = await addEmptyRow() + expandForm(newRow) +}) + const selectCell = (row: number, col: number) => { selected.row = row selected.col = col @@ -293,12 +306,6 @@ const onNavigate = (dir: NavigateDir) => { break } } - -const expandForm = (row: Row, state: Record) => { - expandedFormRow.value = row - expandedFormRowState.value = state - expandedFormDlg.value = true -} diff --git a/packages/nc-gui-v2/components/smartsheet/expanded-form/index.vue b/packages/nc-gui-v2/components/smartsheet/expanded-form/index.vue index e3e1af89fd..076e250cf7 100644 --- a/packages/nc-gui-v2/components/smartsheet/expanded-form/index.vue +++ b/packages/nc-gui-v2/components/smartsheet/expanded-form/index.vue @@ -36,7 +36,7 @@ interface Props { const props = defineProps() -const emits = defineEmits(['update:modelValue']) +const emits = defineEmits(['update:modelValue', 'removeLastEmptyRow']) const row = toRef(props, 'row') @@ -91,6 +91,11 @@ watch( const isExpanded = useVModel(props, 'modelValue', emits, { defaultValue: false, }) + +const onClose = () => { + if (row.value?.rowMeta?.new) emits('removeLastEmptyRow') + isExpanded.value = false +}