From 38bfdcd74921648be3b4378b51b1ec8c29989e8c Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Mon, 25 Mar 2024 18:39:03 +0100 Subject: [PATCH 01/27] Rename attachment to attachment list --- packages/builder/src/constants/backend/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/builder/src/constants/backend/index.js b/packages/builder/src/constants/backend/index.js index dd751d4e13..5b79443f79 100644 --- a/packages/builder/src/constants/backend/index.js +++ b/packages/builder/src/constants/backend/index.js @@ -108,7 +108,7 @@ export const FIELDS = { }, }, ATTACHMENT: { - name: "Attachment", + name: "Attachment List", type: FieldType.ATTACHMENT, icon: "Folder", constraints: { From f7c7ee91e29f5b0fa1f68d3f66b648799fa0a74a Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 26 Mar 2024 10:08:33 +0100 Subject: [PATCH 02/27] Add single attachment type --- .../components/backend/DataTable/modals/CreateEditColumn.svelte | 1 + packages/frontend-core/src/components/grid/lib/utils.js | 1 + packages/types/src/documents/app/row.ts | 1 + 3 files changed, 3 insertions(+) diff --git a/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte b/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte index cfc6e9a7be..2701c30359 100644 --- a/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte +++ b/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte @@ -395,6 +395,7 @@ FIELDS.BOOLEAN, FIELDS.DATETIME, FIELDS.ATTACHMENT, + FIELDS.ATTACHMENT_SINGLE, FIELDS.LINK, FIELDS.FORMULA, FIELDS.JSON, diff --git a/packages/frontend-core/src/components/grid/lib/utils.js b/packages/frontend-core/src/components/grid/lib/utils.js index 8382bfece8..75578133a9 100644 --- a/packages/frontend-core/src/components/grid/lib/utils.js +++ b/packages/frontend-core/src/components/grid/lib/utils.js @@ -17,6 +17,7 @@ const TypeIconMap = { [FieldType.NUMBER]: "123", [FieldType.BOOLEAN]: "Boolean", [FieldType.ATTACHMENT]: "AppleFiles", + [FieldType.ATTACHMENTS]: "AppleFiles", [FieldType.LINK]: "DataCorrelated", [FieldType.FORMULA]: "Calculator", [FieldType.JSON]: "Brackets", diff --git a/packages/types/src/documents/app/row.ts b/packages/types/src/documents/app/row.ts index aa8f50d4a8..5aab87fe6c 100644 --- a/packages/types/src/documents/app/row.ts +++ b/packages/types/src/documents/app/row.ts @@ -9,6 +9,7 @@ export enum FieldType { ARRAY = "array", DATETIME = "datetime", ATTACHMENT = "attachment", + ATTACHMENT_SINGLE = "attachment_single", LINK = "link", FORMULA = "formula", AUTO = "auto", From 7523cf8be31f29fbae3c81c1774f94dc53cfeb5d Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 26 Mar 2024 11:05:06 +0100 Subject: [PATCH 03/27] Single attachment cell --- .../design/settings/controls/FieldConfiguration/utils.js | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/builder/src/components/design/settings/controls/FieldConfiguration/utils.js b/packages/builder/src/components/design/settings/controls/FieldConfiguration/utils.js index 18ebf57d98..665ffffc63 100644 --- a/packages/builder/src/components/design/settings/controls/FieldConfiguration/utils.js +++ b/packages/builder/src/components/design/settings/controls/FieldConfiguration/utils.js @@ -42,6 +42,7 @@ export const FieldTypeToComponentMap = { [FieldType.LONGFORM]: "longformfield", [FieldType.DATETIME]: "datetimefield", [FieldType.ATTACHMENT]: "attachmentfield", + [FieldType.ATTACHMENT_SINGLE]: "attachmentfield", [FieldType.LINK]: "relationshipfield", [FieldType.JSON]: "jsonfield", [FieldType.BARCODEQR]: "codescanner", From 7d885482557a1dc6bd0cbcfa5eadf938aecc0f21 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 26 Mar 2024 11:05:45 +0100 Subject: [PATCH 04/27] More types --- .../client/src/components/app/blocks/FormBlockComponent.svelte | 1 + packages/frontend-core/src/components/grid/lib/renderers.js | 1 + 2 files changed, 2 insertions(+) diff --git a/packages/client/src/components/app/blocks/FormBlockComponent.svelte b/packages/client/src/components/app/blocks/FormBlockComponent.svelte index 34168355c4..9a06fc10ec 100644 --- a/packages/client/src/components/app/blocks/FormBlockComponent.svelte +++ b/packages/client/src/components/app/blocks/FormBlockComponent.svelte @@ -16,6 +16,7 @@ [FieldType.LONGFORM]: "longformfield", [FieldType.DATETIME]: "datetimefield", [FieldType.ATTACHMENT]: "attachmentfield", + [FieldType.ATTACHMENT_SINGLE]: "attachmentfield", [FieldType.LINK]: "relationshipfield", [FieldType.JSON]: "jsonfield", [FieldType.BARCODEQR]: "codescanner", diff --git a/packages/frontend-core/src/components/grid/lib/renderers.js b/packages/frontend-core/src/components/grid/lib/renderers.js index 19bf63312d..d4ac8b86ec 100644 --- a/packages/frontend-core/src/components/grid/lib/renderers.js +++ b/packages/frontend-core/src/components/grid/lib/renderers.js @@ -23,6 +23,7 @@ const TypeComponentMap = { [FieldType.NUMBER]: NumberCell, [FieldType.BOOLEAN]: BooleanCell, [FieldType.ATTACHMENT]: AttachmentCell, + [FieldType.ATTACHMENT_SINGLE]: AttachmentCell, [FieldType.LINK]: RelationshipCell, [FieldType.FORMULA]: FormulaCell, [FieldType.JSON]: JSONCell, From c96e8b273d2ff2cdfb2f41b458d38129ddff5b5d Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 26 Mar 2024 11:38:55 +0100 Subject: [PATCH 05/27] Fix types --- packages/shared-core/src/table.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/shared-core/src/table.ts b/packages/shared-core/src/table.ts index 5eab2fc340..e1f48ce176 100644 --- a/packages/shared-core/src/table.ts +++ b/packages/shared-core/src/table.ts @@ -11,10 +11,10 @@ const allowDisplayColumnByType: Record = { [FieldType.INTERNAL]: true, [FieldType.BARCODEQR]: true, [FieldType.BIGINT]: true, - [FieldType.BOOLEAN]: false, [FieldType.ARRAY]: false, [FieldType.ATTACHMENT]: false, + [FieldType.ATTACHMENT_SINGLE]: false, [FieldType.LINK]: false, [FieldType.JSON]: false, [FieldType.BB_REFERENCE]: false, @@ -35,6 +35,7 @@ const allowSortColumnByType: Record = { [FieldType.FORMULA]: false, [FieldType.ATTACHMENT]: false, + [FieldType.ATTACHMENT_SINGLE]: false, [FieldType.ARRAY]: false, [FieldType.LINK]: false, [FieldType.BB_REFERENCE]: false, From ed228a2288bd4f84a561ec6c61aff05c64605059 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 26 Mar 2024 11:45:09 +0100 Subject: [PATCH 06/27] Single attachment cell --- .../grid/cells/AttachmentCell.svelte | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/packages/frontend-core/src/components/grid/cells/AttachmentCell.svelte b/packages/frontend-core/src/components/grid/cells/AttachmentCell.svelte index a1f5c4f2aa..5f26a9d9b1 100644 --- a/packages/frontend-core/src/components/grid/cells/AttachmentCell.svelte +++ b/packages/frontend-core/src/components/grid/cells/AttachmentCell.svelte @@ -1,6 +1,7 @@ @@ -87,7 +97,7 @@ > {#if fieldState} From d74af112308cc7c3a5f87dee5c2b29f442babb42 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 26 Mar 2024 14:53:41 +0100 Subject: [PATCH 10/27] Handle deletions --- packages/bbui/src/Form/Core/Dropzone.svelte | 2 +- .../src/components/app/forms/AttachmentField.svelte | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/packages/bbui/src/Form/Core/Dropzone.svelte b/packages/bbui/src/Form/Core/Dropzone.svelte index 3d803c0961..dd72167791 100644 --- a/packages/bbui/src/Form/Core/Dropzone.svelte +++ b/packages/bbui/src/Form/Core/Dropzone.svelte @@ -67,7 +67,7 @@ } $: showDropzone = - (!maximum || (maximum && value?.length < maximum)) && !disabled + (!maximum || (maximum && (value?.length || 0) < maximum)) && !disabled async function processFileList(fileList) { if ( diff --git a/packages/client/src/components/app/forms/AttachmentField.svelte b/packages/client/src/components/app/forms/AttachmentField.svelte index 70fa8717d9..63f6d2b39b 100644 --- a/packages/client/src/components/app/forms/AttachmentField.svelte +++ b/packages/client/src/components/app/forms/AttachmentField.svelte @@ -20,9 +20,12 @@ let fieldState let fieldApi + $: isSingle = schema?.type === FieldType.ATTACHMENT_SINGLE $: value = - fieldState?.value && type === FieldType.ATTACHMENT_SINGLE - ? [fieldState.value] + isSingle && !Array.isArray(fieldState?.value) + ? fieldState?.value + ? [fieldState.value] + : [] : fieldState?.value const { API, notificationStore } = getContext("sdk") @@ -72,8 +75,8 @@ const handleChange = e => { let value = e.detail - if (type === FieldType.ATTACHMENT_SINGLE) { - value = value[0] + if (isSingle) { + value = value[0] || null } const changed = fieldApi.setValue(value) if (onChange && changed) { @@ -105,7 +108,7 @@ {deleteAttachments} {handleFileTooLarge} {handleTooManyFiles} - maximum={type === FieldType.ATTACHMENT_SINGLE ? 1 : maximum} + maximum={isSingle ? 1 : maximum} {extensions} {compact} /> From 47ab920bd118171ddef120e4036a83bbbecd54de Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 26 Mar 2024 14:54:17 +0100 Subject: [PATCH 11/27] Fix --- packages/client/src/components/app/forms/AttachmentField.svelte | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/client/src/components/app/forms/AttachmentField.svelte b/packages/client/src/components/app/forms/AttachmentField.svelte index 63f6d2b39b..b38d305a7d 100644 --- a/packages/client/src/components/app/forms/AttachmentField.svelte +++ b/packages/client/src/components/app/forms/AttachmentField.svelte @@ -20,7 +20,7 @@ let fieldState let fieldApi - $: isSingle = schema?.type === FieldType.ATTACHMENT_SINGLE + $: isSingle = type === FieldType.ATTACHMENT_SINGLE $: value = isSingle && !Array.isArray(fieldState?.value) ? fieldState?.value From ac5bae0e232909ff0749b9aad9c5262812b02e87 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Wed, 27 Mar 2024 08:07:49 +0100 Subject: [PATCH 12/27] Lint --- packages/client/src/components/app/forms/AttachmentField.svelte | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/client/src/components/app/forms/AttachmentField.svelte b/packages/client/src/components/app/forms/AttachmentField.svelte index b38d305a7d..eff0b8c408 100644 --- a/packages/client/src/components/app/forms/AttachmentField.svelte +++ b/packages/client/src/components/app/forms/AttachmentField.svelte @@ -62,7 +62,6 @@ } const deleteAttachments = async fileList => { - console.error({ fileList }) try { return await API.deleteAttachments({ keys: fileList, From 21597a44c93ae6aa32136707cd59549e9c44fdd9 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Wed, 27 Mar 2024 09:25:37 +0100 Subject: [PATCH 13/27] SingleAttachmentField component --- packages/client/manifest.json | 99 ++++++++++++++++++- .../app/blocks/FormBlockComponent.svelte | 7 +- .../app/forms/SingleAttachmentField.svelte | 6 ++ .../client/src/components/app/forms/index.js | 1 + 4 files changed, 106 insertions(+), 7 deletions(-) create mode 100644 packages/client/src/components/app/forms/SingleAttachmentField.svelte diff --git a/packages/client/manifest.json b/packages/client/manifest.json index 08d614391b..11b38216fe 100644 --- a/packages/client/manifest.json +++ b/packages/client/manifest.json @@ -4226,7 +4226,7 @@ ] }, "attachmentfield": { - "name": "Attachment", + "name": "Attachment list", "icon": "Attach", "styles": ["size"], "requiredAncestors": ["form"], @@ -4322,6 +4322,103 @@ } ] }, + "singleattachmentfield": { + "name": "Single Attachment", + "icon": "Attach", + "styles": ["size"], + "requiredAncestors": ["form"], + "editable": true, + "size": { + "width": 400, + "height": 200 + }, + "settings": [ + { + "type": "field/attachment_single", + "label": "Field", + "key": "field", + "required": true + }, + { + "type": "text", + "label": "Label", + "key": "label" + }, + { + "type": "text", + "label": "Help text", + "key": "helpText" + }, + { + "type": "text", + "label": "Extensions", + "key": "extensions" + }, + { + "type": "number", + "label": "Max attachments", + "key": "maximum", + "min": 1 + }, + { + "type": "event", + "label": "On change", + "key": "onChange", + "context": [ + { + "label": "Field Value", + "key": "value" + } + ] + }, + { + "type": "boolean", + "label": "Compact", + "key": "compact", + "defaultValue": false + }, + { + "type": "boolean", + "label": "Read only", + "key": "disabled", + "defaultValue": false + }, + { + "type": "validation/attachment", + "label": "Validation", + "key": "validation" + }, + { + "type": "select", + "label": "Layout", + "key": "span", + "defaultValue": 6, + "hidden": true, + "showInBar": true, + "barStyle": "buttons", + "options": [ + { + "label": "1 column", + "value": 6, + "barIcon": "Stop", + "barTitle": "1 column" + }, + { + "label": "2 columns", + "value": 3, + "barIcon": "ColumnTwoA", + "barTitle": "2 columns" + }, + { + "label": "3 columns", + "value": 2, + "barIcon": "ViewColumn", + "barTitle": "3 columns" + } + ] + } + ] + }, "relationshipfield": { "name": "Relationship Picker", "icon": "TaskList", diff --git a/packages/client/src/components/app/blocks/FormBlockComponent.svelte b/packages/client/src/components/app/blocks/FormBlockComponent.svelte index acac79a97f..c88b8f1499 100644 --- a/packages/client/src/components/app/blocks/FormBlockComponent.svelte +++ b/packages/client/src/components/app/blocks/FormBlockComponent.svelte @@ -16,7 +16,7 @@ [FieldType.LONGFORM]: "longformfield", [FieldType.DATETIME]: "datetimefield", [FieldType.ATTACHMENT]: "attachmentfield", - [FieldType.ATTACHMENT_SINGLE]: "attachmentfield", + [FieldType.ATTACHMENT_SINGLE]: "singleattachmentfield", [FieldType.LINK]: "relationshipfield", [FieldType.JSON]: "jsonfield", [FieldType.BARCODEQR]: "codescanner", @@ -66,11 +66,6 @@ maximum: schema?.constraints?.length?.maximum, } }, - [FieldType.ATTACHMENT_SINGLE]: () => { - return { - type: FieldType.ATTACHMENT_SINGLE, - } - }, } const fieldSchema = getFieldSchema(field) diff --git a/packages/client/src/components/app/forms/SingleAttachmentField.svelte b/packages/client/src/components/app/forms/SingleAttachmentField.svelte new file mode 100644 index 0000000000..4810f4e848 --- /dev/null +++ b/packages/client/src/components/app/forms/SingleAttachmentField.svelte @@ -0,0 +1,6 @@ + + + diff --git a/packages/client/src/components/app/forms/index.js b/packages/client/src/components/app/forms/index.js index 5804d3a79d..5f0241c913 100644 --- a/packages/client/src/components/app/forms/index.js +++ b/packages/client/src/components/app/forms/index.js @@ -9,6 +9,7 @@ export { default as booleanfield } from "./BooleanField.svelte" export { default as longformfield } from "./LongFormField.svelte" export { default as datetimefield } from "./DateTimeField.svelte" export { default as attachmentfield } from "./AttachmentField.svelte" +export { default as singleattachmentfield } from "./SingleAttachmentField.svelte" export { default as relationshipfield } from "./RelationshipField.svelte" export { default as passwordfield } from "./PasswordField.svelte" export { default as formstep } from "./FormStep.svelte" From 5df68cfca7703220abe383f60722f9c8d95a0c54 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Wed, 27 Mar 2024 10:04:12 +0100 Subject: [PATCH 14/27] Extract mapper --- .../app/forms/AttachmentField.svelte | 21 +++++++------------ .../app/forms/SingleAttachmentField.svelte | 12 ++++++++++- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/packages/client/src/components/app/forms/AttachmentField.svelte b/packages/client/src/components/app/forms/AttachmentField.svelte index eff0b8c408..7ce1d21998 100644 --- a/packages/client/src/components/app/forms/AttachmentField.svelte +++ b/packages/client/src/components/app/forms/AttachmentField.svelte @@ -16,18 +16,14 @@ export let span export let helpText = null export let type = FieldType.ATTACHMENT + export let fieldApiMapper = { + get: value => value, + set: value => value, + } let fieldState let fieldApi - $: isSingle = type === FieldType.ATTACHMENT_SINGLE - $: value = - isSingle && !Array.isArray(fieldState?.value) - ? fieldState?.value - ? [fieldState.value] - : [] - : fieldState?.value - const { API, notificationStore } = getContext("sdk") const formContext = getContext("form") const BYTES_IN_MB = 1000000 @@ -73,10 +69,7 @@ } const handleChange = e => { - let value = e.detail - if (isSingle) { - value = value[0] || null - } + const value = fieldApiMapper.set(e.detail) const changed = fieldApi.setValue(value) if (onChange && changed) { onChange({ value }) @@ -99,7 +92,7 @@ > {#if fieldState} diff --git a/packages/client/src/components/app/forms/SingleAttachmentField.svelte b/packages/client/src/components/app/forms/SingleAttachmentField.svelte index 4810f4e848..1eab255b9e 100644 --- a/packages/client/src/components/app/forms/SingleAttachmentField.svelte +++ b/packages/client/src/components/app/forms/SingleAttachmentField.svelte @@ -1,6 +1,16 @@ - + From b99a51d48b80bcce38e3669f331b0367e42a4dac Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Wed, 27 Mar 2024 10:10:01 +0100 Subject: [PATCH 15/27] Rename --- packages/client/manifest.json | 2 +- .../client/src/components/app/blocks/FormBlockComponent.svelte | 2 +- ...ingleAttachmentField.svelte => AttachmentSingleField.svelte} | 0 packages/client/src/components/app/forms/index.js | 2 +- 4 files changed, 3 insertions(+), 3 deletions(-) rename packages/client/src/components/app/forms/{SingleAttachmentField.svelte => AttachmentSingleField.svelte} (100%) diff --git a/packages/client/manifest.json b/packages/client/manifest.json index 11b38216fe..cc5c68ea83 100644 --- a/packages/client/manifest.json +++ b/packages/client/manifest.json @@ -4322,7 +4322,7 @@ } ] }, - "singleattachmentfield": { + "attachmentsinglefield": { "name": "Single Attachment", "icon": "Attach", "styles": ["size"], diff --git a/packages/client/src/components/app/blocks/FormBlockComponent.svelte b/packages/client/src/components/app/blocks/FormBlockComponent.svelte index c88b8f1499..1fc7cd3aba 100644 --- a/packages/client/src/components/app/blocks/FormBlockComponent.svelte +++ b/packages/client/src/components/app/blocks/FormBlockComponent.svelte @@ -16,7 +16,7 @@ [FieldType.LONGFORM]: "longformfield", [FieldType.DATETIME]: "datetimefield", [FieldType.ATTACHMENT]: "attachmentfield", - [FieldType.ATTACHMENT_SINGLE]: "singleattachmentfield", + [FieldType.ATTACHMENT_SINGLE]: "attachmentsinglefield", [FieldType.LINK]: "relationshipfield", [FieldType.JSON]: "jsonfield", [FieldType.BARCODEQR]: "codescanner", diff --git a/packages/client/src/components/app/forms/SingleAttachmentField.svelte b/packages/client/src/components/app/forms/AttachmentSingleField.svelte similarity index 100% rename from packages/client/src/components/app/forms/SingleAttachmentField.svelte rename to packages/client/src/components/app/forms/AttachmentSingleField.svelte diff --git a/packages/client/src/components/app/forms/index.js b/packages/client/src/components/app/forms/index.js index 5f0241c913..aa54204454 100644 --- a/packages/client/src/components/app/forms/index.js +++ b/packages/client/src/components/app/forms/index.js @@ -9,7 +9,7 @@ export { default as booleanfield } from "./BooleanField.svelte" export { default as longformfield } from "./LongFormField.svelte" export { default as datetimefield } from "./DateTimeField.svelte" export { default as attachmentfield } from "./AttachmentField.svelte" -export { default as singleattachmentfield } from "./SingleAttachmentField.svelte" +export { default as attachmentsinglefield } from "./AttachmentSingleField.svelte" export { default as relationshipfield } from "./RelationshipField.svelte" export { default as passwordfield } from "./PasswordField.svelte" export { default as formstep } from "./FormStep.svelte" From 39ac734edd705d8fc28be584606c8dc6431ba8a4 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Wed, 27 Mar 2024 10:21:26 +0100 Subject: [PATCH 16/27] Clean components --- .../grid/cells/AttachmentCell.svelte | 24 ++++--------------- .../grid/cells/AttachmentSingleCell.svelte | 20 ++++++++++++++++ .../src/components/grid/lib/renderers.js | 3 ++- 3 files changed, 27 insertions(+), 20 deletions(-) create mode 100644 packages/frontend-core/src/components/grid/cells/AttachmentSingleCell.svelte diff --git a/packages/frontend-core/src/components/grid/cells/AttachmentCell.svelte b/packages/frontend-core/src/components/grid/cells/AttachmentCell.svelte index 6ed6aa0b82..3a1f165b6e 100644 --- a/packages/frontend-core/src/components/grid/cells/AttachmentCell.svelte +++ b/packages/frontend-core/src/components/grid/cells/AttachmentCell.svelte @@ -1,7 +1,6 @@ + + diff --git a/packages/frontend-core/src/components/grid/lib/renderers.js b/packages/frontend-core/src/components/grid/lib/renderers.js index d4ac8b86ec..6d94d16c2d 100644 --- a/packages/frontend-core/src/components/grid/lib/renderers.js +++ b/packages/frontend-core/src/components/grid/lib/renderers.js @@ -11,6 +11,7 @@ import BooleanCell from "../cells/BooleanCell.svelte" import FormulaCell from "../cells/FormulaCell.svelte" import JSONCell from "../cells/JSONCell.svelte" import AttachmentCell from "../cells/AttachmentCell.svelte" +import AttachmentSingleCell from "../cells/AttachmentSingleCell.svelte" import BBReferenceCell from "../cells/BBReferenceCell.svelte" const TypeComponentMap = { @@ -23,7 +24,7 @@ const TypeComponentMap = { [FieldType.NUMBER]: NumberCell, [FieldType.BOOLEAN]: BooleanCell, [FieldType.ATTACHMENT]: AttachmentCell, - [FieldType.ATTACHMENT_SINGLE]: AttachmentCell, + [FieldType.ATTACHMENT_SINGLE]: AttachmentSingleCell, [FieldType.LINK]: RelationshipCell, [FieldType.FORMULA]: FormulaCell, [FieldType.JSON]: JSONCell, From 1992fbc5d25b32e959990cf3ed11e5e2dde379fd Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Wed, 27 Mar 2024 10:29:38 +0100 Subject: [PATCH 17/27] Fix mapping --- .../design/settings/controls/FieldConfiguration/utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/builder/src/components/design/settings/controls/FieldConfiguration/utils.js b/packages/builder/src/components/design/settings/controls/FieldConfiguration/utils.js index 665ffffc63..eeda2ff991 100644 --- a/packages/builder/src/components/design/settings/controls/FieldConfiguration/utils.js +++ b/packages/builder/src/components/design/settings/controls/FieldConfiguration/utils.js @@ -42,7 +42,7 @@ export const FieldTypeToComponentMap = { [FieldType.LONGFORM]: "longformfield", [FieldType.DATETIME]: "datetimefield", [FieldType.ATTACHMENT]: "attachmentfield", - [FieldType.ATTACHMENT_SINGLE]: "attachmentfield", + [FieldType.ATTACHMENT_SINGLE]: "attachmentsinglefield", [FieldType.LINK]: "relationshipfield", [FieldType.JSON]: "jsonfield", [FieldType.BARCODEQR]: "codescanner", From a8c30110717d03108d5eab3e712b5ded1bda152e Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Wed, 3 Apr 2024 10:44:35 +0200 Subject: [PATCH 18/27] Rename FieldType.ATTACHMENT to FieldType.ATTACHMENTS --- .../builder/src/components/backend/DataTable/formula.js | 2 +- .../design/settings/controls/FieldConfiguration/utils.js | 2 +- packages/builder/src/constants/backend/index.js | 4 ++-- .../src/components/app/blocks/FormBlockComponent.svelte | 4 ++-- .../client/src/components/app/forms/AttachmentField.svelte | 2 +- packages/frontend-core/src/components/grid/lib/renderers.js | 2 +- packages/server/src/api/controllers/table/utils.ts | 2 +- packages/server/src/api/routes/tests/row.spec.ts | 4 ++-- packages/server/src/db/defaultData/datasource_bb_default.ts | 4 ++-- packages/server/src/sdk/app/rows/attachments.ts | 2 +- packages/server/src/sdk/app/rows/utils.ts | 4 ++-- packages/server/src/utilities/rowProcessor/attachments.ts | 6 +++--- packages/server/src/utilities/rowProcessor/index.ts | 4 ++-- packages/server/src/utilities/rowProcessor/map.ts | 2 +- .../src/utilities/rowProcessor/tests/attachments.spec.ts | 2 +- .../utilities/rowProcessor/tests/outputProcessing.spec.ts | 2 +- packages/shared-core/src/table.ts | 4 ++-- packages/types/src/documents/app/row.ts | 2 +- packages/types/src/documents/app/table/schema.ts | 6 +++--- 19 files changed, 30 insertions(+), 30 deletions(-) diff --git a/packages/builder/src/components/backend/DataTable/formula.js b/packages/builder/src/components/backend/DataTable/formula.js index e3da4249bc..b339729391 100644 --- a/packages/builder/src/components/backend/DataTable/formula.js +++ b/packages/builder/src/components/backend/DataTable/formula.js @@ -9,7 +9,7 @@ const MAX_DEPTH = 1 const TYPES_TO_SKIP = [ FieldType.FORMULA, FieldType.LONGFORM, - FieldType.ATTACHMENT, + FieldType.ATTACHMENTS, //https://github.com/Budibase/budibase/issues/3030 FieldType.INTERNAL, ] diff --git a/packages/builder/src/components/design/settings/controls/FieldConfiguration/utils.js b/packages/builder/src/components/design/settings/controls/FieldConfiguration/utils.js index eeda2ff991..d0f9afda40 100644 --- a/packages/builder/src/components/design/settings/controls/FieldConfiguration/utils.js +++ b/packages/builder/src/components/design/settings/controls/FieldConfiguration/utils.js @@ -41,7 +41,7 @@ export const FieldTypeToComponentMap = { [FieldType.BOOLEAN]: "booleanfield", [FieldType.LONGFORM]: "longformfield", [FieldType.DATETIME]: "datetimefield", - [FieldType.ATTACHMENT]: "attachmentfield", + [FieldType.ATTACHMENTS]: "attachmentfield", [FieldType.ATTACHMENT_SINGLE]: "attachmentsinglefield", [FieldType.LINK]: "relationshipfield", [FieldType.JSON]: "jsonfield", diff --git a/packages/builder/src/constants/backend/index.js b/packages/builder/src/constants/backend/index.js index 5b79443f79..d88637d670 100644 --- a/packages/builder/src/constants/backend/index.js +++ b/packages/builder/src/constants/backend/index.js @@ -109,7 +109,7 @@ export const FIELDS = { }, ATTACHMENT: { name: "Attachment List", - type: FieldType.ATTACHMENT, + type: FieldType.ATTACHMENTS, icon: "Folder", constraints: { type: "array", @@ -299,7 +299,7 @@ export const PaginationLocations = [ export const BannedSearchTypes = [ FieldType.LINK, - FieldType.ATTACHMENT, + FieldType.ATTACHMENTS, FieldType.FORMULA, FieldType.JSON, "jsonarray", diff --git a/packages/client/src/components/app/blocks/FormBlockComponent.svelte b/packages/client/src/components/app/blocks/FormBlockComponent.svelte index 1fc7cd3aba..968ed36b8b 100644 --- a/packages/client/src/components/app/blocks/FormBlockComponent.svelte +++ b/packages/client/src/components/app/blocks/FormBlockComponent.svelte @@ -15,7 +15,7 @@ [FieldType.BOOLEAN]: "booleanfield", [FieldType.LONGFORM]: "longformfield", [FieldType.DATETIME]: "datetimefield", - [FieldType.ATTACHMENT]: "attachmentfield", + [FieldType.ATTACHMENTS]: "attachmentfield", [FieldType.ATTACHMENT_SINGLE]: "attachmentsinglefield", [FieldType.LINK]: "relationshipfield", [FieldType.JSON]: "jsonfield", @@ -61,7 +61,7 @@ function getPropsByType(field) { const propsMapByType = { - [FieldType.ATTACHMENT]: (_field, schema) => { + [FieldType.ATTACHMENTS]: (_field, schema) => { return { maximum: schema?.constraints?.length?.maximum, } diff --git a/packages/client/src/components/app/forms/AttachmentField.svelte b/packages/client/src/components/app/forms/AttachmentField.svelte index 7ce1d21998..8be70bc011 100644 --- a/packages/client/src/components/app/forms/AttachmentField.svelte +++ b/packages/client/src/components/app/forms/AttachmentField.svelte @@ -15,7 +15,7 @@ export let maximum = undefined export let span export let helpText = null - export let type = FieldType.ATTACHMENT + export let type = FieldType.ATTACHMENTS export let fieldApiMapper = { get: value => value, set: value => value, diff --git a/packages/frontend-core/src/components/grid/lib/renderers.js b/packages/frontend-core/src/components/grid/lib/renderers.js index 6d94d16c2d..c3ee276ff9 100644 --- a/packages/frontend-core/src/components/grid/lib/renderers.js +++ b/packages/frontend-core/src/components/grid/lib/renderers.js @@ -23,7 +23,7 @@ const TypeComponentMap = { [FieldType.ARRAY]: MultiSelectCell, [FieldType.NUMBER]: NumberCell, [FieldType.BOOLEAN]: BooleanCell, - [FieldType.ATTACHMENT]: AttachmentCell, + [FieldType.ATTACHMENTS]: AttachmentCell, [FieldType.ATTACHMENT_SINGLE]: AttachmentSingleCell, [FieldType.LINK]: RelationshipCell, [FieldType.FORMULA]: FormulaCell, diff --git a/packages/server/src/api/controllers/table/utils.ts b/packages/server/src/api/controllers/table/utils.ts index 0c9933a4cf..1dea1a09f9 100644 --- a/packages/server/src/api/controllers/table/utils.ts +++ b/packages/server/src/api/controllers/table/utils.ts @@ -95,7 +95,7 @@ export async function checkForColumnUpdates( updatedTable.schema ).filter( (column): column is AttachmentFieldMetadata => - column.type === FieldType.ATTACHMENT && + column.type === FieldType.ATTACHMENTS && column.subtype !== oldTable?.schema[column.name]?.subtype ) for (const attachmentColumn of changedAttachmentSubtypeColumns) { diff --git a/packages/server/src/api/routes/tests/row.spec.ts b/packages/server/src/api/routes/tests/row.spec.ts index f638f2c4bf..77b64c6975 100644 --- a/packages/server/src/api/routes/tests/row.spec.ts +++ b/packages/server/src/api/routes/tests/row.spec.ts @@ -232,7 +232,7 @@ describe.each([ constraints: { type: "string", presence: false }, } const attachment: FieldSchema = { - type: FieldType.ATTACHMENT, + type: FieldType.ATTACHMENTS, name: "attachment", constraints: { type: "array", presence: false }, } @@ -791,7 +791,7 @@ describe.each([ defaultTable({ schema: { attachment: { - type: FieldType.ATTACHMENT, + type: FieldType.ATTACHMENTS, name: "attachment", constraints: { type: "array", presence: false }, }, diff --git a/packages/server/src/db/defaultData/datasource_bb_default.ts b/packages/server/src/db/defaultData/datasource_bb_default.ts index 03aed3c118..68d49b2d8b 100644 --- a/packages/server/src/db/defaultData/datasource_bb_default.ts +++ b/packages/server/src/db/defaultData/datasource_bb_default.ts @@ -299,7 +299,7 @@ export const DEFAULT_EMPLOYEE_TABLE_SCHEMA: Table = { sortable: false, }, "Badge Photo": { - type: FieldType.ATTACHMENT, + type: FieldType.ATTACHMENTS, constraints: { type: FieldType.ARRAY, presence: false, @@ -607,7 +607,7 @@ export const DEFAULT_EXPENSES_TABLE_SCHEMA: Table = { ignoreTimezones: true, }, Attachment: { - type: FieldType.ATTACHMENT, + type: FieldType.ATTACHMENTS, constraints: { type: FieldType.ARRAY, presence: false, diff --git a/packages/server/src/sdk/app/rows/attachments.ts b/packages/server/src/sdk/app/rows/attachments.ts index 2ab9e83c47..8fd2ccf795 100644 --- a/packages/server/src/sdk/app/rows/attachments.ts +++ b/packages/server/src/sdk/app/rows/attachments.ts @@ -30,7 +30,7 @@ export async function getRowsWithAttachments(appId: string, table: Table) { const db = dbCore.getDB(appId) const attachmentCols: string[] = [] for (let [key, column] of Object.entries(table.schema)) { - if (column.type === FieldType.ATTACHMENT) { + if (column.type === FieldType.ATTACHMENTS) { attachmentCols.push(key) } } diff --git a/packages/server/src/sdk/app/rows/utils.ts b/packages/server/src/sdk/app/rows/utils.ts index 8aa017d238..e1a0fbb5c4 100644 --- a/packages/server/src/sdk/app/rows/utils.ts +++ b/packages/server/src/sdk/app/rows/utils.ts @@ -175,13 +175,13 @@ export async function validate({ errors[fieldName] = [`${fieldName} is required`] } } else if ( - (type === FieldType.ATTACHMENT || type === FieldType.JSON) && + (type === FieldType.ATTACHMENTS || type === FieldType.JSON) && typeof row[fieldName] === "string" ) { // this should only happen if there is an error try { const json = JSON.parse(row[fieldName]) - if (type === FieldType.ATTACHMENT) { + if (type === FieldType.ATTACHMENTS) { if (Array.isArray(json)) { row[fieldName] = json } else { diff --git a/packages/server/src/utilities/rowProcessor/attachments.ts b/packages/server/src/utilities/rowProcessor/attachments.ts index e1c83352d4..652851a48b 100644 --- a/packages/server/src/utilities/rowProcessor/attachments.ts +++ b/packages/server/src/utilities/rowProcessor/attachments.ts @@ -34,7 +34,7 @@ export class AttachmentCleanup { let files: string[] = [] const tableSchema = opts.oldTable?.schema || table.schema for (let [key, schema] of Object.entries(tableSchema)) { - if (schema.type !== FieldType.ATTACHMENT) { + if (schema.type !== FieldType.ATTACHMENTS) { continue } const columnRemoved = opts.oldTable && !table.schema[key] @@ -68,7 +68,7 @@ export class AttachmentCleanup { return AttachmentCleanup.coreCleanup(() => { let files: string[] = [] for (let [key, schema] of Object.entries(table.schema)) { - if (schema.type !== FieldType.ATTACHMENT) { + if (schema.type !== FieldType.ATTACHMENTS) { continue } rows.forEach(row => { @@ -88,7 +88,7 @@ export class AttachmentCleanup { return AttachmentCleanup.coreCleanup(() => { let files: string[] = [] for (let [key, schema] of Object.entries(table.schema)) { - if (schema.type !== FieldType.ATTACHMENT) { + if (schema.type !== FieldType.ATTACHMENTS) { continue } const oldKeys = diff --git a/packages/server/src/utilities/rowProcessor/index.ts b/packages/server/src/utilities/rowProcessor/index.ts index 0015680e77..c421929888 100644 --- a/packages/server/src/utilities/rowProcessor/index.ts +++ b/packages/server/src/utilities/rowProcessor/index.ts @@ -148,7 +148,7 @@ export async function inputProcessing( } // remove any attachment urls, they are generated on read - if (field.type === FieldType.ATTACHMENT) { + if (field.type === FieldType.ATTACHMENTS) { const attachments = clonedRow[key] if (attachments?.length) { attachments.forEach((attachment: RowAttachment) => { @@ -216,7 +216,7 @@ export async function outputProcessing( // process complex types: attachements, bb references... for (let [property, column] of Object.entries(table.schema)) { - if (column.type === FieldType.ATTACHMENT) { + if (column.type === FieldType.ATTACHMENTS) { for (let row of enriched) { if (row[property] == null || !Array.isArray(row[property])) { continue diff --git a/packages/server/src/utilities/rowProcessor/map.ts b/packages/server/src/utilities/rowProcessor/map.ts index 60fe5a001b..2e0ac9efe1 100644 --- a/packages/server/src/utilities/rowProcessor/map.ts +++ b/packages/server/src/utilities/rowProcessor/map.ts @@ -106,7 +106,7 @@ export const TYPE_TRANSFORM_MAP: any = { return date }, }, - [FieldType.ATTACHMENT]: { + [FieldType.ATTACHMENTS]: { //@ts-ignore [null]: [], //@ts-ignore diff --git a/packages/server/src/utilities/rowProcessor/tests/attachments.spec.ts b/packages/server/src/utilities/rowProcessor/tests/attachments.spec.ts index cefea7e504..1b36a4cb81 100644 --- a/packages/server/src/utilities/rowProcessor/tests/attachments.spec.ts +++ b/packages/server/src/utilities/rowProcessor/tests/attachments.spec.ts @@ -34,7 +34,7 @@ function table(): Table { schema: { attach: { name: "attach", - type: FieldType.ATTACHMENT, + type: FieldType.ATTACHMENTS, constraints: {}, }, }, diff --git a/packages/server/src/utilities/rowProcessor/tests/outputProcessing.spec.ts b/packages/server/src/utilities/rowProcessor/tests/outputProcessing.spec.ts index a17bd5f393..93404e0469 100644 --- a/packages/server/src/utilities/rowProcessor/tests/outputProcessing.spec.ts +++ b/packages/server/src/utilities/rowProcessor/tests/outputProcessing.spec.ts @@ -82,7 +82,7 @@ describe("rowProcessor - outputProcessing", () => { sourceType: TableSourceType.INTERNAL, schema: { attach: { - type: FieldType.ATTACHMENT, + type: FieldType.ATTACHMENTS, name: "attach", constraints: {}, }, diff --git a/packages/shared-core/src/table.ts b/packages/shared-core/src/table.ts index e1f48ce176..26a7e77cd0 100644 --- a/packages/shared-core/src/table.ts +++ b/packages/shared-core/src/table.ts @@ -13,7 +13,7 @@ const allowDisplayColumnByType: Record = { [FieldType.BIGINT]: true, [FieldType.BOOLEAN]: false, [FieldType.ARRAY]: false, - [FieldType.ATTACHMENT]: false, + [FieldType.ATTACHMENTS]: false, [FieldType.ATTACHMENT_SINGLE]: false, [FieldType.LINK]: false, [FieldType.JSON]: false, @@ -34,7 +34,7 @@ const allowSortColumnByType: Record = { [FieldType.JSON]: true, [FieldType.FORMULA]: false, - [FieldType.ATTACHMENT]: false, + [FieldType.ATTACHMENTS]: false, [FieldType.ATTACHMENT_SINGLE]: false, [FieldType.ARRAY]: false, [FieldType.LINK]: false, diff --git a/packages/types/src/documents/app/row.ts b/packages/types/src/documents/app/row.ts index 5aab87fe6c..27daec1df1 100644 --- a/packages/types/src/documents/app/row.ts +++ b/packages/types/src/documents/app/row.ts @@ -8,7 +8,7 @@ export enum FieldType { BOOLEAN = "boolean", ARRAY = "array", DATETIME = "datetime", - ATTACHMENT = "attachment", + ATTACHMENTS = "attachment", ATTACHMENT_SINGLE = "attachment_single", LINK = "link", FORMULA = "formula", diff --git a/packages/types/src/documents/app/table/schema.ts b/packages/types/src/documents/app/table/schema.ts index 45e39268ac..946df6836e 100644 --- a/packages/types/src/documents/app/table/schema.ts +++ b/packages/types/src/documents/app/table/schema.ts @@ -114,7 +114,7 @@ export interface BBReferenceFieldMetadata export interface AttachmentFieldMetadata extends Omit { - type: FieldType.ATTACHMENT + type: FieldType.ATTACHMENTS subtype?: FieldSubtype.SINGLE } @@ -164,7 +164,7 @@ interface OtherFieldMetadata extends BaseFieldSchema { | FieldType.NUMBER | FieldType.LONGFORM | FieldType.BB_REFERENCE - | FieldType.ATTACHMENT + | FieldType.ATTACHMENTS > } @@ -217,5 +217,5 @@ export function isBBReferenceField( export function isAttachmentField( field: FieldSchema ): field is AttachmentFieldMetadata { - return field.type === FieldType.ATTACHMENT + return field.type === FieldType.ATTACHMENTS } From 757284d6c053b1b6958e89b8e0f762f013b5c49d Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Wed, 3 Apr 2024 10:58:52 +0200 Subject: [PATCH 19/27] Fix tsconfig --- packages/builder/tsconfig.json | 3 --- 1 file changed, 3 deletions(-) diff --git a/packages/builder/tsconfig.json b/packages/builder/tsconfig.json index be79dfd85c..a7a4c3d800 100644 --- a/packages/builder/tsconfig.json +++ b/packages/builder/tsconfig.json @@ -1,9 +1,6 @@ { "extends": "./tsconfig.build.json", "compilerOptions": { - "composite": true, - "declaration": true, - "sourceMap": true, "baseUrl": ".", "paths": { "assets/*": ["./assets/*"], From aabee4d90e199a5d45471c9a43e9643408c75eae Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Wed, 3 Apr 2024 11:02:25 +0200 Subject: [PATCH 20/27] Rename ATTACHMENT to ATTACHMENTS --- .../components/backend/DataTable/modals/CreateEditColumn.svelte | 2 +- packages/builder/src/constants/backend/index.js | 2 +- packages/client/src/components/app/forms/validation.js | 2 +- packages/server/src/api/controllers/table/utils.ts | 2 +- packages/types/src/documents/app/row.ts | 2 +- 5 files changed, 5 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 2701c30359..615ea73f54 100644 --- a/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte +++ b/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte @@ -394,7 +394,7 @@ FIELDS.BIGINT, FIELDS.BOOLEAN, FIELDS.DATETIME, - FIELDS.ATTACHMENT, + FIELDS.ATTACHMENTS, FIELDS.ATTACHMENT_SINGLE, FIELDS.LINK, FIELDS.FORMULA, diff --git a/packages/builder/src/constants/backend/index.js b/packages/builder/src/constants/backend/index.js index d88637d670..bafecae074 100644 --- a/packages/builder/src/constants/backend/index.js +++ b/packages/builder/src/constants/backend/index.js @@ -107,7 +107,7 @@ export const FIELDS = { }, }, }, - ATTACHMENT: { + ATTACHMENTS: { name: "Attachment List", type: FieldType.ATTACHMENTS, icon: "Folder", diff --git a/packages/client/src/components/app/forms/validation.js b/packages/client/src/components/app/forms/validation.js index 3b3a5d6e1d..cdedd85cf2 100644 --- a/packages/client/src/components/app/forms/validation.js +++ b/packages/client/src/components/app/forms/validation.js @@ -192,7 +192,7 @@ const parseType = (value, type) => { } // Parse attachments, treating no elements as null - if (type === FieldTypes.ATTACHMENT) { + if (type === FieldTypes.ATTACHMENTS) { if (!Array.isArray(value) || !value.length) { return null } diff --git a/packages/server/src/api/controllers/table/utils.ts b/packages/server/src/api/controllers/table/utils.ts index 1dea1a09f9..0611a7ae0d 100644 --- a/packages/server/src/api/controllers/table/utils.ts +++ b/packages/server/src/api/controllers/table/utils.ts @@ -99,7 +99,7 @@ export async function checkForColumnUpdates( column.subtype !== oldTable?.schema[column.name]?.subtype ) for (const attachmentColumn of changedAttachmentSubtypeColumns) { - if (attachmentColumn.subtype === FieldTypeSubtypes.ATTACHMENT.SINGLE) { + if (attachmentColumn.subtype === FieldTypeSubtypes.ATTACHMENTS.SINGLE) { attachmentColumn.constraints ??= { length: {} } attachmentColumn.constraints.length ??= {} attachmentColumn.constraints.length.maximum = 1 diff --git a/packages/types/src/documents/app/row.ts b/packages/types/src/documents/app/row.ts index 27daec1df1..b17aececd7 100644 --- a/packages/types/src/documents/app/row.ts +++ b/packages/types/src/documents/app/row.ts @@ -48,7 +48,7 @@ export const FieldTypeSubtypes = { USER: FieldSubtype.USER as FieldSubtype.USER, USERS: FieldSubtype.USERS as FieldSubtype.USERS, }, - ATTACHMENT: { + ATTACHMENTS: { SINGLE: FieldSubtype.SINGLE as FieldSubtype.SINGLE, }, } From 32d11498d2cd164f46f7f64634c11b93da693cd9 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Wed, 3 Apr 2024 11:07:57 +0200 Subject: [PATCH 21/27] Change icons --- packages/builder/src/constants/backend/index.js | 10 +++++++++- .../frontend-core/src/components/grid/lib/utils.js | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/builder/src/constants/backend/index.js b/packages/builder/src/constants/backend/index.js index bafecae074..e32cbbd0a4 100644 --- a/packages/builder/src/constants/backend/index.js +++ b/packages/builder/src/constants/backend/index.js @@ -110,12 +110,20 @@ export const FIELDS = { ATTACHMENTS: { name: "Attachment List", type: FieldType.ATTACHMENTS, - icon: "Folder", + icon: "AppleFiles", constraints: { type: "array", presence: false, }, }, + ATTACHMENT_SINGLE: { + name: "Attachment", + type: FieldType.ATTACHMENT_SINGLE, + icon: "Document", + constraints: { + presence: false, + }, + }, LINK: { name: "Relationship", type: FieldType.LINK, diff --git a/packages/frontend-core/src/components/grid/lib/utils.js b/packages/frontend-core/src/components/grid/lib/utils.js index 75578133a9..49d6b0a439 100644 --- a/packages/frontend-core/src/components/grid/lib/utils.js +++ b/packages/frontend-core/src/components/grid/lib/utils.js @@ -16,8 +16,8 @@ const TypeIconMap = { [FieldType.ARRAY]: "Dropdown", [FieldType.NUMBER]: "123", [FieldType.BOOLEAN]: "Boolean", - [FieldType.ATTACHMENT]: "AppleFiles", [FieldType.ATTACHMENTS]: "AppleFiles", + [FieldType.ATTACHMENT_SINGLE]: "Document", [FieldType.LINK]: "DataCorrelated", [FieldType.FORMULA]: "Calculator", [FieldType.JSON]: "Brackets", From 291ad618e385381337eda376419fa22512cb4b41 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Wed, 3 Apr 2024 11:09:05 +0200 Subject: [PATCH 22/27] Change order --- .../DataTable/modals/CreateEditColumn.svelte | 2 +- packages/builder/src/constants/backend/index.js | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte b/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte index 615ea73f54..92501bec3b 100644 --- a/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte +++ b/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte @@ -394,8 +394,8 @@ FIELDS.BIGINT, FIELDS.BOOLEAN, FIELDS.DATETIME, - FIELDS.ATTACHMENTS, FIELDS.ATTACHMENT_SINGLE, + FIELDS.ATTACHMENTS, FIELDS.LINK, FIELDS.FORMULA, FIELDS.JSON, diff --git a/packages/builder/src/constants/backend/index.js b/packages/builder/src/constants/backend/index.js index e32cbbd0a4..e3888a52e0 100644 --- a/packages/builder/src/constants/backend/index.js +++ b/packages/builder/src/constants/backend/index.js @@ -107,6 +107,14 @@ export const FIELDS = { }, }, }, + ATTACHMENT_SINGLE: { + name: "Attachment", + type: FieldType.ATTACHMENT_SINGLE, + icon: "Document", + constraints: { + presence: false, + }, + }, ATTACHMENTS: { name: "Attachment List", type: FieldType.ATTACHMENTS, @@ -116,14 +124,6 @@ export const FIELDS = { presence: false, }, }, - ATTACHMENT_SINGLE: { - name: "Attachment", - type: FieldType.ATTACHMENT_SINGLE, - icon: "Document", - constraints: { - presence: false, - }, - }, LINK: { name: "Relationship", type: FieldType.LINK, From 234c7feab2b117c4121c91773e3d3c567eecb0fb Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Wed, 3 Apr 2024 12:36:12 +0200 Subject: [PATCH 23/27] Remove single subtype from attachments --- .../server/src/api/controllers/table/utils.ts | 20 ------------------- packages/types/src/documents/app/row.ts | 4 ---- .../types/src/documents/app/table/schema.ts | 1 - 3 files changed, 25 deletions(-) diff --git a/packages/server/src/api/controllers/table/utils.ts b/packages/server/src/api/controllers/table/utils.ts index 0611a7ae0d..ac3a2a5c8a 100644 --- a/packages/server/src/api/controllers/table/utils.ts +++ b/packages/server/src/api/controllers/table/utils.ts @@ -91,26 +91,6 @@ export async function checkForColumnUpdates( await checkForViewUpdates(updatedTable, deletedColumns, columnRename) } - const changedAttachmentSubtypeColumns = Object.values( - updatedTable.schema - ).filter( - (column): column is AttachmentFieldMetadata => - column.type === FieldType.ATTACHMENTS && - column.subtype !== oldTable?.schema[column.name]?.subtype - ) - for (const attachmentColumn of changedAttachmentSubtypeColumns) { - if (attachmentColumn.subtype === FieldTypeSubtypes.ATTACHMENTS.SINGLE) { - attachmentColumn.constraints ??= { length: {} } - attachmentColumn.constraints.length ??= {} - attachmentColumn.constraints.length.maximum = 1 - attachmentColumn.constraints.length.message = - "cannot contain multiple files" - } else { - delete attachmentColumn.constraints?.length?.maximum - delete attachmentColumn.constraints?.length?.message - } - } - return { rows: updatedRows, table: updatedTable } } diff --git a/packages/types/src/documents/app/row.ts b/packages/types/src/documents/app/row.ts index b17aececd7..222c346591 100644 --- a/packages/types/src/documents/app/row.ts +++ b/packages/types/src/documents/app/row.ts @@ -39,7 +39,6 @@ export interface Row extends Document { export enum FieldSubtype { USER = "user", USERS = "users", - SINGLE = "single", } // The 'as' are required for typescript not to type the outputs as generic FieldSubtype @@ -48,7 +47,4 @@ export const FieldTypeSubtypes = { USER: FieldSubtype.USER as FieldSubtype.USER, USERS: FieldSubtype.USERS as FieldSubtype.USERS, }, - ATTACHMENTS: { - SINGLE: FieldSubtype.SINGLE as FieldSubtype.SINGLE, - }, } diff --git a/packages/types/src/documents/app/table/schema.ts b/packages/types/src/documents/app/table/schema.ts index 946df6836e..3eeeee0a81 100644 --- a/packages/types/src/documents/app/table/schema.ts +++ b/packages/types/src/documents/app/table/schema.ts @@ -115,7 +115,6 @@ export interface BBReferenceFieldMetadata export interface AttachmentFieldMetadata extends Omit { type: FieldType.ATTACHMENTS - subtype?: FieldSubtype.SINGLE } export interface FieldConstraints { From dae0c749cac55e3f95ddbb4ece35b2d9ba15483c Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Wed, 3 Apr 2024 12:39:24 +0200 Subject: [PATCH 24/27] Lint --- packages/server/src/api/controllers/table/utils.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/server/src/api/controllers/table/utils.ts b/packages/server/src/api/controllers/table/utils.ts index ac3a2a5c8a..5649a1d996 100644 --- a/packages/server/src/api/controllers/table/utils.ts +++ b/packages/server/src/api/controllers/table/utils.ts @@ -30,8 +30,6 @@ import { View, RelationshipFieldMetadata, FieldType, - FieldTypeSubtypes, - AttachmentFieldMetadata, } from "@budibase/types" export async function clearColumns(table: Table, columnNames: string[]) { From 2c28e074ed164df837829a62ac72adead61f99a9 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Wed, 3 Apr 2024 12:59:04 +0200 Subject: [PATCH 25/27] Fix types --- packages/types/src/documents/app/table/schema.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/types/src/documents/app/table/schema.ts b/packages/types/src/documents/app/table/schema.ts index 3eeeee0a81..86c34b6a5c 100644 --- a/packages/types/src/documents/app/table/schema.ts +++ b/packages/types/src/documents/app/table/schema.ts @@ -112,8 +112,7 @@ export interface BBReferenceFieldMetadata relationshipType?: RelationshipType } -export interface AttachmentFieldMetadata - extends Omit { +export interface AttachmentFieldMetadata extends BaseFieldSchema { type: FieldType.ATTACHMENTS } From dc91aba52c8b030cb48c3a841a052b76c65688a9 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Wed, 3 Apr 2024 15:37:00 +0200 Subject: [PATCH 26/27] authStore undefined check --- .../client/src/components/devtools/DevToolsStatsTab.svelte | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/client/src/components/devtools/DevToolsStatsTab.svelte b/packages/client/src/components/devtools/DevToolsStatsTab.svelte index 24f587332c..bc0b1a562b 100644 --- a/packages/client/src/components/devtools/DevToolsStatsTab.svelte +++ b/packages/client/src/components/devtools/DevToolsStatsTab.svelte @@ -23,6 +23,6 @@ label="Components" value={$componentStore.mountedComponentCount} /> - - + + From 1cfe4da0278f7784d7a65eee3a77c3ab0c746eeb Mon Sep 17 00:00:00 2001 From: Michael Drury Date: Wed, 3 Apr 2024 16:01:45 +0100 Subject: [PATCH 27/27] Revert "Single attachment column type" --- packages/bbui/src/Form/Core/Dropzone.svelte | 2 +- .../components/backend/DataTable/formula.js | 2 +- .../DataTable/modals/CreateEditColumn.svelte | 3 +- .../controls/FieldConfiguration/utils.js | 3 +- .../builder/src/constants/backend/index.js | 16 +-- packages/builder/tsconfig.json | 3 + packages/client/manifest.json | 99 +------------------ .../app/blocks/FormBlockComponent.svelte | 5 +- .../app/forms/AttachmentField.svelte | 15 +-- .../app/forms/AttachmentSingleField.svelte | 16 --- .../client/src/components/app/forms/index.js | 1 - .../src/components/app/forms/validation.js | 2 +- .../grid/cells/AttachmentCell.svelte | 3 +- .../grid/cells/AttachmentSingleCell.svelte | 20 ---- .../src/components/grid/lib/renderers.js | 4 +- .../src/components/grid/lib/utils.js | 3 +- .../server/src/api/controllers/table/utils.ts | 22 +++++ .../server/src/api/routes/tests/row.spec.ts | 4 +- .../db/defaultData/datasource_bb_default.ts | 4 +- .../server/src/sdk/app/rows/attachments.ts | 2 +- packages/server/src/sdk/app/rows/utils.ts | 4 +- .../src/utilities/rowProcessor/attachments.ts | 6 +- .../src/utilities/rowProcessor/index.ts | 4 +- .../server/src/utilities/rowProcessor/map.ts | 2 +- .../rowProcessor/tests/attachments.spec.ts | 2 +- .../tests/outputProcessing.spec.ts | 2 +- packages/shared-core/src/table.ts | 7 +- packages/types/src/documents/app/row.ts | 7 +- .../types/src/documents/app/table/schema.ts | 10 +- 29 files changed, 73 insertions(+), 200 deletions(-) delete mode 100644 packages/client/src/components/app/forms/AttachmentSingleField.svelte delete mode 100644 packages/frontend-core/src/components/grid/cells/AttachmentSingleCell.svelte diff --git a/packages/bbui/src/Form/Core/Dropzone.svelte b/packages/bbui/src/Form/Core/Dropzone.svelte index dd72167791..3d803c0961 100644 --- a/packages/bbui/src/Form/Core/Dropzone.svelte +++ b/packages/bbui/src/Form/Core/Dropzone.svelte @@ -67,7 +67,7 @@ } $: showDropzone = - (!maximum || (maximum && (value?.length || 0) < maximum)) && !disabled + (!maximum || (maximum && value?.length < maximum)) && !disabled async function processFileList(fileList) { if ( diff --git a/packages/builder/src/components/backend/DataTable/formula.js b/packages/builder/src/components/backend/DataTable/formula.js index b339729391..e3da4249bc 100644 --- a/packages/builder/src/components/backend/DataTable/formula.js +++ b/packages/builder/src/components/backend/DataTable/formula.js @@ -9,7 +9,7 @@ const MAX_DEPTH = 1 const TYPES_TO_SKIP = [ FieldType.FORMULA, FieldType.LONGFORM, - FieldType.ATTACHMENTS, + FieldType.ATTACHMENT, //https://github.com/Budibase/budibase/issues/3030 FieldType.INTERNAL, ] diff --git a/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte b/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte index 92501bec3b..cfc6e9a7be 100644 --- a/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte +++ b/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte @@ -394,8 +394,7 @@ FIELDS.BIGINT, FIELDS.BOOLEAN, FIELDS.DATETIME, - FIELDS.ATTACHMENT_SINGLE, - FIELDS.ATTACHMENTS, + FIELDS.ATTACHMENT, FIELDS.LINK, FIELDS.FORMULA, FIELDS.JSON, diff --git a/packages/builder/src/components/design/settings/controls/FieldConfiguration/utils.js b/packages/builder/src/components/design/settings/controls/FieldConfiguration/utils.js index d0f9afda40..18ebf57d98 100644 --- a/packages/builder/src/components/design/settings/controls/FieldConfiguration/utils.js +++ b/packages/builder/src/components/design/settings/controls/FieldConfiguration/utils.js @@ -41,8 +41,7 @@ export const FieldTypeToComponentMap = { [FieldType.BOOLEAN]: "booleanfield", [FieldType.LONGFORM]: "longformfield", [FieldType.DATETIME]: "datetimefield", - [FieldType.ATTACHMENTS]: "attachmentfield", - [FieldType.ATTACHMENT_SINGLE]: "attachmentsinglefield", + [FieldType.ATTACHMENT]: "attachmentfield", [FieldType.LINK]: "relationshipfield", [FieldType.JSON]: "jsonfield", [FieldType.BARCODEQR]: "codescanner", diff --git a/packages/builder/src/constants/backend/index.js b/packages/builder/src/constants/backend/index.js index e3888a52e0..dd751d4e13 100644 --- a/packages/builder/src/constants/backend/index.js +++ b/packages/builder/src/constants/backend/index.js @@ -107,18 +107,10 @@ export const FIELDS = { }, }, }, - ATTACHMENT_SINGLE: { + ATTACHMENT: { name: "Attachment", - type: FieldType.ATTACHMENT_SINGLE, - icon: "Document", - constraints: { - presence: false, - }, - }, - ATTACHMENTS: { - name: "Attachment List", - type: FieldType.ATTACHMENTS, - icon: "AppleFiles", + type: FieldType.ATTACHMENT, + icon: "Folder", constraints: { type: "array", presence: false, @@ -307,7 +299,7 @@ export const PaginationLocations = [ export const BannedSearchTypes = [ FieldType.LINK, - FieldType.ATTACHMENTS, + FieldType.ATTACHMENT, FieldType.FORMULA, FieldType.JSON, "jsonarray", diff --git a/packages/builder/tsconfig.json b/packages/builder/tsconfig.json index a7a4c3d800..be79dfd85c 100644 --- a/packages/builder/tsconfig.json +++ b/packages/builder/tsconfig.json @@ -1,6 +1,9 @@ { "extends": "./tsconfig.build.json", "compilerOptions": { + "composite": true, + "declaration": true, + "sourceMap": true, "baseUrl": ".", "paths": { "assets/*": ["./assets/*"], diff --git a/packages/client/manifest.json b/packages/client/manifest.json index cc5c68ea83..08d614391b 100644 --- a/packages/client/manifest.json +++ b/packages/client/manifest.json @@ -4226,7 +4226,7 @@ ] }, "attachmentfield": { - "name": "Attachment list", + "name": "Attachment", "icon": "Attach", "styles": ["size"], "requiredAncestors": ["form"], @@ -4322,103 +4322,6 @@ } ] }, - "attachmentsinglefield": { - "name": "Single Attachment", - "icon": "Attach", - "styles": ["size"], - "requiredAncestors": ["form"], - "editable": true, - "size": { - "width": 400, - "height": 200 - }, - "settings": [ - { - "type": "field/attachment_single", - "label": "Field", - "key": "field", - "required": true - }, - { - "type": "text", - "label": "Label", - "key": "label" - }, - { - "type": "text", - "label": "Help text", - "key": "helpText" - }, - { - "type": "text", - "label": "Extensions", - "key": "extensions" - }, - { - "type": "number", - "label": "Max attachments", - "key": "maximum", - "min": 1 - }, - { - "type": "event", - "label": "On change", - "key": "onChange", - "context": [ - { - "label": "Field Value", - "key": "value" - } - ] - }, - { - "type": "boolean", - "label": "Compact", - "key": "compact", - "defaultValue": false - }, - { - "type": "boolean", - "label": "Read only", - "key": "disabled", - "defaultValue": false - }, - { - "type": "validation/attachment", - "label": "Validation", - "key": "validation" - }, - { - "type": "select", - "label": "Layout", - "key": "span", - "defaultValue": 6, - "hidden": true, - "showInBar": true, - "barStyle": "buttons", - "options": [ - { - "label": "1 column", - "value": 6, - "barIcon": "Stop", - "barTitle": "1 column" - }, - { - "label": "2 columns", - "value": 3, - "barIcon": "ColumnTwoA", - "barTitle": "2 columns" - }, - { - "label": "3 columns", - "value": 2, - "barIcon": "ViewColumn", - "barTitle": "3 columns" - } - ] - } - ] - }, "relationshipfield": { "name": "Relationship Picker", "icon": "TaskList", diff --git a/packages/client/src/components/app/blocks/FormBlockComponent.svelte b/packages/client/src/components/app/blocks/FormBlockComponent.svelte index 968ed36b8b..34168355c4 100644 --- a/packages/client/src/components/app/blocks/FormBlockComponent.svelte +++ b/packages/client/src/components/app/blocks/FormBlockComponent.svelte @@ -15,8 +15,7 @@ [FieldType.BOOLEAN]: "booleanfield", [FieldType.LONGFORM]: "longformfield", [FieldType.DATETIME]: "datetimefield", - [FieldType.ATTACHMENTS]: "attachmentfield", - [FieldType.ATTACHMENT_SINGLE]: "attachmentsinglefield", + [FieldType.ATTACHMENT]: "attachmentfield", [FieldType.LINK]: "relationshipfield", [FieldType.JSON]: "jsonfield", [FieldType.BARCODEQR]: "codescanner", @@ -61,7 +60,7 @@ function getPropsByType(field) { const propsMapByType = { - [FieldType.ATTACHMENTS]: (_field, schema) => { + [FieldType.ATTACHMENT]: (_field, schema) => { return { maximum: schema?.constraints?.length?.maximum, } diff --git a/packages/client/src/components/app/forms/AttachmentField.svelte b/packages/client/src/components/app/forms/AttachmentField.svelte index 8be70bc011..b61f88daeb 100644 --- a/packages/client/src/components/app/forms/AttachmentField.svelte +++ b/packages/client/src/components/app/forms/AttachmentField.svelte @@ -1,7 +1,6 @@ @@ -85,14 +78,14 @@ {validation} {span} {helpText} - {type} + type="attachment" bind:fieldState bind:fieldApi defaultValue={[]} > {#if fieldState} - import { FieldType } from "@budibase/types" - import AttachmentField from "./AttachmentField.svelte" - - const fieldApiMapper = { - get: value => (!Array.isArray(value) && value ? [value] : value) || [], - set: value => value[0] || null, - } - - - diff --git a/packages/client/src/components/app/forms/index.js b/packages/client/src/components/app/forms/index.js index aa54204454..5804d3a79d 100644 --- a/packages/client/src/components/app/forms/index.js +++ b/packages/client/src/components/app/forms/index.js @@ -9,7 +9,6 @@ export { default as booleanfield } from "./BooleanField.svelte" export { default as longformfield } from "./LongFormField.svelte" export { default as datetimefield } from "./DateTimeField.svelte" export { default as attachmentfield } from "./AttachmentField.svelte" -export { default as attachmentsinglefield } from "./AttachmentSingleField.svelte" export { default as relationshipfield } from "./RelationshipField.svelte" export { default as passwordfield } from "./PasswordField.svelte" export { default as formstep } from "./FormStep.svelte" diff --git a/packages/client/src/components/app/forms/validation.js b/packages/client/src/components/app/forms/validation.js index cdedd85cf2..3b3a5d6e1d 100644 --- a/packages/client/src/components/app/forms/validation.js +++ b/packages/client/src/components/app/forms/validation.js @@ -192,7 +192,7 @@ const parseType = (value, type) => { } // Parse attachments, treating no elements as null - if (type === FieldTypes.ATTACHMENTS) { + if (type === FieldTypes.ATTACHMENT) { if (!Array.isArray(value) || !value.length) { return null } diff --git a/packages/frontend-core/src/components/grid/cells/AttachmentCell.svelte b/packages/frontend-core/src/components/grid/cells/AttachmentCell.svelte index 3a1f165b6e..a1f5c4f2aa 100644 --- a/packages/frontend-core/src/components/grid/cells/AttachmentCell.svelte +++ b/packages/frontend-core/src/components/grid/cells/AttachmentCell.svelte @@ -10,7 +10,6 @@ export let invertX = false export let invertY = false export let schema - export let maximum const { API, notifications } = getContext("grid") const imageExtensions = ["png", "tiff", "gif", "raw", "jpg", "jpeg"] @@ -99,7 +98,7 @@ {value} compact on:change={e => onChange(e.detail)} - maximum={maximum || schema.constraints?.length?.maximum} + maximum={schema.constraints?.length?.maximum} {processFiles} {deleteAttachments} {handleFileTooLarge} diff --git a/packages/frontend-core/src/components/grid/cells/AttachmentSingleCell.svelte b/packages/frontend-core/src/components/grid/cells/AttachmentSingleCell.svelte deleted file mode 100644 index c2e29b6ede..0000000000 --- a/packages/frontend-core/src/components/grid/cells/AttachmentSingleCell.svelte +++ /dev/null @@ -1,20 +0,0 @@ - - - diff --git a/packages/frontend-core/src/components/grid/lib/renderers.js b/packages/frontend-core/src/components/grid/lib/renderers.js index c3ee276ff9..19bf63312d 100644 --- a/packages/frontend-core/src/components/grid/lib/renderers.js +++ b/packages/frontend-core/src/components/grid/lib/renderers.js @@ -11,7 +11,6 @@ import BooleanCell from "../cells/BooleanCell.svelte" import FormulaCell from "../cells/FormulaCell.svelte" import JSONCell from "../cells/JSONCell.svelte" import AttachmentCell from "../cells/AttachmentCell.svelte" -import AttachmentSingleCell from "../cells/AttachmentSingleCell.svelte" import BBReferenceCell from "../cells/BBReferenceCell.svelte" const TypeComponentMap = { @@ -23,8 +22,7 @@ const TypeComponentMap = { [FieldType.ARRAY]: MultiSelectCell, [FieldType.NUMBER]: NumberCell, [FieldType.BOOLEAN]: BooleanCell, - [FieldType.ATTACHMENTS]: AttachmentCell, - [FieldType.ATTACHMENT_SINGLE]: AttachmentSingleCell, + [FieldType.ATTACHMENT]: AttachmentCell, [FieldType.LINK]: RelationshipCell, [FieldType.FORMULA]: FormulaCell, [FieldType.JSON]: JSONCell, diff --git a/packages/frontend-core/src/components/grid/lib/utils.js b/packages/frontend-core/src/components/grid/lib/utils.js index 49d6b0a439..8382bfece8 100644 --- a/packages/frontend-core/src/components/grid/lib/utils.js +++ b/packages/frontend-core/src/components/grid/lib/utils.js @@ -16,8 +16,7 @@ const TypeIconMap = { [FieldType.ARRAY]: "Dropdown", [FieldType.NUMBER]: "123", [FieldType.BOOLEAN]: "Boolean", - [FieldType.ATTACHMENTS]: "AppleFiles", - [FieldType.ATTACHMENT_SINGLE]: "Document", + [FieldType.ATTACHMENT]: "AppleFiles", [FieldType.LINK]: "DataCorrelated", [FieldType.FORMULA]: "Calculator", [FieldType.JSON]: "Brackets", diff --git a/packages/server/src/api/controllers/table/utils.ts b/packages/server/src/api/controllers/table/utils.ts index 5649a1d996..0c9933a4cf 100644 --- a/packages/server/src/api/controllers/table/utils.ts +++ b/packages/server/src/api/controllers/table/utils.ts @@ -30,6 +30,8 @@ import { View, RelationshipFieldMetadata, FieldType, + FieldTypeSubtypes, + AttachmentFieldMetadata, } from "@budibase/types" export async function clearColumns(table: Table, columnNames: string[]) { @@ -89,6 +91,26 @@ export async function checkForColumnUpdates( await checkForViewUpdates(updatedTable, deletedColumns, columnRename) } + const changedAttachmentSubtypeColumns = Object.values( + updatedTable.schema + ).filter( + (column): column is AttachmentFieldMetadata => + column.type === FieldType.ATTACHMENT && + column.subtype !== oldTable?.schema[column.name]?.subtype + ) + for (const attachmentColumn of changedAttachmentSubtypeColumns) { + if (attachmentColumn.subtype === FieldTypeSubtypes.ATTACHMENT.SINGLE) { + attachmentColumn.constraints ??= { length: {} } + attachmentColumn.constraints.length ??= {} + attachmentColumn.constraints.length.maximum = 1 + attachmentColumn.constraints.length.message = + "cannot contain multiple files" + } else { + delete attachmentColumn.constraints?.length?.maximum + delete attachmentColumn.constraints?.length?.message + } + } + return { rows: updatedRows, table: updatedTable } } diff --git a/packages/server/src/api/routes/tests/row.spec.ts b/packages/server/src/api/routes/tests/row.spec.ts index 0fe8beb7ea..8910522565 100644 --- a/packages/server/src/api/routes/tests/row.spec.ts +++ b/packages/server/src/api/routes/tests/row.spec.ts @@ -234,7 +234,7 @@ describe.each([ constraints: { type: "string", presence: false }, } const attachment: FieldSchema = { - type: FieldType.ATTACHMENTS, + type: FieldType.ATTACHMENT, name: "attachment", constraints: { type: "array", presence: false }, } @@ -790,7 +790,7 @@ describe.each([ defaultTable({ schema: { attachment: { - type: FieldType.ATTACHMENTS, + type: FieldType.ATTACHMENT, name: "attachment", constraints: { type: "array", presence: false }, }, diff --git a/packages/server/src/db/defaultData/datasource_bb_default.ts b/packages/server/src/db/defaultData/datasource_bb_default.ts index 68d49b2d8b..03aed3c118 100644 --- a/packages/server/src/db/defaultData/datasource_bb_default.ts +++ b/packages/server/src/db/defaultData/datasource_bb_default.ts @@ -299,7 +299,7 @@ export const DEFAULT_EMPLOYEE_TABLE_SCHEMA: Table = { sortable: false, }, "Badge Photo": { - type: FieldType.ATTACHMENTS, + type: FieldType.ATTACHMENT, constraints: { type: FieldType.ARRAY, presence: false, @@ -607,7 +607,7 @@ export const DEFAULT_EXPENSES_TABLE_SCHEMA: Table = { ignoreTimezones: true, }, Attachment: { - type: FieldType.ATTACHMENTS, + type: FieldType.ATTACHMENT, constraints: { type: FieldType.ARRAY, presence: false, diff --git a/packages/server/src/sdk/app/rows/attachments.ts b/packages/server/src/sdk/app/rows/attachments.ts index 8fd2ccf795..2ab9e83c47 100644 --- a/packages/server/src/sdk/app/rows/attachments.ts +++ b/packages/server/src/sdk/app/rows/attachments.ts @@ -30,7 +30,7 @@ export async function getRowsWithAttachments(appId: string, table: Table) { const db = dbCore.getDB(appId) const attachmentCols: string[] = [] for (let [key, column] of Object.entries(table.schema)) { - if (column.type === FieldType.ATTACHMENTS) { + if (column.type === FieldType.ATTACHMENT) { attachmentCols.push(key) } } diff --git a/packages/server/src/sdk/app/rows/utils.ts b/packages/server/src/sdk/app/rows/utils.ts index e1a0fbb5c4..8aa017d238 100644 --- a/packages/server/src/sdk/app/rows/utils.ts +++ b/packages/server/src/sdk/app/rows/utils.ts @@ -175,13 +175,13 @@ export async function validate({ errors[fieldName] = [`${fieldName} is required`] } } else if ( - (type === FieldType.ATTACHMENTS || type === FieldType.JSON) && + (type === FieldType.ATTACHMENT || type === FieldType.JSON) && typeof row[fieldName] === "string" ) { // this should only happen if there is an error try { const json = JSON.parse(row[fieldName]) - if (type === FieldType.ATTACHMENTS) { + if (type === FieldType.ATTACHMENT) { if (Array.isArray(json)) { row[fieldName] = json } else { diff --git a/packages/server/src/utilities/rowProcessor/attachments.ts b/packages/server/src/utilities/rowProcessor/attachments.ts index 652851a48b..e1c83352d4 100644 --- a/packages/server/src/utilities/rowProcessor/attachments.ts +++ b/packages/server/src/utilities/rowProcessor/attachments.ts @@ -34,7 +34,7 @@ export class AttachmentCleanup { let files: string[] = [] const tableSchema = opts.oldTable?.schema || table.schema for (let [key, schema] of Object.entries(tableSchema)) { - if (schema.type !== FieldType.ATTACHMENTS) { + if (schema.type !== FieldType.ATTACHMENT) { continue } const columnRemoved = opts.oldTable && !table.schema[key] @@ -68,7 +68,7 @@ export class AttachmentCleanup { return AttachmentCleanup.coreCleanup(() => { let files: string[] = [] for (let [key, schema] of Object.entries(table.schema)) { - if (schema.type !== FieldType.ATTACHMENTS) { + if (schema.type !== FieldType.ATTACHMENT) { continue } rows.forEach(row => { @@ -88,7 +88,7 @@ export class AttachmentCleanup { return AttachmentCleanup.coreCleanup(() => { let files: string[] = [] for (let [key, schema] of Object.entries(table.schema)) { - if (schema.type !== FieldType.ATTACHMENTS) { + if (schema.type !== FieldType.ATTACHMENT) { continue } const oldKeys = diff --git a/packages/server/src/utilities/rowProcessor/index.ts b/packages/server/src/utilities/rowProcessor/index.ts index c421929888..0015680e77 100644 --- a/packages/server/src/utilities/rowProcessor/index.ts +++ b/packages/server/src/utilities/rowProcessor/index.ts @@ -148,7 +148,7 @@ export async function inputProcessing( } // remove any attachment urls, they are generated on read - if (field.type === FieldType.ATTACHMENTS) { + if (field.type === FieldType.ATTACHMENT) { const attachments = clonedRow[key] if (attachments?.length) { attachments.forEach((attachment: RowAttachment) => { @@ -216,7 +216,7 @@ export async function outputProcessing( // process complex types: attachements, bb references... for (let [property, column] of Object.entries(table.schema)) { - if (column.type === FieldType.ATTACHMENTS) { + if (column.type === FieldType.ATTACHMENT) { for (let row of enriched) { if (row[property] == null || !Array.isArray(row[property])) { continue diff --git a/packages/server/src/utilities/rowProcessor/map.ts b/packages/server/src/utilities/rowProcessor/map.ts index 2e0ac9efe1..60fe5a001b 100644 --- a/packages/server/src/utilities/rowProcessor/map.ts +++ b/packages/server/src/utilities/rowProcessor/map.ts @@ -106,7 +106,7 @@ export const TYPE_TRANSFORM_MAP: any = { return date }, }, - [FieldType.ATTACHMENTS]: { + [FieldType.ATTACHMENT]: { //@ts-ignore [null]: [], //@ts-ignore diff --git a/packages/server/src/utilities/rowProcessor/tests/attachments.spec.ts b/packages/server/src/utilities/rowProcessor/tests/attachments.spec.ts index 1b36a4cb81..cefea7e504 100644 --- a/packages/server/src/utilities/rowProcessor/tests/attachments.spec.ts +++ b/packages/server/src/utilities/rowProcessor/tests/attachments.spec.ts @@ -34,7 +34,7 @@ function table(): Table { schema: { attach: { name: "attach", - type: FieldType.ATTACHMENTS, + type: FieldType.ATTACHMENT, constraints: {}, }, }, diff --git a/packages/server/src/utilities/rowProcessor/tests/outputProcessing.spec.ts b/packages/server/src/utilities/rowProcessor/tests/outputProcessing.spec.ts index 93404e0469..a17bd5f393 100644 --- a/packages/server/src/utilities/rowProcessor/tests/outputProcessing.spec.ts +++ b/packages/server/src/utilities/rowProcessor/tests/outputProcessing.spec.ts @@ -82,7 +82,7 @@ describe("rowProcessor - outputProcessing", () => { sourceType: TableSourceType.INTERNAL, schema: { attach: { - type: FieldType.ATTACHMENTS, + type: FieldType.ATTACHMENT, name: "attach", constraints: {}, }, diff --git a/packages/shared-core/src/table.ts b/packages/shared-core/src/table.ts index 26a7e77cd0..5eab2fc340 100644 --- a/packages/shared-core/src/table.ts +++ b/packages/shared-core/src/table.ts @@ -11,10 +11,10 @@ const allowDisplayColumnByType: Record = { [FieldType.INTERNAL]: true, [FieldType.BARCODEQR]: true, [FieldType.BIGINT]: true, + [FieldType.BOOLEAN]: false, [FieldType.ARRAY]: false, - [FieldType.ATTACHMENTS]: false, - [FieldType.ATTACHMENT_SINGLE]: false, + [FieldType.ATTACHMENT]: false, [FieldType.LINK]: false, [FieldType.JSON]: false, [FieldType.BB_REFERENCE]: false, @@ -34,8 +34,7 @@ const allowSortColumnByType: Record = { [FieldType.JSON]: true, [FieldType.FORMULA]: false, - [FieldType.ATTACHMENTS]: false, - [FieldType.ATTACHMENT_SINGLE]: false, + [FieldType.ATTACHMENT]: false, [FieldType.ARRAY]: false, [FieldType.LINK]: false, [FieldType.BB_REFERENCE]: false, diff --git a/packages/types/src/documents/app/row.ts b/packages/types/src/documents/app/row.ts index 222c346591..aa8f50d4a8 100644 --- a/packages/types/src/documents/app/row.ts +++ b/packages/types/src/documents/app/row.ts @@ -8,8 +8,7 @@ export enum FieldType { BOOLEAN = "boolean", ARRAY = "array", DATETIME = "datetime", - ATTACHMENTS = "attachment", - ATTACHMENT_SINGLE = "attachment_single", + ATTACHMENT = "attachment", LINK = "link", FORMULA = "formula", AUTO = "auto", @@ -39,6 +38,7 @@ export interface Row extends Document { export enum FieldSubtype { USER = "user", USERS = "users", + SINGLE = "single", } // The 'as' are required for typescript not to type the outputs as generic FieldSubtype @@ -47,4 +47,7 @@ export const FieldTypeSubtypes = { USER: FieldSubtype.USER as FieldSubtype.USER, USERS: FieldSubtype.USERS as FieldSubtype.USERS, }, + ATTACHMENT: { + SINGLE: FieldSubtype.SINGLE as FieldSubtype.SINGLE, + }, } diff --git a/packages/types/src/documents/app/table/schema.ts b/packages/types/src/documents/app/table/schema.ts index 86c34b6a5c..45e39268ac 100644 --- a/packages/types/src/documents/app/table/schema.ts +++ b/packages/types/src/documents/app/table/schema.ts @@ -112,8 +112,10 @@ export interface BBReferenceFieldMetadata relationshipType?: RelationshipType } -export interface AttachmentFieldMetadata extends BaseFieldSchema { - type: FieldType.ATTACHMENTS +export interface AttachmentFieldMetadata + extends Omit { + type: FieldType.ATTACHMENT + subtype?: FieldSubtype.SINGLE } export interface FieldConstraints { @@ -162,7 +164,7 @@ interface OtherFieldMetadata extends BaseFieldSchema { | FieldType.NUMBER | FieldType.LONGFORM | FieldType.BB_REFERENCE - | FieldType.ATTACHMENTS + | FieldType.ATTACHMENT > } @@ -215,5 +217,5 @@ export function isBBReferenceField( export function isAttachmentField( field: FieldSchema ): field is AttachmentFieldMetadata { - return field.type === FieldType.ATTACHMENTS + return field.type === FieldType.ATTACHMENT }