Factor out default value check to shared-core.

This commit is contained in:
Sam Rose 2024-08-12 11:08:58 +01:00
parent 63789208b7
commit 700356a1ef
No known key found for this signature in database
2 changed files with 33 additions and 9 deletions

View File

@ -19,6 +19,8 @@
helpers,
PROTECTED_INTERNAL_COLUMNS,
PROTECTED_EXTERNAL_COLUMNS,
canBeDisplayColumn,
canHaveDefaultColumn,
} from "@budibase/shared-core"
import { createEventDispatcher, getContext, onMount } from "svelte"
import { cloneDeep } from "lodash/fp"
@ -164,17 +166,10 @@
: availableAutoColumns
// used to select what different options can be displayed for column type
$: canBeDisplay =
editableColumn?.type !== LINK_TYPE &&
editableColumn?.type !== AUTO_TYPE &&
editableColumn?.type !== JSON_TYPE &&
!editableColumn.autocolumn
canBeDisplayColumn(editableColumn.type) && !editableColumn.autocolumn
$: canHaveDefault =
isEnabled(TENANT_FEATURE_FLAGS.DEFAULT_VALUES) &&
(editableColumn?.type === FieldType.NUMBER ||
editableColumn?.type === FieldType.JSON ||
editableColumn?.type === FieldType.DATETIME ||
editableColumn?.type === FieldType.LONGFORM ||
editableColumn?.type === FieldType.STRING)
canHaveDefaultColumn(editableColumn.type)
$: canBeRequired =
editableColumn?.type !== LINK_TYPE &&
!uneditable &&

View File

@ -11,6 +11,7 @@ const allowDisplayColumnByType: Record<FieldType, boolean> = {
[FieldType.AUTO]: true,
[FieldType.INTERNAL]: true,
[FieldType.BARCODEQR]: true,
[FieldType.BIGINT]: true,
[FieldType.BOOLEAN]: false,
[FieldType.ARRAY]: false,
@ -35,6 +36,30 @@ const allowSortColumnByType: Record<FieldType, boolean> = {
[FieldType.BIGINT]: true,
[FieldType.BOOLEAN]: true,
[FieldType.JSON]: true,
[FieldType.FORMULA]: false,
[FieldType.ATTACHMENTS]: false,
[FieldType.ATTACHMENT_SINGLE]: false,
[FieldType.SIGNATURE_SINGLE]: false,
[FieldType.ARRAY]: false,
[FieldType.LINK]: false,
[FieldType.BB_REFERENCE]: false,
[FieldType.BB_REFERENCE_SINGLE]: false,
}
const allowDefaultColumnByType: Record<FieldType, boolean> = {
[FieldType.NUMBER]: true,
[FieldType.JSON]: true,
[FieldType.DATETIME]: true,
[FieldType.LONGFORM]: true,
[FieldType.STRING]: true,
[FieldType.OPTIONS]: false,
[FieldType.AUTO]: false,
[FieldType.INTERNAL]: false,
[FieldType.BARCODEQR]: false,
[FieldType.BIGINT]: false,
[FieldType.BOOLEAN]: false,
[FieldType.FORMULA]: false,
[FieldType.ATTACHMENTS]: false,
[FieldType.ATTACHMENT_SINGLE]: false,
@ -53,6 +78,10 @@ export function canBeSortColumn(type: FieldType): boolean {
return !!allowSortColumnByType[type]
}
export function canHaveDefaultColumn(type: FieldType): boolean {
return !!allowDefaultColumnByType[type]
}
export function findDuplicateInternalColumns(table: Table): string[] {
// maintains the case of keys
const casedKeys = Object.keys(table.schema)