From e9dd47b562d1dc9775234655e4ebca714551d80c Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Mon, 1 Nov 2021 17:18:38 +0000 Subject: [PATCH 01/24] Add initial structure of table with search block --- .../design/AppPreview/componentStructure.json | 7 ++ packages/client/manifest.json | 83 ++++++++++++++++ .../app/blocks/TableWithSearch.svelte | 99 +++++++++++++++++++ .../components/app/blocks/block-builder.js | 14 +++ .../app/blocks/component-builder.js | 49 +++++++++ .../client/src/components/app/blocks/index.js | 1 + packages/client/src/components/app/index.js | 1 + 7 files changed, 254 insertions(+) create mode 100644 packages/client/src/components/app/blocks/TableWithSearch.svelte create mode 100644 packages/client/src/components/app/blocks/block-builder.js create mode 100644 packages/client/src/components/app/blocks/component-builder.js create mode 100644 packages/client/src/components/app/blocks/index.js diff --git a/packages/builder/src/components/design/AppPreview/componentStructure.json b/packages/builder/src/components/design/AppPreview/componentStructure.json index 3bc2554fde..b6675c2480 100644 --- a/packages/builder/src/components/design/AppPreview/componentStructure.json +++ b/packages/builder/src/components/design/AppPreview/componentStructure.json @@ -1,4 +1,11 @@ [ + { + "name": "Blocks", + "icon": "Article", + "children": [ + "tablewithsearch" + ] + }, "section", "container", "dataprovider", diff --git a/packages/client/manifest.json b/packages/client/manifest.json index 2adfd96626..9b0bf7605c 100644 --- a/packages/client/manifest.json +++ b/packages/client/manifest.json @@ -2574,5 +2574,88 @@ "label": "Horizontal" } ] + }, + "tablewithsearch": { + "block": true, + "name": "Table with search", + "icon": "Table", + "styles": ["size"], + "settings": [ + { + "type": "dataSource", + "label": "Data", + "key": "dataSource" + }, + { + "type": "multifield", + "label": "Search Columns", + "key": "searchColumns", + "dependsOn": "dataSource", + "placeholder": "All columns" + }, + { + "type": "filter", + "label": "Filtering", + "key": "filter" + }, + { + "type": "field", + "label": "Sort Column", + "key": "sortColumn" + }, + { + "type": "select", + "label": "Sort Order", + "key": "sortOrder", + "options": ["Ascending", "Descending"], + "defaultValue": "Descending" + }, + { + "type": "boolean", + "label": "Paginate", + "key": "paginate", + "defaultValue": true + }, + { + "type": "number", + "label": "Row Count", + "key": "rowCount", + "defaultValue": 8 + }, + { + "type": "multifield", + "label": "Table Columns", + "key": "tableColumns", + "dependsOn": "dataSource", + "placeholder": "All columns" + }, + { + "type": "select", + "label": "Size", + "key": "size", + "defaultValue": "spectrum--medium", + "options": [ + { + "label": "Medium", + "value": "spectrum--medium" + }, + { + "label": "Large", + "value": "spectrum--large" + } + ] + }, + { + "type": "boolean", + "label": "Quiet", + "key": "quiet" + }, + { + "type": "boolean", + "label": "Auto Columns", + "key": "showAutoColumns", + "defaultValue": false + } + ] } } diff --git a/packages/client/src/components/app/blocks/TableWithSearch.svelte b/packages/client/src/components/app/blocks/TableWithSearch.svelte new file mode 100644 index 0000000000..dba50eb4b8 --- /dev/null +++ b/packages/client/src/components/app/blocks/TableWithSearch.svelte @@ -0,0 +1,99 @@ + + +
+ +
diff --git a/packages/client/src/components/app/blocks/block-builder.js b/packages/client/src/components/app/blocks/block-builder.js new file mode 100644 index 0000000000..2d56094806 --- /dev/null +++ b/packages/client/src/components/app/blocks/block-builder.js @@ -0,0 +1,14 @@ +import { ComponentBuilder } from "./component-builder" + +export class BlockBuilder { + context + componentCount = 0 + + constructor(context) { + this.context = context + } + + createComponent(type, props) { + return new ComponentBuilder(this, type, props) + } +} diff --git a/packages/client/src/components/app/blocks/component-builder.js b/packages/client/src/components/app/blocks/component-builder.js new file mode 100644 index 0000000000..90ce30c066 --- /dev/null +++ b/packages/client/src/components/app/blocks/component-builder.js @@ -0,0 +1,49 @@ +export class ComponentBuilder { + context + + constructor(blockBuilder, type, props) { + this.blockBuilder = blockBuilder + this.type = type + this.id = `${blockBuilder.context.id}-${blockBuilder.componentCount++}` + this.props = props + this.children = [] + this.styles = null + } + + setProp(key, value) { + this.props[key] = value + return this + } + + setProps(props) { + this.props = { + ...this.props, + ...props, + } + return this + } + + setStyles(styles) { + this.styles = styles + return this + } + + addChild(component) { + this.children.push(component) + return this + } + + build() { + return { + _component: `@budibase/standard-components/${this.type}`, + _id: this.id, + _children: this.children?.map(child => child.build()), + _styles: { + normal: { + ...this.styles, + }, + }, + ...this.props, + } + } +} diff --git a/packages/client/src/components/app/blocks/index.js b/packages/client/src/components/app/blocks/index.js new file mode 100644 index 0000000000..16b123d17e --- /dev/null +++ b/packages/client/src/components/app/blocks/index.js @@ -0,0 +1 @@ +export { default as tablewithsearch } from "./TableWithSearch.svelte" diff --git a/packages/client/src/components/app/index.js b/packages/client/src/components/app/index.js index b01763e2f0..92725f0738 100644 --- a/packages/client/src/components/app/index.js +++ b/packages/client/src/components/app/index.js @@ -32,6 +32,7 @@ export { default as spectrumcard } from "./SpectrumCard.svelte" export * from "./charts" export * from "./forms" export * from "./table" +export * from "./blocks" // Deprecated component left for compatibility in old apps export { default as navigation } from "./deprecated/Navigation.svelte" From e6ffccaff7b8d1d0342fa157ac4bf4b492b826dd Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Tue, 2 Nov 2021 08:45:27 +0000 Subject: [PATCH 02/24] Add generic block structure with support for writing blocks like normal svelte components rather than a JSON builder --- packages/client/manifest.json | 1 - .../client/src/components/Component.svelte | 6 +- .../src/components/app/DataProvider.svelte | 2 +- .../src/components/app/blocks/Block.svelte | 14 ++ .../app/blocks/BlockComponent.svelte | 33 ++++ .../app/blocks/TableWithSearch.svelte | 148 ++++++++---------- packages/client/src/utils/styleable.js | 12 +- 7 files changed, 125 insertions(+), 91 deletions(-) create mode 100644 packages/client/src/components/app/blocks/Block.svelte create mode 100644 packages/client/src/components/app/blocks/BlockComponent.svelte diff --git a/packages/client/manifest.json b/packages/client/manifest.json index 9b0bf7605c..08744c1952 100644 --- a/packages/client/manifest.json +++ b/packages/client/manifest.json @@ -2576,7 +2576,6 @@ ] }, "tablewithsearch": { - "block": true, "name": "Table with search", "icon": "Table", "styles": ["size"], diff --git a/packages/client/src/components/Component.svelte b/packages/client/src/components/Component.svelte index faf0226604..c13a50d52e 100644 --- a/packages/client/src/components/Component.svelte +++ b/packages/client/src/components/Component.svelte @@ -40,6 +40,7 @@ // Get contexts const context = getContext("context") const insideScreenslot = !!getContext("screenslot") + const insideBlock = !!getContext("block") // Create component context const componentStore = writable({}) @@ -53,7 +54,8 @@ $: name = instance._instanceName $: interactive = $builderStore.inBuilder && - ($builderStore.previewType === "layout" || insideScreenslot) + ($builderStore.previewType === "layout" || insideScreenslot) && + !insideBlock $: empty = interactive && !children.length && definition?.hasChildren $: emptyState = empty && definition?.showEmptyState !== false $: rawProps = getRawProps(instance) @@ -197,6 +199,8 @@ {/each} {:else if emptyState} + {:else if insideBlock} + {/if} diff --git a/packages/client/src/components/app/DataProvider.svelte b/packages/client/src/components/app/DataProvider.svelte index 991c41b77d..df59820506 100644 --- a/packages/client/src/components/app/DataProvider.svelte +++ b/packages/client/src/components/app/DataProvider.svelte @@ -234,7 +234,7 @@ {:else} - {#if !$component.children} + {#if $component.emptyState} {:else} diff --git a/packages/client/src/components/app/blocks/Block.svelte b/packages/client/src/components/app/blocks/Block.svelte new file mode 100644 index 0000000000..112b2387a7 --- /dev/null +++ b/packages/client/src/components/app/blocks/Block.svelte @@ -0,0 +1,14 @@ + + +
+ +
diff --git a/packages/client/src/components/app/blocks/BlockComponent.svelte b/packages/client/src/components/app/blocks/BlockComponent.svelte new file mode 100644 index 0000000000..5ef0509391 --- /dev/null +++ b/packages/client/src/components/app/blocks/BlockComponent.svelte @@ -0,0 +1,33 @@ + + + + + diff --git a/packages/client/src/components/app/blocks/TableWithSearch.svelte b/packages/client/src/components/app/blocks/TableWithSearch.svelte index dba50eb4b8..95960e49af 100644 --- a/packages/client/src/components/app/blocks/TableWithSearch.svelte +++ b/packages/client/src/components/app/blocks/TableWithSearch.svelte @@ -1,99 +1,89 @@ -
- -
+ + + {#if searchColumns?.length} + + {/if} + + + + + + + diff --git a/packages/client/src/utils/styleable.js b/packages/client/src/utils/styleable.js index 6a2562fb48..f35e45d3fe 100644 --- a/packages/client/src/utils/styleable.js +++ b/packages/client/src/utils/styleable.js @@ -64,9 +64,7 @@ export const styleable = (node, styles = {}) => { // Handler to select a component in the builder when clicking it in the // builder preview selectComponent = event => { - if (newStyles.interactive) { - builderStore.actions.selectComponent(componentId) - } + builderStore.actions.selectComponent(componentId) event.preventDefault() event.stopPropagation() return false @@ -77,7 +75,7 @@ export const styleable = (node, styles = {}) => { node.addEventListener("mouseout", applyNormalStyles) // Add builder preview click listener - if (get(builderStore).inBuilder) { + if (newStyles.interactive) { node.addEventListener("click", selectComponent, false) } @@ -89,11 +87,7 @@ export const styleable = (node, styles = {}) => { const removeListeners = () => { node.removeEventListener("mouseover", applyHoverStyles) node.removeEventListener("mouseout", applyNormalStyles) - - // Remove builder preview click listener - if (get(builderStore).inBuilder) { - node.removeEventListener("click", selectComponent) - } + node.removeEventListener("click", selectComponent) } // Apply initial styles From 38eacb5a10ef625cd65013e94b63b6549b7c92c0 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Tue, 2 Nov 2021 08:47:19 +0000 Subject: [PATCH 03/24] Remove old files and tidy up --- .../components/{app/blocks => }/Block.svelte | 0 .../{app/blocks => }/BlockComponent.svelte | 0 .../components/app/blocks/block-builder.js | 14 ------ .../app/blocks/component-builder.js | 49 ------------------- 4 files changed, 63 deletions(-) rename packages/client/src/components/{app/blocks => }/Block.svelte (100%) rename packages/client/src/components/{app/blocks => }/BlockComponent.svelte (100%) delete mode 100644 packages/client/src/components/app/blocks/block-builder.js delete mode 100644 packages/client/src/components/app/blocks/component-builder.js diff --git a/packages/client/src/components/app/blocks/Block.svelte b/packages/client/src/components/Block.svelte similarity index 100% rename from packages/client/src/components/app/blocks/Block.svelte rename to packages/client/src/components/Block.svelte diff --git a/packages/client/src/components/app/blocks/BlockComponent.svelte b/packages/client/src/components/BlockComponent.svelte similarity index 100% rename from packages/client/src/components/app/blocks/BlockComponent.svelte rename to packages/client/src/components/BlockComponent.svelte diff --git a/packages/client/src/components/app/blocks/block-builder.js b/packages/client/src/components/app/blocks/block-builder.js deleted file mode 100644 index 2d56094806..0000000000 --- a/packages/client/src/components/app/blocks/block-builder.js +++ /dev/null @@ -1,14 +0,0 @@ -import { ComponentBuilder } from "./component-builder" - -export class BlockBuilder { - context - componentCount = 0 - - constructor(context) { - this.context = context - } - - createComponent(type, props) { - return new ComponentBuilder(this, type, props) - } -} diff --git a/packages/client/src/components/app/blocks/component-builder.js b/packages/client/src/components/app/blocks/component-builder.js deleted file mode 100644 index 90ce30c066..0000000000 --- a/packages/client/src/components/app/blocks/component-builder.js +++ /dev/null @@ -1,49 +0,0 @@ -export class ComponentBuilder { - context - - constructor(blockBuilder, type, props) { - this.blockBuilder = blockBuilder - this.type = type - this.id = `${blockBuilder.context.id}-${blockBuilder.componentCount++}` - this.props = props - this.children = [] - this.styles = null - } - - setProp(key, value) { - this.props[key] = value - return this - } - - setProps(props) { - this.props = { - ...this.props, - ...props, - } - return this - } - - setStyles(styles) { - this.styles = styles - return this - } - - addChild(component) { - this.children.push(component) - return this - } - - build() { - return { - _component: `@budibase/standard-components/${this.type}`, - _id: this.id, - _children: this.children?.map(child => child.build()), - _styles: { - normal: { - ...this.styles, - }, - }, - ...this.props, - } - } -} From 0f1d9c4de38e690165341657e5a9b0deb6ecbc23 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Tue, 2 Nov 2021 08:51:48 +0000 Subject: [PATCH 04/24] Add title setting to table with search block and fix import paths --- packages/client/manifest.json | 5 +++++ .../components/app/blocks/TableWithSearch.svelte | 14 ++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/packages/client/manifest.json b/packages/client/manifest.json index 08744c1952..541bd80a18 100644 --- a/packages/client/manifest.json +++ b/packages/client/manifest.json @@ -2580,6 +2580,11 @@ "icon": "Table", "styles": ["size"], "settings": [ + { + "type": "text", + "label": "Title", + "key": "title" + }, { "type": "dataSource", "label": "Data", diff --git a/packages/client/src/components/app/blocks/TableWithSearch.svelte b/packages/client/src/components/app/blocks/TableWithSearch.svelte index 95960e49af..a11f11be26 100644 --- a/packages/client/src/components/app/blocks/TableWithSearch.svelte +++ b/packages/client/src/components/app/blocks/TableWithSearch.svelte @@ -1,7 +1,9 @@
diff --git a/packages/client/src/components/BlockComponent.svelte b/packages/client/src/components/BlockComponent.svelte index e12c6eb86e..02456322da 100644 --- a/packages/client/src/components/BlockComponent.svelte +++ b/packages/client/src/components/BlockComponent.svelte @@ -14,22 +14,18 @@ const block = getContext("block") const rand = generate() - $: id = block.id + rand - $: instance = createInstance(type, props, id) - // Create a fake component instance so that we can use the core Component // to render this part of the block, taking advantage of binding enrichment - const createInstance = (type, props, id) => { - return { - _component: `@budibase/standard-components/${type}`, - _id: id, - _styles: { - normal: { - ...styles, - }, + $: id = block.id + rand + $: instance = { + _component: `@budibase/standard-components/${type}`, + _id: id, + _styles: { + normal: { + ...styles, }, - ...props, - } + }, + ...props, } From 08de9c0b45fc584ca6ab85e43e6b0f07ca9cf327 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Wed, 3 Nov 2021 11:02:59 +0000 Subject: [PATCH 07/24] Fix spectrum bug with larger checkboxes --- packages/bbui/src/Form/Core/Checkbox.svelte | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/packages/bbui/src/Form/Core/Checkbox.svelte b/packages/bbui/src/Form/Core/Checkbox.svelte index ca3cef383f..4290984331 100644 --- a/packages/bbui/src/Form/Core/Checkbox.svelte +++ b/packages/bbui/src/Form/Core/Checkbox.svelte @@ -21,6 +21,7 @@