From aeae4f50e26b39a576c15d229581958176db1a76 Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Mon, 1 Jun 2020 21:26:32 +0100 Subject: [PATCH] tidy up --- packages/builder/package.json | 1 - .../builderStore/store/workflow/Workflow.js | 17 +- .../src/builderStore/store/workflow/index.js | 12 +- .../builder/src/components/common/binding.js | 31 ---- .../src/components/common/eventHandlers.js | 9 +- .../modals/CreateEditModel/FieldView.svelte | 1 - .../AppPreview/iframeTemplate.js | 1 - .../EventsEditor/StateBindingCascader.svelte | 5 +- .../ParamInputs/ModelSelector.svelte | 1 - .../workflow/SetupPanel/SetupPanel.svelte | 138 +++++++++++---- .../SetupPanel/WorkflowBlockSetup.svelte | 2 + .../WorkflowList/WorkflowList.svelte | 1 - .../WorkflowPanel/blockDefinitions.js | 4 +- packages/client/src/api/workflow/actions.js | 8 +- packages/client/src/api/workflow/index.js | 10 +- packages/client/src/createApp.js | 2 - packages/client/src/render/screenRouter.js | 2 - packages/client/src/state/eventHandlers.js | 7 +- packages/client/src/state/parseBinding.js | 67 -------- packages/client/src/state/stateManager.js | 160 +----------------- .../client/tests/workflowOrchestrator.spec.js | 43 ----- packages/server/src/api/controllers/view.js | 3 +- .../src/api/controllers/workflow/index.js | 7 +- packages/server/src/api/routes/workflow.js | 4 +- packages/server/src/events/index.js | 10 +- packages/server/src/events/workflow.js | 5 +- 26 files changed, 156 insertions(+), 395 deletions(-) delete mode 100644 packages/builder/src/components/common/binding.js delete mode 100644 packages/client/src/state/parseBinding.js delete mode 100644 packages/client/tests/workflowOrchestrator.spec.js diff --git a/packages/builder/package.json b/packages/builder/package.json index 7e4e7b9cab..22ee0e5302 100644 --- a/packages/builder/package.json +++ b/packages/builder/package.json @@ -54,7 +54,6 @@ "safe-buffer": "^5.1.2", "shortid": "^2.2.8", "string_decoder": "^1.2.0", - "svelte-grid": "^1.10.8", "svelte-simple-modal": "^0.3.0", "uikit": "^3.1.7" }, diff --git a/packages/builder/src/builderStore/store/workflow/Workflow.js b/packages/builder/src/builderStore/store/workflow/Workflow.js index e2bc5c1ee2..d9c1ee249f 100644 --- a/packages/builder/src/builderStore/store/workflow/Workflow.js +++ b/packages/builder/src/builderStore/store/workflow/Workflow.js @@ -17,9 +17,9 @@ export default class Workflow { addBlock(block) { // Make sure to add trigger if doesn't exist - if (!this.hasTrigger()) { + if (!this.hasTrigger() && block.type === "TRIGGER") { this.workflow.definition.trigger = { id: generate(), ...block } - return; + return } this.workflow.definition.steps.push({ @@ -30,7 +30,7 @@ export default class Workflow { updateBlock(updatedBlock, id) { const { steps, trigger } = this.workflow.definition - + if (trigger && trigger.id === id) { this.workflow.definition.trigger = null return @@ -43,7 +43,7 @@ export default class Workflow { deleteBlock(id) { const { steps, trigger } = this.workflow.definition - + if (trigger && trigger.id === id) { this.workflow.definition.trigger = null return @@ -60,7 +60,10 @@ export default class Workflow { } static buildUiTree(definition) { - const steps = definition.steps.map(step => { + const steps = [] + if (definition.trigger) steps.push(definition.trigger) + + return [...steps, ...definition.steps].map(step => { // The client side display definition for the block const definition = blockDefinitions[step.type][step.actionId] if (!definition) { @@ -88,9 +91,5 @@ export default class Workflow { name: definition.name, } }) - - console.log(definition); - - return definition.trigger ? [definition.trigger, ...steps] : steps } } diff --git a/packages/builder/src/builderStore/store/workflow/index.js b/packages/builder/src/builderStore/store/workflow/index.js index cc403115b4..8d5e63b197 100644 --- a/packages/builder/src/builderStore/store/workflow/index.js +++ b/packages/builder/src/builderStore/store/workflow/index.js @@ -13,12 +13,12 @@ const workflowActions = store => ({ }) }, create: async ({ instanceId, name }) => { - const workflow = { - name, - definition: { - steps: [] - } - }; + const workflow = { + name, + definition: { + steps: [], + }, + } const CREATE_WORKFLOW_URL = `/api/${instanceId}/workflows` const response = await api.post(CREATE_WORKFLOW_URL, workflow) const json = await response.json() diff --git a/packages/builder/src/components/common/binding.js b/packages/builder/src/components/common/binding.js deleted file mode 100644 index 18c31e8040..0000000000 --- a/packages/builder/src/components/common/binding.js +++ /dev/null @@ -1,31 +0,0 @@ -// import { isString } from "lodash/fp" - -// import { -// BB_STATE_BINDINGPATH, -// BB_STATE_FALLBACK, -// BB_STATE_BINDINGSOURCE, -// isBound, -// parseBinding, -// } from "@budibase/client/src/state/parseBinding" - -// export const isBinding = isBound - -// export const setBinding = ({ path, fallback, source }, binding = {}) => { -// if (isNonEmptyString(path)) binding[BB_STATE_BINDINGPATH] = path -// if (isNonEmptyString(fallback)) binding[BB_STATE_FALLBACK] = fallback -// binding[BB_STATE_BINDINGSOURCE] = source || "store" -// return binding -// } - -// export const getBinding = val => { -// const binding = parseBinding(val) -// return binding -// ? binding -// : { -// path: "", -// source: "store", -// fallback: "", -// } -// } - -// const isNonEmptyString = s => isString(s) && s.length > 0 diff --git a/packages/builder/src/components/common/eventHandlers.js b/packages/builder/src/components/common/eventHandlers.js index 9dac01eb86..2e7a62ac3e 100644 --- a/packages/builder/src/components/common/eventHandlers.js +++ b/packages/builder/src/components/common/eventHandlers.js @@ -1,13 +1,8 @@ import { eventHandlers } from "../../../../client/src/state/eventHandlers" -import { writable } from "svelte/store" export { EVENT_TYPE_MEMBER_NAME } from "../../../../client/src/state/eventHandlers" -export const allHandlers = user => { - const store = writable({ - _bbuser: user, - }) - - const handlersObj = eventHandlers(store) +export const allHandlers = () => { + const handlersObj = eventHandlers() const handlers = Object.keys(handlersObj).map(name => ({ name, diff --git a/packages/builder/src/components/database/ModelDataTable/modals/CreateEditModel/FieldView.svelte b/packages/builder/src/components/database/ModelDataTable/modals/CreateEditModel/FieldView.svelte index 46f8bd9189..2c3443ae56 100644 --- a/packages/builder/src/components/database/ModelDataTable/modals/CreateEditModel/FieldView.svelte +++ b/packages/builder/src/components/database/ModelDataTable/modals/CreateEditModel/FieldView.svelte @@ -64,7 +64,6 @@ {:else if type === 'datetime'} - diff --git a/packages/builder/src/components/userInterface/AppPreview/iframeTemplate.js b/packages/builder/src/components/userInterface/AppPreview/iframeTemplate.js index da17bead3f..d3a94b6cf5 100644 --- a/packages/builder/src/components/userInterface/AppPreview/iframeTemplate.js +++ b/packages/builder/src/components/userInterface/AppPreview/iframeTemplate.js @@ -4,7 +4,6 @@ export default ({ selectedComponentType, selectedComponentId, frontendDefinition, - currentPageFunctions, }) => ` ${stylesheetLinks} diff --git a/packages/builder/src/components/userInterface/EventsEditor/StateBindingCascader.svelte b/packages/builder/src/components/userInterface/EventsEditor/StateBindingCascader.svelte index 2f72d98672..130b0f8269 100644 --- a/packages/builder/src/components/userInterface/EventsEditor/StateBindingCascader.svelte +++ b/packages/builder/src/components/userInterface/EventsEditor/StateBindingCascader.svelte @@ -6,8 +6,7 @@ import { find, map, keys, reduce, keyBy } from "lodash/fp" import { pipe } from "components/common/core" import { - EVENT_TYPE_MEMBER_NAME, - allHandlers, + EVENT_TYPE_MEMBER_NAME } from "components/common/eventHandlers" import { store, workflowStore } from "builderStore" import { ArrowDownIcon } from "components/common/Icons/" @@ -26,7 +25,7 @@ class="budibase__input" on:change={onChange} bind:value={parameter.value}> - {#each $workflowStore.workflows as workflow} + {#each $workflowStore.workflows.filter(wf => wf.live) as workflow} {/each} diff --git a/packages/builder/src/components/workflow/SetupPanel/ParamInputs/ModelSelector.svelte b/packages/builder/src/components/workflow/SetupPanel/ParamInputs/ModelSelector.svelte index 5f12f74919..1c39e19505 100644 --- a/packages/builder/src/components/workflow/SetupPanel/ParamInputs/ModelSelector.svelte +++ b/packages/builder/src/components/workflow/SetupPanel/ParamInputs/ModelSelector.svelte @@ -5,7 +5,6 @@
-
+ {#if selectedTab === 'TEST'} +
+ {#if testResult} + + {/if} + +
+ {/if} + {#if selectedTab === 'SETUP'} + {#if workflowBlock} + + + {:else if $workflowStore.currentWorkflow} +
+ +
+ +
+ +
+
+
+ + +
+ +
-
- - Some User Access Stuff Here -
-
- + + {/if} {/if} @@ -78,21 +129,30 @@ font-weight: bold; display: flex; align-items: center; - justify-content: space-between; margin-bottom: 20px; } - header > span { + .selected { color: var(--font); } + .config-item { + padding: 20px; + background: var(--light-grey); + } + + header > span { + color: var(--dark-grey); + margin-right: 20px; + } + label { font-weight: 500; font-size: 14px; color: var(--font); } - .delete-workflow-button { + .workflow-button { font-family: Roboto; width: 100%; border: solid 1px #f2f2f2; @@ -102,4 +162,24 @@ font-size: 12px; font-weight: 500; } + + .test-result { + border: none; + width: 100%; + border-radius: 2px; + height: 32px; + font-size: 12px; + font-weight: 500; + color: var(--white); + text-align: center; + margin-bottom: 10px; + } + + .passed { + background: #84c991; + } + + .failed { + background: var(--coral); + } diff --git a/packages/builder/src/components/workflow/SetupPanel/WorkflowBlockSetup.svelte b/packages/builder/src/components/workflow/SetupPanel/WorkflowBlockSetup.svelte index 7bb16daa52..d629630099 100644 --- a/packages/builder/src/components/workflow/SetupPanel/WorkflowBlockSetup.svelte +++ b/packages/builder/src/components/workflow/SetupPanel/WorkflowBlockSetup.svelte @@ -76,5 +76,7 @@ textarea { min-height: 150px; + font-family: inherit; + padding: 5px; } diff --git a/packages/builder/src/components/workflow/WorkflowPanel/WorkflowList/WorkflowList.svelte b/packages/builder/src/components/workflow/WorkflowPanel/WorkflowList/WorkflowList.svelte index 9b03ee2f6d..ff13782114 100644 --- a/packages/builder/src/components/workflow/WorkflowPanel/WorkflowList/WorkflowList.svelte +++ b/packages/builder/src/components/workflow/WorkflowPanel/WorkflowList/WorkflowList.svelte @@ -28,7 +28,6 @@ async function saveWorkflow() { const workflow = $workflowStore.currentWorkflow.workflow - // TODO: Clean up args await workflowStore.actions.save({ instanceId: $backendUiStore.selectedDatabase._id, workflow, diff --git a/packages/builder/src/components/workflow/WorkflowPanel/blockDefinitions.js b/packages/builder/src/components/workflow/WorkflowPanel/blockDefinitions.js index 4e36353532..96da6a3910 100644 --- a/packages/builder/src/components/workflow/WorkflowPanel/blockDefinitions.js +++ b/packages/builder/src/components/workflow/WorkflowPanel/blockDefinitions.js @@ -22,17 +22,19 @@ const ACTION = { }, SAVE_RECORD: { name: "Save Record", + tagline: "Save a {{model.name}} record", icon: "ri-save-3-fill", description: "Save a record to your database.", environment: "SERVER", params: { - model: "string", + model: "model", }, }, DELETE_RECORD: { description: "Delete a record from your database.", icon: "ri-delete-bin-line", name: "Delete Record", + tagline: "Delete a {{model.name}} record", environment: "SERVER", params: { record: "string", diff --git a/packages/client/src/api/workflow/actions.js b/packages/client/src/api/workflow/actions.js index 795d34fad3..f7d4755fbf 100644 --- a/packages/client/src/api/workflow/actions.js +++ b/packages/client/src/api/workflow/actions.js @@ -1,6 +1,4 @@ -import { get } from "svelte/store" import { setState } from "../../state/setState" -import { appStore } from "../../state/store" const delay = ms => new Promise(resolve => setTimeout(resolve, ms)) @@ -12,11 +10,11 @@ export default { [id]: args, } }, - NAVIGATE: ({ context, args, id }) => { + NAVIGATE: () => { // TODO client navigation }, - DELAY: async ({ context, args }) => await delay(args.time), - FILTER: ({ context, args }) => { + DELAY: async ({ args }) => await delay(args.time), + FILTER: ({ args }) => { const { field, condition, value } = args switch (condition) { case "equals": diff --git a/packages/client/src/api/workflow/index.js b/packages/client/src/api/workflow/index.js index 94cd6fb6f8..6d6d12a97e 100644 --- a/packages/client/src/api/workflow/index.js +++ b/packages/client/src/api/workflow/index.js @@ -1,7 +1,7 @@ import { get } from "svelte/store" import mustache from "mustache" import { appStore } from "../../state/store" -import Orchestrator from "./orchestrator"; +import Orchestrator from "./orchestrator" import clientActions from "./actions" // Execute a workflow from a running budibase app @@ -28,8 +28,6 @@ export const clientStrategy = ({ api, instanceId }) => ({ }, run: async function(workflow) { for (let block of workflow.steps) { - console.log("Executing workflow block", block) - // This code gets run in the browser if (block.environment === "CLIENT") { const action = clientActions[block.actionId] @@ -60,13 +58,11 @@ export const clientStrategy = ({ api, instanceId }) => ({ }, }) -export const triggerWorkflow = api => async ({ workflow }) => { - const instanceId = "inst_ad75c7f_4f3e7d5d80a74b17a5187a18e2aba85e"; - +export const triggerWorkflow = api => async ({ workflow, instanceId }) => { const workflowOrchestrator = new Orchestrator(api, instanceId) workflowOrchestrator.strategy = clientStrategy - const EXECUTE_WORKFLOW_URL = `/api/${instanceId}/workflows/${workflow}` + 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/createApp.js b/packages/client/src/createApp.js index d3fb51b124..a80c1009c7 100644 --- a/packages/client/src/createApp.js +++ b/packages/client/src/createApp.js @@ -1,4 +1,3 @@ -import { writable } from "svelte/store" import { attachChildren } from "./render/attachChildren" import { createTreeNode } from "./render/prepareRenderComponent" import { screenRouter } from "./render/screenRouter" @@ -7,7 +6,6 @@ import { createStateManager } from "./state/stateManager" export const createApp = ({ componentLibraries, frontendDefinition, - user, window, }) => { let routeTo diff --git a/packages/client/src/render/screenRouter.js b/packages/client/src/render/screenRouter.js index 1325bbd20a..262ed65f66 100644 --- a/packages/client/src/render/screenRouter.js +++ b/packages/client/src/render/screenRouter.js @@ -1,8 +1,6 @@ import regexparam from "regexparam" import { routerStore } from "../state/store" -import { initRouteStore } from "../state/store" -// TODO: refactor export const screenRouter = ({ screens, onScreenSelected, appRootPath }) => { const makeRootedPath = url => { if (appRootPath) { diff --git a/packages/client/src/state/eventHandlers.js b/packages/client/src/state/eventHandlers.js index 88418ba1a3..b013956dd4 100644 --- a/packages/client/src/state/eventHandlers.js +++ b/packages/client/src/state/eventHandlers.js @@ -6,17 +6,12 @@ import { createApi } from "../api" export const EVENT_TYPE_MEMBER_NAME = "##eventHandlerType" -export const eventHandlers = (store, rootPath, routeTo) => { +export const eventHandlers = (rootPath, routeTo) => { const handler = (parameters, execute) => ({ execute, parameters, }) - let currentState - store.subscribe(state => { - currentState = state - }) - const api = createApi({ rootPath, setState, diff --git a/packages/client/src/state/parseBinding.js b/packages/client/src/state/parseBinding.js deleted file mode 100644 index 4ecf9887ef..0000000000 --- a/packages/client/src/state/parseBinding.js +++ /dev/null @@ -1,67 +0,0 @@ -// export const BB_STATE_BINDINGPATH = "##bbstate" -// export const BB_STATE_BINDINGSOURCE = "##bbsource" -// export const BB_STATE_FALLBACK = "##bbstatefallback" - -// export const isBound = prop => !!parseBinding(prop) - -// /** -// * -// * @param {object|string|number} prop - component property to parse for a dynamic state binding -// * @returns {object|boolean} -// */ -// export const parseBinding = prop => { -// if (!prop) return false - -// if (isBindingExpression(prop)) { -// return parseBindingExpression(prop) -// } - -// if (isAlreadyBinding(prop)) { -// return { -// path: prop.path, -// source: prop.source || "store", -// fallback: prop.fallback, -// } -// } - -// if (hasBindingObject(prop)) { -// return { -// path: prop[BB_STATE_BINDINGPATH], -// fallback: prop[BB_STATE_FALLBACK] || "", -// source: prop[BB_STATE_BINDINGSOURCE] || "store", -// } -// } -// } - -// export const isStoreBinding = binding => binding && binding.source === "store" -// export const isContextBinding = binding => -// binding && binding.source === "context" -// // export const isEventBinding = binding => binding && binding.source === "event" - -// const hasBindingObject = prop => -// typeof prop === "object" && prop[BB_STATE_BINDINGPATH] !== undefined - -// const isAlreadyBinding = prop => typeof prop === "object" && prop.path - -// const isBindingExpression = prop => -// typeof prop === "string" && -// (prop.startsWith("state.") || -// prop.startsWith("context.") || -// prop.startsWith("event.") || -// prop.startsWith("route.")) - -// const parseBindingExpression = prop => { -// let [source, ...rest] = prop.split(".") -// let path = rest.join(".") - -// if (source === "route") { -// source = "state" -// path = `##routeParams.${path}` -// } - -// return { -// fallback: "", // TODO: provide fallback support -// source, -// path, -// } -// } diff --git a/packages/client/src/state/stateManager.js b/packages/client/src/state/stateManager.js index b4597be5dd..8e777ca4b9 100644 --- a/packages/client/src/state/stateManager.js +++ b/packages/client/src/state/stateManager.js @@ -21,27 +21,16 @@ const isMetaProp = propName => propName === "_styles" export const createStateManager = ({ - // store, appRootPath, frontendDefinition, componentLibraries, onScreenSlotRendered, routeTo, }) => { - let handlerTypes = eventHandlers(appStore, appRootPath, routeTo) + let handlerTypes = eventHandlers(appRootPath, routeTo) let currentState - // any nodes that have props that are bound to the store - // let nodesBoundByProps = [] - - // any node whose children depend on code, that uses the store - // let nodesWithCodeBoundChildren = [] - const getCurrentState = () => currentState - // const registerBindings = _registerBindings( - // nodesBoundByProps, - // nodesWithCodeBoundChildren - // ) const bb = bbFactory({ store: appStore, @@ -53,131 +42,26 @@ export const createStateManager = ({ const setup = _setup({ handlerTypes, getCurrentState, bb, store: appStore }) - // TODO: remove - const unsubscribe = appStore.subscribe(state => { - console.log("store updated", state) - return state - }) - - // const unsubscribe = store.subscribe( - // onStoreStateUpdated({ - // setCurrentState: state => (currentState = state), - // getCurrentState, - // // nodesWithCodeBoundChildren, - // // nodesBoundByProps, - // componentLibraries, - // onScreenSlotRendered, - // setupState: setup, - // }) - // ) - return { setup, - destroy: () => unsubscribe(), + destroy: () => {}, getCurrentState, store: appStore, } } -const onStoreStateUpdated = ({ - setCurrentState, - getCurrentState, - componentLibraries, - onScreenSlotRendered, - setupState, -}) => state => { - // fire the state update event to re-render anything bound to this - // setCurrentState(state) - // setCurrentState(state) - // attachChildren({ - // componentLibraries, - // treeNode: createTreeNode(), - // onScreenSlotRendered, - // setupState, - // getCurrentState, - // })(document.querySelector("#app"), { hydrate: true, force: true }) - // // the original array gets changed by components' destroy() - // // so we make a clone and check if they are still in the original - // const nodesWithBoundChildren_clone = [...nodesWithCodeBoundChildren] - // for (let node of nodesWithBoundChildren_clone) { - // if (!nodesWithCodeBoundChildren.includes(node)) continue - // attachChildren({ - // componentLibraries, - // treeNode: node, - // onScreenSlotRendered, - // setupState, - // getCurrentState, - // })(node.rootElement, { hydrate: true, force: true }) - // } -} - -// const _registerBindings = (nodesBoundByProps, nodesWithCodeBoundChildren) => ( -// node, -// bindings -// ) => { -// if (bindings.length > 0) { -// node.bindings = bindings -// nodesBoundByProps.push(node) -// const onDestroy = () => { -// nodesBoundByProps = nodesBoundByProps.filter(n => n === node) -// node.onDestroy = node.onDestroy.filter(d => d === onDestroy) -// } -// node.onDestroy.push(onDestroy) -// } -// if ( -// node.props._children && -// node.props._children.filter(c => c._codeMeta && c._codeMeta.dependsOnStore) -// .length > 0 -// ) { -// nodesWithCodeBoundChildren.push(node) -// const onDestroy = () => { -// nodesWithCodeBoundChildren = nodesWithCodeBoundChildren.filter( -// n => n === node -// ) -// node.onDestroy = node.onDestroy.filter(d => d === onDestroy) -// } -// node.onDestroy.push(onDestroy) -// } -// } - -// const setNodeState = (storeState, node) => { -// if (!node.component) return -// const newProps = { ...node.bindings.initialProps } - -// for (let binding of node.bindings) { -// const val = getState(storeState, binding.path, binding.fallback) - -// if (val === undefined && newProps[binding.propName] !== undefined) { -// delete newProps[binding.propName] -// } - -// if (val !== undefined) { -// newProps[binding.propName] = val -// } -// } - -// node.component.$set(newProps) -// } - const _setup = ({ handlerTypes, getCurrentState, bb, store }) => node => { const props = node.props const context = node.context || {} const initialProps = { ...props } - // const storeBoundProps = [] const currentStoreState = get(appStore) - console.log("node", node) - - // console.log("node", node); - // console.log("nodeComponent", node.component); - for (let propName in props) { if (isMetaProp(propName)) continue const propValue = props[propName] - // const binding = parseBinding(propValue) - // TODO: better binding stuff + // A little bit of a hack - won't bind if the string doesn't start with {{ const isBound = typeof propValue === "string" && propValue.startsWith("{{") if (isBound) { @@ -191,27 +75,6 @@ const _setup = ({ handlerTypes, getCurrentState, bb, store }) => node => { } } - // if (isBound) binding.propName = propName - - // if (isBound && binding.source === "state") { - // storeBoundProps.push(binding) - - // initialProps[propName] = !currentStoreState - // ? binding.fallback - // : getState( - // currentStoreState, - // binding.path, - // binding.fallback, - // binding.source - // ) - // } - - // if (isBound && binding.source === "context") { - // initialProps[propName] = !context - // ? propValue - // : getState(context, binding.path, binding.fallback, binding.source) - // } - if (isEventType(propValue)) { const handlersInfos = [] for (let event of propValue) { @@ -228,21 +91,6 @@ const _setup = ({ handlerTypes, getCurrentState, bb, store }) => node => { state: getCurrentState(), context, }) - // const paramBinding = parseBinding(paramValue) - // if (!paramBinding) { - // resolvedParams[paramName] = () => paramValue - // continue - // } - - // let paramValueSource - - // if (paramBinding.source === "context") paramValueSource = context - // if (paramBinding.source === "state") - // paramValueSource = getCurrentState() - - // // The new dynamic event parameter bound to the relevant source - // resolvedParams[paramName] = () => - // getState(paramValueSource, paramBinding.path, paramBinding.fallback) } handlerInfo.parameters = resolvedParams @@ -262,8 +110,6 @@ const _setup = ({ handlerTypes, getCurrentState, bb, store }) => node => { } } - // registerBindings(node, storeBoundProps) - const setup = _setup({ handlerTypes, getCurrentState, bb, store }) initialProps._bb = bb(node, setup) diff --git a/packages/client/tests/workflowOrchestrator.spec.js b/packages/client/tests/workflowOrchestrator.spec.js deleted file mode 100644 index 4858e9f51b..0000000000 --- a/packages/client/tests/workflowOrchestrator.spec.js +++ /dev/null @@ -1,43 +0,0 @@ -const TEST_WORKFLOW = { - "_id": "8ebe79daf1c744c7ab204c0b964e309e", - "_rev": "37-94ae573300721c98267cc1d18822c94d", - "name": "Workflow", - "type": "workflow", - "definition": { - "next": { - "type": "CLIENT", - "actionId": "SET_STATE", - "args": { - "path": "myPath", - "value": "foo" - }, - "next": { - "type": "SERVER", - "actionId": "SAVE_RECORD", - "args": { - "record": { - "modelId": "f452a2b9c3a94251b9ea7be1e20e3b19", - "name": "workflowRecord" - }, - "next": { - "type": "CLIENT", - "actionId": "SET_STATE", - "args": { - "path": "myPath", - "value": "$context.SAVE_RECORD.record.name" - }, - } - } - } - } - } -}; - -describe("Workflow Orchestrator", () => { - it("executes a workflow", () => { - }); - - it("", () => { - - }); -}); \ No newline at end of file diff --git a/packages/server/src/api/controllers/view.js b/packages/server/src/api/controllers/view.js index 8456837c6a..2f15d41570 100644 --- a/packages/server/src/api/controllers/view.js +++ b/packages/server/src/api/controllers/view.js @@ -11,7 +11,8 @@ const controller = { if ( !name.startsWith("all") && name !== "by_type" && - name !== "by_username" + name !== "by_username" && + name !== "by_workflow_trigger" ) { response.push({ name, diff --git a/packages/server/src/api/controllers/workflow/index.js b/packages/server/src/api/controllers/workflow/index.js index 55173c28cb..4c5394ab2f 100644 --- a/packages/server/src/api/controllers/workflow/index.js +++ b/packages/server/src/api/controllers/workflow/index.js @@ -1,5 +1,5 @@ -const CouchDB = require("../../db") -const newid = require("../../db/newid") +const CouchDB = require("../../../db") +const newid = require("../../../db/newid") exports.create = async function(ctx) { const db = new CouchDB(ctx.params.instanceId) @@ -49,7 +49,7 @@ exports.fetch = async function(ctx) { } exports.find = async function(ctx) { - const db = new CouchDB(ctx.params.instanceId) + const db = new CouchDB(ctx.user.instanceId) ctx.body = await db.get(ctx.params.id) } @@ -61,7 +61,6 @@ exports.executeAction = async function(ctx) { exports.fetchActionScript = async function(ctx) { const workflowAction = require(`./actions/${ctx.action}`) - console.log(workflowAction) ctx.body = workflowAction } diff --git a/packages/server/src/api/routes/workflow.js b/packages/server/src/api/routes/workflow.js index b4d8920261..2420e4cb52 100644 --- a/packages/server/src/api/routes/workflow.js +++ b/packages/server/src/api/routes/workflow.js @@ -1,13 +1,13 @@ const Router = require("@koa/router") const controller = require("../controllers/workflow") const authorized = require("../../middleware/authorized") -const { BUILDER, EXECUTE_WORKFLOW } = require("../../utilities/accessLevels") +const { BUILDER } = require("../../utilities/accessLevels") const router = Router() router .get("/api/:instanceId/workflows", authorized(BUILDER), controller.fetch) - .get("/api/:instanceId/workflows/:id", authorized(BUILDER), controller.find) + .get("/api/workflows/:id", authorized(BUILDER), controller.find) .get( "/api/:instanceId/workflows/:id/:action", authorized(BUILDER), diff --git a/packages/server/src/events/index.js b/packages/server/src/events/index.js index 93b08bd1d8..019b866f9b 100644 --- a/packages/server/src/events/index.js +++ b/packages/server/src/events/index.js @@ -1,6 +1,6 @@ const EventEmitter = require("events").EventEmitter const CouchDB = require("../db") -const { Orchestrator, serverStrategy } = require("./workflow"); +const { Orchestrator, serverStrategy } = require("./workflow") const emitter = new EventEmitter() @@ -8,7 +8,7 @@ async function executeRelevantWorkflows(event, eventType) { const db = new CouchDB(event.instanceId) const workflowsToTrigger = await db.query("database/by_workflow_trigger", { key: [eventType], - include_docs: true + include_docs: true, }) const workflows = workflowsToTrigger.rows.map(wf => wf.doc) @@ -22,12 +22,12 @@ async function executeRelevantWorkflows(event, eventType) { } } -emitter.on("record:save", async function(event) { - await executeRelevantWorkflows(event, "record:save"); +emitter.on("action", async function(event) { + await executeRelevantWorkflows(event, "record:save") }) emitter.on("record:delete", async function(event) { - await executeRelevantWorkflows(event, "record:delete"); + await executeRelevantWorkflows(event, "record:delete") }) module.exports = emitter diff --git a/packages/server/src/events/workflow.js b/packages/server/src/events/workflow.js index f2796d91e2..6368274dff 100644 --- a/packages/server/src/events/workflow.js +++ b/packages/server/src/events/workflow.js @@ -37,7 +37,6 @@ exports.serverStrategy = () => ({ }, run: async function(workflow) { for (let block of workflow.steps) { - console.log("Executing workflow block", block) if (block.type === "CLIENT") continue const action = require(`../api/controllers/workflow/actions/${block.actionId}`) @@ -48,5 +47,5 @@ exports.serverStrategy = () => ({ [block.id]: response, } } - } -}); + }, +})