Browse Source

fix(nc-gui): default value update issue if value is 0 (#8857)

pull/8846/head
Ramesh Mane 5 months ago committed by GitHub
parent
commit
f921535cf2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 2
      packages/nc-gui/components/smartsheet/Form.vue
  2. 2
      packages/nc-gui/components/smartsheet/column/DefaultValue.vue
  3. 4
      packages/nc-gui/components/smartsheet/column/EditOrAdd.vue
  4. 2
      packages/nc-gui/composables/useData.ts
  5. 2
      packages/nc-gui/composables/useSharedFormViewStore.ts
  6. 2
      packages/nc-gui/utils/columnUtils.ts
  7. 22
      packages/nc-gui/utils/dataUtils.ts

2
packages/nc-gui/components/smartsheet/Form.vue

@ -236,7 +236,7 @@ function isDbRequired(column: Record<string, any>) {
// column required / not null // column required / not null
column.rqd && column.rqd &&
// column default value // column default value
!column.cdf && !isValidValue(column?.cdf) &&
// confirm it's not foreign key // confirm it's not foreign key
!columns.value.some( !columns.value.some(
(c: Record<string, any>) => (c: Record<string, any>) =>

2
packages/nc-gui/components/smartsheet/column/DefaultValue.vue

@ -32,7 +32,7 @@ const updateCdfValue = (cdf: string | null) => {
} }
onMounted(() => { onMounted(() => {
updateCdfValue(vModel.value?.cdf ? vModel.value.cdf : null) updateCdfValue(vModel.value?.cdf ?? null)
}) })
watch( watch(

4
packages/nc-gui/components/smartsheet/column/EditOrAdd.vue

@ -82,11 +82,11 @@ const showHoverEffectOnSelectedType = ref(true)
const isVisibleDefaultValueInput = computed({ const isVisibleDefaultValueInput = computed({
get: () => { get: () => {
if (formState.value.cdf && !showDefaultValueInput.value) { if (isValidValue(formState.value.cdf) && !showDefaultValueInput.value) {
showDefaultValueInput.value = true showDefaultValueInput.value = true
} }
return formState.value.cdf !== null || showDefaultValueInput.value return isValidValue(formState.value.cdf) || showDefaultValueInput.value
}, },
set: (value: boolean) => { set: (value: boolean) => {
showDefaultValueInput.value = value showDefaultValueInput.value = value

2
packages/nc-gui/composables/useData.ts

@ -284,7 +284,7 @@ export function useData(args: {
col.uidt === UITypes.LastModifiedBy || col.uidt === UITypes.LastModifiedBy ||
col.uidt === UITypes.Lookup || col.uidt === UITypes.Lookup ||
col.au || col.au ||
(col.cdf && / on update /i.test(col.cdf))) (isValidValue(col?.cdf) && / on update /i.test(col.cdf)))
) )
acc[col.title!] = updatedRowData[col.title!] acc[col.title!] = updatedRowData[col.title!]
return acc return acc

2
packages/nc-gui/composables/useSharedFormViewStore.ts

@ -116,7 +116,7 @@ const [useProvideSharedFormStore, useSharedFormStore] = useInjectionState((share
!isAttachment(c) && !isAttachment(c) &&
c.uidt !== UITypes.SpecificDBType && c.uidt !== UITypes.SpecificDBType &&
c?.title && c?.title &&
c?.cdf && isValidValue(c?.cdf) &&
!/^\w+\(\)|CURRENT_TIMESTAMP$/.test(c.cdf) !/^\w+\(\)|CURRENT_TIMESTAMP$/.test(c.cdf)
) { ) {
const defaultValue = typeof c.cdf === 'string' ? c.cdf.replace(/^'|'$/g, '') : c.cdf const defaultValue = typeof c.cdf === 'string' ? c.cdf.replace(/^'|'$/g, '') : c.cdf

2
packages/nc-gui/utils/columnUtils.ts

@ -177,7 +177,7 @@ const getUIDTIcon = (uidt: UITypes | string) => {
// 1. column not having default value // 1. column not having default value
// 2. column is not auto increment // 2. column is not auto increment
// 3. column is not auto generated // 3. column is not auto generated
const isColumnRequired = (col?: ColumnType) => col && col.rqd && !col.cdf && !col.ai && !col.meta?.ag const isColumnRequired = (col?: ColumnType) => col && col.rqd && !isValidValue(col?.cdf) && !col.ai && !col.meta?.ag
const isVirtualColRequired = (col: ColumnType, columns: ColumnType[]) => const isVirtualColRequired = (col: ColumnType, columns: ColumnType[]) =>
col.uidt === UITypes.LinkToAnotherRecord && col.uidt === UITypes.LinkToAnotherRecord &&

22
packages/nc-gui/utils/dataUtils.ts

@ -3,6 +3,26 @@ import type { ColumnType, LinkToAnotherRecordType, TableType } from 'nocodb-sdk'
import { isColumnRequiredAndNull } from './columnUtils' import { isColumnRequiredAndNull } from './columnUtils'
import type { Row } from '~/lib/types' import type { Row } from '~/lib/types'
export const isValidValue = (val: unknown) => {
if (val === null || val === undefined) {
return false
}
if (typeof val === 'string' && val === '') {
return false
}
if (Array.isArray(val) && val.length === 0) {
return false
}
if (typeof val === 'object' && !Array.isArray(val) && Object.keys(val).length === 0) {
return false
}
return true
}
export const extractPkFromRow = (row: Record<string, any>, columns: ColumnType[]) => { export const extractPkFromRow = (row: Record<string, any>, columns: ColumnType[]) => {
if (!row || !columns) return null if (!row || !columns) return null
@ -105,7 +125,7 @@ export const rowDefaultData = (columns: ColumnType[] = []) => {
!isSystemColumn(col) && !isSystemColumn(col) &&
!isVirtualCol(col) && !isVirtualCol(col) &&
![UITypes.Rollup, UITypes.Lookup, UITypes.Formula, UITypes.Barcode, UITypes.QrCode].includes(col.uidt) && ![UITypes.Rollup, UITypes.Lookup, UITypes.Formula, UITypes.Barcode, UITypes.QrCode].includes(col.uidt) &&
col?.cdf && isValidValue(col?.cdf) &&
!/^\w+\(\)|CURRENT_TIMESTAMP$/.test(col.cdf) !/^\w+\(\)|CURRENT_TIMESTAMP$/.test(col.cdf)
) { ) {
const defaultValue = col.cdf const defaultValue = col.cdf

Loading…
Cancel
Save