Browse Source

feat(gui): if bt column is required then mark it as required in header

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/3953/head
Pranav C 2 years ago
parent
commit
491f9557a3
  1. 3
      packages/nc-gui/components/smartsheet/header/VirtualCell.vue
  2. 1
      packages/nc-gui/composables/useExpandedFormStore.ts
  3. 7
      packages/nc-gui/composables/useViewData.ts
  4. 14
      packages/nc-gui/utils/columnUtils.ts
  5. 6
      packages/nc-gui/utils/dataUtils.ts

3
packages/nc-gui/components/smartsheet/header/VirtualCell.vue

@ -7,6 +7,7 @@ import {
MetaInj,
computed,
inject,
isVirtualColRequired,
provide,
ref,
toRef,
@ -108,7 +109,7 @@ const tooltipMsg = computed(() => {
<span class="name" style="white-space: nowrap" :title="column.title"> {{ column.title }}</span>
</a-tooltip>
<span v-if="column.rqd || required" class="text-red-500">&nbsp;*</span>
<span v-if="isVirtualColRequired(column, meta.columns) || required" class="text-red-500">&nbsp;*</span>
<template v-if="!hideMenu">
<div class="flex-1" />

1
packages/nc-gui/composables/useExpandedFormStore.ts

@ -147,6 +147,7 @@ const [useProvideExpandedFormStore, useExpandedFormStore] = useInjectionState((m
ltarState,
getMeta,
row: row.value.row,
throwError: true,
})
if (missingRequiredColumns.size) return

7
packages/nc-gui/composables/useViewData.ts

@ -204,7 +204,12 @@ export function useViewData(
try {
const { getMeta } = useMetas()
const { missingRequiredColumns, insertObj } = await populateInsertObject({ meta, ltarState, getMeta, row })
const { missingRequiredColumns, insertObj } = await populateInsertObject({
meta: meta.value!,
ltarState,
getMeta,
row,
})
if (missingRequiredColumns.size) return

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

@ -1,5 +1,5 @@
import type { ColumnType } from 'nocodb-sdk'
import { UITypes } from 'nocodb-sdk'
import type { ColumnType, LinkToAnotherRecordType } from 'nocodb-sdk'
import { RelationTypes, UITypes } from 'nocodb-sdk'
import LinkVariant from '~icons/mdi/link-variant'
import TableColumnPlusBefore from '~icons/mdi/table-column-plus-before'
import FormatColorText from '~icons/mdi/format-color-text'
@ -168,13 +168,17 @@ const getUIDTIcon = (uidt: UITypes | string) => {
).icon
}
const isColumnRequired = (col: ColumnType) => col.rqd && !col.cdf && !col.ai
const isColumnRequired = (col?: ColumnType) => col && col.rqd && !col.cdf && !col.ai
const isVirtualColRequired = (col: ColumnType, columns: ColumnType[]) =>
col.uidt === UITypes.LinkToAnotherRecord &&
(<LinkToAnotherRecordType>col.colOptions).type === RelationTypes.BELONGS_TO &&
isColumnRequired(columns.find((c) => c.id === (<LinkToAnotherRecordType>col.colOptions).fk_child_column_id))
const isColumnRequiredAndNull = (col: ColumnType, row: Record<string, any>) => {
return isColumnRequired(col) && (row[col.title!] === undefined || row[col.title!] === null) // && isVirtualColRequired()
return isColumnRequired(col) && (row[col.title!] === undefined || row[col.title!] === null)
}
export { uiTypes, getUIDTIcon, isColumnRequiredAndNull }
export { uiTypes, getUIDTIcon, isColumnRequiredAndNull, isColumnRequired, isVirtualColRequired }
/**
* @copyright Copyright (c) 2021, Xgene Cloud Ltd

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

@ -17,11 +17,13 @@ export async function populateInsertObject({
row,
meta,
ltarState,
throwError,
}: {
meta: TableType
ltarState: Record<string, any>
getMeta: (tableIdOrTitle: string, force?: boolean) => Promise<TableType | TableInfoType | null>
row: Record<string, any>
throwError?: boolean
}) {
const missingRequiredColumns = new Set()
const insertObj = await meta.columns?.reduce(async (_o: Promise<any>, col) => {
@ -56,5 +58,9 @@ export async function populateInsertObject({
return o
}, Promise.resolve({}))
if (throwError && missingRequiredColumns.size) {
throw new Error(`Missing required columns: ${[...missingRequiredColumns].join(', ')}`)
}
return { missingRequiredColumns, insertObj }
}

Loading…
Cancel
Save