From ea847973819967c389d2fb7cc48041ac21e0557a Mon Sep 17 00:00:00 2001 From: Pranav C Date: Thu, 6 Oct 2022 15:16:23 +0530 Subject: [PATCH] fix(gui): save record only after all required fields are provided Signed-off-by: Pranav C --- packages/nc-gui/composables/useViewData.ts | 10 ++++++++++ packages/nc-gui/utils/columnUtils.ts | 6 +++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/packages/nc-gui/composables/useViewData.ts b/packages/nc-gui/composables/useViewData.ts index 47102427bb..f5ca81dd36 100644 --- a/packages/nc-gui/composables/useViewData.ts +++ b/packages/nc-gui/composables/useViewData.ts @@ -8,6 +8,7 @@ import { extractPkFromRow, extractSdkResponseErrorMsg, getHTMLEncodedText, + isColumnRequiredAndNull, message, ref, useApi, @@ -196,13 +197,22 @@ export function useViewData( async function insertRow(row: Record, rowIndex = formattedData.value?.length) { try { + let allRequiredColumnsProvided = true const insertObj = meta?.value?.columns?.reduce((o: any, col) => { + // check all the required columns are not null + if (isColumnRequiredAndNull(col, row)) { + allRequiredColumnsProvided = false + } + if (!col.ai && row?.[col.title as string] !== null) { o[col.title as string] = row?.[col.title as string] } + return o }, {}) + if (!allRequiredColumnsProvided) return + const insertedData = await $api.dbViewRow.create( NOCO, project?.value.id as string, diff --git a/packages/nc-gui/utils/columnUtils.ts b/packages/nc-gui/utils/columnUtils.ts index 70c07d7827..e6a328928d 100644 --- a/packages/nc-gui/utils/columnUtils.ts +++ b/packages/nc-gui/utils/columnUtils.ts @@ -167,7 +167,11 @@ const getUIDTIcon = (uidt: UITypes | string) => { ).icon } -export { uiTypes, getUIDTIcon } +const isColumnRequiredAndNull = (col: any, row: Record) => { + return col.rqd && (!col.cdf || !col.ai) && (row[col.title!] === undefined || row[col.title!] === null) +} + +export { uiTypes, getUIDTIcon, isColumnRequiredAndNull } /** * @copyright Copyright (c) 2021, Xgene Cloud Ltd