From e3a816f2c868354473dfdc20cb902de732368d01 Mon Sep 17 00:00:00 2001 From: Ari Date: Sun, 12 Jun 2022 21:39:45 -0400 Subject: [PATCH] wait template --- webapp/src/components/Inputs/InputNumber.tsx | 50 +++++++++---------- .../NodeEditor/OptionManager/ActionWait.tsx | 28 ++++++++++- .../NodeEditor/OptionManager/OptionManager.ts | 17 +++++-- webapp/src/utils/automations.ts | 2 +- 4 files changed, 65 insertions(+), 32 deletions(-) diff --git a/webapp/src/components/Inputs/InputNumber.tsx b/webapp/src/components/Inputs/InputNumber.tsx index 8dec170..1b34166 100644 --- a/webapp/src/components/Inputs/InputNumber.tsx +++ b/webapp/src/components/Inputs/InputNumber.tsx @@ -1,5 +1,8 @@ -import InputWrapper from "./InputWrapper"; -import { useInputNumberStyles } from "./styles"; +import Close from "@mui/icons-material/Close"; +import TextField from "@mui/material/TextField"; +import IconButton from "@mui/material/IconButton"; +import InputAdornment from "@mui/material/InputAdornment"; +import Edit from "@mui/icons-material/Edit"; export interface Props { label: string; @@ -17,27 +20,24 @@ export default function InputNumber({ className = "", min, max, step, }: Props) { - const { classes } = useInputNumberStyles({}); - return - { - e.preventDefault(); - let v = Number(e.target.value); - if (max) { - v = Math.min(v, max) - } - if (min) { - v = Math.max(v, min) - } - onChange(v) - }} - step={step} - min={min} - max={max} - /> - {value && } - + const disabled = (value === undefined) || (value === null); + return onChange(Number(e.target.value ?? 0))} + disabled={disabled} + className={className} + InputProps={{ + endAdornment: + onChange(disabled ? 0 : undefined)}> + {disabled ? : } + + , + inputProps: { + min, max, type: 'number' + } + }} + /> } diff --git a/webapp/src/components/NodeEditor/OptionManager/ActionWait.tsx b/webapp/src/components/NodeEditor/OptionManager/ActionWait.tsx index 045e135..37f5712 100644 --- a/webapp/src/components/NodeEditor/OptionManager/ActionWait.tsx +++ b/webapp/src/components/NodeEditor/OptionManager/ActionWait.tsx @@ -30,6 +30,30 @@ export const ActionWaitState: OptionManager = { const update = updateActionData(state, setState); const [current, _setCurrent] = useState(getCurrentOption(state)); const setCurrent = (opt: Option) => { + const base: any = { + alias: state.alias, + variables: state.variables, + } + if (opt === 'delay') { + setState({ + ...base, + delay: (state as any).delay ?? "", + }) + } else { + base.timeout = (state as any).timeout + base.continue_on_timeout = (state as any).continue_on_timeout + if (opt === 'template') { + setState({ + ...base, + wait_template: (state as any).wait_template ?? "", + }) + } else { + setState({ + ...base, + wait_for_trigger: (state as any).wait_for_trigger ?? "", + }) + } + } _setCurrent(opt) } @@ -72,8 +96,8 @@ export const ActionWaitState: OptionManager = { {current !== 'delay' ?
update({ timeout: String(timeout) })} + value={(state as any).timeout ? Number((state as any).timeout) : undefined} + onChange={timeout => update({ timeout: timeout === undefined ? undefined : String(timeout) })} /> = { }> }) +export const cleanUpUndefined = (data: Record): any => { + const clean: any = {}; + Object.keys(data).forEach(k => { + if ((data[k] !== undefined) && (data[k] !== null)) { + clean[k] = data[k] + } + }) + return clean; +} export const updateConditionData = ( setState: (s: T) => void ) => ( state: T, data: Partial, -) => setState({ +) => setState(cleanUpUndefined({ ...state, ...data, -}) +})) export const updateActionData = ( state: T, setState: (s: T) => void ) => ( data: Partial, -) => setState({ +) => setState(cleanUpUndefined({ ...state, ...data, -}) +})) diff --git a/webapp/src/utils/automations.ts b/webapp/src/utils/automations.ts index 7a24466..ee80e88 100644 --- a/webapp/src/utils/automations.ts +++ b/webapp/src/utils/automations.ts @@ -104,7 +104,7 @@ export const getNodeSubType = ( return 'service' as any } else if ('repeat' in node) { return 'repeat' as any - } else if ('wait_template' in node) { + } else if (('wait_template' in node) || ('wait_for_trigger' in node)) { return 'wait' as any } else if ('event' in node) { return 'event' as any