From d08d9d12488fe4b48822b59cef1626e4f2470bfa Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Fri, 1 Apr 2022 12:51:23 +0100 Subject: [PATCH] Add form block and form block plus components --- .../queryLevelTransformers.spec.js | 1 - .../builder/src/builderStore/dataBinding.js | 36 +-- .../design/AppPreview/componentStructure.json | 31 +-- .../ScreenDropdownMenu.svelte | 1 - .../ButtonActionDrawer.svelte | 2 + .../ButtonActionEditor.svelte | 2 + .../ButtonActionEditor/actions/SaveRow.svelte | 4 +- .../PropertyControls/PropertyControl.svelte | 1 + .../PropertyControls/TableSelect.svelte | 42 +-- packages/client/manifest.json | 250 ++++++++++++++++++ .../components/app/blocks/FormBlock.svelte | 132 +++++++++ .../app/blocks/FormBlockPlus.svelte | 199 ++++++++++++++ .../client/src/components/app/blocks/index.js | 2 + .../src/components/app/charts/BarChart.svelte | 1 - .../src/components/app/forms/Form.svelte | 31 +-- packages/client/src/stores/screens.js | 1 - packages/client/src/utils/schema.js | 14 +- packages/frontend-core/src/api/attachments.js | 1 - 18 files changed, 654 insertions(+), 97 deletions(-) create mode 100644 packages/client/src/components/app/blocks/FormBlock.svelte create mode 100644 packages/client/src/components/app/blocks/FormBlockPlus.svelte diff --git a/packages/builder/cypress/integration/queryLevelTransformers.spec.js b/packages/builder/cypress/integration/queryLevelTransformers.spec.js index 86aea8eafb..f1678655f4 100644 --- a/packages/builder/cypress/integration/queryLevelTransformers.spec.js +++ b/packages/builder/cypress/integration/queryLevelTransformers.spec.js @@ -47,7 +47,6 @@ filterTests(["smoke", "all"], () => { cy.readFile( "cypress/support/queryLevelTransformerFunctionWithData.js" ).then(transformerFunction => { - //console.log(transformerFunction[1]) cy.get(".CodeMirror textarea") // Highlight current text and overwrite with file contents .type(Cypress.platform === "darwin" ? "{cmd}a" : "{ctrl}a", { diff --git a/packages/builder/src/builderStore/dataBinding.js b/packages/builder/src/builderStore/dataBinding.js index c8b4ae8de9..cd4b9d4187 100644 --- a/packages/builder/src/builderStore/dataBinding.js +++ b/packages/builder/src/builderStore/dataBinding.js @@ -65,7 +65,12 @@ export const getComponentBindableProperties = (asset, componentId) => { /** * Gets all data provider components above a component. */ -export const getContextProviderComponents = (asset, componentId, type) => { +export const getContextProviderComponents = ( + asset, + componentId, + type, + options = { includeSelf: false } +) => { if (!asset || !componentId) { return [] } @@ -73,7 +78,9 @@ export const getContextProviderComponents = (asset, componentId, type) => { // Get the component tree leading up to this component, ignoring the component // itself const path = findComponentPath(asset.props, componentId) - path.pop() + if (!options?.includeSelf) { + path.pop() + } // Filter by only data provider components return path.filter(component => { @@ -138,19 +145,7 @@ export const getDatasourceForProvider = (asset, component) => { if (!datasourceSetting) { return null } - - // There are different types of setting which can be a datasource, for - // example an actual datasource object, or a table ID string. - // Convert the datasource setting into a proper datasource object so that - // we can use it properly - if (datasourceSetting.type === "table") { - return { - tableId: component[datasourceSetting?.key], - type: "table", - } - } else { - return component[datasourceSetting?.key] - } + return component[datasourceSetting?.key] } /** @@ -643,6 +638,17 @@ const buildFormSchema = component => { if (!component) { return schema } + + // If this is a form block, simply use the fields setting + if (component._component.endsWith("formblock")) { + let schema = {} + component.fields?.forEach(field => { + schema[field] = { type: "string" } + }) + return schema + } + + // Otherwise find all field component children const settings = getComponentSettings(component._component) const fieldSetting = settings.find( setting => setting.key === "field" && setting.type.startsWith("field/") diff --git a/packages/builder/src/components/design/AppPreview/componentStructure.json b/packages/builder/src/components/design/AppPreview/componentStructure.json index 6873ae547d..b49e546f32 100644 --- a/packages/builder/src/components/design/AppPreview/componentStructure.json +++ b/packages/builder/src/components/design/AppPreview/componentStructure.json @@ -5,26 +5,20 @@ "children": [ "tableblock", "cardsblock", - "repeaterblock" + "repeaterblock", + "formblock", + "formblockplus" ] }, { "name": "Layout", "icon": "ClassicGridView", - "children": [ - "container", - "section" - ] + "children": ["container", "section"] }, { "name": "Data", "icon": "Data", - "children": [ - "dataprovider", - "repeater", - "table", - "dynamicfilter" - ] + "children": ["dataprovider", "repeater", "table", "dynamicfilter"] }, { "name": "Form", @@ -51,22 +45,12 @@ { "name": "Card", "icon": "Card", - "children": [ - "spectrumcard", - "cardstat" - ] + "children": ["spectrumcard", "cardstat"] }, { "name": "Chart", "icon": "GraphBarVertical", - "children": [ - "bar", - "line", - "area", - "pie", - "donut", - "candlestick" - ] + "children": ["bar", "line", "area", "pie", "donut", "candlestick"] }, { "name": "Elements", @@ -87,4 +71,3 @@ ] } ] - diff --git a/packages/builder/src/components/design/NavigationPanel/ComponentNavigationTree/ScreenDropdownMenu.svelte b/packages/builder/src/components/design/NavigationPanel/ComponentNavigationTree/ScreenDropdownMenu.svelte index 76bb48a26c..08b9f9996d 100644 --- a/packages/builder/src/components/design/NavigationPanel/ComponentNavigationTree/ScreenDropdownMenu.svelte +++ b/packages/builder/src/components/design/NavigationPanel/ComponentNavigationTree/ScreenDropdownMenu.svelte @@ -49,7 +49,6 @@ } } catch (error) { notifications.error("Error duplicating screen") - console.log(error) } } diff --git a/packages/builder/src/components/design/PropertiesPanel/PropertyControls/ButtonActionEditor/ButtonActionDrawer.svelte b/packages/builder/src/components/design/PropertiesPanel/PropertyControls/ButtonActionEditor/ButtonActionDrawer.svelte index 5b0ab4a6a3..24283ed2fe 100644 --- a/packages/builder/src/components/design/PropertiesPanel/PropertyControls/ButtonActionEditor/ButtonActionDrawer.svelte +++ b/packages/builder/src/components/design/PropertiesPanel/PropertyControls/ButtonActionEditor/ButtonActionDrawer.svelte @@ -21,6 +21,7 @@ export let key export let actions export let bindings = [] + export let nested let selectedAction = actions?.length ? actions[0] : null @@ -137,6 +138,7 @@ this={selectedActionComponent} parameters={selectedAction.parameters} bindings={allBindings} + {nested} /> {/key} diff --git a/packages/builder/src/components/design/PropertiesPanel/PropertyControls/ButtonActionEditor/ButtonActionEditor.svelte b/packages/builder/src/components/design/PropertiesPanel/PropertyControls/ButtonActionEditor/ButtonActionEditor.svelte index 550d982013..af198d169e 100644 --- a/packages/builder/src/components/design/PropertiesPanel/PropertyControls/ButtonActionEditor/ButtonActionEditor.svelte +++ b/packages/builder/src/components/design/PropertiesPanel/PropertyControls/ButtonActionEditor/ButtonActionEditor.svelte @@ -12,6 +12,7 @@ export let value = [] export let name export let bindings + export let nested let drawer let tmpValue @@ -83,5 +84,6 @@ eventType={name} {bindings} {key} + {nested} /> diff --git a/packages/builder/src/components/design/PropertiesPanel/PropertyControls/ButtonActionEditor/actions/SaveRow.svelte b/packages/builder/src/components/design/PropertiesPanel/PropertyControls/ButtonActionEditor/actions/SaveRow.svelte index c88b301fc9..bc5e6a7be7 100644 --- a/packages/builder/src/components/design/PropertiesPanel/PropertyControls/ButtonActionEditor/actions/SaveRow.svelte +++ b/packages/builder/src/components/design/PropertiesPanel/PropertyControls/ButtonActionEditor/actions/SaveRow.svelte @@ -10,11 +10,13 @@ export let parameters export let bindings = [] + export let nested $: formComponents = getContextProviderComponents( $currentAsset, $store.selectedComponentId, - "form" + "form", + { includeSelf: nested } ) $: schemaComponents = getContextProviderComponents( $currentAsset, diff --git a/packages/builder/src/components/design/PropertiesPanel/PropertyControls/PropertyControl.svelte b/packages/builder/src/components/design/PropertiesPanel/PropertyControls/PropertyControl.svelte index 617b1c83ab..e5889fbf23 100644 --- a/packages/builder/src/components/design/PropertiesPanel/PropertyControls/PropertyControl.svelte +++ b/packages/builder/src/components/design/PropertiesPanel/PropertyControls/PropertyControl.svelte @@ -79,6 +79,7 @@ bindings={allBindings} name={key} text={label} + {nested} {key} {type} {...props} diff --git a/packages/builder/src/components/design/PropertiesPanel/PropertyControls/TableSelect.svelte b/packages/builder/src/components/design/PropertiesPanel/PropertyControls/TableSelect.svelte index b41098da2d..384bbe1e3a 100644 --- a/packages/builder/src/components/design/PropertiesPanel/PropertyControls/TableSelect.svelte +++ b/packages/builder/src/components/design/PropertiesPanel/PropertyControls/TableSelect.svelte @@ -1,26 +1,28 @@ -
- -
- - +