From a64436c9c8f01192c948a4b47dfbd0ad31f66f3d Mon Sep 17 00:00:00 2001 From: Gerard Burns Date: Mon, 5 Dec 2022 12:09:27 +0000 Subject: [PATCH] Multifield Input Autoselect All Fields (#8884) * Multifield Input Autoselect All Fields * PR Feedback * PR Feedback * Linting --- .../src/builderStore/store/frontend.js | 26 ++++++++++++++++++- packages/client/manifest.json | 8 +++--- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/packages/builder/src/builderStore/store/frontend.js b/packages/builder/src/builderStore/store/frontend.js index aca25dbe05..e831f6a343 100644 --- a/packages/builder/src/builderStore/store/frontend.js +++ b/packages/builder/src/builderStore/store/frontend.js @@ -25,6 +25,7 @@ import { DB_TYPE_INTERNAL, DB_TYPE_EXTERNAL, } from "constants/backend" +import { getSchemaForDatasource } from "builderStore/dataBinding" const INITIAL_FRONTEND_STATE = { apps: [], @@ -524,7 +525,9 @@ export const getFrontendStore = () => { // Generate default props let props = { ...presetProps } settings.forEach(setting => { - if (setting.defaultValue !== undefined) { + if (setting.type === "multifield" && setting.selectAllFields) { + props[setting.key] = Object.keys(defaultDatasource.schema || {}) + } else if (setting.defaultValue !== undefined) { props[setting.key] = setting.defaultValue } }) @@ -1041,6 +1044,27 @@ export const getFrontendStore = () => { if (component[name] === value) { return false } + + const settings = getComponentSettings(component._component) + const updatedSetting = settings.find(setting => setting.key === name) + + if ( + updatedSetting.type === "dataSource" || + updatedSetting.type === "table" + ) { + const { schema } = getSchemaForDatasource(null, value) + const columnNames = Object.keys(schema || {}) + const multifieldKeysToSelectAll = settings + .filter(setting => { + return setting.type === "multifield" && setting.selectAllFields + }) + .map(setting => setting.key) + + multifieldKeysToSelectAll.forEach(key => { + component[key] = columnNames + }) + } + component[name] = value }) }, diff --git a/packages/client/manifest.json b/packages/client/manifest.json index e0282eb8a9..dbbb7726be 100644 --- a/packages/client/manifest.json +++ b/packages/client/manifest.json @@ -5118,7 +5118,8 @@ { "type": "multifield", "label": "Fields", - "key": "fields" + "key": "fields", + "selectAllFields": true }, { "type": "select", @@ -5284,7 +5285,8 @@ "type": "multifield", "label": "Fields", "key": "detailFields", - "nested": true + "nested": true, + "selectAllFields": true } ] } @@ -5294,4 +5296,4 @@ "suffix": "repeater" } } -} \ No newline at end of file +}