refactor: Differentiate trigger and action for get app helper
This commit is contained in:
@@ -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;
|
||||
};
|
||||
|
Reference in New Issue
Block a user