Updating filter/condition action to show a stopped status rather than error, updating everything else to be aware of this.

This commit is contained in:
mike12345567 2022-06-28 17:02:24 +01:00
parent a01790b837
commit e921547c64
7 changed files with 82 additions and 53 deletions

View File

@ -19,6 +19,7 @@
} }
} }
$: isTrigger = isTrigger || block.type === "TRIGGER" $: isTrigger = isTrigger || block.type === "TRIGGER"
$: status = updateStatus(testResult, isTrigger)
async function onSelect(block) { async function onSelect(block) {
await automationStore.update(state => { await automationStore.update(state => {
@ -26,6 +27,16 @@
return state return state
}) })
} }
function updateStatus(results, isTrigger) {
if (results.outputs?.status?.toLowerCase() === "stopped") {
return { yellow: true, message: "Stopped" }
} else if (results.outputs?.success || isTrigger) {
return { positive: true, message: "Success" }
} else {
return { negative: true, message: "Error" }
}
}
</script> </script>
<div class="blockSection"> <div class="blockSection">
@ -69,13 +80,10 @@
{#if showTestStatus && testResult} {#if showTestStatus && testResult}
<div style="float: right;"> <div style="float: right;">
<StatusLight <StatusLight
positive={isTrigger || testResult.outputs?.success} positive={status?.positive}
negative={!testResult.outputs?.success} yellow={status?.yellow}
><Body size="XS" negative={status?.negative}
>{testResult.outputs?.success || isTrigger ><Body size="XS">{status?.message}</Body></StatusLight
? "Success"
: "Error"}</Body
></StatusLight
> >
</div> </div>
{/if} {/if}

View File

@ -8,7 +8,8 @@
import dayjs from "dayjs" import dayjs from "dayjs"
const ERROR = "error", const ERROR = "error",
SUCCESS = "success" SUCCESS = "success",
STOPPED = "stopped"
export let app export let app
let runHistory = null let runHistory = null
@ -37,6 +38,7 @@
const statusOptions = [ const statusOptions = [
{ value: SUCCESS, label: "Success" }, { value: SUCCESS, label: "Success" },
{ value: ERROR, label: "Error" }, { value: ERROR, label: "Error" },
{ value: STOPPED, label: "Stopped" },
] ]
const runHistorySchema = { const runHistorySchema = {

View File

@ -3,15 +3,28 @@
export let value export let value
$: isError = !value || value.toLowerCase() === "error" $: isError = !value || value.toLowerCase() === "error"
$: color = isError $: isStopped = value?.toLowerCase() === "stopped"
? "var(--spectrum-semantic-negative-color-background)" $: status = getStatus(isError, isStopped)
: "var(--green)"
function getStatus(error, stopped) {
if (error) {
return { color: "var(--red)", message: "Error", icon: "Alert" }
} else if (stopped) {
return { color: "var(--yellow)", message: "Stopped", icon: "StopCircle" }
} else {
return {
color: "var(--green)",
message: "Success",
icon: "CheckmarkCircle",
}
}
}
</script> </script>
<div class="cell"> <div class="cell">
<Icon {color} name={isError ? "Alert" : "CheckmarkCircle"} /> <Icon color={status.color} name={status.icon} />
<div class:green={!isError} class:red={isError}> <div style={`color: ${status.color};`}>
{isError ? "Error" : "Success"} {status.message}
</div> </div>
</div> </div>
@ -22,12 +35,4 @@
gap: var(--spacing-m); gap: var(--spacing-m);
align-items: center; align-items: center;
} }
.green {
color: var(--green);
}
.red {
color: var(--spectrum-semantic-negative-color-background);
}
</style> </style>

View File

@ -2,8 +2,8 @@ import { getAppId, getProdAppDB } from "@budibase/backend-core/context"
import { import {
DocumentTypes, DocumentTypes,
generateAutomationLogID, generateAutomationLogID,
SEPARATOR,
isProdAppID, isProdAppID,
SEPARATOR,
} from "../../db/utils" } from "../../db/utils"
import { Automation, MetadataErrors } from "../../definitions/common" import { Automation, MetadataErrors } from "../../definitions/common"
import { app } from "@budibase/backend-core/cache" import { app } from "@budibase/backend-core/cache"
@ -14,6 +14,7 @@ import {
AutomationResults, AutomationResults,
AutomationStatus, AutomationStatus,
} from "../../definitions/automation" } from "../../definitions/automation"
const { logAlert } = require("@budibase/backend-core/logging") const { logAlert } = require("@budibase/backend-core/logging")
function getStatus(results: AutomationResults) { function getStatus(results: AutomationResults) {
@ -27,6 +28,10 @@ function getStatus(results: AutomationResults) {
} }
if (!step.outputs?.success) { if (!step.outputs?.success) {
status = AutomationStatus.ERROR status = AutomationStatus.ERROR
break
} else if (step.outputs?.status?.toLowerCase() === "stopped") {
status = AutomationStatus.STOPPED
break
} }
} }
return status return status

View File

@ -50,16 +50,21 @@ exports.definition = {
outputs: { outputs: {
properties: { properties: {
success: { success: {
type: "boolean",
description: "Whether the action was successful",
},
result: {
type: "boolean", type: "boolean",
description: "Whether the logic block passed", description: "Whether the logic block passed",
}, },
}, },
required: ["success"], required: ["success", "result"],
}, },
}, },
} }
exports.run = async function filter({ inputs }) { exports.run = async function filter({ inputs }) {
try {
let { field, condition, value } = inputs let { field, condition, value } = inputs
// coerce types so that we can use them // coerce types so that we can use them
if (!isNaN(value) && !isNaN(field)) { if (!isNaN(value) && !isNaN(field)) {
@ -69,24 +74,27 @@ exports.run = async function filter({ inputs }) {
value = Date.parse(value) value = Date.parse(value)
field = Date.parse(field) field = Date.parse(field)
} }
let success = false let result = false
if (typeof field !== "object" && typeof value !== "object") { if (typeof field !== "object" && typeof value !== "object") {
switch (condition) { switch (condition) {
case FilterConditions.EQUAL: case FilterConditions.EQUAL:
success = field === value result = field === value
break break
case FilterConditions.NOT_EQUAL: case FilterConditions.NOT_EQUAL:
success = field !== value result = field !== value
break break
case FilterConditions.GREATER_THAN: case FilterConditions.GREATER_THAN:
success = field > value result = field > value
break break
case FilterConditions.LESS_THAN: case FilterConditions.LESS_THAN:
success = field < value result = field < value
break break
} }
} else { } else {
success = false result = false
}
return { success: true, result }
} catch (err) {
return { success: false, result: false }
} }
return { success }
} }

View File

@ -1,6 +1,7 @@
export enum AutomationStatus { export enum AutomationStatus {
SUCCESS = "success", SUCCESS = "success",
ERROR = "error", ERROR = "error",
STOPPED = "stopped",
} }
export interface AutomationResults { export interface AutomationResults {

View File

@ -14,7 +14,7 @@ const FILTER_STEP_ID = actions.ACTION_DEFINITIONS.FILTER.stepId
const LOOP_STEP_ID = actions.ACTION_DEFINITIONS.LOOP.stepId const LOOP_STEP_ID = actions.ACTION_DEFINITIONS.LOOP.stepId
const CRON_STEP_ID = triggerDefs.CRON.stepId const CRON_STEP_ID = triggerDefs.CRON.stepId
const STOPPED_STATUS = { success: false, status: "STOPPED" } const STOPPED_STATUS = { success: true, status: "STOPPED" }
const { cloneDeep } = require("lodash/fp") const { cloneDeep } = require("lodash/fp")
const env = require("../environment") const env = require("../environment")
@ -276,7 +276,7 @@ class Orchestrator {
this._context.steps[stepCount] = outputs this._context.steps[stepCount] = outputs
// if filter causes us to stop execution don't break the loop, set a var // if filter causes us to stop execution don't break the loop, set a var
// so that we can finish iterating through the steps and record that it stopped // so that we can finish iterating through the steps and record that it stopped
if (step.stepId === FILTER_STEP_ID && !outputs.success) { if (step.stepId === FILTER_STEP_ID && !outputs.result) {
stopped = true stopped = true
this.updateExecutionOutput(step.id, step.stepId, step.inputs, { this.updateExecutionOutput(step.id, step.stepId, step.inputs, {
...outputs, ...outputs,