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 Close from "@mui/icons-material/Close";
|
||||||
import { useInputNumberStyles } from "./styles";
|
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 {
|
export interface Props {
|
||||||
label: string;
|
label: string;
|
||||||
@@ -17,27 +20,24 @@ export default function InputNumber({
|
|||||||
className = "",
|
className = "",
|
||||||
min, max, step,
|
min, max, step,
|
||||||
}: Props) {
|
}: Props) {
|
||||||
const { classes } = useInputNumberStyles({});
|
const disabled = (value === undefined) || (value === null);
|
||||||
return <InputWrapper className={className} label={label} labelSize={value !== undefined ? 'small' : 'normal'}>
|
return <TextField
|
||||||
<input
|
variant="filled"
|
||||||
className={classes.input}
|
label={label}
|
||||||
type="number"
|
value={value}
|
||||||
value={value ?? ""}
|
defaultValue={value}
|
||||||
onChange={e => {
|
onChange={e => onChange(Number(e.target.value ?? 0))}
|
||||||
e.preventDefault();
|
disabled={disabled}
|
||||||
let v = Number(e.target.value);
|
className={className}
|
||||||
if (max) {
|
InputProps={{
|
||||||
v = Math.min(v, max)
|
endAdornment: <InputAdornment position="end">
|
||||||
}
|
<IconButton onClick={() => onChange(disabled ? 0 : undefined)}>
|
||||||
if (min) {
|
{disabled ? <Edit /> : <Close />}
|
||||||
v = Math.max(v, min)
|
</IconButton>
|
||||||
}
|
</InputAdornment>,
|
||||||
onChange(v)
|
inputProps: {
|
||||||
}}
|
min, max, type: 'number'
|
||||||
step={step}
|
}
|
||||||
min={min}
|
}}
|
||||||
max={max}
|
/>
|
||||||
/>
|
|
||||||
{value && <button className={classes.deleteIcon} onClick={() => onChange(undefined)}>X</button>}
|
|
||||||
</InputWrapper>
|
|
||||||
}
|
}
|
||||||
@@ -30,6 +30,30 @@ export const ActionWaitState: OptionManager<ThisAction> = {
|
|||||||
const update = updateActionData(state, setState);
|
const update = updateActionData(state, setState);
|
||||||
const [current, _setCurrent] = useState(getCurrentOption(state));
|
const [current, _setCurrent] = useState(getCurrentOption(state));
|
||||||
const setCurrent = (opt: Option) => {
|
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)
|
_setCurrent(opt)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,8 +96,8 @@ export const ActionWaitState: OptionManager<ThisAction> = {
|
|||||||
{current !== 'delay' ? <div className="wait-options">
|
{current !== 'delay' ? <div className="wait-options">
|
||||||
<InputNumber
|
<InputNumber
|
||||||
label="Timeout"
|
label="Timeout"
|
||||||
value={(state as any).timeout ? Number((state as any).timeout) : 0}
|
value={(state as any).timeout ? Number((state as any).timeout) : undefined}
|
||||||
onChange={(timeout = 0) => update({ timeout: String(timeout) })}
|
onChange={timeout => update({ timeout: timeout === undefined ? undefined : String(timeout) })}
|
||||||
/>
|
/>
|
||||||
<InputBoolean
|
<InputBoolean
|
||||||
label="Continue on Timeout"
|
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>(
|
export const updateConditionData = <T extends AutomationCondition>(
|
||||||
setState: (s: T) => void
|
setState: (s: T) => void
|
||||||
) => (
|
) => (
|
||||||
state: T,
|
state: T,
|
||||||
data: Partial<T>,
|
data: Partial<T>,
|
||||||
) => setState({
|
) => setState(cleanUpUndefined({
|
||||||
...state,
|
...state,
|
||||||
...data,
|
...data,
|
||||||
})
|
}))
|
||||||
|
|
||||||
export const updateActionData = <T extends AutomationAction>(
|
export const updateActionData = <T extends AutomationAction>(
|
||||||
state: T,
|
state: T,
|
||||||
setState: (s: T) => void
|
setState: (s: T) => void
|
||||||
) => (
|
) => (
|
||||||
data: Partial<T>,
|
data: Partial<T>,
|
||||||
) => setState({
|
) => setState(cleanUpUndefined({
|
||||||
...state,
|
...state,
|
||||||
...data,
|
...data,
|
||||||
})
|
}))
|
||||||
@@ -104,7 +104,7 @@ export const getNodeSubType = <T extends AutomationNodeTypes>(
|
|||||||
return 'service' as any
|
return 'service' as any
|
||||||
} else if ('repeat' in node) {
|
} else if ('repeat' in node) {
|
||||||
return 'repeat' as any
|
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
|
return 'wait' as any
|
||||||
} else if ('event' in node) {
|
} else if ('event' in node) {
|
||||||
return 'event' as any
|
return 'event' as any
|
||||||
|
|||||||
Reference in new issue
Block a user