recommit work for trigger binding suggestions
This commit is contained in:
parent
eabe74a2c1
commit
a6c09e25e6
1 changed files with 99 additions and 74 deletions
|
@ -51,7 +51,7 @@
|
||||||
export let testData
|
export let testData
|
||||||
export let schemaProperties
|
export let schemaProperties
|
||||||
export let isTestModal = false
|
export let isTestModal = false
|
||||||
|
$: console.log(inputData)
|
||||||
let webhookModal
|
let webhookModal
|
||||||
let drawer
|
let drawer
|
||||||
let fillWidth = true
|
let fillWidth = true
|
||||||
|
@ -101,7 +101,6 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const onChange = Utils.sequential(async (e, key) => {
|
const onChange = Utils.sequential(async (e, key) => {
|
||||||
// We need to cache the schema as part of the definition because it is
|
// 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
|
// used in the server to detect relationships. It would be far better to
|
||||||
|
@ -145,34 +144,89 @@
|
||||||
if (!block || !automation) {
|
if (!block || !automation) {
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
// Find previous steps to the selected one
|
|
||||||
let allSteps = [...automation.steps]
|
|
||||||
|
|
||||||
if (automation.trigger) {
|
let allSteps = automation.trigger
|
||||||
allSteps = [automation.trigger, ...allSteps]
|
? [automation.trigger, ...automation.steps]
|
||||||
}
|
: [...automation.steps]
|
||||||
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 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++) {
|
for (let idx = 0; idx < blockIdx; idx++) {
|
||||||
let wasLoopBlock = allSteps[idx - 1]?.stepId === ActionStepID.LOOP
|
let wasLoopBlock = allSteps[idx - 1]?.stepId === ActionStepID.LOOP
|
||||||
let isLoopBlock =
|
let isLoopBlock =
|
||||||
allSteps[idx]?.stepId === ActionStepID.LOOP &&
|
allSteps[idx]?.stepId === ActionStepID.LOOP &&
|
||||||
allSteps.find(x => x.blockToLoop === block.id)
|
allSteps.some(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
|
|
||||||
}
|
|
||||||
|
|
||||||
let schema = allSteps[idx]?.schema?.outputs?.properties ?? {}
|
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) {
|
if (isLoopBlock) {
|
||||||
|
// Reset schema to only include 'currentItem' for loop blocks
|
||||||
schema = {
|
schema = {
|
||||||
currentItem: {
|
currentItem: {
|
||||||
type: "string",
|
type: "string",
|
||||||
|
@ -180,75 +234,46 @@
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const outputs = Object.entries(schema)
|
|
||||||
let bindingIcon = ""
|
if (idx === 0 && automation.trigger?.event === "app:trigger") {
|
||||||
let bindingRank = 0
|
schema = Object.fromEntries(
|
||||||
if (idx === 0) {
|
Object.keys(automation.trigger.inputs.fields).map(key => [
|
||||||
bindingIcon = automation.trigger.icon
|
key,
|
||||||
} else if (isLoopBlock) {
|
{ type: automation.trigger.inputs.fields[key] },
|
||||||
bindingIcon = "Reuse"
|
])
|
||||||
bindingRank = idx + 1
|
)
|
||||||
} else {
|
|
||||||
bindingIcon = allSteps[idx].icon
|
|
||||||
bindingRank = idx - loopBlockCount
|
|
||||||
}
|
}
|
||||||
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
|
let icon =
|
||||||
if (idx === 0) {
|
idx === 0
|
||||||
categoryName = "Trigger outputs"
|
? automation.trigger.icon
|
||||||
} else if (isLoopBlock) {
|
: isLoopBlock
|
||||||
categoryName = "Loop Outputs"
|
? "Reuse"
|
||||||
} else if (bindingName) {
|
: allSteps[idx].icon
|
||||||
categoryName = `${bindingName} outputs`
|
|
||||||
} else {
|
|
||||||
categoryName = `Step ${idx - loopBlockCount} outputs`
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
// Continue if the previous block was a loop block to skip bindings from the block that the loop is attached to
|
||||||
readableBinding: bindingName ? `${bindingName}.${name}` : runtime,
|
if (wasLoopBlock) {
|
||||||
runtimeBinding: runtime,
|
loopBlockCount++
|
||||||
type: value.type,
|
continue
|
||||||
description: value.description,
|
}
|
||||||
icon: bindingIcon,
|
|
||||||
category: categoryName,
|
Object.entries(schema).forEach(([name, value]) =>
|
||||||
display: {
|
addBinding(name, value, icon, idx, isLoopBlock, bindingName)
|
||||||
type: value.type,
|
|
||||||
name: name,
|
|
||||||
rank: bindingRank,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
})
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Environment bindings
|
// Environment bindings
|
||||||
if ($licensing.environmentVariablesEnabled) {
|
if ($licensing.environmentVariablesEnabled) {
|
||||||
bindings = bindings.concat(
|
bindings = bindings.concat(
|
||||||
getEnvironmentBindings().map(binding => {
|
getEnvironmentBindings().map(binding => ({
|
||||||
return {
|
...binding,
|
||||||
...binding,
|
display: { ...binding.display, rank: 98 },
|
||||||
display: {
|
}))
|
||||||
...binding.display,
|
|
||||||
rank: 98,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
})
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
return bindings
|
return bindings
|
||||||
}
|
}
|
||||||
|
|
||||||
function lookForFilters(properties) {
|
function lookForFilters(properties) {
|
||||||
if (!properties) {
|
if (!properties) {
|
||||||
return []
|
return []
|
||||||
|
|
Loading…
Reference in a new issue