wait template
This commit is contained in:
1 parent
240f8faef7
commit
e3a816f2c8
4 files changed
+65
-32
No files matched your search
@@ -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 <InputWrapper className={className} label={label} labelSize={value !== undefined ? 'small' : 'normal'}>
|
||||
<input
|
||||
className={classes.input}
|
||||
type="number"
|
||||
value={value ?? ""}
|
||||
onChange={e => {
|
||||
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 && <button className={classes.deleteIcon} onClick={() => onChange(undefined)}>X</button>}
|
||||
</InputWrapper>
|
||||
const disabled = (value === undefined) || (value === null);
|
||||
return <TextField
|
||||
variant="filled"
|
||||
label={label}
|
||||
value={value}
|
||||
defaultValue={value}
|
||||
onChange={e => onChange(Number(e.target.value ?? 0))}
|
||||
disabled={disabled}
|
||||
className={className}
|
||||
InputProps={{
|
||||
endAdornment: <InputAdornment position="end">
|
||||
<IconButton onClick={() => onChange(disabled ? 0 : undefined)}>
|
||||
{disabled ? <Edit /> : <Close />}
|
||||
</IconButton>
|
||||
</InputAdornment>,
|
||||
inputProps: {
|
||||
min, max, type: 'number'
|
||||
}
|
||||
}}
|
||||
/>
|
||||
}
|
||||
@@ -30,6 +30,30 @@ export const ActionWaitState: OptionManager<ThisAction> = {
|
||||
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<ThisAction> = {
|
||||
{current !== 'delay' ? <div className="wait-options">
|
||||
<InputNumber
|
||||
label="Timeout"
|
||||
value={(state as any).timeout ? Number((state as any).timeout) : 0}
|
||||
onChange={(timeout = 0) => update({ timeout: String(timeout) })}
|
||||
value={(state as any).timeout ? Number((state as any).timeout) : undefined}
|
||||
onChange={timeout => update({ timeout: timeout === undefined ? undefined : String(timeout) })}
|
||||
/>
|
||||
<InputBoolean
|
||||
label="Continue on Timeout"
|
||||
|
||||
@@ -15,23 +15,32 @@ export type OptionManager<T> = {
|
||||
}>
|
||||
})
|
||||
|
||||
export const cleanUpUndefined = (data: Record<string, any>): 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 = <T extends AutomationCondition>(
|
||||
setState: (s: T) => void
|
||||
) => (
|
||||
state: T,
|
||||
data: Partial<T>,
|
||||
) => setState({
|
||||
) => setState(cleanUpUndefined({
|
||||
...state,
|
||||
...data,
|
||||
})
|
||||
}))
|
||||
|
||||
export const updateActionData = <T extends AutomationAction>(
|
||||
state: T,
|
||||
setState: (s: T) => void
|
||||
) => (
|
||||
data: Partial<T>,
|
||||
) => setState({
|
||||
) => setState(cleanUpUndefined({
|
||||
...state,
|
||||
...data,
|
||||
})
|
||||
}))
|
||||
@@ -104,7 +104,7 @@ export const getNodeSubType = <T extends AutomationNodeTypes>(
|
||||
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
|
||||
|
||||
Reference in new issue
Block a user