diff --git a/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte b/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte index 06c47f94af..98243c6e2f 100644 --- a/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte +++ b/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte @@ -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 && diff --git a/packages/shared-core/src/table.ts b/packages/shared-core/src/table.ts index 9e7626cb1c..8a8069ce4d 100644 --- a/packages/shared-core/src/table.ts +++ b/packages/shared-core/src/table.ts @@ -11,6 +11,7 @@ const allowDisplayColumnByType: Record = { [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.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.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)