diff --git a/packages/builder/rollup.config.js b/packages/builder/rollup.config.js index ae9a7e069e..fd7c487c3f 100644 --- a/packages/builder/rollup.config.js +++ b/packages/builder/rollup.config.js @@ -152,7 +152,7 @@ export default { { find: "builderStore", replacement: path.resolve(projectRootDir, "src/builderStore"), - } + }, ], customResolver, }), diff --git a/packages/builder/src/App.svelte b/packages/builder/src/App.svelte index 54968a52c2..4ead618ba6 100644 --- a/packages/builder/src/App.svelte +++ b/packages/builder/src/App.svelte @@ -7,8 +7,7 @@ import AppNotification, { showAppNotification, } from "components/common/AppNotification.svelte" - import { NotificationDisplay } from '@beyonk/svelte-notifications' - + import { NotificationDisplay } from "@beyonk/svelte-notifications" function showErrorBanner() { showAppNotification({ diff --git a/packages/builder/src/builderStore/store/workflow/Workflow.js b/packages/builder/src/builderStore/store/workflow/Workflow.js index 3e5a0e8b4e..c8ae55dbf3 100644 --- a/packages/builder/src/builderStore/store/workflow/Workflow.js +++ b/packages/builder/src/builderStore/store/workflow/Workflow.js @@ -13,82 +13,109 @@ export default class Workflow { } isEmpty() { - return !this.workflow.definition.next + // return this.workflow.definition.next + return this.workflow.length > 0 } addBlock(block) { - let node = this.workflow.definition - while (node.next) node = node.next - node.next = { + // Make sure to add trigger if doesn't exist + this.workflow.definition.steps.push({ id: generate(), - ...block - } + ...block, + }) } updateBlock(updatedBlock, id) { - let block = this.workflow.definition + const { steps, trigger } = this.workflow.definition - while (block.id !== id) block = block.next - if (!block) throw new Error("Block not found.") + // if the block is a trigger do X - block = updatedBlock + // if step + const stepIdx = steps.findIndex(step => step.id === id) + + // while (block.id !== id) block = block.next + if (stepIdx < 0) throw new Error("Block not found.") + + steps.splice(stepIdx, 1, updatedBlock) } deleteBlock(id) { - let previous = null - let block = this.workflow.definition + const { steps, trigger } = this.workflow.definition - // iterate through the blocks - while (block.id !== id) { - previous = block - block = block.next - } + const stepIdx = steps.findIndex(step => step.id === id) - // delete the block matching your id - if (!block.next) { - delete previous.next - } else { - previous.next = block.next - } + if (stepIdx < 0) throw new Error("Block not found.") + steps.splice(stepIdx, 1) } createUiTree() { - if (!this.workflow.definition.next) return [] - return Workflow.buildUiTree(this.workflow.definition.next) + if (!this.workflow.definition) return [] + return Workflow.buildUiTree(this.workflow.definition) } - static buildUiTree(block, tree = []) { - if (!block) return tree + static buildUiTree(definition) { + return definition.steps.map(step => { + // The client side display definition for the block + const definition = blockDefinitions[step.type][step.actionId] + if (!definition) { + throw new Error( + `No block definition exists for the chosen block. Check there's an entry in the block definitions for ${step.actionId}` + ) + } - // The client side display definition for the block - const definition = blockDefinitions[block.type][block.actionId] - if (!definition) { - throw new Error( - `No block definition exists for the chosen block. Check there's an entry in the block definitions for ${block.actionId}` - ) - } + if (!definition.params) { + throw new Error( + `Blocks should always have parameters. Ensure that the block definition is correct for ${step.actionId}` + ) + } - if (!definition.params) { - throw new Error( - `Blocks should always have parameters. Ensure that the block definition is correct for ${block.actionId}` - ) - } + const tagline = definition.tagline || "" + const args = step.args || {} - const tagline = definition.tagline || "" - const args = block.args || {} - - // all the fields the workflow block needs to render in the UI - tree.push({ - id: block.id, - type: block.type, - params: block.params, - args, - heading: block.actionId, - body: mustache.render(tagline, args), - name: definition.name + return { + id: step.id, + type: step.type, + params: step.params, + args, + heading: step.actionId, + body: mustache.render(tagline, args), + name: definition.name, + } }) - - return this.buildUiTree(block.next, tree) } + + // static buildUiTree(block, tree = []) { + // if (!block) return tree + + // // The client side display definition for the block + // const definition = blockDefinitions[block.type][block.actionId] + // if (!definition) { + // throw new Error( + // `No block definition exists for the chosen block. Check there's an entry in the block definitions for ${block.actionId}` + // ) + // } + + // if (!definition.params) { + // throw new Error( + // `Blocks should always have parameters. Ensure that the block definition is correct for ${block.actionId}` + // ) + // } + + // const tagline = definition.tagline || "" + // const args = block.args || {} + + // // all the fields the workflow block needs to render in the UI + // tree.push({ + // id: block.id, + // type: block.type, + // params: block.params, + // args, + // heading: block.actionId, + // body: mustache.render(tagline, args), + // name: definition.name + // }) + + // return this.buildUiTree(block.next, tree) + // } } diff --git a/packages/builder/src/builderStore/store/workflow/index.js b/packages/builder/src/builderStore/store/workflow/index.js index 971312c2ef..8b534aab5c 100644 --- a/packages/builder/src/builderStore/store/workflow/index.js +++ b/packages/builder/src/builderStore/store/workflow/index.js @@ -13,7 +13,8 @@ const workflowActions = store => ({ }) }, create: async ({ instanceId, name }) => { - const workflow = { name, definition: {} } + // TODO: set these defaults in the backend + const workflow = { name, definition: { trigger: {}, 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/userInterface/AppPreview/CurrentItemPreview.svelte b/packages/builder/src/components/userInterface/AppPreview/CurrentItemPreview.svelte index ad52602afc..a7288c8c91 100644 --- a/packages/builder/src/components/userInterface/AppPreview/CurrentItemPreview.svelte +++ b/packages/builder/src/components/userInterface/AppPreview/CurrentItemPreview.svelte @@ -116,7 +116,7 @@ stylesheetLinks, selectedComponentType, selectedComponentId, - frontendDefinition: JSON.stringify(frontendDefinition) + frontendDefinition: JSON.stringify(frontendDefinition), })} /> {/if} diff --git a/packages/builder/src/components/userInterface/EventsEditor/StateBindingCascader.svelte b/packages/builder/src/components/userInterface/EventsEditor/StateBindingCascader.svelte index 79cd776c61..37681aa399 100644 --- a/packages/builder/src/components/userInterface/EventsEditor/StateBindingCascader.svelte +++ b/packages/builder/src/components/userInterface/EventsEditor/StateBindingCascader.svelte @@ -17,14 +17,16 @@ export let onChange let isOpen = false -