From 65abee10d06cd0186e6725672d9eef9f7d5186c4 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Tue, 23 May 2023 16:02:05 +0100 Subject: [PATCH 1/2] Fix issue with schema mutation in grids. Use displayName to represent grid column labels. Allow deletion of duplicated user columns --- .../backend/DataTable/DataTable.svelte | 10 +++++----- .../src/components/grid/stores/columns.js | 20 ++++++++++++++++--- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/packages/builder/src/components/backend/DataTable/DataTable.svelte b/packages/builder/src/components/backend/DataTable/DataTable.svelte index dfe30a3711..d51be23baf 100644 --- a/packages/builder/src/components/backend/DataTable/DataTable.svelte +++ b/packages/builder/src/components/backend/DataTable/DataTable.svelte @@ -16,11 +16,11 @@ import GridEditColumnModal from "components/backend/DataTable/modals/grid/GridEditColumnModal.svelte" const userSchemaOverrides = { - firstName: { name: "First name", disabled: true }, - lastName: { name: "Last name", disabled: true }, - email: { name: "Email", disabled: true }, - roleId: { name: "Role", disabled: true }, - status: { name: "Status", disabled: true }, + firstName: { displayName: "First name", disabled: true }, + lastName: { displayName: "Last name", disabled: true }, + email: { displayName: "Email", disabled: true }, + roleId: { displayName: "Role", disabled: true }, + status: { displayName: "Status", disabled: true }, } $: id = $tables.selected?._id diff --git a/packages/frontend-core/src/components/grid/stores/columns.js b/packages/frontend-core/src/components/grid/stores/columns.js index e953977487..a66aef0411 100644 --- a/packages/frontend-core/src/components/grid/stores/columns.js +++ b/packages/frontend-core/src/components/grid/stores/columns.js @@ -116,10 +116,24 @@ export const initialise = context => { const schema = derived( [table, schemaOverrides], ([$table, $schemaOverrides]) => { - let newSchema = $table?.schema - if (!newSchema) { + if (!$table?.schema) { return null } + let newSchema = { ...$table?.schema } + + // Edge case to temporarily allow deletion of duplicated user + // fields that were saved with the "disabled" flag set. + // By overriding the saved schema we ensure only overrides can + // set the disabled flag. + // TODO: remove in future + Object.keys(newSchema).forEach(field => { + newSchema[field] = { + ...newSchema[field], + disabled: false, + } + }) + + // Apply schema overrides Object.keys($schemaOverrides || {}).forEach(field => { if (newSchema[field]) { newSchema[field] = { @@ -160,7 +174,7 @@ export const initialise = context => { fields .map(field => ({ name: field, - label: $schema[field].name || field, + label: $schema[field].displayName || field, schema: $schema[field], width: $schema[field].width || DefaultColumnWidth, visible: $schema[field].visible ?? true, From f0b27f06748e2666fdbf48dd838e406c52190c68 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Tue, 23 May 2023 18:01:04 +0100 Subject: [PATCH 2/2] Ensure text cells account for being used for number cells too --- .../frontend-core/src/components/grid/cells/TextCell.svelte | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/frontend-core/src/components/grid/cells/TextCell.svelte b/packages/frontend-core/src/components/grid/cells/TextCell.svelte index 533b030b5c..04485a6b50 100644 --- a/packages/frontend-core/src/components/grid/cells/TextCell.svelte +++ b/packages/frontend-core/src/components/grid/cells/TextCell.svelte @@ -52,7 +52,7 @@ {:else}
- {value || ""} + {value ?? ""}
{/if}