Some fixes after playing around with the new Builder UI.

This commit is contained in:
mike12345567 2020-09-17 16:16:05 +01:00
parent 210080c834
commit cc5994539d
4 changed files with 21 additions and 9 deletions

View File

@ -3,11 +3,16 @@ const validateJs = require("validate.js")
const newid = require("../../db/newid") const newid = require("../../db/newid")
function emitEvent(eventType, ctx, record) { 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 &&
ctx.eventEmitter.emit(eventType, { ctx.eventEmitter.emit(eventType, {
args: { record,
record,
},
instanceId: ctx.user.instanceId, instanceId: ctx.user.instanceId,
}) })
} }

View File

@ -27,8 +27,8 @@ function generateValidator(existing = false) {
// prettier-ignore // prettier-ignore
return joiValidator.body(Joi.object({ return joiValidator.body(Joi.object({
live: Joi.bool(), live: Joi.bool(),
id: existing ? Joi.string().required() : Joi.string(), _id: existing ? Joi.string().required() : Joi.string(),
rev: existing ? Joi.string().required() : Joi.string(), _rev: existing ? Joi.string().required() : Joi.string(),
name: Joi.string().required(), name: Joi.string().required(),
type: Joi.string().valid("workflow").required(), type: Joi.string().valid("workflow").required(),
definition: Joi.object({ definition: Joi.object({

View File

@ -25,7 +25,7 @@ module.exports.definition = {
schema: { schema: {
inputs: { inputs: {
properties: { properties: {
filter: { field: {
type: "string", type: "string",
title: "Reference Value", title: "Reference Value",
}, },
@ -40,7 +40,7 @@ module.exports.definition = {
title: "Comparison Value", title: "Comparison Value",
}, },
}, },
required: ["filter", "condition", "value"], required: ["field", "condition", "value"],
}, },
outputs: { outputs: {
properties: { properties: {
@ -59,10 +59,10 @@ module.exports.run = async function filter({ inputs }) {
let success let success
if (typeof field !== "object" && typeof value !== "object") { if (typeof field !== "object" && typeof value !== "object") {
switch (condition) { switch (condition) {
case LogicConditions.EQUALS: case LogicConditions.EQUAL:
success = field === value success = field === value
break break
case LogicConditions.NOT_EQUALS: case LogicConditions.NOT_EQUAL:
success = field !== value success = field !== value
break break
case LogicConditions.GREATER_THAN: case LogicConditions.GREATER_THAN:

View File

@ -2,6 +2,8 @@ const mustache = require("mustache")
const actions = require("./actions") const actions = require("./actions")
const logic = require("./logic") const logic = require("./logic")
const FILTER_STEP_ID = logic.BUILTIN_DEFINITIONS.FILTER.stepId
function cleanMustache(string) { function cleanMustache(string) {
let charToReplace = { let charToReplace = {
"[": ".", "[": ".",
@ -47,6 +49,8 @@ function recurseMustache(inputs, context) {
class Orchestrator { class Orchestrator {
constructor(workflow, triggerOutput) { constructor(workflow, triggerOutput) {
this._instanceId = triggerOutput.instanceId this._instanceId = triggerOutput.instanceId
// remove from context
delete triggerOutput.instanceId
// step zero is never used as the mustache is zero indexed for customer facing // step zero is never used as the mustache is zero indexed for customer facing
this._context = { steps: [{}], trigger: triggerOutput } this._context = { steps: [{}], trigger: triggerOutput }
this._workflow = workflow this._workflow = workflow
@ -75,6 +79,9 @@ class Orchestrator {
inputs: step.inputs, inputs: step.inputs,
instanceId: this._instanceId, instanceId: this._instanceId,
}) })
if (step.stepId === FILTER_STEP_ID && !outputs.success) {
break
}
this._context.steps.push(outputs) this._context.steps.push(outputs)
} }
} }