diff --git a/packages/builder/src/components/automation/SetupPanel/AutomationBlockSetup.svelte b/packages/builder/src/components/automation/SetupPanel/AutomationBlockSetup.svelte index c16260779e..eceb2420dc 100644 --- a/packages/builder/src/components/automation/SetupPanel/AutomationBlockSetup.svelte +++ b/packages/builder/src/components/automation/SetupPanel/AutomationBlockSetup.svelte @@ -2,8 +2,16 @@ import TableSelector from "./TableSelector.svelte" import RowSelector from "./RowSelector.svelte" import SchemaSetup from "./SchemaSetup.svelte" - import { Button, Input, Select, Label } from "@budibase/bbui" + import { + Button, + Input, + Select, + Label, + ActionButton, + Drawer, + } from "@budibase/bbui" import { automationStore } from "builderStore" + import { tables } from "stores/backend" import WebhookDisplay from "../Shared/WebhookDisplay.svelte" import DrawerBindableInput from "../../common/bindings/DrawerBindableInput.svelte" import AutomationBindingPanel from "../../common/bindings/ServerBindingPanel.svelte" @@ -15,11 +23,17 @@ import { database } from "stores/backend" import { debounce } from "lodash" import ModalBindableInput from "components/common/bindings/ModalBindableInput.svelte" + import FilterDrawer from "components/design/PropertiesPanel/PropertyControls/FilterEditor/FilterDrawer.svelte" + // need the client lucene builder to convert to the structure API expects + import { buildLuceneQuery } from "../../../../../client/src/utils/lucene" export let block export let webhookModal export let testData export let schemaProperties + let drawer + let tempFilters = lookForFilters(schemaProperties) || [] + $: stepId = block.stepId $: bindings = getAvailableBindings( block || $automationStore.selectedBlock, @@ -28,6 +42,11 @@ $: instanceId = $database._id $: inputData = testData ? testData : block.inputs + $: tableId = inputData ? inputData.tableId : null + $: table = tableId + ? $tables.list.find(table => table._id === inputData.tableId) + : { schema: {} } + $: schemaFields = table ? Object.values(table.schema) : [] const onChange = debounce(async function (e, key) { if (testData) { @@ -71,6 +90,35 @@ } return bindings } + + function lookForFilters(properties) { + console.log("testing") + if (!properties) { + return [] + } + let filters + const inputs = testData ? testData : block.inputs + for (let [key, field] of properties) { + // need to look for the builder definition (keyed separately, see saveFilters) + const defKey = `${key}-def` + if (field.customType === "filters" && inputs?.[defKey]) { + filters = inputs[defKey] + break + } + } + return filters || [] + } + + function saveFilters(key) { + const filters = buildLuceneQuery(tempFilters) + const defKey = `${key}-def` + inputData[key] = filters + inputData[defKey] = tempFilters + onChange({ detail: filters }, key) + // need to store the builder definition in the automation + onChange({ detail: tempFilters }, defKey) + drawer.hide() + }
Block helper that always renders the inverse block unless a is less than or equal to b.
a
b
Extend the context with the properties of other objects. A shallow merge is performed to avoid mutating the context.
Block helper that iterates over the properties of an object, exposing each key and value on the context.
Block helper that iterates over the own properties of an object, exposing each key and value on the context.
Take arguments and, if they are string or number, convert them to a dot-delineated object property path.
Use property paths (a.b.c) to get a value or nested value from the context. Works as a regular helper or block helper.
a.b.c
Use property paths (a.b.c) to get an object from the context. Differs from the get helper in that this helper will return the actual object, including the given property key. Also, this helper does not work as a block helper.
get
Return true if key is an own, enumerable property of the given context object.
key
context
Return true if value is an object.
value
Parses the given string using JSON.parse.
JSON.parse
Stringify an object using JSON.stringify.
JSON.stringify
Deeply merge the properties of the given objects with the context object.
objects
Pick properties from the context object.