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, MetaInj,
computed, computed,
inject, inject,
isVirtualColRequired,
provide, provide,
ref, ref,
toRef, toRef,
@ -108,7 +109,7 @@ const tooltipMsg = computed(() => {
<span class="name" style="white-space: nowrap" :title="column.title"> {{ column.title }}</span> <span class="name" style="white-space: nowrap" :title="column.title"> {{ column.title }}</span>
</a-tooltip> </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"> <template v-if="!hideMenu">
<div class="flex-1" /> <div class="flex-1" />

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

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

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

@ -204,7 +204,12 @@ export function useViewData(
try { try {
const { getMeta } = useMetas() 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 if (missingRequiredColumns.size) return

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

@ -1,5 +1,5 @@
import type { ColumnType } from 'nocodb-sdk' import type { ColumnType, LinkToAnotherRecordType } from 'nocodb-sdk'
import { UITypes } from 'nocodb-sdk' import { RelationTypes, UITypes } from 'nocodb-sdk'
import LinkVariant from '~icons/mdi/link-variant' import LinkVariant from '~icons/mdi/link-variant'
import TableColumnPlusBefore from '~icons/mdi/table-column-plus-before' import TableColumnPlusBefore from '~icons/mdi/table-column-plus-before'
import FormatColorText from '~icons/mdi/format-color-text' import FormatColorText from '~icons/mdi/format-color-text'
@ -168,13 +168,17 @@ const getUIDTIcon = (uidt: UITypes | string) => {
).icon ).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>) => { 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 * @copyright Copyright (c) 2021, Xgene Cloud Ltd

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

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

Loading…
Cancel
Save