From 77587c86868b9970daa9664db3a38d3befe6b847 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Fri, 6 Sep 2024 12:23:32 +0200 Subject: [PATCH 01/57] Add related columns --- .../GridColumnConfiguration/getColumns.js | 44 ++++++++++++++++--- .../src/components/app/GridBlock.svelte | 1 + .../src/components/grid/stores/datasource.js | 14 ++++++ 3 files changed, 52 insertions(+), 7 deletions(-) diff --git a/packages/builder/src/components/design/settings/controls/GridColumnConfiguration/getColumns.js b/packages/builder/src/components/design/settings/controls/GridColumnConfiguration/getColumns.js index 148055d727..384f20cf65 100644 --- a/packages/builder/src/components/design/settings/controls/GridColumnConfiguration/getColumns.js +++ b/packages/builder/src/components/design/settings/controls/GridColumnConfiguration/getColumns.js @@ -1,3 +1,5 @@ +import { FieldType } from "@budibase/types" + const modernize = columns => { if (!columns) { return [] @@ -8,6 +10,7 @@ const modernize = columns => { label: column.displayName, field: column.name, active: true, + related: column.related, })) } @@ -50,12 +53,35 @@ const removeInvalidAddMissing = ( const getDefault = (schema = {}) => { const defaultValues = Object.values(schema) .filter(column => !column.nestedJSON) - .map(column => ({ - label: column.name, - field: column.name, - active: column.visible ?? true, - order: column.visible ? column.order ?? -1 : Number.MAX_SAFE_INTEGER, - })) + .flatMap(column => { + const order = column.visible + ? column.order ?? -1 + : Number.MAX_SAFE_INTEGER + const columns = [ + { + label: column.name, + field: column.name, + active: column.visible ?? true, + order, + }, + ] + + if (column.columns) { + for (const relColumn of Object.keys(column.columns).filter( + relColumn => column.columns[relColumn].visible !== false + )) { + columns.push({ + label: `${relColumn} (${column.name})`, + field: `${column.name}.${relColumn}`, + active: column.visible ?? true, + order, + related: true, + }) + } + } + + return columns + }) defaultValues.sort((a, b) => a.order - b.order) @@ -69,6 +95,7 @@ const toGridFormat = draggableListColumns => { active: entry.active, width: entry.width, conditions: entry.conditions, + related: entry.related, })) } @@ -82,9 +109,12 @@ const toDraggableListFormat = (gridFormatColumns, createComponent, schema) => { active: column.active, field: column.field, label: column.label, - columnType: schema[column.field].type, + columnType: column.related + ? FieldType.FORMULA + : schema[column.field]?.type, width: column.width, conditions: column.conditions, + related: column.related, }, {} ) diff --git a/packages/client/src/components/app/GridBlock.svelte b/packages/client/src/components/app/GridBlock.svelte index 30a35b0713..45aba66bab 100644 --- a/packages/client/src/components/app/GridBlock.svelte +++ b/packages/client/src/components/app/GridBlock.svelte @@ -98,6 +98,7 @@ order: idx, conditions: column.conditions, visible: !!column.active, + related: column.related, } if (column.width) { overrides[column.field].width = column.width diff --git a/packages/frontend-core/src/components/grid/stores/datasource.js b/packages/frontend-core/src/components/grid/stores/datasource.js index 68053f38ae..3af6948650 100644 --- a/packages/frontend-core/src/components/grid/stores/datasource.js +++ b/packages/frontend-core/src/components/grid/stores/datasource.js @@ -1,6 +1,7 @@ import { derived, get } from "svelte/store" import { getDatasourceDefinition, getDatasourceSchema } from "../../../fetch" import { memo } from "../../../utils" +import { FieldType } from "@budibase/types" export const createStores = () => { const definition = memo(null) @@ -73,6 +74,19 @@ export const deriveStores = context => { } } }) + if ($schemaOverrides) { + Object.keys($schemaOverrides).forEach(field => { + if (!$schemaOverrides[field].related) { + return + } + enrichedSchema[field] = { + ...$schemaOverrides[field], + name: field, + type: FieldType.FORMULA, + related: true, + } + }) + } return enrichedSchema } ) From 55190883763eb2b58f64a10d79fe557c8ee7872a Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Fri, 6 Sep 2024 12:36:04 +0200 Subject: [PATCH 02/57] Display related --- .../GridColumnConfiguration/getColumns.js | 2 +- .../src/components/grid/stores/datasource.js | 1 - .../src/components/grid/stores/rows.js | 32 +++++++++++++++---- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/packages/builder/src/components/design/settings/controls/GridColumnConfiguration/getColumns.js b/packages/builder/src/components/design/settings/controls/GridColumnConfiguration/getColumns.js index 384f20cf65..419628ead2 100644 --- a/packages/builder/src/components/design/settings/controls/GridColumnConfiguration/getColumns.js +++ b/packages/builder/src/components/design/settings/controls/GridColumnConfiguration/getColumns.js @@ -75,7 +75,7 @@ const getDefault = (schema = {}) => { field: `${column.name}.${relColumn}`, active: column.visible ?? true, order, - related: true, + related: { field: column.name, subField: relColumn }, }) } } diff --git a/packages/frontend-core/src/components/grid/stores/datasource.js b/packages/frontend-core/src/components/grid/stores/datasource.js index 3af6948650..6e0b31de4b 100644 --- a/packages/frontend-core/src/components/grid/stores/datasource.js +++ b/packages/frontend-core/src/components/grid/stores/datasource.js @@ -83,7 +83,6 @@ export const deriveStores = context => { ...$schemaOverrides[field], name: field, type: FieldType.FORMULA, - related: true, } }) } diff --git a/packages/frontend-core/src/components/grid/stores/rows.js b/packages/frontend-core/src/components/grid/stores/rows.js index fb7a487c8e..e13767cbca 100644 --- a/packages/frontend-core/src/components/grid/stores/rows.js +++ b/packages/frontend-core/src/components/grid/stores/rows.js @@ -6,6 +6,7 @@ import { tick } from "svelte" import { Helpers } from "@budibase/bbui" import { sleep } from "../../../utils/utils" import { FieldType } from "@budibase/types" +import { processStringSync } from "@budibase/string-templates" export const createStores = () => { const rows = writable([]) @@ -42,15 +43,32 @@ export const createStores = () => { } export const deriveStores = context => { - const { rows } = context + const { rows, enrichedSchema } = context // Enrich rows with an index property and any pending changes - const enrichedRows = derived(rows, $rows => { - return $rows.map((row, idx) => ({ - ...row, - __idx: idx, - })) - }) + const enrichedRows = derived( + [rows, enrichedSchema], + ([$rows, $enrichedSchema]) => { + const customColumns = Object.values($enrichedSchema || {}).filter( + f => f.related + ) + return $rows.map((row, idx) => ({ + ...row, + __idx: idx, + ...customColumns.reduce((acc, c) => { + try { + acc[c.name] = processStringSync( + `{{ join (pluck ${c.related.field} '${c.related.subField}') ', ' }}`, + row + ) + } catch { + // It might be some formula not set, or anything being incorrect + } + return acc + }, {}), + })) + } + ) // Generate a lookup map to quick find a row by ID const rowLookupMap = derived(enrichedRows, $enrichedRows => { From 49502afbeed80088fd5e161e4ab6bd886b3cbe9e Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Fri, 6 Sep 2024 13:04:57 +0200 Subject: [PATCH 03/57] Default off --- .../settings/controls/GridColumnConfiguration/getColumns.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/builder/src/components/design/settings/controls/GridColumnConfiguration/getColumns.js b/packages/builder/src/components/design/settings/controls/GridColumnConfiguration/getColumns.js index 419628ead2..22b42dd427 100644 --- a/packages/builder/src/components/design/settings/controls/GridColumnConfiguration/getColumns.js +++ b/packages/builder/src/components/design/settings/controls/GridColumnConfiguration/getColumns.js @@ -73,7 +73,7 @@ const getDefault = (schema = {}) => { columns.push({ label: `${relColumn} (${column.name})`, field: `${column.name}.${relColumn}`, - active: column.visible ?? true, + active: false, order, related: { field: column.name, subField: relColumn }, }) From 8ee6e52f08c133231e94dd6b607830421be4de6a Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Fri, 6 Sep 2024 13:24:10 +0200 Subject: [PATCH 04/57] Use types --- .../frontend-core/src/components/grid/stores/datasource.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/frontend-core/src/components/grid/stores/datasource.js b/packages/frontend-core/src/components/grid/stores/datasource.js index 6e0b31de4b..ed84dc478a 100644 --- a/packages/frontend-core/src/components/grid/stores/datasource.js +++ b/packages/frontend-core/src/components/grid/stores/datasource.js @@ -79,10 +79,14 @@ export const deriveStores = context => { if (!$schemaOverrides[field].related) { return } + + const { field: relField, subField: relSubField } = + $schemaOverrides[field].related + enrichedSchema[field] = { ...$schemaOverrides[field], name: field, - type: FieldType.FORMULA, + type: $schema[relField]?.columns?.[relSubField]?.type, } }) } From 574b2e5a3c16668a710df57d2625e30906a6329b Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Fri, 6 Sep 2024 13:34:23 +0200 Subject: [PATCH 05/57] Map types --- .../GridColumnConfiguration/getColumns.js | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/packages/builder/src/components/design/settings/controls/GridColumnConfiguration/getColumns.js b/packages/builder/src/components/design/settings/controls/GridColumnConfiguration/getColumns.js index 22b42dd427..7380e40de0 100644 --- a/packages/builder/src/components/design/settings/controls/GridColumnConfiguration/getColumns.js +++ b/packages/builder/src/components/design/settings/controls/GridColumnConfiguration/getColumns.js @@ -1,5 +1,3 @@ -import { FieldType } from "@budibase/types" - const modernize = columns => { if (!columns) { return [] @@ -20,7 +18,8 @@ const modernize = columns => { const removeInvalidAddMissing = ( columns = [], defaultColumns, - primaryDisplayColumnName + primaryDisplayColumnName, + schema ) => { const defaultColumnNames = defaultColumns.map(column => column.field) const columnNames = columns.map(column => column.field) @@ -47,6 +46,16 @@ const removeInvalidAddMissing = ( combinedColumns[primaryDisplayIndex].active = true } + for (const column of combinedColumns) { + if (!column.related) { + column.columnType = schema[column.field]?.type + continue + } + + const { field: relField, subField: relSubField } = column.related + column.columnType = schema[relField]?.columns?.[relSubField]?.type + } + return combinedColumns } @@ -99,7 +108,7 @@ const toGridFormat = draggableListColumns => { })) } -const toDraggableListFormat = (gridFormatColumns, createComponent, schema) => { +const toDraggableListFormat = (gridFormatColumns, createComponent) => { return gridFormatColumns.map(column => { return createComponent( "@budibase/standard-components/labelfield", @@ -109,9 +118,7 @@ const toDraggableListFormat = (gridFormatColumns, createComponent, schema) => { active: column.active, field: column.field, label: column.label, - columnType: column.related - ? FieldType.FORMULA - : schema[column.field]?.type, + columnType: column.columnType, width: column.width, conditions: column.conditions, related: column.related, @@ -131,13 +138,10 @@ const getColumns = ({ const validatedColumns = removeInvalidAddMissing( modernize(columns), getDefault(schema), - primaryDisplayColumnName - ) - const draggableList = toDraggableListFormat( - validatedColumns, - createComponent, + primaryDisplayColumnName, schema ) + const draggableList = toDraggableListFormat(validatedColumns, createComponent) const primary = draggableList .filter(entry => entry.field === primaryDisplayColumnName) .map(instance => ({ ...instance, schema }))[0] From d799bfacb60022c44c95ace62ca24f08fd9dfd04 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Fri, 6 Sep 2024 13:35:11 +0200 Subject: [PATCH 06/57] Readonly --- packages/frontend-core/src/components/grid/stores/datasource.js | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/frontend-core/src/components/grid/stores/datasource.js b/packages/frontend-core/src/components/grid/stores/datasource.js index ed84dc478a..399ec341ee 100644 --- a/packages/frontend-core/src/components/grid/stores/datasource.js +++ b/packages/frontend-core/src/components/grid/stores/datasource.js @@ -87,6 +87,7 @@ export const deriveStores = context => { ...$schemaOverrides[field], name: field, type: $schema[relField]?.columns?.[relSubField]?.type, + readonly: true, } }) } From 4aa9e08ec564083ca6ff0e38f0feb45767631fa3 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Fri, 6 Sep 2024 13:39:04 +0200 Subject: [PATCH 07/57] Don't show non visible even if previously configured --- .../frontend-core/src/components/grid/stores/datasource.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/frontend-core/src/components/grid/stores/datasource.js b/packages/frontend-core/src/components/grid/stores/datasource.js index 399ec341ee..65e925fdf2 100644 --- a/packages/frontend-core/src/components/grid/stores/datasource.js +++ b/packages/frontend-core/src/components/grid/stores/datasource.js @@ -83,6 +83,10 @@ export const deriveStores = context => { const { field: relField, subField: relSubField } = $schemaOverrides[field].related + if (!$schema[relField]?.columns?.[relSubField]?.visible) { + return + } + enrichedSchema[field] = { ...$schemaOverrides[field], name: field, From e9db3d64e7a8914cb154c654417e74ddd642e799 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Fri, 6 Sep 2024 13:50:11 +0200 Subject: [PATCH 08/57] Extra enrichement --- .../frontend-core/src/components/grid/stores/datasource.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/frontend-core/src/components/grid/stores/datasource.js b/packages/frontend-core/src/components/grid/stores/datasource.js index 65e925fdf2..a7a3083cde 100644 --- a/packages/frontend-core/src/components/grid/stores/datasource.js +++ b/packages/frontend-core/src/components/grid/stores/datasource.js @@ -83,7 +83,10 @@ export const deriveStores = context => { const { field: relField, subField: relSubField } = $schemaOverrides[field].related - if (!$schema[relField]?.columns?.[relSubField]?.visible) { + if ( + !$schema[relField].visible || + !$schema[relField]?.columns?.[relSubField]?.visible + ) { return } From 488165d85985056ad3b6034bb10aa87ec47347d3 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Fri, 6 Sep 2024 14:00:53 +0200 Subject: [PATCH 09/57] Lint --- packages/frontend-core/src/components/grid/stores/datasource.js | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/frontend-core/src/components/grid/stores/datasource.js b/packages/frontend-core/src/components/grid/stores/datasource.js index a7a3083cde..bdd338618c 100644 --- a/packages/frontend-core/src/components/grid/stores/datasource.js +++ b/packages/frontend-core/src/components/grid/stores/datasource.js @@ -1,7 +1,6 @@ import { derived, get } from "svelte/store" import { getDatasourceDefinition, getDatasourceSchema } from "../../../fetch" import { memo } from "../../../utils" -import { FieldType } from "@budibase/types" export const createStores = () => { const definition = memo(null) From eed82075fd6c678a4b509a76a9e3e7ef1060603f Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Mon, 9 Sep 2024 09:52:09 +0200 Subject: [PATCH 10/57] Enrich visible columns --- .../src/components/grid/stores/columns.js | 39 ++++++++++++++++--- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/packages/frontend-core/src/components/grid/stores/columns.js b/packages/frontend-core/src/components/grid/stores/columns.js index 0073754a5d..9648b367f9 100644 --- a/packages/frontend-core/src/components/grid/stores/columns.js +++ b/packages/frontend-core/src/components/grid/stores/columns.js @@ -31,7 +31,7 @@ export const createStores = () => { } export const deriveStores = context => { - const { columns } = context + const { columns, enrichedSchema } = context // Derive a lookup map for all columns by name const columnLookupMap = derived(columns, $columns => { @@ -43,9 +43,38 @@ export const deriveStores = context => { }) // Derived list of columns which have not been explicitly hidden - const visibleColumns = derived(columns, $columns => { - return $columns.filter(col => col.visible) - }) + const visibleColumns = derived( + [columns, enrichedSchema], + ([$columns, $enrichedSchema]) => { + return $columns + .filter(col => col.visible) + .flatMap(c => { + const relatedColumns = [] + + const schemaColumns = $enrichedSchema?.[c.name]?.columns + if (schemaColumns) { + for (const relColumn of Object.keys(schemaColumns)) { + const relFieldSchema = schemaColumns[relColumn] + if (!relFieldSchema.visible) { + continue + } + relatedColumns.push({ + name: `${c.name}.${relColumn}`, + label: `${relColumn} (${c.name})`, + schema: relFieldSchema, + width: relFieldSchema.width || DefaultColumnWidth, + visible: relFieldSchema.visible ?? true, + readonly: relFieldSchema.readonly, + order: relFieldSchema.order, + conditions: relFieldSchema.conditions, + }) + } + } + + return [c, ...relatedColumns] + }) + } + ) // Split visible columns into their discrete types const displayColumn = derived(visibleColumns, $visibleColumns => { @@ -136,7 +165,7 @@ export const initialise = context => { .map(field => { const fieldSchema = $enrichedSchema[field] const oldColumn = $columns?.find(col => col.name === field) - let column = { + const column = { name: field, label: fieldSchema.displayName || field, schema: fieldSchema, From 4272b614e254927ddbea2bce2762ca4128854522 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Mon, 9 Sep 2024 09:58:43 +0200 Subject: [PATCH 11/57] Cleanup --- .../GridColumnConfiguration/getColumns.js | 17 ----------------- .../client/src/components/app/GridBlock.svelte | 1 - 2 files changed, 18 deletions(-) diff --git a/packages/builder/src/components/design/settings/controls/GridColumnConfiguration/getColumns.js b/packages/builder/src/components/design/settings/controls/GridColumnConfiguration/getColumns.js index 7380e40de0..f5ac106162 100644 --- a/packages/builder/src/components/design/settings/controls/GridColumnConfiguration/getColumns.js +++ b/packages/builder/src/components/design/settings/controls/GridColumnConfiguration/getColumns.js @@ -8,7 +8,6 @@ const modernize = columns => { label: column.displayName, field: column.name, active: true, - related: column.related, })) } @@ -75,20 +74,6 @@ const getDefault = (schema = {}) => { }, ] - if (column.columns) { - for (const relColumn of Object.keys(column.columns).filter( - relColumn => column.columns[relColumn].visible !== false - )) { - columns.push({ - label: `${relColumn} (${column.name})`, - field: `${column.name}.${relColumn}`, - active: false, - order, - related: { field: column.name, subField: relColumn }, - }) - } - } - return columns }) @@ -104,7 +89,6 @@ const toGridFormat = draggableListColumns => { active: entry.active, width: entry.width, conditions: entry.conditions, - related: entry.related, })) } @@ -121,7 +105,6 @@ const toDraggableListFormat = (gridFormatColumns, createComponent) => { columnType: column.columnType, width: column.width, conditions: column.conditions, - related: column.related, }, {} ) diff --git a/packages/client/src/components/app/GridBlock.svelte b/packages/client/src/components/app/GridBlock.svelte index 45aba66bab..30a35b0713 100644 --- a/packages/client/src/components/app/GridBlock.svelte +++ b/packages/client/src/components/app/GridBlock.svelte @@ -98,7 +98,6 @@ order: idx, conditions: column.conditions, visible: !!column.active, - related: column.related, } if (column.width) { overrides[column.field].width = column.width From 6d8505cee617cd3ebdc50d5edaf4d6733ba97688 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Mon, 9 Sep 2024 10:18:43 +0200 Subject: [PATCH 12/57] Add tablecolumns --- .../grid/controls/ColumnsSettingButton.svelte | 12 ++-- .../src/components/grid/stores/columns.js | 69 ++++++++++--------- 2 files changed, 43 insertions(+), 38 deletions(-) diff --git a/packages/frontend-core/src/components/grid/controls/ColumnsSettingButton.svelte b/packages/frontend-core/src/components/grid/controls/ColumnsSettingButton.svelte index 2a3ca139fc..75108870bd 100644 --- a/packages/frontend-core/src/components/grid/controls/ColumnsSettingButton.svelte +++ b/packages/frontend-core/src/components/grid/controls/ColumnsSettingButton.svelte @@ -4,13 +4,15 @@ import ColumnsSettingContent from "./ColumnsSettingContent.svelte" import { FieldPermissions } from "../../../constants" - const { columns, datasource } = getContext("grid") + const { tableColumns, datasource } = getContext("grid") let open = false let anchor - $: anyRestricted = $columns.filter(col => !col.visible || col.readonly).length - $: text = anyRestricted ? `Columns: (${anyRestricted} restricted)` : "Columns" + $: anyRestricted = $tableColumns.filter( + col => !col.visible || col.readonly + ).length + $: text = anyRestricted ? `Columns (${anyRestricted} restricted)` : "Columns" $: permissions = $datasource.type === "viewV2" ? [ @@ -28,12 +30,12 @@ size="M" on:click={() => (open = !open)} selected={open || anyRestricted} - disabled={!$columns.length} + disabled={!$tableColumns.length} > {text} - + diff --git a/packages/frontend-core/src/components/grid/stores/columns.js b/packages/frontend-core/src/components/grid/stores/columns.js index 9648b367f9..b20f17fd4d 100644 --- a/packages/frontend-core/src/components/grid/stores/columns.js +++ b/packages/frontend-core/src/components/grid/stores/columns.js @@ -31,7 +31,7 @@ export const createStores = () => { } export const deriveStores = context => { - const { columns, enrichedSchema } = context + const { columns } = context // Derive a lookup map for all columns by name const columnLookupMap = derived(columns, $columns => { @@ -42,39 +42,15 @@ export const deriveStores = context => { return map }) + // Derived list of columns which are direct part of the table + const tableColumns = derived(columns, $columns => { + return $columns.filter(col => !col.related) + }) + // Derived list of columns which have not been explicitly hidden - const visibleColumns = derived( - [columns, enrichedSchema], - ([$columns, $enrichedSchema]) => { - return $columns - .filter(col => col.visible) - .flatMap(c => { - const relatedColumns = [] - - const schemaColumns = $enrichedSchema?.[c.name]?.columns - if (schemaColumns) { - for (const relColumn of Object.keys(schemaColumns)) { - const relFieldSchema = schemaColumns[relColumn] - if (!relFieldSchema.visible) { - continue - } - relatedColumns.push({ - name: `${c.name}.${relColumn}`, - label: `${relColumn} (${c.name})`, - schema: relFieldSchema, - width: relFieldSchema.width || DefaultColumnWidth, - visible: relFieldSchema.visible ?? true, - readonly: relFieldSchema.readonly, - order: relFieldSchema.order, - conditions: relFieldSchema.conditions, - }) - } - } - - return [c, ...relatedColumns] - }) - } - ) + const visibleColumns = derived(columns, $columns => { + return $columns.filter(col => col.visible) + }) // Split visible columns into their discrete types const displayColumn = derived(visibleColumns, $visibleColumns => { @@ -93,6 +69,7 @@ export const deriveStores = context => { }) return { + tableColumns, displayColumn, columnLookupMap, visibleColumns, @@ -183,6 +160,32 @@ export const initialise = context => { } return column }) + .flatMap(field => { + const relatedColumns = [] + + const schemaColumns = $enrichedSchema?.[field.name]?.columns + if (field.visible && schemaColumns) { + for (const relColumn of Object.keys(schemaColumns)) { + const relFieldSchema = schemaColumns[relColumn] + if (!relFieldSchema.visible) { + continue + } + relatedColumns.push({ + name: `${field.name}.${relColumn}`, + label: `${relColumn} (${field.name})`, + schema: relFieldSchema, + width: relFieldSchema.width || DefaultColumnWidth, + visible: relFieldSchema.visible ?? true, + readonly: relFieldSchema.readonly, + order: relFieldSchema.order, + conditions: relFieldSchema.conditions, + related: true, + }) + } + } + + return [field, ...relatedColumns] + }) .sort((a, b) => { // Display column should always come first if (a.name === primaryDisplay) { From 083e6ae15bb1a3d87b1cf48ff5a07dfd4241f918 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Mon, 9 Sep 2024 12:31:00 +0200 Subject: [PATCH 13/57] Enrich at schema level --- .../src/components/grid/stores/columns.js | 27 +--------- .../src/components/grid/stores/datasource.js | 49 +++++++++---------- 2 files changed, 24 insertions(+), 52 deletions(-) diff --git a/packages/frontend-core/src/components/grid/stores/columns.js b/packages/frontend-core/src/components/grid/stores/columns.js index b20f17fd4d..b4eba300ad 100644 --- a/packages/frontend-core/src/components/grid/stores/columns.js +++ b/packages/frontend-core/src/components/grid/stores/columns.js @@ -151,6 +151,7 @@ export const initialise = context => { readonly: fieldSchema.readonly, order: fieldSchema.order ?? oldColumn?.order, conditions: fieldSchema.conditions, + related: fieldSchema.related, } // Override a few properties for primary display if (field === primaryDisplay) { @@ -160,32 +161,6 @@ export const initialise = context => { } return column }) - .flatMap(field => { - const relatedColumns = [] - - const schemaColumns = $enrichedSchema?.[field.name]?.columns - if (field.visible && schemaColumns) { - for (const relColumn of Object.keys(schemaColumns)) { - const relFieldSchema = schemaColumns[relColumn] - if (!relFieldSchema.visible) { - continue - } - relatedColumns.push({ - name: `${field.name}.${relColumn}`, - label: `${relColumn} (${field.name})`, - schema: relFieldSchema, - width: relFieldSchema.width || DefaultColumnWidth, - visible: relFieldSchema.visible ?? true, - readonly: relFieldSchema.readonly, - order: relFieldSchema.order, - conditions: relFieldSchema.conditions, - related: true, - }) - } - } - - return [field, ...relatedColumns] - }) .sort((a, b) => { // Display column should always come first if (a.name === primaryDisplay) { diff --git a/packages/frontend-core/src/components/grid/stores/datasource.js b/packages/frontend-core/src/components/grid/stores/datasource.js index bdd338618c..5ec94874dd 100644 --- a/packages/frontend-core/src/components/grid/stores/datasource.js +++ b/packages/frontend-core/src/components/grid/stores/datasource.js @@ -53,10 +53,31 @@ export const deriveStores = context => { if (!$schema) { return null } + + const schemaWithRelatedColumns = Object.keys($schema || {}).reduce( + (acc, c) => { + const field = $schema[c] + acc[c] = field + + if (field.columns) { + for (const relColumn of Object.keys(field.columns)) { + const name = `${field.name}.${relColumn}` + acc[name] = { + ...field.columns[relColumn], + name, + related: { field: c, subField: relColumn }, + } + } + } + return acc + }, + {} + ) + let enrichedSchema = {} - Object.keys($schema).forEach(field => { + Object.keys(schemaWithRelatedColumns).forEach(field => { enrichedSchema[field] = { - ...$schema[field], + ...schemaWithRelatedColumns[field], ...$schemaOverrides?.[field], ...$schemaMutations[field], } @@ -73,30 +94,6 @@ export const deriveStores = context => { } } }) - if ($schemaOverrides) { - Object.keys($schemaOverrides).forEach(field => { - if (!$schemaOverrides[field].related) { - return - } - - const { field: relField, subField: relSubField } = - $schemaOverrides[field].related - - if ( - !$schema[relField].visible || - !$schema[relField]?.columns?.[relSubField]?.visible - ) { - return - } - - enrichedSchema[field] = { - ...$schemaOverrides[field], - name: field, - type: $schema[relField]?.columns?.[relSubField]?.type, - readonly: true, - } - }) - } return enrichedSchema } ) From 4e83daf5d96fc734f74fe62150545a1130de729d Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Mon, 9 Sep 2024 12:41:59 +0200 Subject: [PATCH 14/57] Allow selecting columns in design --- .../GridColumnConfiguration.svelte | 4 ++- .../src/components/grid/stores/datasource.js | 24 +++-------------- packages/frontend-core/src/utils/index.js | 1 + packages/frontend-core/src/utils/schema.js | 27 +++++++++++++++++++ 4 files changed, 34 insertions(+), 22 deletions(-) create mode 100644 packages/frontend-core/src/utils/schema.js diff --git a/packages/builder/src/components/design/settings/controls/GridColumnConfiguration/GridColumnConfiguration.svelte b/packages/builder/src/components/design/settings/controls/GridColumnConfiguration/GridColumnConfiguration.svelte index 17cb171da5..b89c45046e 100644 --- a/packages/builder/src/components/design/settings/controls/GridColumnConfiguration/GridColumnConfiguration.svelte +++ b/packages/builder/src/components/design/settings/controls/GridColumnConfiguration/GridColumnConfiguration.svelte @@ -1,4 +1,5 @@