Browse Source

fix(gui): save record only after all required fields are provided

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/3953/head
Pranav C 2 years ago
parent
commit
ea84797381
  1. 10
      packages/nc-gui/composables/useViewData.ts
  2. 6
      packages/nc-gui/utils/columnUtils.ts

10
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<string, any>, 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,

6
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<string, any>) => {
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

Loading…
Cancel
Save