From d6c0690324039e3e7caa701f33135242cee6a3c7 Mon Sep 17 00:00:00 2001 From: Faruk AYDIN Date: Mon, 31 Oct 2022 23:31:28 +0100 Subject: [PATCH] refactor: Differentiate trigger and action for get app helper --- packages/backend/src/helpers/get-app.ts | 36 ++++++++++++++----------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/packages/backend/src/helpers/get-app.ts b/packages/backend/src/helpers/get-app.ts index 44d102c2..c3217d72 100644 --- a/packages/backend/src/helpers/get-app.ts +++ b/packages/backend/src/helpers/get-app.ts @@ -15,25 +15,15 @@ function stripFunctions(data: C): C { return JSON.parse(JSON.stringify(data)); } -const chooseConnectionStep = { - key: 'chooseConnection', - name: 'Choose connection', -}; - -const testStep = { - key: 'testStep', - name: 'Test trigger', -}; - const getApp = async (appKey: string, stripFuncs = true) => { const appData: IApp = cloneDeep(await getDefaultExport(`../apps/${appKey}`)); appData.triggers = appData?.triggers?.map((trigger: IRawTrigger) => { - return addStaticSubsteps(appData, trigger); + return addStaticSubsteps('trigger', appData, trigger); }); appData.actions = appData?.actions?.map((action: IRawAction) => { - return addStaticSubsteps(appData, action); + return addStaticSubsteps('action', appData, action); }); if (stripFuncs) { @@ -43,7 +33,23 @@ const getApp = async (appKey: string, stripFuncs = true) => { return appData; }; -const addStaticSubsteps = (appData: IApp, step: IRawTrigger | IRawAction) => { +const chooseConnectionStep = { + key: 'chooseConnection', + name: 'Choose connection', +}; + +const testStep = (stepType: 'trigger' | 'action') => { + return { + key: 'testStep', + name: stepType === 'trigger' ? 'Test trigger' : 'Test action', + }; +}; + +const addStaticSubsteps = ( + stepType: 'trigger' | 'action', + appData: IApp, + step: IRawTrigger | IRawAction +) => { const computedStep: ITrigger | IAction = omit(step, ['arguments']); computedStep.substeps = []; @@ -55,12 +61,12 @@ const addStaticSubsteps = (appData: IApp, step: IRawTrigger | IRawAction) => { if (step.arguments) { computedStep.substeps.push({ key: 'chooseTrigger', - name: 'Set up a trigger', + name: stepType === 'trigger' ? 'Set up a trigger' : 'Set up action', arguments: step.arguments, }); } - computedStep.substeps.push(testStep); + computedStep.substeps.push(testStep(stepType)); return computedStep; };