From fe15b4d1e3bba9e6ea677803d53b73a9163e241b Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Wed, 4 Oct 2023 13:06:57 +0200 Subject: [PATCH 01/21] Use types --- .../builder/src/constants/backend/index.js | 34 ++++++++++--------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/packages/builder/src/constants/backend/index.js b/packages/builder/src/constants/backend/index.js index 8b76207822..e0c4084814 100644 --- a/packages/builder/src/constants/backend/index.js +++ b/packages/builder/src/constants/backend/index.js @@ -1,7 +1,9 @@ +import { FieldType, FieldSubtype } from "@budibase/types" + export const FIELDS = { STRING: { name: "Text", - type: "string", + type: FieldType.STRING, icon: "Text", constraints: { type: "string", @@ -11,7 +13,7 @@ export const FIELDS = { }, BARCODEQR: { name: "Barcode/QR", - type: "barcodeqr", + type: FieldType.BARCODEQR, icon: "Camera", constraints: { type: "string", @@ -21,7 +23,7 @@ export const FIELDS = { }, LONGFORM: { name: "Long Form Text", - type: "longform", + type: FieldType.LONGFORM, icon: "TextAlignLeft", constraints: { type: "string", @@ -31,7 +33,7 @@ export const FIELDS = { }, OPTIONS: { name: "Options", - type: "options", + type: FieldType.OPTIONS, icon: "Dropdown", constraints: { type: "string", @@ -41,7 +43,7 @@ export const FIELDS = { }, ARRAY: { name: "Multi-select", - type: "array", + type: FieldType.ARRAY, icon: "Duplicate", constraints: { type: "array", @@ -51,7 +53,7 @@ export const FIELDS = { }, NUMBER: { name: "Number", - type: "number", + type: FieldType.NUMBER, icon: "123", constraints: { type: "number", @@ -61,12 +63,12 @@ export const FIELDS = { }, BIGINT: { name: "BigInt", - type: "bigint", + type: FieldType.BIGINT, icon: "TagBold", }, BOOLEAN: { name: "Boolean", - type: "boolean", + type: FieldType.BOOLEAN, icon: "Boolean", constraints: { type: "boolean", @@ -75,7 +77,7 @@ export const FIELDS = { }, DATETIME: { name: "Date/Time", - type: "datetime", + type: FieldType.DATETIME, icon: "Calendar", constraints: { type: "string", @@ -89,7 +91,7 @@ export const FIELDS = { }, ATTACHMENT: { name: "Attachment", - type: "attachment", + type: FieldType.ATTACHMENT, icon: "Folder", constraints: { type: "array", @@ -98,7 +100,7 @@ export const FIELDS = { }, LINK: { name: "Relationship", - type: "link", + type: FieldType.LINK, icon: "Link", constraints: { type: "array", @@ -107,13 +109,13 @@ export const FIELDS = { }, FORMULA: { name: "Formula", - type: "formula", + type: FieldType.FORMULA, icon: "Calculator", constraints: {}, }, JSON: { name: "JSON", - type: "json", + type: FieldType.JSON, icon: "Brackets", constraints: { type: "object", @@ -122,9 +124,9 @@ export const FIELDS = { }, BB_REFERENCE_USER: { name: "User", - type: "bb_reference", - subtype: "user", - compositeType: "bb_reference_user", // Used for working with the subtype on CreateEditColumn as is it was a primary type + type: FieldType.BB_REFERENCE, + subtype: FieldSubtype.USER, + compositeType: `${FieldType.BB_REFERENCE}_${FieldSubtype.USER}`, // Used for working with the subtype on CreateEditColumn as is it was a primary type icon: "User", }, } From d22fac9bf9f08bca6fa5d51c755a51e00b332dcf Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Wed, 4 Oct 2023 13:28:33 +0200 Subject: [PATCH 02/21] Replace relationshipType for subtype --- .../DataTable/modals/CreateEditColumn.svelte | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte b/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte index 8233278e58..5af64d5bd7 100644 --- a/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte +++ b/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte @@ -659,18 +659,16 @@ - {:else if editableColumn.type === USER_REFRENCE_TYPE} - - + /> {/if} {#if editableColumn.type === AUTO_TYPE || editableColumn.autocolumn} field.name} @@ -670,7 +679,7 @@ - {:else if editableColumn.type === USER_REFRENCE_TYPE} + {:else if editableColumn.type === FieldType.BB_REFERENCE && [FieldSubtype.USER, FieldSubtype.USERS].includes(editableColumn.subtype)} diff --git a/packages/builder/src/constants/backend/index.js b/packages/builder/src/constants/backend/index.js index e0c4084814..3718b7f680 100644 --- a/packages/builder/src/constants/backend/index.js +++ b/packages/builder/src/constants/backend/index.js @@ -122,12 +122,19 @@ export const FIELDS = { presence: false, }, }, - BB_REFERENCE_USER: { + USER: { name: "User", type: FieldType.BB_REFERENCE, subtype: FieldSubtype.USER, - compositeType: `${FieldType.BB_REFERENCE}_${FieldSubtype.USER}`, // Used for working with the subtype on CreateEditColumn as is it was a primary type icon: "User", + compositeType: `${FieldType.BB_REFERENCE}_${FieldSubtype.USER}`, // Used for working with the subtype on CreateEditColumn as is it was a primary type + }, + USERS: { + name: "Users", + type: FieldType.BB_REFERENCE, + subtype: FieldSubtype.USERS, + icon: "User", + compositeType: `${FieldType.BB_REFERENCE}_${FieldSubtype.USERS}`, }, } From b19c5ae5c639b326ea0633162ceb5e3b165b0430 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Wed, 4 Oct 2023 14:28:43 +0200 Subject: [PATCH 07/21] Add subtype --- packages/types/src/documents/app/row.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/types/src/documents/app/row.ts b/packages/types/src/documents/app/row.ts index 708cbc3b9e..cce428f48c 100644 --- a/packages/types/src/documents/app/row.ts +++ b/packages/types/src/documents/app/row.ts @@ -37,10 +37,12 @@ export interface Row extends Document { export enum FieldSubtype { USER = "user", + USERS = "users", } export const FieldTypeSubtypes = { BB_REFERENCE: { USER: FieldSubtype.USER, + USESR: FieldSubtype.USERS, }, } From 23702391ffdcd4e58bff7c674a09beb78c1c5b62 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Wed, 4 Oct 2023 14:41:51 +0200 Subject: [PATCH 08/21] Use field ids instead of playing with the type/subtype --- .../DataTable/modals/CreateEditColumn.svelte | 98 ++++++++++--------- 1 file changed, 54 insertions(+), 44 deletions(-) diff --git a/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte b/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte index 90bf0edfce..77eed5bdc6 100644 --- a/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte +++ b/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte @@ -51,13 +51,18 @@ export let field let mounted = false - let fieldDefinitions = Object.entries(FIELDS).reduce( - (acc, [fieldName, field]) => { - acc[field.compositeType?.toUpperCase() || fieldName] = field - return acc - }, - {} - ) + const fieldDefinitions = Object.values(FIELDS).reduce((acc, field) => { + const fieldId = makeFieldId(field) + + acc[fieldId] = { ...field, fieldId } + return acc + }, {}) + + function makeFieldId(field) { + return `${field.type}${field.subtype || ""}`.toUpperCase() + } + + $: console.warn(fieldDefinitions) let originalName let linkEditDisabled @@ -145,9 +150,8 @@ $tables.selected.primaryDisplay == null || $tables.selected.primaryDisplay === editableColumn.name - if (editableColumn.type === FieldType.BB_REFERENCE) { - editableColumn.type = `${editableColumn.type}_${editableColumn.subtype}` - } + editableColumn.fieldId = makeFieldId(editableColumn) + // Here we are setting the relationship values based on the editableColumn // This part of the code is used when viewing an existing field hence the check // for the tableId @@ -176,6 +180,8 @@ } else { editableColumn.name = "Column 01" } + + editableColumn.fieldId = makeFieldId(editableColumn) } allowedTypes = getAllowedTypes() @@ -255,13 +261,7 @@ let saveColumn = cloneDeep(editableColumn) - // Handle types on composite types - const definition = fieldDefinitions[saveColumn.type.toUpperCase()] - if (definition && saveColumn.type === definition.compositeType) { - saveColumn.type = definition.type - saveColumn.subtype = definition.subtype - delete saveColumn.compositeType - } + delete saveColumn.fieldId if (saveColumn.type === AUTO_TYPE) { saveColumn = buildAutoColumn( @@ -390,38 +390,48 @@ if (!external) { return [ - FIELDS.STRING, - FIELDS.BARCODEQR, - FIELDS.LONGFORM, - FIELDS.OPTIONS, - FIELDS.ARRAY, - FIELDS.NUMBER, - FIELDS.BIGINT, - FIELDS.BOOLEAN, - FIELDS.DATETIME, - FIELDS.ATTACHMENT, - FIELDS.LINK, - FIELDS.FORMULA, - FIELDS.JSON, - FIELDS.USER, + fieldDefinitions.STRING, + fieldDefinitions.BARCODEQR, + fieldDefinitions.LONGFORM, + fieldDefinitions.OPTIONS, + fieldDefinitions.ARRAY, + fieldDefinitions.NUMBER, + fieldDefinitions.BIGINT, + fieldDefinitions.BOOLEAN, + fieldDefinitions.DATETIME, + fieldDefinitions.ATTACHMENT, + fieldDefinitions.LINK, + fieldDefinitions.FORMULA, + fieldDefinitions.JSON, + fieldDefinitions[ + makeFieldId({ + type: FieldType.BB_REFERENCE, + subtype: FieldSubtype.USER, + }) + ], { name: "Auto Column", type: AUTO_TYPE }, ] } else { let fields = [ - FIELDS.STRING, - FIELDS.BARCODEQR, - FIELDS.LONGFORM, - FIELDS.OPTIONS, - FIELDS.DATETIME, - FIELDS.NUMBER, - FIELDS.BOOLEAN, - FIELDS.FORMULA, - FIELDS.BIGINT, - FIELDS.BB_REFERENCE_USER, + fieldDefinitions.STRING, + fieldDefinitions.BARCODEQR, + fieldDefinitions.LONGFORM, + fieldDefinitions.OPTIONS, + fieldDefinitions.DATETIME, + fieldDefinitions.NUMBER, + fieldDefinitions.BOOLEAN, + fieldDefinitions.FORMULA, + fieldDefinitions.BIGINT, + fieldDefinitions[ + getFieldId({ + type: FieldType.BB_REFERENCE, + subtype: FieldSubtype.USER, + }) + ], ] // no-sql or a spreadsheet if (!external || table.sql) { - fields = [...fields, FIELDS.LINK, FIELDS.ARRAY] + fields = [...fields, fieldDefinitions.LINK, fieldDefinitions.ARRAY] } return fields } @@ -509,11 +519,11 @@ {/if} field.name} getOptionValue={field => field.fieldId} @@ -693,9 +700,12 @@ - (editableColumn.subtype = e.detail - ? FieldSubtype.USERS - : FieldSubtype.USER)} + handleTypeChange( + makeFieldId( + FieldType.BB_REFERENCE, + e.detail ? FieldSubtype.USERS : FieldSubtype.USER + ) + )} disabled={!isCreating} thin text="Allow multiple users" From 583721ac477d78e0098a0449a8bfbc3926c4938d Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Wed, 4 Oct 2023 14:49:34 +0200 Subject: [PATCH 10/21] Remove composite types --- packages/builder/src/constants/backend/index.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/builder/src/constants/backend/index.js b/packages/builder/src/constants/backend/index.js index 3718b7f680..0da50aac49 100644 --- a/packages/builder/src/constants/backend/index.js +++ b/packages/builder/src/constants/backend/index.js @@ -127,14 +127,12 @@ export const FIELDS = { type: FieldType.BB_REFERENCE, subtype: FieldSubtype.USER, icon: "User", - compositeType: `${FieldType.BB_REFERENCE}_${FieldSubtype.USER}`, // Used for working with the subtype on CreateEditColumn as is it was a primary type }, USERS: { name: "Users", type: FieldType.BB_REFERENCE, subtype: FieldSubtype.USERS, icon: "User", - compositeType: `${FieldType.BB_REFERENCE}_${FieldSubtype.USERS}`, }, } From 6d5e95af6e74950a76bfb43570c36cad3459e112 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Wed, 4 Oct 2023 14:58:34 +0200 Subject: [PATCH 11/21] Add icons --- packages/frontend-core/src/components/grid/lib/utils.js | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/frontend-core/src/components/grid/lib/utils.js b/packages/frontend-core/src/components/grid/lib/utils.js index 9383f69f66..22740c779d 100644 --- a/packages/frontend-core/src/components/grid/lib/utils.js +++ b/packages/frontend-core/src/components/grid/lib/utils.js @@ -21,6 +21,7 @@ const TypeIconMap = { bigint: "TagBold", bb_reference: { user: "User", + users: "UserGroup", }, } From 9b45c1fe9257a817a35ca33cd7228c7f35c363eb Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Wed, 4 Oct 2023 16:14:17 +0200 Subject: [PATCH 12/21] Fix wrong constraints --- .../DataTable/modals/CreateEditColumn.svelte | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte b/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte index 12a693efab..09e6ff80ec 100644 --- a/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte +++ b/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte @@ -62,8 +62,6 @@ return `${type}${subtype || ""}`.toUpperCase() } - $: console.warn(fieldDefinitions) - let originalName let linkEditDisabled let primaryDisplay @@ -343,6 +341,7 @@ delete editableColumn.tableId delete editableColumn.relationshipType delete editableColumn.formulaType + delete editableColumn.constraints // Add in defaults and initial definition const definition = fieldDefinitions[type?.toUpperCase()] @@ -398,6 +397,16 @@ return ALLOWABLE_NUMBER_OPTIONS } + const userFieldDefinition = + fieldDefinitions[ + makeFieldId( + FieldType.BB_REFERENCE, + editableColumn.type === FieldType.BB_REFERENCE + ? editableColumn.subtype + : FieldSubtype.USER + ) + ] + if (!external) { return [ fieldDefinitions.STRING, @@ -413,9 +422,7 @@ fieldDefinitions.LINK, fieldDefinitions.FORMULA, fieldDefinitions.JSON, - fieldDefinitions[ - makeFieldId(FieldType.BB_REFERENCE, FieldSubtype.USER) - ], + userFieldDefinition, { name: "Auto Column", type: AUTO_TYPE }, ] } else { @@ -429,12 +436,7 @@ fieldDefinitions.BOOLEAN, fieldDefinitions.FORMULA, fieldDefinitions.BIGINT, - fieldDefinitions[ - getFieldId({ - type: FieldType.BB_REFERENCE, - subtype: FieldSubtype.USER, - }) - ], + userFieldDefinition, ] // no-sql or a spreadsheet if (!external || table.sql) { From 753cb442c27172f15f6b015a7cf3f5c1570579d4 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Wed, 4 Oct 2023 16:14:28 +0200 Subject: [PATCH 13/21] Allow edit --- .../src/components/grid/cells/BBReferenceCell.svelte | 8 ++++++-- .../src/utilities/rowProcessor/bbReferenceProcessor.ts | 6 +++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/packages/frontend-core/src/components/grid/cells/BBReferenceCell.svelte b/packages/frontend-core/src/components/grid/cells/BBReferenceCell.svelte index b4168474b0..4e76c264a1 100644 --- a/packages/frontend-core/src/components/grid/cells/BBReferenceCell.svelte +++ b/packages/frontend-core/src/components/grid/cells/BBReferenceCell.svelte @@ -1,7 +1,7 @@