refactor: Differentiate trigger and action for get app helper

This commit is contained in:
Faruk AYDIN
2022-10-31 23:31:28 +01:00
parent 1cfe84fc3d
commit d6c0690324

View File

@@ -15,25 +15,15 @@ function stripFunctions<C>(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;
};