From 637f7f514ae69f1ac9a9c39710ce31c27dc4f573 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Fri, 26 Apr 2024 12:18:50 +0200 Subject: [PATCH 1/4] Remove FieldTypeSubtypes --- packages/frontend-core/src/constants.js | 6 +++--- packages/server/src/api/routes/tests/row.spec.ts | 6 +++--- .../server/src/sdk/app/rows/search/tests/utils.spec.ts | 6 +++--- .../utilities/rowProcessor/tests/inputProcessing.spec.ts | 8 ++++---- .../utilities/rowProcessor/tests/outputProcessing.spec.ts | 7 +++---- packages/types/src/documents/app/row.ts | 8 -------- 6 files changed, 16 insertions(+), 25 deletions(-) diff --git a/packages/frontend-core/src/constants.js b/packages/frontend-core/src/constants.js index 95228c3bdc..2a9b0379f8 100644 --- a/packages/frontend-core/src/constants.js +++ b/packages/frontend-core/src/constants.js @@ -4,7 +4,7 @@ export { OperatorOptions, SqlNumberTypeRangeMap } from "@budibase/shared-core" export { Feature as Features } from "@budibase/types" import { BpmCorrelationKey } from "@budibase/shared-core" -import { FieldType, FieldTypeSubtypes } from "@budibase/types" +import { FieldType, FieldSubtype } from "@budibase/types" // Cookie names export const Cookies = { @@ -134,7 +134,7 @@ export const TypeIconMap = { [FieldType.USER]: "User", [FieldType.USERS]: "UserGroup", [FieldType.BB_REFERENCE]: { - [FieldTypeSubtypes.BB_REFERENCE.USER]: "User", - [FieldTypeSubtypes.BB_REFERENCE.USERS]: "UserGroup", + [FieldSubtype.USER]: "User", + [FieldSubtype.USERS]: "UserGroup", }, } diff --git a/packages/server/src/api/routes/tests/row.spec.ts b/packages/server/src/api/routes/tests/row.spec.ts index 8e1014f825..f2ace8f795 100644 --- a/packages/server/src/api/routes/tests/row.spec.ts +++ b/packages/server/src/api/routes/tests/row.spec.ts @@ -13,7 +13,7 @@ import { DeleteRow, FieldSchema, FieldType, - FieldTypeSubtypes, + FieldSubtype, FormulaType, INTERNAL_TABLE_SOURCE_ID, NumberFieldMetadata, @@ -1015,12 +1015,12 @@ describe.each([ user: { name: "user", type: FieldType.BB_REFERENCE, - subtype: FieldTypeSubtypes.BB_REFERENCE.USER, + subtype: FieldSubtype.USER, }, users: { name: "users", type: FieldType.BB_REFERENCE, - subtype: FieldTypeSubtypes.BB_REFERENCE.USERS, + subtype: FieldSubtype.USERS, }, }), () => config.createUser(), diff --git a/packages/server/src/sdk/app/rows/search/tests/utils.spec.ts b/packages/server/src/sdk/app/rows/search/tests/utils.spec.ts index bf7799402d..413b5e28cf 100644 --- a/packages/server/src/sdk/app/rows/search/tests/utils.spec.ts +++ b/packages/server/src/sdk/app/rows/search/tests/utils.spec.ts @@ -2,7 +2,7 @@ import { searchInputMapping } from "../utils" import { db as dbCore } from "@budibase/backend-core" import { FieldType, - FieldTypeSubtypes, + FieldSubtype, INTERNAL_TABLE_SOURCE_ID, RowSearchParams, Table, @@ -20,7 +20,7 @@ const tableWithUserCol: Table = { user: { name: "user", type: FieldType.BB_REFERENCE, - subtype: FieldTypeSubtypes.BB_REFERENCE.USER, + subtype: FieldSubtype.USER, }, }, } @@ -35,7 +35,7 @@ const tableWithUsersCol: Table = { user: { name: "user", type: FieldType.BB_REFERENCE, - subtype: FieldTypeSubtypes.BB_REFERENCE.USERS, + subtype: FieldSubtype.USERS, }, }, } diff --git a/packages/server/src/utilities/rowProcessor/tests/inputProcessing.spec.ts b/packages/server/src/utilities/rowProcessor/tests/inputProcessing.spec.ts index 859a203133..47f930803b 100644 --- a/packages/server/src/utilities/rowProcessor/tests/inputProcessing.spec.ts +++ b/packages/server/src/utilities/rowProcessor/tests/inputProcessing.spec.ts @@ -2,7 +2,7 @@ import { inputProcessing } from ".." import { generator, structures } from "@budibase/backend-core/tests" import { FieldType, - FieldTypeSubtypes, + FieldSubtype, INTERNAL_TABLE_SOURCE_ID, Table, TableSourceType, @@ -39,7 +39,7 @@ describe("rowProcessor - inputProcessing", () => { }, user: { type: FieldType.BB_REFERENCE, - subtype: FieldTypeSubtypes.BB_REFERENCE.USER, + subtype: FieldSubtype.USER, name: "user", constraints: { presence: true, @@ -93,7 +93,7 @@ describe("rowProcessor - inputProcessing", () => { }, user: { type: FieldType.BB_REFERENCE, - subtype: FieldTypeSubtypes.BB_REFERENCE.USER, + subtype: FieldSubtype.USER, name: "user", constraints: { presence: false, @@ -135,7 +135,7 @@ describe("rowProcessor - inputProcessing", () => { }, user: { type: FieldType.BB_REFERENCE, - subtype: FieldTypeSubtypes.BB_REFERENCE.USER, + subtype: FieldSubtype.USER, name: "user", constraints: { presence: false, diff --git a/packages/server/src/utilities/rowProcessor/tests/outputProcessing.spec.ts b/packages/server/src/utilities/rowProcessor/tests/outputProcessing.spec.ts index 74d55aff36..7a7c319bb8 100644 --- a/packages/server/src/utilities/rowProcessor/tests/outputProcessing.spec.ts +++ b/packages/server/src/utilities/rowProcessor/tests/outputProcessing.spec.ts @@ -1,7 +1,6 @@ import { - FieldSubtype, FieldType, - FieldTypeSubtypes, + FieldSubtype, INTERNAL_TABLE_SOURCE_ID, RowAttachment, Table, @@ -42,7 +41,7 @@ describe("rowProcessor - outputProcessing", () => { }, user: { type: FieldType.BB_REFERENCE, - subtype: FieldTypeSubtypes.BB_REFERENCE.USER, + subtype: FieldSubtype.USER, name: "user", constraints: { presence: false, @@ -175,7 +174,7 @@ describe("rowProcessor - outputProcessing", () => { }, user: { type: FieldType.BB_REFERENCE, - subtype: FieldTypeSubtypes.BB_REFERENCE.USER, + subtype: FieldSubtype.USER, name: "user", constraints: { presence: false, diff --git a/packages/types/src/documents/app/row.ts b/packages/types/src/documents/app/row.ts index 865ab4ba64..b98bd8dc32 100644 --- a/packages/types/src/documents/app/row.ts +++ b/packages/types/src/documents/app/row.ts @@ -129,11 +129,3 @@ export enum FieldSubtype { USER = "user", USERS = "users", } - -// The 'as' are required for typescript not to type the outputs as generic FieldSubtype -export const FieldTypeSubtypes = { - BB_REFERENCE: { - USER: FieldSubtype.USER as FieldSubtype.USER, - USERS: FieldSubtype.USERS as FieldSubtype.USERS, - }, -} From b1b5b49687b2773f404c0ac61ef0a84622424a4f Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Fri, 26 Apr 2024 12:21:53 +0200 Subject: [PATCH 2/4] Move and rename BBReferenceFieldSubType --- packages/types/src/documents/app/row.ts | 5 ----- packages/types/src/documents/app/table/constants.ts | 5 +++++ 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/types/src/documents/app/row.ts b/packages/types/src/documents/app/row.ts index b98bd8dc32..d6a9bb7842 100644 --- a/packages/types/src/documents/app/row.ts +++ b/packages/types/src/documents/app/row.ts @@ -124,8 +124,3 @@ export interface Row extends Document { _viewId?: string [key: string]: any } - -export enum FieldSubtype { - USER = "user", - USERS = "users", -} diff --git a/packages/types/src/documents/app/table/constants.ts b/packages/types/src/documents/app/table/constants.ts index 1d9d14695a..ddf8b5e6ea 100644 --- a/packages/types/src/documents/app/table/constants.ts +++ b/packages/types/src/documents/app/table/constants.ts @@ -24,3 +24,8 @@ export enum FormulaType { STATIC = "static", DYNAMIC = "dynamic", } + +export enum BBReferenceFieldSubType { + USER = "user", + USERS = "users", +} From 1aad2ee6d29b5ab7910662621af0f5f28cfa542a Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Fri, 26 Apr 2024 12:23:11 +0200 Subject: [PATCH 3/4] Fix after renames --- .../DataTable/modals/CreateEditColumn.svelte | 24 ++++++++----- .../ExistingTableDataImport.svelte | 6 ++-- .../builder/src/constants/backend/index.js | 6 ++-- .../grid/cells/BBReferenceCell.svelte | 9 +++-- .../grid/controls/MigrationModal.svelte | 10 ++++-- packages/frontend-core/src/constants.js | 6 ++-- .../src/api/routes/tests/datasource.spec.ts | 4 +-- .../server/src/api/routes/tests/row.spec.ts | 6 ++-- .../server/src/api/routes/tests/table.spec.ts | 20 +++++------ packages/server/src/integrations/base/sql.ts | 4 +-- .../server/src/integrations/base/sqlTable.ts | 6 ++-- .../sdk/app/rows/search/tests/utils.spec.ts | 6 ++-- .../server/src/sdk/app/rows/search/utils.ts | 6 ++-- .../server/src/sdk/app/tables/migration.ts | 6 ++-- .../rowProcessor/bbReferenceProcessor.ts | 25 ++++++++----- .../src/utilities/rowProcessor/errors.ts | 4 +-- .../tests/bbReferenceProcessor.spec.ts | 35 +++++++++++-------- .../tests/inputProcessing.spec.ts | 8 ++--- .../tests/outputProcessing.spec.ts | 8 ++--- packages/server/src/utilities/schema.ts | 17 +++++---- packages/shared-core/src/filters.ts | 14 +++++--- .../types/src/documents/app/table/schema.ts | 5 +-- 22 files changed, 136 insertions(+), 99 deletions(-) diff --git a/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte b/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte index d271462f3e..f3ae207cb4 100644 --- a/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte +++ b/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte @@ -29,7 +29,11 @@ import ModalBindableInput from "components/common/bindings/ModalBindableInput.svelte" import { getBindings } from "components/backend/DataTable/formula" import JSONSchemaModal from "./JSONSchemaModal.svelte" - import { FieldType, FieldSubtype, SourceName } from "@budibase/types" + import { + FieldType, + BBReferenceFieldSubType, + SourceName, + } from "@budibase/types" import RelationshipSelector from "components/common/RelationshipSelector.svelte" import { RowUtils } from "@budibase/frontend-core" import ServerBindingPanel from "components/common/bindings/ServerBindingPanel.svelte" @@ -41,8 +45,6 @@ const NUMBER_TYPE = FieldType.NUMBER const JSON_TYPE = FieldType.JSON const DATE_TYPE = FieldType.DATETIME - const USER_TYPE = FieldSubtype.USER - const USERS_TYPE = FieldSubtype.USERS const dispatch = createEventDispatcher() const PROHIBITED_COLUMN_NAMES = ["type", "_id", "_rev", "tableId"] @@ -263,9 +265,9 @@ delete saveColumn.fieldName } if (isUsersColumn(saveColumn)) { - if (saveColumn.subtype === USER_TYPE) { + if (saveColumn.subtype === BBReferenceFieldSubType.USER) { saveColumn.relationshipType = RelationshipType.ONE_TO_MANY - } else if (saveColumn.subtype === USERS_TYPE) { + } else if (saveColumn.subtype === BBReferenceFieldSubType.USERS) { saveColumn.relationshipType = RelationshipType.MANY_TO_MANY } } @@ -375,7 +377,7 @@ const isUsers = editableColumn.type === FieldType.BB_REFERENCE && - editableColumn.subtype === FieldSubtype.USERS + editableColumn.subtype === BBReferenceFieldSubType.USERS if (!externalTable) { return [ @@ -485,7 +487,9 @@ function isUsersColumn(column) { return ( column.type === FieldType.BB_REFERENCE && - [FieldSubtype.USER, FieldSubtype.USERS].includes(column.subtype) + [BBReferenceFieldSubType.USER, BBReferenceFieldSubType.USERS].includes( + column.subtype + ) ) } @@ -688,12 +692,14 @@ > {:else if isUsersColumn(editableColumn) && datasource?.source !== SourceName.GOOGLE_SHEETS} handleTypeChange( makeFieldId( FieldType.BB_REFERENCE, - e.detail ? FieldSubtype.USERS : FieldSubtype.USER + e.detail + ? BBReferenceFieldSubType.USERS + : BBReferenceFieldSubType.USER ) )} disabled={!isCreating} diff --git a/packages/builder/src/components/backend/TableNavigator/ExistingTableDataImport.svelte b/packages/builder/src/components/backend/TableNavigator/ExistingTableDataImport.svelte index 6901503071..b7fa243c07 100644 --- a/packages/builder/src/components/backend/TableNavigator/ExistingTableDataImport.svelte +++ b/packages/builder/src/components/backend/TableNavigator/ExistingTableDataImport.svelte @@ -1,5 +1,5 @@