From cadadca048be483452db5e8951f1ee8be453e120 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Fri, 10 Feb 2023 11:00:20 +0000 Subject: [PATCH] Generate option inclusion constraint (#9647) * Fix options inclusion constrant not being generated when creating a table from file upload * Fix 0 being treated as null when specifying min and max constraints for number fields * Sort newly generated option field inclusion constraints * Revert previous solution and fix problem by removing incorrect local assignment statement --- .../_components/settings/ComponentSettingsSection.svelte | 4 ++-- packages/server/src/api/controllers/table/utils.ts | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/builder/src/pages/builder/app/[application]/design/[screenId]/components/[componentId]/_components/settings/ComponentSettingsSection.svelte b/packages/builder/src/pages/builder/app/[application]/design/[screenId]/components/[componentId]/_components/settings/ComponentSettingsSection.svelte index bf8bff1292..21bed847f5 100644 --- a/packages/builder/src/pages/builder/app/[application]/design/[screenId]/components/[componentId]/_components/settings/ComponentSettingsSection.svelte +++ b/packages/builder/src/pages/builder/app/[application]/design/[screenId]/components/[componentId]/_components/settings/ComponentSettingsSection.svelte @@ -147,8 +147,8 @@ options: setting.options || [], // Number fields - min: setting.min || null, - max: setting.max || null, + min: setting.min ?? null, + max: setting.max ?? null, }} {bindings} {componentBindings} diff --git a/packages/server/src/api/controllers/table/utils.ts b/packages/server/src/api/controllers/table/utils.ts index 162df3754c..bbccde467b 100644 --- a/packages/server/src/api/controllers/table/utils.ts +++ b/packages/server/src/api/controllers/table/utils.ts @@ -104,7 +104,6 @@ export function importToRows(data: any, table: any, user: any = {}) { const processed: any = inputProcessing(user, table, row, { noAutoRelationships: true, }) - table = processed.table row = processed.row let fieldName: any @@ -113,6 +112,7 @@ export function importToRows(data: any, table: any, user: any = {}) { // check whether the options need to be updated for inclusion as part of the data import if ( schema.type === FieldTypes.OPTIONS && + row[fieldName] && (!schema.constraints.inclusion || schema.constraints.inclusion.indexOf(row[fieldName]) === -1) ) { @@ -120,6 +120,7 @@ export function importToRows(data: any, table: any, user: any = {}) { ...schema.constraints.inclusion, row[fieldName], ] + schema.constraints.inclusion.sort() } }