From a6c09e25e6dcbfd7475b508b5f550671b6ef8ff3 Mon Sep 17 00:00:00 2001 From: Peter Clement Date: Thu, 4 Jan 2024 14:30:18 +0000 Subject: [PATCH 1/7] recommit work for trigger binding suggestions --- .../SetupPanel/AutomationBlockSetup.svelte | 173 ++++++++++-------- 1 file changed, 99 insertions(+), 74 deletions(-) diff --git a/packages/builder/src/components/automation/SetupPanel/AutomationBlockSetup.svelte b/packages/builder/src/components/automation/SetupPanel/AutomationBlockSetup.svelte index 158ecd8281..9a16b23fa2 100644 --- a/packages/builder/src/components/automation/SetupPanel/AutomationBlockSetup.svelte +++ b/packages/builder/src/components/automation/SetupPanel/AutomationBlockSetup.svelte @@ -51,7 +51,7 @@ export let testData export let schemaProperties export let isTestModal = false - + $: console.log(inputData) let webhookModal let drawer let fillWidth = true @@ -101,7 +101,6 @@ } } } - const onChange = Utils.sequential(async (e, key) => { // We need to cache the schema as part of the definition because it is // used in the server to detect relationships. It would be far better to @@ -145,34 +144,89 @@ if (!block || !automation) { return [] } - // Find previous steps to the selected one - let allSteps = [...automation.steps] - if (automation.trigger) { - allSteps = [automation.trigger, ...allSteps] - } + let allSteps = automation.trigger + ? [automation.trigger, ...automation.steps] + : [...automation.steps] let blockIdx = allSteps.findIndex(step => step.id === block.id) - - // Extract all outputs from all previous steps as available bindingsx§x let bindings = [] let loopBlockCount = 0 + + const addBinding = (name, value, icon, idx, isLoopBlock, bindingName) => { + const runtimeBinding = determineRuntimeBinding(name, idx, isLoopBlock) + const categoryName = determineCategoryName(idx, isLoopBlock, bindingName) + + bindings.push( + createBindingObject( + name, + value, + icon, + idx, + loopBlockCount, + isLoopBlock, + runtimeBinding, + categoryName, + bindingName + ) + ) + } + + const determineRuntimeBinding = (name, idx, isLoopBlock) => { + if (idx === 0 && automation.trigger?.event === "app:trigger") { + return `trigger.fields.${name}` + } + return isLoopBlock + ? `loop.${name}` + : `steps.${idx - loopBlockCount}.${name}` + } + + const determineCategoryName = (idx, isLoopBlock, bindingName) => { + if (idx === 0) return "Trigger outputs" + if (isLoopBlock) return "Loop Outputs" + return bindingName + ? `${bindingName} outputs` + : `Step ${idx - loopBlockCount} outputs` + } + + const createBindingObject = ( + name, + value, + icon, + idx, + loopBlockCount, + isLoopBlock, + runtimeBinding, + categoryName, + bindingName + ) => { + return { + readableBinding: bindingName + ? `${bindingName}.${name}` + : runtimeBinding, + runtimeBinding, + type: value.type, + description: value.description, + icon, + category: categoryName, + display: { + type: value.type, + name, + rank: isLoopBlock ? idx + 1 : idx - loopBlockCount, + }, + } + } + for (let idx = 0; idx < blockIdx; idx++) { let wasLoopBlock = allSteps[idx - 1]?.stepId === ActionStepID.LOOP let isLoopBlock = allSteps[idx]?.stepId === ActionStepID.LOOP && - allSteps.find(x => x.blockToLoop === block.id) - - // If the previous block was a loop block, decrement the index so the following - // steps are in the correct order - if (wasLoopBlock) { - loopBlockCount++ - continue - } - + allSteps.some(x => x.blockToLoop === block.id) let schema = allSteps[idx]?.schema?.outputs?.properties ?? {} + let bindingName = + automation.stepNames?.[allSteps[idx - loopBlockCount].id] - // If its a Loop Block, we need to add this custom schema if (isLoopBlock) { + // Reset schema to only include 'currentItem' for loop blocks schema = { currentItem: { type: "string", @@ -180,75 +234,46 @@ }, } } - const outputs = Object.entries(schema) - let bindingIcon = "" - let bindingRank = 0 - if (idx === 0) { - bindingIcon = automation.trigger.icon - } else if (isLoopBlock) { - bindingIcon = "Reuse" - bindingRank = idx + 1 - } else { - bindingIcon = allSteps[idx].icon - bindingRank = idx - loopBlockCount + + if (idx === 0 && automation.trigger?.event === "app:trigger") { + schema = Object.fromEntries( + Object.keys(automation.trigger.inputs.fields).map(key => [ + key, + { type: automation.trigger.inputs.fields[key] }, + ]) + ) } - let bindingName = - automation.stepNames?.[allSteps[idx - loopBlockCount].id] - bindings = bindings.concat( - outputs.map(([name, value]) => { - let runtimeName = isLoopBlock - ? `loop.${name}` - : block.name.startsWith("JS") - ? `steps[${idx - loopBlockCount}].${name}` - : `steps.${idx - loopBlockCount}.${name}` - const runtime = idx === 0 ? `trigger.${name}` : runtimeName - let categoryName - if (idx === 0) { - categoryName = "Trigger outputs" - } else if (isLoopBlock) { - categoryName = "Loop Outputs" - } else if (bindingName) { - categoryName = `${bindingName} outputs` - } else { - categoryName = `Step ${idx - loopBlockCount} outputs` - } + let icon = + idx === 0 + ? automation.trigger.icon + : isLoopBlock + ? "Reuse" + : allSteps[idx].icon - return { - readableBinding: bindingName ? `${bindingName}.${name}` : runtime, - runtimeBinding: runtime, - type: value.type, - description: value.description, - icon: bindingIcon, - category: categoryName, - display: { - type: value.type, - name: name, - rank: bindingRank, - }, - } - }) + // Continue if the previous block was a loop block to skip bindings from the block that the loop is attached to + if (wasLoopBlock) { + loopBlockCount++ + continue + } + + Object.entries(schema).forEach(([name, value]) => + addBinding(name, value, icon, idx, isLoopBlock, bindingName) ) } // Environment bindings if ($licensing.environmentVariablesEnabled) { bindings = bindings.concat( - getEnvironmentBindings().map(binding => { - return { - ...binding, - display: { - ...binding.display, - rank: 98, - }, - } - }) + getEnvironmentBindings().map(binding => ({ + ...binding, + display: { ...binding.display, rank: 98 }, + })) ) } return bindings } - function lookForFilters(properties) { if (!properties) { return [] From 186fd844843c21ef3d7d016c5856b1f59928699e Mon Sep 17 00:00:00 2001 From: Peter Clement Date: Mon, 8 Jan 2024 09:31:41 +0000 Subject: [PATCH 2/7] remove log --- .../automation/SetupPanel/AutomationBlockSetup.svelte | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/builder/src/components/automation/SetupPanel/AutomationBlockSetup.svelte b/packages/builder/src/components/automation/SetupPanel/AutomationBlockSetup.svelte index 9a16b23fa2..10ddd29c63 100644 --- a/packages/builder/src/components/automation/SetupPanel/AutomationBlockSetup.svelte +++ b/packages/builder/src/components/automation/SetupPanel/AutomationBlockSetup.svelte @@ -51,7 +51,7 @@ export let testData export let schemaProperties export let isTestModal = false - $: console.log(inputData) + let webhookModal let drawer let fillWidth = true From 93c5b3721bbc09a15727608901be2e545c997dae Mon Sep 17 00:00:00 2001 From: Peter Clement Date: Tue, 9 Jan 2024 11:02:51 +0000 Subject: [PATCH 3/7] some tweaks to fix bindings for row created / updated events --- .../SetupPanel/AutomationBlockSetup.svelte | 70 ++++++++++++++----- 1 file changed, 53 insertions(+), 17 deletions(-) diff --git a/packages/builder/src/components/automation/SetupPanel/AutomationBlockSetup.svelte b/packages/builder/src/components/automation/SetupPanel/AutomationBlockSetup.svelte index 10ddd29c63..ecc748599f 100644 --- a/packages/builder/src/components/automation/SetupPanel/AutomationBlockSetup.svelte +++ b/packages/builder/src/components/automation/SetupPanel/AutomationBlockSetup.svelte @@ -51,7 +51,6 @@ export let testData export let schemaProperties export let isTestModal = false - let webhookModal let drawer let fillWidth = true @@ -145,13 +144,17 @@ return [] } - let allSteps = automation.trigger - ? [automation.trigger, ...automation.steps] - : [...automation.steps] + // Find previous steps to the selected one + let allSteps = [...automation.steps] + + if (automation.trigger) { + allSteps = [automation.trigger, ...allSteps] + } let blockIdx = allSteps.findIndex(step => step.id === block.id) + + // Extract all outputs from all previous steps as available bindingsx§x let bindings = [] let loopBlockCount = 0 - const addBinding = (name, value, icon, idx, isLoopBlock, bindingName) => { const runtimeBinding = determineRuntimeBinding(name, idx, isLoopBlock) const categoryName = determineCategoryName(idx, isLoopBlock, bindingName) @@ -172,12 +175,28 @@ } const determineRuntimeBinding = (name, idx, isLoopBlock) => { + let runtimeName + + /* Begin special cases for generating custom schemas based on triggers */ if (idx === 0 && automation.trigger?.event === "app:trigger") { return `trigger.fields.${name}` } - return isLoopBlock - ? `loop.${name}` - : `steps.${idx - loopBlockCount}.${name}` + + if ( + (idx === 0 && automation.trigger?.event === "row:update") || + automation.trigger?.event === "row:save" + ) { + if (name !== "id" && name !== "revision") return `trigger.row.${name}` + } + /* end special cases */ + if (isLoopBlock) { + runtimeName = `loop.${name}` + } else if (block.name.startsWith("JS")) { + runtimeName = `steps[${idx - loopBlockCount}].${name}` + } else { + runtimeName = `steps.${idx - loopBlockCount}.${name}` + } + return idx === 0 ? `trigger.${name}` : runtimeName } const determineCategoryName = (idx, isLoopBlock, bindingName) => { @@ -221,12 +240,11 @@ let isLoopBlock = allSteps[idx]?.stepId === ActionStepID.LOOP && allSteps.some(x => x.blockToLoop === block.id) - let schema = allSteps[idx]?.schema?.outputs?.properties ?? {} + let schema = cloneDeep(allSteps[idx]?.schema?.outputs?.properties) ?? {} let bindingName = automation.stepNames?.[allSteps[idx - loopBlockCount].id] if (isLoopBlock) { - // Reset schema to only include 'currentItem' for loop blocks schema = { currentItem: { type: "string", @@ -243,7 +261,22 @@ ]) ) } - + if ( + (idx === 0 && automation.trigger.event === "row:update") || + (idx === 0 && automation.trigger.event === "row:save") + ) { + let table = $tables.list.find( + table => table._id === automation.trigger.inputs.tableId + ) + // We want to generate our own schema for the bindings from the table schema itself + for (const key in table?.schema) { + schema[key] = { + type: table.schema[key].type, + } + } + // remove the original binding + delete schema.row + } let icon = idx === 0 ? automation.trigger.icon @@ -251,7 +284,6 @@ ? "Reuse" : allSteps[idx].icon - // Continue if the previous block was a loop block to skip bindings from the block that the loop is attached to if (wasLoopBlock) { loopBlockCount++ continue @@ -265,13 +297,17 @@ // Environment bindings if ($licensing.environmentVariablesEnabled) { bindings = bindings.concat( - getEnvironmentBindings().map(binding => ({ - ...binding, - display: { ...binding.display, rank: 98 }, - })) + getEnvironmentBindings().map(binding => { + return { + ...binding, + display: { + ...binding.display, + rank: 98, + }, + } + }) ) } - return bindings } function lookForFilters(properties) { From c3f77f3b42618eddf2007839b0ebd75a7e549939 Mon Sep 17 00:00:00 2001 From: Peter Clement Date: Thu, 11 Jan 2024 09:47:04 +0000 Subject: [PATCH 4/7] linting --- .../automation/SetupPanel/AutomationBlockSetup.svelte | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/builder/src/components/automation/SetupPanel/AutomationBlockSetup.svelte b/packages/builder/src/components/automation/SetupPanel/AutomationBlockSetup.svelte index ecc748599f..34c7c44ecd 100644 --- a/packages/builder/src/components/automation/SetupPanel/AutomationBlockSetup.svelte +++ b/packages/builder/src/components/automation/SetupPanel/AutomationBlockSetup.svelte @@ -188,7 +188,8 @@ ) { if (name !== "id" && name !== "revision") return `trigger.row.${name}` } - /* end special cases */ + /* End special cases for generating custom schemas based on triggers */ + if (isLoopBlock) { runtimeName = `loop.${name}` } else if (block.name.startsWith("JS")) { From bf12e5bc1e456a0218295cc5a7444ea89900e483 Mon Sep 17 00:00:00 2001 From: Peter Clement Date: Thu, 11 Jan 2024 11:01:23 +0000 Subject: [PATCH 5/7] revert to empty array on fields object being empty --- .../automation/SetupPanel/AutomationBlockSetup.svelte | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/builder/src/components/automation/SetupPanel/AutomationBlockSetup.svelte b/packages/builder/src/components/automation/SetupPanel/AutomationBlockSetup.svelte index 34c7c44ecd..b8aaf10443 100644 --- a/packages/builder/src/components/automation/SetupPanel/AutomationBlockSetup.svelte +++ b/packages/builder/src/components/automation/SetupPanel/AutomationBlockSetup.svelte @@ -256,7 +256,7 @@ if (idx === 0 && automation.trigger?.event === "app:trigger") { schema = Object.fromEntries( - Object.keys(automation.trigger.inputs.fields).map(key => [ + Object.keys(automation.trigger.inputs.fields || []).map(key => [ key, { type: automation.trigger.inputs.fields[key] }, ]) From 7f82f89942c45e97a9a9bcff54af686c4f31fe16 Mon Sep 17 00:00:00 2001 From: Peter Clement Date: Wed, 17 Jan 2024 09:43:34 +0000 Subject: [PATCH 6/7] pro update --- packages/pro | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/pro b/packages/pro index 6f5e2d9a6e..8c466d6ef2 160000 --- a/packages/pro +++ b/packages/pro @@ -1 +1 @@ -Subproject commit 6f5e2d9a6ee671c5d987462ceb4156e2c3276a2f +Subproject commit 8c466d6ef2a0c09b843ef63276793ab5af2e96f7 From 1131dc34aacce244d09f8049f23cca6d9dfe2bae Mon Sep 17 00:00:00 2001 From: Peter Clement Date: Wed, 17 Jan 2024 09:45:24 +0000 Subject: [PATCH 7/7] fix pro --- packages/pro | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/pro b/packages/pro index 8c466d6ef2..9d80daaa5b 160000 --- a/packages/pro +++ b/packages/pro @@ -1 +1 @@ -Subproject commit 8c466d6ef2a0c09b843ef63276793ab5af2e96f7 +Subproject commit 9d80daaa5b79da68730d6c5f497f629c47a78ef8