input booleans

This commit is contained in:
Ari Sosnovsky committed 2021-11-02 21:45:15 -04:00
1 parent 70eba32b34
commit 126f1df657
7 files changed
+166 -5

No files matched your search

@@ -0,0 +1,36 @@
import InputNumber from "../../components/InputNumber";
import InputText from "../../components/InputText";
import { RepeatScript } from "../types/script";
import { BaseState } from "./BaseState";
export default class ScriptRepeatState extends BaseState<RepeatScript> {
defaultState = () => ({
alias: "Repeat",
repeat: {
count: 1,
sequence: [],
}
})
isReady(state: RepeatScript): boolean {
return state.alias !== '' &&
state?.repeat?.sequence.length > 0
}
renderOptionList(state: RepeatScript): JSX.Element {
return <div className="state-manager-options">
<InputText
label="Description"
value={state.alias}
onChange={alias => this.setState({...state, alias})}
/>
<InputNumber
label="How many times?"
value={state?.repeat?.count}
onChange={count => this.setState({...state, repeat: {...state.repeat, count}})}
/>
<div>
{JSON.stringify(state?.repeat?.sequence)}
</div>
</div>
}
}
@@ -0,0 +1,44 @@
import InputBoolean from "../../components/InputBoolean";
import InputNumber from "../../components/InputNumber";
import InputText from "../../components/InputText";
import { WaitScript } from "../types/script";
import { BaseState } from "./BaseState";
export default class ScriptWaitState extends BaseState<WaitScript> {
defaultState = () => ({
alias: "Wait",
wait_template: "",
timeout: 0,
continue_on_timeout: false,
})
isReady(state: WaitScript): boolean {
return state.alias !== '' &&
state.wait_template !== ""
}
renderOptionList(state: WaitScript): JSX.Element {
return <div className="state-manager-options">
<InputText
label="Description"
value={state.alias}
onChange={alias => this.setState({...state, alias})}
/>
<InputText
textBoxFor="template"
label="Timeout"
value={state.wait_template}
onChange={wait_template => this.setState({...state, wait_template})}
/>
<InputNumber
label="Timeout"
value={state.timeout ?? 0}
onChange={timeout => this.setState({...state, timeout})}
/>
<InputBoolean
label="Continue on Timeout"
value={state.continue_on_timeout ?? false}
onChange={continue_on_timeout => this.setState({...state, continue_on_timeout})}
/>
</div>
}
}
@@ -1,16 +1,22 @@
import { AutomationNode, AutomationNodeType, NodeSubType } from "../types"
import { BaseState } from "./BaseState"
import { AutomationNodeType, NodeSubType } from "../types"
import ScriptRepeatState from "./ScriptRepeat"
import ScriptCallServiceState from "./ScriptService"
import ScriptWaitState from "./ScriptWait"
export const getBaseState = <T extends AutomationNodeType>(
node_type: T,
node_subtype: NodeSubType<T>
) : any => {
console.log(node_subtype)
if ( node_type === 'action') {
switch (node_subtype) {
case 'Service':
return ScriptCallServiceState
case "Repeat":
return ScriptRepeatState;
case "Wait":
return ScriptWaitState;
}
}
throw new Error(`Invalid or Not implemented node type ${node_type} -> ${node_subtype}`)
+26
View File
@@ -0,0 +1,26 @@
import InputWrapper from "./InputWrapper";
export interface Props {
label: string;
value: boolean;
onChange: (v: boolean) => void;
}
export default function InputBoolean({
label,
value=false,
onChange,
}: Props) {
return <InputWrapper label={label} style={{
flexDirection: 'row',
justifyContent: 'space-between',
marginTop: '3%',
marginBottom: '3%'
}}>
<span className="checkbox" onClick={e => {
e.preventDefault()
onChange(!value)
}}>
{value ? '✔️' : ' '}
</span>
</InputWrapper>
}
+25
View File
@@ -0,0 +1,25 @@
import { useToolTip } from "../tooltip/context";
import InputWrapper from "./InputWrapper";
export interface Props {
label: string;
value: number;
onChange: (v: number) => void;
}
export default function InputNumber({
label,
value=0,
onChange,
}: Props) {
const tooltip = useToolTip();
return <InputWrapper label={label}>
<input
type="number"
value={value}
onChange={e => {
e.preventDefault();
onChange(Number(e.target.value))
}}
/>
</InputWrapper>
}
+4 -3
View File
@@ -1,11 +1,12 @@
import { PropsWithChildren } from "react";
import { CSSProperties, PropsWithChildren } from "react";
export interface Props {
label: string;
style?: CSSProperties;
}
export default function InputWrapper({label, children}: PropsWithChildren<Props>) {
return <div className="input-wrapper">
export default function InputWrapper({label, children, style={}}: PropsWithChildren<Props>) {
return <div className="input-wrapper" style={style}>
<label>{label}</label>
{children}
</div>
+23
View File
@@ -95,3 +95,26 @@ input {
margin: 0;
cursor: text;
}
input[type="number"]::-webkit-inner-spin-button,
::-webkit-outer-spin-button {
opacity: 0;
}
span.checkbox {
height: 16px;
width: 16px;
font-size: 12px;
cursor: pointer;
border: 1px $primary-accent solid;
align-content: center;
text-align: center;
justify-content: center;
display: flex;
background-color: $primary;
color: $primary-accent;
overflow: hidden;
&:hover {
background-color: $secondary;
color: $secondary-accent;
}
}