From 06f1a7bbf10375c8941fc0d557f0a2eb5d1b91a1 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Thu, 10 Sep 2020 14:16:43 +0100 Subject: [PATCH] Load workflow blocks from server and remove block definitions from builder --- .../builderStore/store/workflow/Workflow.js | 12 +- .../src/builderStore/store/workflow/index.js | 36 +++- .../WorkflowPanel/BlockList/BlockList.svelte | 7 +- .../WorkflowPanel/blockDefinitions.js | 170 ------------------ 4 files changed, 36 insertions(+), 189 deletions(-) delete mode 100644 packages/builder/src/components/workflow/WorkflowPanel/blockDefinitions.js diff --git a/packages/builder/src/builderStore/store/workflow/Workflow.js b/packages/builder/src/builderStore/store/workflow/Workflow.js index d9c1ee249f..94f1c85229 100644 --- a/packages/builder/src/builderStore/store/workflow/Workflow.js +++ b/packages/builder/src/builderStore/store/workflow/Workflow.js @@ -1,5 +1,4 @@ import mustache from "mustache" -import blockDefinitions from "components/workflow/WorkflowPanel/blockDefinitions" import { generate } from "shortid" /** @@ -7,8 +6,9 @@ import { generate } from "shortid" * Workflow definitions are stored in linked lists. */ export default class Workflow { - constructor(workflow) { + constructor(workflow, blockDefinitions) { this.workflow = workflow + this.blockDefinitions = blockDefinitions } hasTrigger() { @@ -56,12 +56,14 @@ export default class Workflow { createUiTree() { if (!this.workflow.definition) return [] - return Workflow.buildUiTree(this.workflow.definition) + return Workflow.buildUiTree(this.workflow.definition, this.blockDefinitions) } - static buildUiTree(definition) { + static buildUiTree(definition, blockDefinitions) { const steps = [] - if (definition.trigger) steps.push(definition.trigger) + if (definition.trigger) { + steps.push(definition.trigger) + } return [...steps, ...definition.steps].map(step => { // The client side display definition for the block diff --git a/packages/builder/src/builderStore/store/workflow/index.js b/packages/builder/src/builderStore/store/workflow/index.js index 9d50f85661..d4ba9fe76f 100644 --- a/packages/builder/src/builderStore/store/workflow/index.js +++ b/packages/builder/src/builderStore/store/workflow/index.js @@ -4,11 +4,20 @@ import Workflow from "./Workflow" const workflowActions = store => ({ fetch: async () => { - const WORKFLOWS_URL = `/api/workflows` - const workflowResponse = await api.get(WORKFLOWS_URL) - const json = await workflowResponse.json() + const responses = await Promise.all([ + api.get(`/api/workflows`), + api.get(`/api/workflows/trigger/list`), + api.get(`/api/workflows/action/list`), + api.get(`/api/workflows/logic/list`), + ]) + const jsonResponses = await Promise.all(responses.map(x => x.json())) store.update(state => { - state.workflows = json + state.workflows = jsonResponses[0] + state.blockDefinitions = { + TRIGGER: jsonResponses[1], + ACTION: jsonResponses[2], + LOGIC: jsonResponses[3], + } return state }) }, @@ -24,7 +33,10 @@ const workflowActions = store => ({ const json = await response.json() store.update(state => { state.workflows = state.workflows.concat(json.workflow) - state.currentWorkflow = new Workflow(json.workflow) + state.currentWorkflow = new Workflow( + json.workflow, + state.blockDefinitions + ) return state }) }, @@ -38,7 +50,10 @@ const workflowActions = store => ({ ) state.workflows.splice(existingIdx, 1, json.workflow) state.workflows = state.workflows - state.currentWorkflow = new Workflow(json.workflow) + state.currentWorkflow = new Workflow( + json.workflow, + state.blockDefinitions + ) return state }) }, @@ -72,7 +87,7 @@ const workflowActions = store => ({ }, select: workflow => { store.update(state => { - state.currentWorkflow = new Workflow(workflow) + state.currentWorkflow = new Workflow(workflow, state.blockDefinitions) state.selectedWorkflowBlock = null return state }) @@ -96,11 +111,14 @@ const workflowActions = store => ({ export const getWorkflowStore = () => { const INITIAL_WORKFLOW_STATE = { workflows: [], + blockDefinitions: { + TRIGGER: [], + ACTION: [], + LOGIC: [], + }, } const store = writable(INITIAL_WORKFLOW_STATE) - store.actions = workflowActions(store) - return store } diff --git a/packages/builder/src/components/workflow/WorkflowPanel/BlockList/BlockList.svelte b/packages/builder/src/components/workflow/WorkflowPanel/BlockList/BlockList.svelte index 3851e1a204..ea3d23bd38 100644 --- a/packages/builder/src/components/workflow/WorkflowPanel/BlockList/BlockList.svelte +++ b/packages/builder/src/components/workflow/WorkflowPanel/BlockList/BlockList.svelte @@ -1,9 +1,6 @@