From 22ef6eb4d350f326b3a3c870590bdfcef7898ac7 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Thu, 17 Sep 2020 16:16:05 +0100 Subject: [PATCH] Some fixes after playing around with the new Builder UI. --- packages/server/src/api/controllers/record.js | 11 ++++++++--- packages/server/src/api/routes/workflow.js | 4 ++-- packages/server/src/workflows/steps/filter.js | 8 ++++---- packages/server/src/workflows/thread.js | 7 +++++++ 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/packages/server/src/api/controllers/record.js b/packages/server/src/api/controllers/record.js index 2a8ec79c05..c959c75043 100644 --- a/packages/server/src/api/controllers/record.js +++ b/packages/server/src/api/controllers/record.js @@ -3,11 +3,16 @@ const validateJs = require("validate.js") const newid = require("../../db/newid") function emitEvent(eventType, ctx, record) { + // add syntactic sugar for mustache later + if (record._id) { + record.id = record._id + } + if (record._rev) { + record.revision = record._rev + } ctx.eventEmitter && ctx.eventEmitter.emit(eventType, { - args: { - record, - }, + record, instanceId: ctx.user.instanceId, }) } diff --git a/packages/server/src/api/routes/workflow.js b/packages/server/src/api/routes/workflow.js index 1101b3ab61..24176645be 100644 --- a/packages/server/src/api/routes/workflow.js +++ b/packages/server/src/api/routes/workflow.js @@ -27,8 +27,8 @@ function generateValidator(existing = false) { // prettier-ignore return joiValidator.body(Joi.object({ live: Joi.bool(), - id: existing ? Joi.string().required() : Joi.string(), - rev: existing ? Joi.string().required() : Joi.string(), + _id: existing ? Joi.string().required() : Joi.string(), + _rev: existing ? Joi.string().required() : Joi.string(), name: Joi.string().required(), type: Joi.string().valid("workflow").required(), definition: Joi.object({ diff --git a/packages/server/src/workflows/steps/filter.js b/packages/server/src/workflows/steps/filter.js index 8fb1603b99..bed79553b5 100644 --- a/packages/server/src/workflows/steps/filter.js +++ b/packages/server/src/workflows/steps/filter.js @@ -25,7 +25,7 @@ module.exports.definition = { schema: { inputs: { properties: { - filter: { + field: { type: "string", title: "Reference Value", }, @@ -40,7 +40,7 @@ module.exports.definition = { title: "Comparison Value", }, }, - required: ["filter", "condition", "value"], + required: ["field", "condition", "value"], }, outputs: { properties: { @@ -59,10 +59,10 @@ module.exports.run = async function filter({ inputs }) { let success if (typeof field !== "object" && typeof value !== "object") { switch (condition) { - case LogicConditions.EQUALS: + case LogicConditions.EQUAL: success = field === value break - case LogicConditions.NOT_EQUALS: + case LogicConditions.NOT_EQUAL: success = field !== value break case LogicConditions.GREATER_THAN: diff --git a/packages/server/src/workflows/thread.js b/packages/server/src/workflows/thread.js index 0c897761a6..7fa0edc7db 100644 --- a/packages/server/src/workflows/thread.js +++ b/packages/server/src/workflows/thread.js @@ -2,6 +2,8 @@ const mustache = require("mustache") const actions = require("./actions") const logic = require("./logic") +const FILTER_STEP_ID = logic.BUILTIN_DEFINITIONS.FILTER.stepId + function cleanMustache(string) { let charToReplace = { "[": ".", @@ -47,6 +49,8 @@ function recurseMustache(inputs, context) { class Orchestrator { constructor(workflow, triggerOutput) { this._instanceId = triggerOutput.instanceId + // remove from context + delete triggerOutput.instanceId // step zero is never used as the mustache is zero indexed for customer facing this._context = { steps: [{}], trigger: triggerOutput } this._workflow = workflow @@ -75,6 +79,9 @@ class Orchestrator { inputs: step.inputs, instanceId: this._instanceId, }) + if (step.stepId === FILTER_STEP_ID && !outputs.success) { + break + } this._context.steps.push(outputs) } }