From 98ffd6f971c55bb31f815b67db9d2504d37781bd Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Thu, 10 Sep 2020 11:27:31 +0100 Subject: [PATCH] Remove client workflow execution --- packages/client/src/api/index.js | 2 - packages/client/src/api/workflow/actions.js | 18 ----- packages/client/src/api/workflow/index.js | 68 ------------------- .../client/src/api/workflow/orchestrator.js | 22 ------ packages/client/src/state/eventHandlers.js | 3 - 5 files changed, 113 deletions(-) delete mode 100644 packages/client/src/api/workflow/actions.js delete mode 100644 packages/client/src/api/workflow/index.js delete mode 100644 packages/client/src/api/workflow/orchestrator.js diff --git a/packages/client/src/api/index.js b/packages/client/src/api/index.js index 1b829f16c6..d0ece0f10e 100644 --- a/packages/client/src/api/index.js +++ b/packages/client/src/api/index.js @@ -1,5 +1,4 @@ import { authenticate } from "./authenticate" -import { triggerWorkflow } from "./workflow" import appStore from "../state/store" const apiCall = method => async ({ url, body }) => { @@ -55,5 +54,4 @@ const apiOpts = { export default { authenticate: authenticate(apiOpts), - triggerWorkflow: triggerWorkflow(apiOpts), } diff --git a/packages/client/src/api/workflow/actions.js b/packages/client/src/api/workflow/actions.js deleted file mode 100644 index 09ba734231..0000000000 --- a/packages/client/src/api/workflow/actions.js +++ /dev/null @@ -1,18 +0,0 @@ -const delay = ms => new Promise(resolve => setTimeout(resolve, ms)) - -export default { - NAVIGATE: () => { - // TODO client navigation - }, - DELAY: async ({ args }) => await delay(args.time), - FILTER: ({ args }) => { - const { field, condition, value } = args - switch (condition) { - case "equals": - if (field !== value) return - break - default: - return - } - }, -} diff --git a/packages/client/src/api/workflow/index.js b/packages/client/src/api/workflow/index.js deleted file mode 100644 index 4a15d04772..0000000000 --- a/packages/client/src/api/workflow/index.js +++ /dev/null @@ -1,68 +0,0 @@ -import renderTemplateString from "../../state/renderTemplateString" -import appStore from "../../state/store" -import Orchestrator from "./orchestrator" -import clientActions from "./actions" - -// Execute a workflow from a running budibase app -export const clientStrategy = ({ api }) => ({ - context: {}, - bindContextArgs: function(args) { - const mappedArgs = { ...args } - - // bind the workflow action args to the workflow context, if required - for (let arg in args) { - const argValue = args[arg] - - // We don't want to render mustache templates on non-strings - if (typeof argValue !== "string") continue - - // Render the string with values from the workflow context and state - mappedArgs[arg] = renderTemplateString(argValue, { - context: this.context, - state: appStore.get(), - }) - } - - return mappedArgs - }, - run: async function(workflow) { - for (let block of workflow.steps) { - // This code gets run in the browser - if (block.environment === "CLIENT") { - const action = clientActions[block.actionId] - await action({ - context: this.context, - args: this.bindContextArgs(block.args), - id: block.id, - }) - } - - // this workflow block gets executed on the server - if (block.environment === "SERVER") { - const EXECUTE_WORKFLOW_URL = `/api/workflows/action` - const response = await api.post({ - url: EXECUTE_WORKFLOW_URL, - body: { - action: block.actionId, - args: this.bindContextArgs(block.args, api), - }, - }) - - this.context = { - ...this.context, - [block.actionId]: response, - } - } - } - }, -}) - -export const triggerWorkflow = api => async ({ workflow }) => { - const workflowOrchestrator = new Orchestrator(api) - workflowOrchestrator.strategy = clientStrategy - - const EXECUTE_WORKFLOW_URL = `/api/workflows/${workflow}` - const workflowDefinition = await api.get({ url: EXECUTE_WORKFLOW_URL }) - - workflowOrchestrator.execute(workflowDefinition) -} diff --git a/packages/client/src/api/workflow/orchestrator.js b/packages/client/src/api/workflow/orchestrator.js deleted file mode 100644 index b1d17fac59..0000000000 --- a/packages/client/src/api/workflow/orchestrator.js +++ /dev/null @@ -1,22 +0,0 @@ -/** - * The workflow orchestrator is a class responsible for executing workflows. - * It relies on the strategy pattern, which allows composable behaviour to be - * passed into its execute() function. This allows custom execution behaviour based - * on where the orchestrator is run. - * - */ -export default class Orchestrator { - constructor(api) { - this.api = api - } - - set strategy(strategy) { - this._strategy = strategy({ api: this.api }) - } - - async execute(workflow) { - if (workflow.live) { - this._strategy.run(workflow.definition) - } - } -} diff --git a/packages/client/src/state/eventHandlers.js b/packages/client/src/state/eventHandlers.js index 56e760e555..6a1c297798 100644 --- a/packages/client/src/state/eventHandlers.js +++ b/packages/client/src/state/eventHandlers.js @@ -1,5 +1,3 @@ -import api from "../api" - export const EVENT_TYPE_MEMBER_NAME = "##eventHandlerType" export const eventHandlers = routeTo => { @@ -10,7 +8,6 @@ export const eventHandlers = routeTo => { return { "Navigate To": handler(["url"], param => routeTo(param && param.url)), - "Trigger Workflow": handler(["workflow"], api.triggerWorkflow), } }