From 07a14fbde8adc00919eb5b7df4ccac3243495c10 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Mon, 9 Oct 2023 17:15:14 +0200 Subject: [PATCH 01/17] 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 7bf2bbbbabd..6f441350064 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 5108d2277c60f52b817277e9b3babfbac303d678 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 10 Oct 2023 13:52:16 +0200 Subject: [PATCH 12/17] 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 a4794c18369..7294a43dd68 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 4bcc44954dcddb6f755e55cc6e5ef920270b0273 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 10 Oct 2023 14:07:12 +0200 Subject: [PATCH 13/17] 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 4dcc9b3c8c8..186326964c0 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 8588c5275d4253be3dcc5cb3bc786beb3fef63eb Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 10 Oct 2023 14:20:26 +0200 Subject: [PATCH 14/17] 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 79c797ab002..4e1b726cfdf 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 6e0ad038d7de27ffe643d72ff45b4231fe522f5b Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 10 Oct 2023 14:39:55 +0200 Subject: [PATCH 15/17] 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 4e1b726cfdf..04c96431834 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 ef983a2486531ab706d51c6742ecea419388e422 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 10 Oct 2023 15:35:00 +0200 Subject: [PATCH 16/17] 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 b6174861d4d..10d339f6b4c 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 9a5dd716149c0fdfc0309ba56764765ff0adcfe4 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 10 Oct 2023 15:39:05 +0200 Subject: [PATCH 17/17] 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 04c96431834..40e4152b632 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 }