some tweaks to fix bindings for row created / updated events
This commit is contained in:
parent
8a8001ff18
commit
93c5b3721b
|
@ -51,7 +51,6 @@
|
||||||
export let testData
|
export let testData
|
||||||
export let schemaProperties
|
export let schemaProperties
|
||||||
export let isTestModal = false
|
export let isTestModal = false
|
||||||
|
|
||||||
let webhookModal
|
let webhookModal
|
||||||
let drawer
|
let drawer
|
||||||
let fillWidth = true
|
let fillWidth = true
|
||||||
|
@ -145,13 +144,17 @@
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
|
|
||||||
let allSteps = automation.trigger
|
// Find previous steps to the selected one
|
||||||
? [automation.trigger, ...automation.steps]
|
let allSteps = [...automation.steps]
|
||||||
: [...automation.steps]
|
|
||||||
|
if (automation.trigger) {
|
||||||
|
allSteps = [automation.trigger, ...allSteps]
|
||||||
|
}
|
||||||
let blockIdx = allSteps.findIndex(step => step.id === block.id)
|
let blockIdx = allSteps.findIndex(step => step.id === block.id)
|
||||||
|
|
||||||
|
// Extract all outputs from all previous steps as available bindingsx§x
|
||||||
let bindings = []
|
let bindings = []
|
||||||
let loopBlockCount = 0
|
let loopBlockCount = 0
|
||||||
|
|
||||||
const addBinding = (name, value, icon, idx, isLoopBlock, bindingName) => {
|
const addBinding = (name, value, icon, idx, isLoopBlock, bindingName) => {
|
||||||
const runtimeBinding = determineRuntimeBinding(name, idx, isLoopBlock)
|
const runtimeBinding = determineRuntimeBinding(name, idx, isLoopBlock)
|
||||||
const categoryName = determineCategoryName(idx, isLoopBlock, bindingName)
|
const categoryName = determineCategoryName(idx, isLoopBlock, bindingName)
|
||||||
|
@ -172,12 +175,28 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
const determineRuntimeBinding = (name, idx, isLoopBlock) => {
|
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") {
|
if (idx === 0 && automation.trigger?.event === "app:trigger") {
|
||||||
return `trigger.fields.${name}`
|
return `trigger.fields.${name}`
|
||||||
}
|
}
|
||||||
return isLoopBlock
|
|
||||||
? `loop.${name}`
|
if (
|
||||||
: `steps.${idx - loopBlockCount}.${name}`
|
(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) => {
|
const determineCategoryName = (idx, isLoopBlock, bindingName) => {
|
||||||
|
@ -221,12 +240,11 @@
|
||||||
let isLoopBlock =
|
let isLoopBlock =
|
||||||
allSteps[idx]?.stepId === ActionStepID.LOOP &&
|
allSteps[idx]?.stepId === ActionStepID.LOOP &&
|
||||||
allSteps.some(x => x.blockToLoop === block.id)
|
allSteps.some(x => x.blockToLoop === block.id)
|
||||||
let schema = allSteps[idx]?.schema?.outputs?.properties ?? {}
|
let schema = cloneDeep(allSteps[idx]?.schema?.outputs?.properties) ?? {}
|
||||||
let bindingName =
|
let bindingName =
|
||||||
automation.stepNames?.[allSteps[idx - loopBlockCount].id]
|
automation.stepNames?.[allSteps[idx - loopBlockCount].id]
|
||||||
|
|
||||||
if (isLoopBlock) {
|
if (isLoopBlock) {
|
||||||
// Reset schema to only include 'currentItem' for loop blocks
|
|
||||||
schema = {
|
schema = {
|
||||||
currentItem: {
|
currentItem: {
|
||||||
type: "string",
|
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 =
|
let icon =
|
||||||
idx === 0
|
idx === 0
|
||||||
? automation.trigger.icon
|
? automation.trigger.icon
|
||||||
|
@ -251,7 +284,6 @@
|
||||||
? "Reuse"
|
? "Reuse"
|
||||||
: allSteps[idx].icon
|
: 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) {
|
if (wasLoopBlock) {
|
||||||
loopBlockCount++
|
loopBlockCount++
|
||||||
continue
|
continue
|
||||||
|
@ -265,13 +297,17 @@
|
||||||
// Environment bindings
|
// Environment bindings
|
||||||
if ($licensing.environmentVariablesEnabled) {
|
if ($licensing.environmentVariablesEnabled) {
|
||||||
bindings = bindings.concat(
|
bindings = bindings.concat(
|
||||||
getEnvironmentBindings().map(binding => ({
|
getEnvironmentBindings().map(binding => {
|
||||||
...binding,
|
return {
|
||||||
display: { ...binding.display, rank: 98 },
|
...binding,
|
||||||
}))
|
display: {
|
||||||
|
...binding.display,
|
||||||
|
rank: 98,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
})
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
return bindings
|
return bindings
|
||||||
}
|
}
|
||||||
function lookForFilters(properties) {
|
function lookForFilters(properties) {
|
||||||
|
|
Loading…
Reference in New Issue