Factor out default value check to shared-core.
This commit is contained in:
parent
63789208b7
commit
700356a1ef
|
@ -19,6 +19,8 @@
|
||||||
helpers,
|
helpers,
|
||||||
PROTECTED_INTERNAL_COLUMNS,
|
PROTECTED_INTERNAL_COLUMNS,
|
||||||
PROTECTED_EXTERNAL_COLUMNS,
|
PROTECTED_EXTERNAL_COLUMNS,
|
||||||
|
canBeDisplayColumn,
|
||||||
|
canHaveDefaultColumn,
|
||||||
} from "@budibase/shared-core"
|
} from "@budibase/shared-core"
|
||||||
import { createEventDispatcher, getContext, onMount } from "svelte"
|
import { createEventDispatcher, getContext, onMount } from "svelte"
|
||||||
import { cloneDeep } from "lodash/fp"
|
import { cloneDeep } from "lodash/fp"
|
||||||
|
@ -164,17 +166,10 @@
|
||||||
: availableAutoColumns
|
: availableAutoColumns
|
||||||
// used to select what different options can be displayed for column type
|
// used to select what different options can be displayed for column type
|
||||||
$: canBeDisplay =
|
$: canBeDisplay =
|
||||||
editableColumn?.type !== LINK_TYPE &&
|
canBeDisplayColumn(editableColumn.type) && !editableColumn.autocolumn
|
||||||
editableColumn?.type !== AUTO_TYPE &&
|
|
||||||
editableColumn?.type !== JSON_TYPE &&
|
|
||||||
!editableColumn.autocolumn
|
|
||||||
$: canHaveDefault =
|
$: canHaveDefault =
|
||||||
isEnabled(TENANT_FEATURE_FLAGS.DEFAULT_VALUES) &&
|
isEnabled(TENANT_FEATURE_FLAGS.DEFAULT_VALUES) &&
|
||||||
(editableColumn?.type === FieldType.NUMBER ||
|
canHaveDefaultColumn(editableColumn.type)
|
||||||
editableColumn?.type === FieldType.JSON ||
|
|
||||||
editableColumn?.type === FieldType.DATETIME ||
|
|
||||||
editableColumn?.type === FieldType.LONGFORM ||
|
|
||||||
editableColumn?.type === FieldType.STRING)
|
|
||||||
$: canBeRequired =
|
$: canBeRequired =
|
||||||
editableColumn?.type !== LINK_TYPE &&
|
editableColumn?.type !== LINK_TYPE &&
|
||||||
!uneditable &&
|
!uneditable &&
|
||||||
|
|
|
@ -11,6 +11,7 @@ const allowDisplayColumnByType: Record<FieldType, boolean> = {
|
||||||
[FieldType.AUTO]: true,
|
[FieldType.AUTO]: true,
|
||||||
[FieldType.INTERNAL]: true,
|
[FieldType.INTERNAL]: true,
|
||||||
[FieldType.BARCODEQR]: true,
|
[FieldType.BARCODEQR]: true,
|
||||||
|
|
||||||
[FieldType.BIGINT]: true,
|
[FieldType.BIGINT]: true,
|
||||||
[FieldType.BOOLEAN]: false,
|
[FieldType.BOOLEAN]: false,
|
||||||
[FieldType.ARRAY]: false,
|
[FieldType.ARRAY]: false,
|
||||||
|
@ -35,6 +36,30 @@ const allowSortColumnByType: Record<FieldType, boolean> = {
|
||||||
[FieldType.BIGINT]: true,
|
[FieldType.BIGINT]: true,
|
||||||
[FieldType.BOOLEAN]: true,
|
[FieldType.BOOLEAN]: true,
|
||||||
[FieldType.JSON]: 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.FORMULA]: false,
|
||||||
[FieldType.ATTACHMENTS]: false,
|
[FieldType.ATTACHMENTS]: false,
|
||||||
[FieldType.ATTACHMENT_SINGLE]: false,
|
[FieldType.ATTACHMENT_SINGLE]: false,
|
||||||
|
@ -53,6 +78,10 @@ export function canBeSortColumn(type: FieldType): boolean {
|
||||||
return !!allowSortColumnByType[type]
|
return !!allowSortColumnByType[type]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function canHaveDefaultColumn(type: FieldType): boolean {
|
||||||
|
return !!allowDefaultColumnByType[type]
|
||||||
|
}
|
||||||
|
|
||||||
export function findDuplicateInternalColumns(table: Table): string[] {
|
export function findDuplicateInternalColumns(table: Table): string[] {
|
||||||
// maintains the case of keys
|
// maintains the case of keys
|
||||||
const casedKeys = Object.keys(table.schema)
|
const casedKeys = Object.keys(table.schema)
|
||||||
|
|
Loading…
Reference in New Issue