From aaaf1732954fdd3dee5ade7a255bed4b88c02d50 Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Wed, 17 Jul 2024 11:02:47 +0100 Subject: [PATCH] Initial UI. --- .../DataTable/modals/CreateEditColumn.svelte | 45 +++++++++++++++++-- .../types/src/documents/app/table/schema.ts | 1 - 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte b/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte index a9ea90242a..6f657f57d6 100644 --- a/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte +++ b/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte @@ -133,7 +133,9 @@ } $: initialiseField(field, savingColumn) $: checkConstraints(editableColumn) - $: required = !!editableColumn?.constraints?.presence || primaryDisplay + $: required = hasDefault + ? false + : !!editableColumn?.constraints?.presence || primaryDisplay $: uneditable = $tables.selected?._id === TableNames.USERS && UNEDITABLE_USER_FIELDS.includes(editableColumn.name) @@ -165,11 +167,19 @@ editableColumn?.type !== AUTO_TYPE && editableColumn?.type !== JSON_TYPE && !editableColumn.autocolumn + $: canHaveDefault = + editableColumn?.type === FieldType.NUMBER || + editableColumn?.type === FieldType.JSON || + editableColumn?.type === FieldType.DATETIME || + editableColumn?.type === FieldType.LONGFORM || + editableColumn?.type === FieldType.STRING $: canBeRequired = editableColumn?.type !== LINK_TYPE && !uneditable && editableColumn?.type !== AUTO_TYPE && !editableColumn.autocolumn + $: hasDefault = + editableColumn?.default != null && editableColumn?.default !== "" $: externalTable = table.sourceType === DB_TYPE_EXTERNAL // in the case of internal tables the sourceId will just be undefined $: tableOptions = $tables.list.filter( @@ -349,12 +359,15 @@ } } - function onChangeRequired(e) { - const req = e.detail + function setRequired(req) { editableColumn.constraints.presence = req ? { allowEmpty: false } : false required = req } + function onChangeRequired(e) { + setRequired(e.detail) + } + function openJsonSchemaEditor() { jsonSchemaModal.show() } @@ -748,13 +761,37 @@ {/if} {/if} + + {#if canHaveDefault} +
+ { + editableColumn = { + ...editableColumn, + default: e.detail, + } + + if (e.detail) { + setRequired(false) + } + }} + bindings={getBindings({ table })} + allowJS + context={rowGoldenSample} + /> +
+ {/if}
diff --git a/packages/types/src/documents/app/table/schema.ts b/packages/types/src/documents/app/table/schema.ts index 7b89b610be..6078f73d1d 100644 --- a/packages/types/src/documents/app/table/schema.ts +++ b/packages/types/src/documents/app/table/schema.ts @@ -114,7 +114,6 @@ export interface FormulaFieldMetadata extends BaseFieldSchema { type: FieldType.FORMULA formula: string formulaType?: FormulaType - default?: string } export interface BBReferenceFieldMetadata