From 09280166c736ae8315ac761cc03a3cbf94c036e1 Mon Sep 17 00:00:00 2001 From: Dean Date: Tue, 26 Sep 2023 15:15:30 +0100 Subject: [PATCH 001/111] Added comment updates to reflect new naming behaviour --- packages/builder/src/helpers/duplicate.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/builder/src/helpers/duplicate.js b/packages/builder/src/helpers/duplicate.js index e84a600138..1547fcd4d1 100644 --- a/packages/builder/src/helpers/duplicate.js +++ b/packages/builder/src/helpers/duplicate.js @@ -3,16 +3,17 @@ * e.g. * name all names result * ------ ----------- -------- - * ("foo") ["foo"] "foo (1)" - * ("foo") ["foo", "foo (1)"] "foo (2)" - * ("foo (1)") ["foo", "foo (1)"] "foo (2)" - * ("foo") ["foo", "foo (2)"] "foo (1)" + * ("foo") ["foo"] "foo 1" + * ("foo") ["foo", "foo 1"] "foo 2" + * ("foo 1") ["foo", "foo 1"] "foo 2" + * ("foo") ["foo", "foo 2"] "foo 1" * * Repl */ export const duplicateName = (name, allNames) => { - const baseName = name.split(" (")[0] - const isDuplicate = new RegExp(`${baseName}\\s\\((\\d+)\\)$`) + const duplicatePattern = new RegExp(`\\s(\\d+)$`) + const baseName = name.split(duplicatePattern)[0] + const isDuplicate = new RegExp(`${baseName}\\s(\\d+)$`) // get the sequence from matched names const sequence = [] @@ -28,7 +29,6 @@ export const duplicateName = (name, allNames) => { return false }) sequence.sort((a, b) => a - b) - // get the next number in the sequence let number if (sequence.length === 0) { @@ -46,5 +46,5 @@ export const duplicateName = (name, allNames) => { } } - return `${baseName} (${number})` + return `${baseName} ${number}` } From e73ddef040847f45df09a607e3e251562c56908b Mon Sep 17 00:00:00 2001 From: Dean Date: Tue, 26 Sep 2023 15:29:40 +0100 Subject: [PATCH 002/111] Updated UI tests --- .../builder/src/helpers/tests/duplicate.test.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/builder/src/helpers/tests/duplicate.test.js b/packages/builder/src/helpers/tests/duplicate.test.js index a571054e0c..400abed0aa 100644 --- a/packages/builder/src/helpers/tests/duplicate.test.js +++ b/packages/builder/src/helpers/tests/duplicate.test.js @@ -9,34 +9,34 @@ describe("duplicate", () => { const duplicate = duplicateName(name, names) - expect(duplicate).toBe("foo (1)") + expect(duplicate).toBe("foo 1") }) it("with multiple existing", async () => { - const names = ["foo", "foo (1)", "foo (2)"] + const names = ["foo", "foo 1", "foo 2"] const name = "foo" const duplicate = duplicateName(name, names) - expect(duplicate).toBe("foo (3)") + expect(duplicate).toBe("foo 3") }) it("with mixed multiple existing", async () => { - const names = ["foo", "foo (1)", "foo (2)", "bar", "bar (1)", "bar (2)"] + const names = ["foo", "foo 1", "foo 2", "bar", "bar 1", "bar 2"] const name = "foo" const duplicate = duplicateName(name, names) - expect(duplicate).toBe("foo (3)") + expect(duplicate).toBe("foo 3") }) it("with incomplete sequence", async () => { - const names = ["foo", "foo (2)", "foo (3)"] + const names = ["foo", "foo 2", "foo 3"] const name = "foo" const duplicate = duplicateName(name, names) - expect(duplicate).toBe("foo (1)") + expect(duplicate).toBe("foo 1") }) }) }) From fe15b4d1e3bba9e6ea677803d53b73a9163e241b Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Wed, 4 Oct 2023 13:06:57 +0200 Subject: [PATCH 003/111] 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 004/111] 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 009/111] 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 010/111] 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 012/111] 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 013/111] 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 014/111] 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 015/111] 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 @@ @@ -231,8 +246,7 @@ Use as display column From 0909e0547ea882e68577d61db57b34ed0651af83 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Mon, 9 Oct 2023 15:28:27 +0200 Subject: [PATCH 027/111] Process formulas after processing complex fields --- packages/server/src/utilities/rowProcessor/index.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/server/src/utilities/rowProcessor/index.ts b/packages/server/src/utilities/rowProcessor/index.ts index 0bdaaa393e..298cc42f7b 100644 --- a/packages/server/src/utilities/rowProcessor/index.ts +++ b/packages/server/src/utilities/rowProcessor/index.ts @@ -219,9 +219,6 @@ export async function outputProcessing( ? await linkRows.attachFullLinkedDocs(table, safeRows) : safeRows - // process formulas - enriched = processFormulas(table, enriched, { dynamic: true }) as Row[] - // set the attachments URLs for (let [property, column] of Object.entries(table.schema)) { if (column.type === FieldTypes.ATTACHMENT) { @@ -242,6 +239,10 @@ export async function outputProcessing( } } } + + // process formulas + enriched = processFormulas(table, enriched, { dynamic: true }) as Row[] + if (opts.squash) { enriched = (await linkRows.squashLinksToPrimaryDisplay( table, From 6f77be622f6bb19f14243ba3339f06ec99acbebc Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Mon, 9 Oct 2023 15:36:17 +0200 Subject: [PATCH 028/111] Simplify --- .../components/grid/cells/HeaderCell.svelte | 36 +++++++------------ 1 file changed, 12 insertions(+), 24 deletions(-) diff --git a/packages/frontend-core/src/components/grid/cells/HeaderCell.svelte b/packages/frontend-core/src/components/grid/cells/HeaderCell.svelte index 18b014131b..9f58dc9f9f 100644 --- a/packages/frontend-core/src/components/grid/cells/HeaderCell.svelte +++ b/packages/frontend-core/src/components/grid/cells/HeaderCell.svelte @@ -1,6 +1,6 @@ @@ -246,7 +233,8 @@ Use as display column From 7d6cd53c2960dcb60d8ae66480cc36be35b69fff Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Mon, 9 Oct 2023 15:37:42 +0200 Subject: [PATCH 029/111] Add comments --- packages/server/src/utilities/rowProcessor/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/server/src/utilities/rowProcessor/index.ts b/packages/server/src/utilities/rowProcessor/index.ts index 298cc42f7b..d6aa5e682a 100644 --- a/packages/server/src/utilities/rowProcessor/index.ts +++ b/packages/server/src/utilities/rowProcessor/index.ts @@ -219,7 +219,7 @@ export async function outputProcessing( ? await linkRows.attachFullLinkedDocs(table, safeRows) : safeRows - // set the attachments URLs + // process complex types: attachements, bb references... for (let [property, column] of Object.entries(table.schema)) { if (column.type === FieldTypes.ATTACHMENT) { for (let row of enriched) { @@ -240,7 +240,7 @@ export async function outputProcessing( } } - // process formulas + // process formulas after the complex types had been processed enriched = processFormulas(table, enriched, { dynamic: true }) as Row[] if (opts.squash) { From c87a67a37a4c5c2a95d319ed2ff1b0becb5cf4bd Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Mon, 9 Oct 2023 18:18:34 +0100 Subject: [PATCH 030/111] Converting user IDs where necessary to global user IDs in the frontend, correcting the null entry when using current user IDs, or other user IDs, as a default value for a user column form type. --- packages/backend-core/src/constants/db.ts | 11 ++++++----- .../app/forms/BBReferenceField.svelte | 8 ++++++++ .../app/forms/RelationshipField.svelte | 9 +++++++-- .../shared-core/src/sdk/documents/users.ts | 19 ++++++++++++++++++- packages/types/src/documents/document.ts | 4 ++++ 5 files changed, 43 insertions(+), 8 deletions(-) diff --git a/packages/backend-core/src/constants/db.ts b/packages/backend-core/src/constants/db.ts index f918dcc352..b33b4835a9 100644 --- a/packages/backend-core/src/constants/db.ts +++ b/packages/backend-core/src/constants/db.ts @@ -1,5 +1,10 @@ import { prefixed, DocumentType } from "@budibase/types" -export { SEPARATOR, UNICODE_MAX, DocumentType } from "@budibase/types" +export { + SEPARATOR, + UNICODE_MAX, + DocumentType, + InternalTable, +} from "@budibase/types" /** * Can be used to create a few different forms of querying a view. @@ -30,10 +35,6 @@ export const DeprecatedViews = { ], } -export enum InternalTable { - USER_METADATA = "ta_users", -} - export const StaticDatabases = { GLOBAL: { name: "global-db", diff --git a/packages/client/src/components/app/forms/BBReferenceField.svelte b/packages/client/src/components/app/forms/BBReferenceField.svelte index 7d11ff5525..4573452973 100644 --- a/packages/client/src/components/app/forms/BBReferenceField.svelte +++ b/packages/client/src/components/app/forms/BBReferenceField.svelte @@ -1,9 +1,17 @@ { + if (Array.isArray(value)) { + return value.map(val => sdk.users.getGlobalUserID(val)) + } else { + return sdk.users.getGlobalUserID(value) + } + }} /> diff --git a/packages/client/src/components/app/forms/RelationshipField.svelte b/packages/client/src/components/app/forms/RelationshipField.svelte index bb003730b3..c114a51f87 100644 --- a/packages/client/src/components/app/forms/RelationshipField.svelte +++ b/packages/client/src/components/app/forms/RelationshipField.svelte @@ -18,6 +18,7 @@ export let filter export let datasourceType = "table" export let primaryDisplay + export let valueConversion let fieldState let fieldApi @@ -160,7 +161,9 @@ const handleChange = value => { const changed = fieldApi.setValue(value) if (onChange && changed) { - onChange({ value }) + onChange({ + value: valueConversion ? valueConversion(value) : value, + }) } } @@ -176,7 +179,9 @@ {field} {disabled} {validation} - defaultValue={expandedDefaultValue} + defaultValue={valueConversion + ? valueConversion(expandedDefaultValue) + : expandedDefaultValue} {type} bind:fieldState bind:fieldApi diff --git a/packages/shared-core/src/sdk/documents/users.ts b/packages/shared-core/src/sdk/documents/users.ts index 1be8845656..cb171cfd5b 100644 --- a/packages/shared-core/src/sdk/documents/users.ts +++ b/packages/shared-core/src/sdk/documents/users.ts @@ -1,4 +1,10 @@ -import { ContextUser, User } from "@budibase/types" +import { + ContextUser, + DocumentType, + SEPARATOR, + User, + InternalTable, +} from "@budibase/types" import { getProdAppID } from "./applications" // checks if a user is specifically a builder, given an app ID @@ -67,3 +73,14 @@ export function hasAdminPermissions(user?: User | ContextUser): boolean { } return !!user.admin?.global } + +export function getGlobalUserID(userId?: string): string | undefined { + if (typeof userId !== "string") { + return userId + } + const prefix = `${DocumentType.ROW}${SEPARATOR}${InternalTable.USER_METADATA}${SEPARATOR}` + if (!userId.startsWith(prefix)) { + return userId + } + return userId.split(prefix)[1] +} diff --git a/packages/types/src/documents/document.ts b/packages/types/src/documents/document.ts index 763da62d61..fb9589b24d 100644 --- a/packages/types/src/documents/document.ts +++ b/packages/types/src/documents/document.ts @@ -58,6 +58,10 @@ export const DocumentTypesToImport: DocumentType[] = [ DocumentType.LAYOUT, ] +export enum InternalTable { + USER_METADATA = "ta_users", +} + // these documents don't really exist, they are part of other // documents or enriched into existence as part of get requests export enum VirtualDocumentType { From 635f33f81e6a4a837a6a7c193fc2506df72de784 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Mon, 9 Oct 2023 18:28:09 +0100 Subject: [PATCH 031/111] Make sure that external tables preserve the BB_REFERNECE type, under the hood it is text/array, but it should continue to be treated correctly as its own indpendent type when updating Budibase tables (fetching). --- packages/server/src/integrations/utils.ts | 104 ++++++++++++---------- 1 file changed, 55 insertions(+), 49 deletions(-) diff --git a/packages/server/src/integrations/utils.ts b/packages/server/src/integrations/utils.ts index b6b6f60fee..db562473e3 100644 --- a/packages/server/src/integrations/utils.ts +++ b/packages/server/src/integrations/utils.ts @@ -1,7 +1,12 @@ -import { SqlQuery, Table, SearchFilters, Datasource } from "@budibase/types" +import { + SqlQuery, + Table, + SearchFilters, + Datasource, + FieldType, +} from "@budibase/types" import { DocumentType, SEPARATOR } from "../db/utils" import { - FieldTypes, BuildSchemaErrors, InvalidColumns, NoEmptyFilterStrings, @@ -13,57 +18,57 @@ const ROW_ID_REGEX = /^\[.*]$/g const ENCODED_SPACE = encodeURIComponent(" ") const SQL_NUMBER_TYPE_MAP = { - integer: FieldTypes.NUMBER, - int: FieldTypes.NUMBER, - decimal: FieldTypes.NUMBER, - smallint: FieldTypes.NUMBER, - real: FieldTypes.NUMBER, - float: FieldTypes.NUMBER, - numeric: FieldTypes.NUMBER, - mediumint: FieldTypes.NUMBER, - dec: FieldTypes.NUMBER, - double: FieldTypes.NUMBER, - fixed: FieldTypes.NUMBER, - "double precision": FieldTypes.NUMBER, - number: FieldTypes.NUMBER, - binary_float: FieldTypes.NUMBER, - binary_double: FieldTypes.NUMBER, - money: FieldTypes.NUMBER, - smallmoney: FieldTypes.NUMBER, + integer: FieldType.NUMBER, + int: FieldType.NUMBER, + decimal: FieldType.NUMBER, + smallint: FieldType.NUMBER, + real: FieldType.NUMBER, + float: FieldType.NUMBER, + numeric: FieldType.NUMBER, + mediumint: FieldType.NUMBER, + dec: FieldType.NUMBER, + double: FieldType.NUMBER, + fixed: FieldType.NUMBER, + "double precision": FieldType.NUMBER, + number: FieldType.NUMBER, + binary_float: FieldType.NUMBER, + binary_double: FieldType.NUMBER, + money: FieldType.NUMBER, + smallmoney: FieldType.NUMBER, } const SQL_DATE_TYPE_MAP = { - timestamp: FieldTypes.DATETIME, - time: FieldTypes.DATETIME, - datetime: FieldTypes.DATETIME, - smalldatetime: FieldTypes.DATETIME, - date: FieldTypes.DATETIME, + timestamp: FieldType.DATETIME, + time: FieldType.DATETIME, + datetime: FieldType.DATETIME, + smalldatetime: FieldType.DATETIME, + date: FieldType.DATETIME, } const SQL_DATE_ONLY_TYPES = ["date"] const SQL_TIME_ONLY_TYPES = ["time"] const SQL_STRING_TYPE_MAP = { - varchar: FieldTypes.STRING, - char: FieldTypes.STRING, - nchar: FieldTypes.STRING, - nvarchar: FieldTypes.STRING, - ntext: FieldTypes.STRING, - enum: FieldTypes.STRING, - blob: FieldTypes.STRING, - long: FieldTypes.STRING, - text: FieldTypes.STRING, + varchar: FieldType.STRING, + char: FieldType.STRING, + nchar: FieldType.STRING, + nvarchar: FieldType.STRING, + ntext: FieldType.STRING, + enum: FieldType.STRING, + blob: FieldType.STRING, + long: FieldType.STRING, + text: FieldType.STRING, } const SQL_BOOLEAN_TYPE_MAP = { - boolean: FieldTypes.BOOLEAN, - bit: FieldTypes.BOOLEAN, - tinyint: FieldTypes.BOOLEAN, + boolean: FieldType.BOOLEAN, + bit: FieldType.BOOLEAN, + tinyint: FieldType.BOOLEAN, } const SQL_MISC_TYPE_MAP = { - json: FieldTypes.JSON, - bigint: FieldTypes.BIGINT, + json: FieldType.JSON, + bigint: FieldType.BIGINT, } const SQL_TYPE_MAP = { @@ -154,7 +159,7 @@ export function breakRowIdField(_id: string | { _id: string }): any[] { } export function convertSqlType(type: string) { - let foundType = FieldTypes.STRING + let foundType = FieldType.STRING const lcType = type.toLowerCase() let matchingTypes = [] for (let [external, internal] of Object.entries(SQL_TYPE_MAP)) { @@ -169,7 +174,7 @@ export function convertSqlType(type: string) { }).internal } const schema: any = { type: foundType } - if (foundType === FieldTypes.DATETIME) { + if (foundType === FieldType.DATETIME) { schema.dateOnly = SQL_DATE_ONLY_TYPES.includes(lcType) schema.timeOnly = SQL_TIME_ONLY_TYPES.includes(lcType) } @@ -212,7 +217,7 @@ export function shouldCopyRelationship( tableIds: string[] ) { return ( - column.type === FieldTypes.LINK && + column.type === FieldType.LINK && column.tableId && tableIds.includes(column.tableId) ) @@ -230,22 +235,23 @@ export function shouldCopySpecialColumn( column: { type: string }, fetchedColumn: { type: string } | undefined ) { - const isFormula = column.type === FieldTypes.FORMULA + const isFormula = column.type === FieldType.FORMULA const specialTypes = [ - FieldTypes.OPTIONS, - FieldTypes.LONGFORM, - FieldTypes.ARRAY, - FieldTypes.FORMULA, + FieldType.OPTIONS, + FieldType.LONGFORM, + FieldType.ARRAY, + FieldType.FORMULA, + FieldType.BB_REFERENCE, ] // column has been deleted, remove - formulas will never exist, always copy if (!isFormula && column && !fetchedColumn) { return false } const fetchedIsNumber = - !fetchedColumn || fetchedColumn.type === FieldTypes.NUMBER + !fetchedColumn || fetchedColumn.type === FieldType.NUMBER return ( - specialTypes.indexOf(column.type as FieldTypes) !== -1 || - (fetchedIsNumber && column.type === FieldTypes.BOOLEAN) + specialTypes.indexOf(column.type as FieldType) !== -1 || + (fetchedIsNumber && column.type === FieldType.BOOLEAN) ) } From 95caee66a75f0d3b7d6596feee4b2d6df0948315 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Tue, 10 Oct 2023 11:22:59 +0100 Subject: [PATCH 032/111] PR comments. --- .../app/forms/BBReferenceField.svelte | 26 ++++++++++++++----- .../app/forms/RelationshipField.svelte | 7 ++--- .../shared-core/src/sdk/documents/users.ts | 7 +++++ 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/packages/client/src/components/app/forms/BBReferenceField.svelte b/packages/client/src/components/app/forms/BBReferenceField.svelte index 4573452973..f93c955be2 100644 --- a/packages/client/src/components/app/forms/BBReferenceField.svelte +++ b/packages/client/src/components/app/forms/BBReferenceField.svelte @@ -1,17 +1,31 @@ { - if (Array.isArray(value)) { - return value.map(val => sdk.users.getGlobalUserID(val)) - } else { - return sdk.users.getGlobalUserID(value) - } + defaultValue={updateReferences(defaultValue)} + onChange={value => { + return updateReferences(value) }} /> diff --git a/packages/client/src/components/app/forms/RelationshipField.svelte b/packages/client/src/components/app/forms/RelationshipField.svelte index c114a51f87..52faf46615 100644 --- a/packages/client/src/components/app/forms/RelationshipField.svelte +++ b/packages/client/src/components/app/forms/RelationshipField.svelte @@ -18,7 +18,6 @@ export let filter export let datasourceType = "table" export let primaryDisplay - export let valueConversion let fieldState let fieldApi @@ -162,7 +161,7 @@ const changed = fieldApi.setValue(value) if (onChange && changed) { onChange({ - value: valueConversion ? valueConversion(value) : value, + value, }) } } @@ -179,9 +178,7 @@ {field} {disabled} {validation} - defaultValue={valueConversion - ? valueConversion(expandedDefaultValue) - : expandedDefaultValue} + defaultValue={expandedDefaultValue} {type} bind:fieldState bind:fieldApi diff --git a/packages/shared-core/src/sdk/documents/users.ts b/packages/shared-core/src/sdk/documents/users.ts index cb171cfd5b..03d86daa85 100644 --- a/packages/shared-core/src/sdk/documents/users.ts +++ b/packages/shared-core/src/sdk/documents/users.ts @@ -84,3 +84,10 @@ export function getGlobalUserID(userId?: string): string | undefined { } return userId.split(prefix)[1] } + +export function containsUserID(value: string | undefined): boolean { + if (typeof value !== "string") { + return false + } + return value.includes(`${DocumentType.USER}${SEPARATOR}`) +} From 4b73f636fc32f689089a892756294e7ab9fe00d0 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Tue, 10 Oct 2023 11:34:14 +0100 Subject: [PATCH 033/111] Updating CI to only check pro when going to base branch. --- .github/workflows/budibase_ci.yml | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/.github/workflows/budibase_ci.yml b/.github/workflows/budibase_ci.yml index 9d1131ed7f..55dedb6481 100644 --- a/.github/workflows/budibase_ci.yml +++ b/.github/workflows/budibase_ci.yml @@ -270,18 +270,23 @@ jobs: if [[ $branch == "master" ]]; then base_commit=$(git rev-parse origin/master) - else + else if [[ $branch == "develop" ]]; then base_commit=$(git rev-parse origin/develop) fi - echo "target_branch=$branch" - echo "target_branch=$branch" >> "$GITHUB_OUTPUT" - echo "pro_commit=$pro_commit" - echo "pro_commit=$pro_commit" >> "$GITHUB_OUTPUT" - echo "base_commit=$base_commit" - echo "base_commit=$base_commit" >> "$GITHUB_OUTPUT" + if [[ ! -z $base_commit ]]; then + echo "target_branch=$branch" + echo "target_branch=$branch" >> "$GITHUB_OUTPUT" + echo "pro_commit=$pro_commit" + echo "pro_commit=$pro_commit" >> "$GITHUB_OUTPUT" + echo "base_commit=$base_commit" + echo "base_commit=$base_commit" >> "$GITHUB_OUTPUT" + else + echo "Nothing to do - branch to branch merge." + fi - - name: Check submodule merged to develop + - name: Check submodule merged to base branch + if: ${{ base_commit != '' }} uses: actions/github-script@v4 with: github-token: ${{ secrets.GITHUB_TOKEN }} From cd5d438a96273e10d1c6d9a988cc81b80b37b80a Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Tue, 10 Oct 2023 11:35:07 +0100 Subject: [PATCH 034/111] Quick fix. --- .github/workflows/budibase_ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/budibase_ci.yml b/.github/workflows/budibase_ci.yml index 55dedb6481..77b864b8ea 100644 --- a/.github/workflows/budibase_ci.yml +++ b/.github/workflows/budibase_ci.yml @@ -286,7 +286,7 @@ jobs: fi - name: Check submodule merged to base branch - if: ${{ base_commit != '' }} + if: ${{ steps.get_pro_commits.outputs.base_commit != '' }} uses: actions/github-script@v4 with: github-token: ${{ secrets.GITHUB_TOKEN }} From 27abfdccc2fce0ca3c86e9f6653c2e5654df0b7e Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Tue, 10 Oct 2023 11:50:45 +0100 Subject: [PATCH 035/111] Removing onChange handler. --- .../client/src/components/app/forms/BBReferenceField.svelte | 3 --- 1 file changed, 3 deletions(-) diff --git a/packages/client/src/components/app/forms/BBReferenceField.svelte b/packages/client/src/components/app/forms/BBReferenceField.svelte index f93c955be2..5f00c503c2 100644 --- a/packages/client/src/components/app/forms/BBReferenceField.svelte +++ b/packages/client/src/components/app/forms/BBReferenceField.svelte @@ -25,7 +25,4 @@ datasourceType={"user"} primaryDisplay={"email"} defaultValue={updateReferences(defaultValue)} - onChange={value => { - return updateReferences(value) - }} /> From 6c2eb693959cd7158cdeff763e99cda6bae97d7d Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Tue, 10 Oct 2023 11:58:30 +0100 Subject: [PATCH 036/111] Correcting syntax. --- .github/workflows/budibase_ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/budibase_ci.yml b/.github/workflows/budibase_ci.yml index 77b864b8ea..c9de51957b 100644 --- a/.github/workflows/budibase_ci.yml +++ b/.github/workflows/budibase_ci.yml @@ -270,7 +270,7 @@ jobs: if [[ $branch == "master" ]]; then base_commit=$(git rev-parse origin/master) - else if [[ $branch == "develop" ]]; then + elif [[ $branch == "develop" ]]; then base_commit=$(git rev-parse origin/develop) fi @@ -295,7 +295,7 @@ jobs: const baseCommit = '${{ steps.get_pro_commits.outputs.base_commit }}'; if (submoduleCommit !== baseCommit) { - console.error('Submodule commit does not match the latest commit on the "${{ steps.get_pro_commits.outputs.target_branch }}"" branch.'); + console.error('Submodule commit does not match the latest commit on the "${{ steps.get_pro_commits.outputs.target_branch }}" branch.'); console.error('Refer to the pro repo to merge your changes: https://github.com/Budibase/budibase-pro/blob/develop/docs/getting_started.md') process.exit(1); } else { From a514358e57732b10b8c2245d92a41a82de3b79d8 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Mon, 9 Oct 2023 17:15:14 +0200 Subject: [PATCH 037/111] Allow selecting user column type --- .../TableNavigator/TableDataImport.svelte | 73 +++++++++++++++---- 1 file changed, 60 insertions(+), 13 deletions(-) diff --git a/packages/builder/src/components/backend/TableNavigator/TableDataImport.svelte b/packages/builder/src/components/backend/TableNavigator/TableDataImport.svelte index 7bf2bbbbab..6f44135006 100644 --- a/packages/builder/src/components/backend/TableNavigator/TableDataImport.svelte +++ b/packages/builder/src/components/backend/TableNavigator/TableDataImport.svelte @@ -10,36 +10,73 @@ export let displayColumn = null export let promptUpload = false - const typeOptions = [ - { + const typeOptions = { + [FIELDS.STRING.type]: { label: "Text", value: FIELDS.STRING.type, + config: { + type: FIELDS.STRING.type, + constraints: FIELDS.STRING.constraints, + }, }, - { + [FIELDS.NUMBER.type]: { label: "Number", value: FIELDS.NUMBER.type, + config: { + type: FIELDS.NUMBER.type, + constraints: FIELDS.NUMBER.constraints, + }, }, - { + [FIELDS.DATETIME.type]: { label: "Date", value: FIELDS.DATETIME.type, + config: { + type: FIELDS.DATETIME.type, + constraints: FIELDS.DATETIME.constraints, + }, }, - { + [FIELDS.OPTIONS.type]: { label: "Options", value: FIELDS.OPTIONS.type, + config: { + type: FIELDS.OPTIONS.type, + constraints: FIELDS.OPTIONS.constraints, + }, }, - { + [FIELDS.ARRAY.type]: { label: "Multi-select", value: FIELDS.ARRAY.type, + config: { + type: FIELDS.ARRAY.type, + constraints: FIELDS.ARRAY.constraints, + }, }, - { + [FIELDS.BARCODEQR.type]: { label: "Barcode/QR", value: FIELDS.BARCODEQR.type, + config: { + type: FIELDS.BARCODEQR.type, + constraints: FIELDS.BARCODEQR.constraints, + }, }, - { + [FIELDS.LONGFORM.type]: { label: "Long Form Text", value: FIELDS.LONGFORM.type, + config: { + type: FIELDS.LONGFORM.type, + constraints: FIELDS.LONGFORM.constraints, + }, }, - ] + user: { + label: "User", + value: "user", + config: { + type: FIELDS.USER.type, + subtype: FIELDS.USER.subtype, + constraints: FIELDS.USER.constraints, + }, + }, + } let fileInput let error = null @@ -48,6 +85,7 @@ let validation = {} let validateHash = "" let errors = {} + let selectedColumnTypes = {} $: displayColumnOptions = Object.keys(schema || {}).filter(column => { return validation[column] @@ -72,6 +110,13 @@ rows = response.rows schema = response.schema fileName = response.fileName + selectedColumnTypes = Object.entries(response.schema).reduce( + (acc, [colName, fieldConfig]) => ({ + ...acc, + [colName]: fieldConfig.type, + }), + {} + ) } catch (e) { loading = false error = e @@ -98,8 +143,10 @@ } const handleChange = (name, e) => { - schema[name].type = e.detail - schema[name].constraints = FIELDS[e.detail.toUpperCase()].constraints + const { config } = typeOptions[e.detail] + schema[name].type = config.type + schema[name].subtype = config.subtype + schema[name].constraints = config.constraints } const openFileUpload = (promptUpload, fileInput) => { @@ -142,9 +189,9 @@
{column.name} option.label} From 48afa2aa0db209064ec03cd5f06a1d36fdf6de5a Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 10 Oct 2023 13:52:16 +0200 Subject: [PATCH 048/111] Lint --- .../src/components/backend/TableNavigator/TableDataImport.svelte | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/builder/src/components/backend/TableNavigator/TableDataImport.svelte b/packages/builder/src/components/backend/TableNavigator/TableDataImport.svelte index a4794c1836..7294a43dd6 100644 --- a/packages/builder/src/components/backend/TableNavigator/TableDataImport.svelte +++ b/packages/builder/src/components/backend/TableNavigator/TableDataImport.svelte @@ -3,7 +3,6 @@ import { FIELDS } from "constants/backend" import { API } from "api" import { parseFile } from "./utils" - import { FieldType } from "@budibase/types" export let rows = [] export let schema = {} From 012d0f4fe912d80a4eb861a102c51d4f7e15a20b Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Tue, 10 Oct 2023 12:54:49 +0100 Subject: [PATCH 049/111] Removing the option to add a filter to the dataset of a user column picker, as there is no current API for searching this. --- packages/client/manifest.json | 5 ----- 1 file changed, 5 deletions(-) diff --git a/packages/client/manifest.json b/packages/client/manifest.json index 4e56ca758d..d987344956 100644 --- a/packages/client/manifest.json +++ b/packages/client/manifest.json @@ -5673,11 +5673,6 @@ "label": "Validation", "key": "validation" }, - { - "type": "filter/relationship", - "label": "Filtering", - "key": "filter" - }, { "type": "boolean", "label": "Search", From e473c8b3a85c7741fb9a061d133b9db10ba14749 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 10 Oct 2023 14:07:12 +0200 Subject: [PATCH 050/111] Fix tests --- packages/server/src/api/routes/tests/row.spec.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/packages/server/src/api/routes/tests/row.spec.ts b/packages/server/src/api/routes/tests/row.spec.ts index 4dcc9b3c8c..186326964c 100644 --- a/packages/server/src/api/routes/tests/row.spec.ts +++ b/packages/server/src/api/routes/tests/row.spec.ts @@ -1578,9 +1578,6 @@ describe.each([ () => config.createUser(), (row: Row) => ({ _id: row._id, - email: row.email, - firstName: row.firstName, - lastName: row.lastName, primaryDisplay: row.email, }), ], From 78335be26a789d0a09a5d338ef36b8d9470ca62d Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 10 Oct 2023 14:20:26 +0200 Subject: [PATCH 051/111] Clean --- packages/server/src/utilities/schema.ts | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/packages/server/src/utilities/schema.ts b/packages/server/src/utilities/schema.ts index 79c797ab00..4e1b726cfd 100644 --- a/packages/server/src/utilities/schema.ts +++ b/packages/server/src/utilities/schema.ts @@ -196,33 +196,22 @@ function isValidBBReference( switch (columnSubtype) { case FieldSubtype.USER: case FieldSubtype.USERS: - if (!columnData) { - // Empty columns are valid by default - return true - } - if (typeof columnData !== "string") { return false } - - const castedData = parseCsvExport(columnData) - - if (!Array.isArray(castedData)) { - // It must be an array field + const userArray = parseCsvExport<{ _id: string }[]>(columnData) + if (columnSubtype === FieldSubtype.USER && userArray.length > 1) { return false } - if (columnSubtype === FieldSubtype.USER && castedData.length > 1) { + if (!Array.isArray(columnData)) { return false } - for (const d of castedData) { - if (!db.isGlobalUserID(d._id)) { - return false - } - } - - return true + const constainsWrongId = userArray.find( + user => !db.isGlobalUserID(user._id) + ) + return !constainsWrongId default: throw utils.unreachable(columnSubtype) From 21420c59faa1c64fe756085c31d3c49ddd6a7819 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 10 Oct 2023 14:39:55 +0200 Subject: [PATCH 052/111] Fix order --- packages/server/src/utilities/schema.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/server/src/utilities/schema.ts b/packages/server/src/utilities/schema.ts index 4e1b726cfd..04c9643183 100644 --- a/packages/server/src/utilities/schema.ts +++ b/packages/server/src/utilities/schema.ts @@ -200,11 +200,11 @@ function isValidBBReference( return false } const userArray = parseCsvExport<{ _id: string }[]>(columnData) - if (columnSubtype === FieldSubtype.USER && userArray.length > 1) { + if (!Array.isArray(columnData)) { return false } - if (!Array.isArray(columnData)) { + if (columnSubtype === FieldSubtype.USER && userArray.length > 1) { return false } From c49a16fdac4bc5fb9b7d8a4fe0d0ca415baef51b Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 10 Oct 2023 15:35:00 +0200 Subject: [PATCH 053/111] Fix tests --- .../rowProcessor/tests/bbReferenceProcessor.spec.ts | 6 ------ 1 file changed, 6 deletions(-) diff --git a/packages/server/src/utilities/rowProcessor/tests/bbReferenceProcessor.spec.ts b/packages/server/src/utilities/rowProcessor/tests/bbReferenceProcessor.spec.ts index b6174861d4..10d339f6b4 100644 --- a/packages/server/src/utilities/rowProcessor/tests/bbReferenceProcessor.spec.ts +++ b/packages/server/src/utilities/rowProcessor/tests/bbReferenceProcessor.spec.ts @@ -180,9 +180,6 @@ describe("bbReferenceProcessor", () => { { _id: user._id, primaryDisplay: user.email, - email: user.email, - firstName: user.firstName, - lastName: user.lastName, }, ]) expect(cacheGetUsersSpy).toBeCalledTimes(1) @@ -207,9 +204,6 @@ describe("bbReferenceProcessor", () => { [user1, user2].map(u => ({ _id: u._id, primaryDisplay: u.email, - email: u.email, - firstName: u.firstName, - lastName: u.lastName, })) ) ) From 530857a6ff94420e0e4a07be30efb1f491dc92e2 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 10 Oct 2023 15:39:05 +0200 Subject: [PATCH 054/111] Fix --- packages/server/src/utilities/schema.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/server/src/utilities/schema.ts b/packages/server/src/utilities/schema.ts index 04c9643183..40e4152b63 100644 --- a/packages/server/src/utilities/schema.ts +++ b/packages/server/src/utilities/schema.ts @@ -200,7 +200,7 @@ function isValidBBReference( return false } const userArray = parseCsvExport<{ _id: string }[]>(columnData) - if (!Array.isArray(columnData)) { + if (!Array.isArray(userArray)) { return false } From 36909ff7f6dc2ecc1ee00bcb0a03dd10ab5044e4 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 10 Oct 2023 15:50:12 +0200 Subject: [PATCH 055/111] Export bannedDisplayColumnTypes --- .../components/grid/cells/HeaderCell.svelte | 16 +++--------- packages/shared-core/src/table.ts | 25 +++++++++++++++++++ 2 files changed, 28 insertions(+), 13 deletions(-) create mode 100644 packages/shared-core/src/table.ts diff --git a/packages/frontend-core/src/components/grid/cells/HeaderCell.svelte b/packages/frontend-core/src/components/grid/cells/HeaderCell.svelte index 9f58dc9f9f..13fdc602a4 100644 --- a/packages/frontend-core/src/components/grid/cells/HeaderCell.svelte +++ b/packages/frontend-core/src/components/grid/cells/HeaderCell.svelte @@ -1,8 +1,8 @@