refactor: Use only arguments for action definitions

This commit is contained in:
Faruk AYDIN
2022-10-31 18:26:58 +01:00
parent bcfc9beb99
commit 1cfe84fc3d
10 changed files with 246 additions and 321 deletions

View File

@@ -1,5 +1,5 @@
import { IAction } from '@automatisch/types';
import { IRawAction } from '@automatisch/types';
export default function defineAction(actionDefinition: IAction): IAction {
export default function defineAction(actionDefinition: IRawAction): IRawAction {
return actionDefinition;
}

View File

@@ -1,4 +1,10 @@
import { IApp, IRawTrigger, ITrigger } from '@automatisch/types';
import {
IAction,
IApp,
IRawAction,
IRawTrigger,
ITrigger,
} from '@automatisch/types';
import { omit, cloneDeep } from 'lodash';
async function getDefaultExport(path: string) {
@@ -23,25 +29,11 @@ const getApp = async (appKey: string, stripFuncs = true) => {
const appData: IApp = cloneDeep(await getDefaultExport(`../apps/${appKey}`));
appData.triggers = appData?.triggers?.map((trigger: IRawTrigger) => {
const computedTrigger: ITrigger = omit(trigger, ['arguments']);
return addStaticSubsteps(appData, trigger);
});
computedTrigger.substeps = [];
if (appData.supportsConnections) {
computedTrigger.substeps.push(chooseConnectionStep);
}
if (trigger.arguments) {
computedTrigger.substeps.push({
key: 'chooseTrigger',
name: 'Set up a trigger',
arguments: trigger.arguments,
});
}
computedTrigger.substeps.push(testStep);
return computedTrigger;
appData.actions = appData?.actions?.map((action: IRawAction) => {
return addStaticSubsteps(appData, action);
});
if (stripFuncs) {
@@ -51,4 +43,26 @@ const getApp = async (appKey: string, stripFuncs = true) => {
return appData;
};
const addStaticSubsteps = (appData: IApp, step: IRawTrigger | IRawAction) => {
const computedStep: ITrigger | IAction = omit(step, ['arguments']);
computedStep.substeps = [];
if (appData.supportsConnections) {
computedStep.substeps.push(chooseConnectionStep);
}
if (step.arguments) {
computedStep.substeps.push({
key: 'chooseTrigger',
name: 'Set up a trigger',
arguments: step.arguments,
});
}
computedStep.substeps.push(testStep);
return computedStep;
};
export default getApp;