From 06e7517529fa1dca5d50f469bb69b69cc9d49c3e Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Fri, 28 Jun 2024 11:25:00 +0100 Subject: [PATCH] Add row conditions --- .../common/bindings/ClientBindingPanel.svelte | 2 + .../bindings/DrawerBindableInput.svelte | 2 + .../design/settings/componentSettings.js | 2 + .../controls/CellConditionEditor.svelte | 8 +- .../controls/RowConditionEditor.svelte | 200 ++++++++++++++++ .../Component/ConditionalUISection.svelte | 16 ++ packages/client/manifest.json | 12 + .../src/components/app/GridBlock.svelte | 8 + .../src/components/grid/cells/DataCell.svelte | 5 +- .../components/grid/cells/GutterCell.svelte | 1 + .../grid/layout/ButtonColumn.svelte | 1 + .../src/components/grid/layout/Grid.svelte | 3 + .../src/components/grid/stores/conditions.js | 216 +++++++++++------- .../src/components/grid/stores/config.js | 2 + .../src/components/grid/stores/viewport.js | 12 +- 15 files changed, 404 insertions(+), 86 deletions(-) create mode 100644 packages/builder/src/components/design/settings/controls/RowConditionEditor.svelte diff --git a/packages/builder/src/components/common/bindings/ClientBindingPanel.svelte b/packages/builder/src/components/common/bindings/ClientBindingPanel.svelte index 4e5789b563..4aa7ced9dc 100644 --- a/packages/builder/src/components/common/bindings/ClientBindingPanel.svelte +++ b/packages/builder/src/components/common/bindings/ClientBindingPanel.svelte @@ -5,6 +5,7 @@ export let bindings = [] export let value = "" + export let allowHBS = true export let allowJS = false export let allowHelpers = true export let autofocusEditor = false @@ -31,6 +32,7 @@ context={{ ...$previewStore.selectedComponentContext, ...context }} snippets={$snippets} {value} + {allowHBS} {allowJS} {allowHelpers} {autofocusEditor} diff --git a/packages/builder/src/components/common/bindings/DrawerBindableInput.svelte b/packages/builder/src/components/common/bindings/DrawerBindableInput.svelte index 0cb10d1aa5..65a9b2f8c7 100644 --- a/packages/builder/src/components/common/bindings/DrawerBindableInput.svelte +++ b/packages/builder/src/components/common/bindings/DrawerBindableInput.svelte @@ -16,6 +16,7 @@ export let placeholder export let label export let disabled = false + export let allowHBS = true export let allowJS = true export let allowHelpers = true export let updateOnChange = true @@ -98,6 +99,7 @@ value={readableValue} on:change={event => (tempValue = event.detail)} {bindings} + {allowHBS} {allowJS} {allowHelpers} {context} diff --git a/packages/builder/src/components/design/settings/componentSettings.js b/packages/builder/src/components/design/settings/componentSettings.js index 3540c8b990..b397cba7d1 100644 --- a/packages/builder/src/components/design/settings/componentSettings.js +++ b/packages/builder/src/components/design/settings/componentSettings.js @@ -31,6 +31,7 @@ import FormStepConfiguration from "./controls/FormStepConfiguration.svelte" import FormStepControls from "./controls/FormStepControls.svelte" import PaywalledSetting from "./controls/PaywalledSetting.svelte" import CellConditionEditor from "./controls/CellConditionEditor.svelte" +import RowConditionEditor from "./controls/RowConditionEditor.svelte" const componentMap = { text: DrawerBindableInput, @@ -63,6 +64,7 @@ const componentMap = { "columns/basic": BasicColumnEditor, "columns/grid": GridColumnEditor, cellConditions: CellConditionEditor, + rowConditions: RowConditionEditor, "field/sortable": SortableFieldSelect, "field/string": FormFieldSelect, "field/number": FormFieldSelect, diff --git a/packages/builder/src/components/design/settings/controls/CellConditionEditor.svelte b/packages/builder/src/components/design/settings/controls/CellConditionEditor.svelte index 997155fbdf..b901437cba 100644 --- a/packages/builder/src/components/design/settings/controls/CellConditionEditor.svelte +++ b/packages/builder/src/components/design/settings/controls/CellConditionEditor.svelte @@ -113,11 +113,17 @@ {conditionText} - +
+ Update the appearance of cells based on their value. {#if tempValue.length}
+ import { + ActionButton, + Drawer, + Button, + DrawerContent, + Layout, + Select, + Icon, + } from "@budibase/bbui" + import { createEventDispatcher } from "svelte" + import { cloneDeep } from "lodash" + import ColorPicker from "./ColorPicker.svelte" + import DrawerBindableInput from "components/common/bindings/DrawerBindableInput.svelte" + import { Constants } from "@budibase/frontend-core" + import { generate } from "shortid" + import { dndzone } from "svelte-dnd-action" + import { flip } from "svelte/animate" + import { getDatasourceForProvider, getSchemaForDatasource } from "dataBinding" + import { selectedScreen, selectedComponent } from "stores/builder" + import { makePropSafe } from "@budibase/string-templates" + + export let value + + const dispatch = createEventDispatcher() + const flipDuration = 130 + const conditionOptions = [ + { + label: "Update background color", + value: "backgroundColor", + }, + { + label: "Update text color", + value: "textColor", + }, + ] + + let tempValue = [] + let drawer + let dragDisabled = true + + $: count = value?.length + $: conditionText = `${count || "No"} condition${count !== 1 ? "s" : ""} set` + $: datasource = getDatasourceForProvider($selectedScreen, $selectedComponent) + $: schema = getSchemaForDatasource($selectedScreen, datasource)?.schema + $: rowBindings = generateRowBindings(schema) + + const generateRowBindings = schema => { + let bindings = [] + for (let key of Object.keys(schema || {})) { + bindings.push({ + type: "context", + runtimeBinding: `${makePropSafe("row")}.${makePropSafe(key)}`, + readableBinding: `Row.${key}`, + category: "Row", + icon: "RailTop", + display: { name: key }, + }) + } + + return bindings + } + + const openDrawer = () => { + tempValue = cloneDeep(value || []) + drawer.show() + } + + const save = async () => { + dispatch("change", tempValue) + drawer.hide() + } + + const addCondition = () => { + const condition = { + id: generate(), + metadataKey: conditionOptions[0].value, + operator: Constants.OperatorOptions.Equals.value, + referenceValue: true, + } + tempValue = [...tempValue, condition] + } + + const duplicateCondition = condition => { + const dupe = { ...condition, id: generate() } + tempValue = [...tempValue, dupe] + } + + const removeCondition = condition => { + tempValue = tempValue.filter(c => c.id !== condition.id) + } + + const updateConditions = e => { + tempValue = e.detail.items + } + + const handleFinalize = e => { + updateConditions(e) + dragDisabled = true + } + + +{conditionText} + + + + + +
+ + Update the appearance of rows based on the entire row value. + {#if tempValue.length} +
+ {#each tempValue as condition (condition.id)} +
+
(dragDisabled = false)} + > + +
+