diff --git a/packages/builder/src/stores/builder/automations.ts b/packages/builder/src/stores/builder/automations.ts index ce16c47668..066ace0326 100644 --- a/packages/builder/src/stores/builder/automations.ts +++ b/packages/builder/src/stores/builder/automations.ts @@ -26,6 +26,9 @@ import { UILogicalOperator, EmptyFilterOption, AutomationIOType, + AutomationStepSchema, + AutomationTriggerSchema, + BranchPath, } from "@budibase/types" import { ActionStepID } from "constants/backend/automations" import { FIELDS } from "constants/backend" @@ -165,7 +168,7 @@ const automationActions = (store: AutomationStore) => ({ * @param {*} automation the automation to alter. * @returns {Object} contains the deleted nodes and new updated automation */ - deleteBlock: (pathTo: Array, automation: Automation) => { + deleteBlock: (pathTo: Array, automation: Automation) => { let newAutomation = cloneDeep(automation) const steps = [ @@ -253,7 +256,7 @@ const automationActions = (store: AutomationStore) => ({ registerBlock: ( blocks: Record, block: AutomationStep | AutomationTrigger, - pathTo: Array, + pathTo: Array, terminating: boolean ) => { blocks[block.id] = { @@ -278,7 +281,7 @@ const automationActions = (store: AutomationStore) => ({ * @param {Array} pathWay e.g. [{stepIdx:2},{branchIdx:0, stepIdx:2},...] * @returns {Array} all steps encountered on the provided path */ - getPathSteps: (pathWay: Array, automation: Automation) => { + getPathSteps: (pathWay: Array, automation: Automation) => { // Base Steps, including trigger const steps = [ automation.definition.trigger, @@ -319,7 +322,7 @@ const automationActions = (store: AutomationStore) => ({ * @returns */ updateStep: ( - pathWay: Array, + pathWay: Array, automation: Automation, update: AutomationStep | AutomationTrigger, insert = false @@ -474,7 +477,7 @@ const automationActions = (store: AutomationStore) => ({ branches.forEach((branch, bIdx) => { block.inputs?.children[branch.id].forEach( - (bBlock: any, sIdx: any, array: any) => { + (bBlock: AutomationStep, sIdx: number, array: AutomationStep[]) => { const ended = array.length - 1 === sIdx && !bBlock.inputs?.branches?.length treeTraverse(bBlock, pathToCurrentNode, sIdx, bIdx, ended) @@ -569,7 +572,7 @@ const automationActions = (store: AutomationStore) => ({ const isLoopBlock = pathBlock.stepId === ActionStepID.LOOP && - pathBlock.blockToLoop in blocks + pathBlock.blockToLoop! in blocks const isTrigger = pathBlock.type === AutomationStepType.TRIGGER @@ -910,7 +913,10 @@ const automationActions = (store: AutomationStore) => ({ ...newAutomation.definition.steps, ] - let cache: any + let cache: + | AutomationStepSchema + | AutomationTriggerSchema + pathWay.forEach((path, pathIdx, array) => { const { stepIdx, branchIdx } = path const final = pathIdx === array.length - 1 @@ -931,7 +937,6 @@ const automationActions = (store: AutomationStore) => ({ } return } - if (Number.isInteger(branchIdx)) { const branchId = cache.inputs.branches[branchIdx].id const children = cache.inputs.children[branchId] @@ -982,7 +987,7 @@ const automationActions = (store: AutomationStore) => ({ branchAutomation: async (path: Array, automation: Automation) => { const insertPoint = path.at(-1) let newAutomation = cloneDeep(automation) - let cache: any = null + let cache: any let atRoot = false // Generate a default empty branch @@ -1105,7 +1110,7 @@ const automationActions = (store: AutomationStore) => ({ * @param {Object} block */ branchRight: async ( - pathTo: Array, + pathTo: Array, automation: Automation, block: AutomationStep ) => { @@ -1254,7 +1259,7 @@ const automationActions = (store: AutomationStore) => ({ * * @param {Array} pathTo the path to the target node */ - deleteAutomationBlock: async (pathTo: Array) => { + deleteAutomationBlock: async (pathTo: Array) => { const automation = get(selectedAutomation)?.data if (!automation) { return diff --git a/packages/types/src/documents/app/automation/automation.ts b/packages/types/src/documents/app/automation/automation.ts index 55fbd26b23..d56f0de879 100644 --- a/packages/types/src/documents/app/automation/automation.ts +++ b/packages/types/src/documents/app/automation/automation.ts @@ -193,7 +193,7 @@ export enum AutomationStoppedReason { export interface AutomationResults { automationId?: string status?: AutomationStatus - trigger?: any + trigger?: AutomationTrigger steps: { stepId: AutomationTriggerStepId | AutomationActionStepId inputs: { diff --git a/packages/types/src/ui/stores/automations.ts b/packages/types/src/ui/stores/automations.ts new file mode 100644 index 0000000000..81e669ba4a --- /dev/null +++ b/packages/types/src/ui/stores/automations.ts @@ -0,0 +1,5 @@ +export interface BranchPath { + stepIdx: number + branchIdx: number + branchStepId: string +} diff --git a/packages/types/src/ui/stores/index.ts b/packages/types/src/ui/stores/index.ts index 658691cc6d..9c58b54867 100644 --- a/packages/types/src/ui/stores/index.ts +++ b/packages/types/src/ui/stores/index.ts @@ -1 +1,2 @@ export * from "./integration" +export * from "./automations"