From 2b9298963ff0e2b28a1229b9ed8e87f673f76c63 Mon Sep 17 00:00:00 2001 From: Dean Date: Mon, 5 Aug 2024 09:57:27 +0100 Subject: [PATCH 1/6] Assorted builder fixes and a fix for Google sheets filtering --- packages/bbui/src/Form/Core/Select.svelte | 4 +++- .../components/design/settings/componentSettings.js | 1 + .../src/components/grid/cells/SignatureCell.svelte | 5 +++++ packages/server/src/integrations/googlesheets.ts | 8 +++++++- packages/shared-core/src/filters.ts | 11 +++++++++-- 5 files changed, 25 insertions(+), 4 deletions(-) diff --git a/packages/bbui/src/Form/Core/Select.svelte b/packages/bbui/src/Form/Core/Select.svelte index 3806281438..7d325bb6cc 100644 --- a/packages/bbui/src/Form/Core/Select.svelte +++ b/packages/bbui/src/Form/Core/Select.svelte @@ -102,7 +102,9 @@ {onOptionMouseenter} {onOptionMouseleave} isPlaceholder={value == null || value === ""} - placeholderOption={placeholder === false ? null : placeholder} + placeholderOption={placeholder === false + ? null + : placeholder || "Choose an option"} isOptionSelected={option => compareOptionAndValue(option, value)} onSelectOption={selectOption} {loading} diff --git a/packages/builder/src/components/design/settings/componentSettings.js b/packages/builder/src/components/design/settings/componentSettings.js index f5ab1cb157..ede48b84ba 100644 --- a/packages/builder/src/components/design/settings/componentSettings.js +++ b/packages/builder/src/components/design/settings/componentSettings.js @@ -80,6 +80,7 @@ const componentMap = { "field/barcodeqr": FormFieldSelect, "field/signature_single": FormFieldSelect, "field/bb_reference": FormFieldSelect, + "field/bb_reference_single": FormFieldSelect, // Some validation types are the same as others, so not all types are // explicitly listed here. e.g. options uses string validation "validation/string": ValidationEditor, diff --git a/packages/frontend-core/src/components/grid/cells/SignatureCell.svelte b/packages/frontend-core/src/components/grid/cells/SignatureCell.svelte index 8b37cd8847..c3e1557ac5 100644 --- a/packages/frontend-core/src/components/grid/cells/SignatureCell.svelte +++ b/packages/frontend-core/src/components/grid/cells/SignatureCell.svelte @@ -129,6 +129,11 @@ width: 100%; min-width: unset; } + .signature-cell img { + max-width: 100%; + max-height: 100%; + object-fit: contain; + } .signature-cell.light img { -webkit-filter: invert(100%); filter: invert(100%); diff --git a/packages/server/src/integrations/googlesheets.ts b/packages/server/src/integrations/googlesheets.ts index 9dee9b2a53..f8f5209890 100644 --- a/packages/server/src/integrations/googlesheets.ts +++ b/packages/server/src/integrations/googlesheets.ts @@ -566,7 +566,13 @@ class GoogleSheetsIntegration implements DatasourcePlus { query.filters.equal[`_${GOOGLE_SHEETS_PRIMARY_KEY}`] = id } } - let filtered = dataFilters.runQuery(rows, query.filters || {}) + let filtered = dataFilters.runQuery( + rows, + query.filters || {}, + (row: GoogleSpreadsheetRow, headerKey: string) => { + return row.get(headerKey) + } + ) if (hasFilters && query.paginate) { filtered = filtered.slice(offset, offset + limit) } diff --git a/packages/shared-core/src/filters.ts b/packages/shared-core/src/filters.ts index 65caa9c434..f3fe3f726b 100644 --- a/packages/shared-core/src/filters.ts +++ b/packages/shared-core/src/filters.ts @@ -393,8 +393,15 @@ export const search = ( * Performs a client-side search on an array of data * @param docs the data * @param query the JSON query + * @param findInDoc optional fn when trying to extract a value + * from custom doc type e.g. Google Sheets + * */ -export const runQuery = (docs: Record[], query: SearchFilters) => { +export const runQuery = ( + docs: Record[], + query: SearchFilters, + findInDoc: Function = deepGet +) => { if (!docs || !Array.isArray(docs)) { return [] } @@ -419,7 +426,7 @@ export const runQuery = (docs: Record[], query: SearchFilters) => { ) => (doc: Record) => { for (const [key, testValue] of Object.entries(query[type] || {})) { - const result = test(deepGet(doc, removeKeyNumbering(key)), testValue) + const result = test(findInDoc(doc, removeKeyNumbering(key)), testValue) if (query.allOr && result) { return true } else if (!query.allOr && !result) { From e3f021aea13aecff2426b1fa276a7db42b537ff9 Mon Sep 17 00:00:00 2001 From: Dean Date: Mon, 5 Aug 2024 17:05:09 +0100 Subject: [PATCH 2/6] Added single user validation config so user fields display as set when bindings are used. --- .../src/components/common/bindings/DrawerBindableSlot.svelte | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/builder/src/components/common/bindings/DrawerBindableSlot.svelte b/packages/builder/src/components/common/bindings/DrawerBindableSlot.svelte index 3a787a70cb..3180ceb960 100644 --- a/packages/builder/src/components/common/bindings/DrawerBindableSlot.svelte +++ b/packages/builder/src/components/common/bindings/DrawerBindableSlot.svelte @@ -105,6 +105,7 @@ datetime: isValidDate, link: hasValidLinks, bb_reference: hasValidLinks, + bb_reference_single: hasValidLinks, array: hasValidOptions, longform: value => !isJSBinding(value), json: value => !isJSBinding(value), From 853e8916646ce35f71da2899961e04a0d19730dc Mon Sep 17 00:00:00 2001 From: Dean Date: Tue, 6 Aug 2024 11:58:12 +0100 Subject: [PATCH 3/6] Fixes for Single select and Single user pickers. Now displaying binding status correctly --- .../SetupPanel/RowSelectorTypes.svelte | 4 ++-- .../backend/DataTable/RowFieldControl.svelte | 2 +- .../common/LinkedRowSelector.svelte | 23 ++++++++++++++----- .../common/bindings/DrawerBindableSlot.svelte | 3 ++- 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/packages/builder/src/components/automation/SetupPanel/RowSelectorTypes.svelte b/packages/builder/src/components/automation/SetupPanel/RowSelectorTypes.svelte index 85d57e665a..ee9fd12c0c 100644 --- a/packages/builder/src/components/automation/SetupPanel/RowSelectorTypes.svelte +++ b/packages/builder/src/components/automation/SetupPanel/RowSelectorTypes.svelte @@ -157,7 +157,7 @@ {:else if schema.type === "link"} onChange({ @@ -169,7 +169,7 @@ /> {:else if schema.type === "bb_reference" || schema.type === "bb_reference_single"} diff --git a/packages/builder/src/components/backend/DataTable/RowFieldControl.svelte b/packages/builder/src/components/backend/DataTable/RowFieldControl.svelte index b012766171..745f29d56a 100644 --- a/packages/builder/src/components/backend/DataTable/RowFieldControl.svelte +++ b/packages/builder/src/components/backend/DataTable/RowFieldControl.svelte @@ -146,7 +146,7 @@ {:else if type === "link"} (value = e.detail)} /> diff --git a/packages/builder/src/components/common/LinkedRowSelector.svelte b/packages/builder/src/components/common/LinkedRowSelector.svelte index 8db4a7dc03..dc094bc1ab 100644 --- a/packages/builder/src/components/common/LinkedRowSelector.svelte +++ b/packages/builder/src/components/common/LinkedRowSelector.svelte @@ -6,7 +6,7 @@ import { createEventDispatcher } from "svelte" export let schema - export let linkedRows = [] + export let linkedData export let useLabel = true export let linkedTableId export let label @@ -15,14 +15,25 @@ let rows = [] let linkedIds = [] - $: linkedIds = (Array.isArray(linkedRows) ? linkedRows : [])?.map( - row => row?._id || row - ) + $: fieldValue = getFieldValue(linkedData) $: label = label || capitalise(schema.name) $: linkedTableId = linkedTableId || schema.tableId $: linkedTable = $tables.list.find(table => table._id === linkedTableId) $: fetchRows(linkedTableId) + const getFieldValue = val => { + const linkedIds = (Array.isArray(val) ? val : [])?.map( + row => row?._id || row + ) + if (schema.relationshipType === "one-to-many") { + return linkedIds?.[0] + } else if (schema.type === "bb_reference_single") { + return val + } else { + return linkedIds + } + } + async function fetchRows(linkedTableId) { try { rows = await API.fetchTableData(linkedTableId) @@ -45,7 +56,7 @@ {:else if schema.relationshipType === "one-to-many" || schema.type === "bb_reference_single"}