enabled flag

This commit is contained in:
ari committed 2022-06-12 21:55:32 -04:00
1 parent e3a816f2c8
commit b30f4ed59a
7 files changed
+45 -5

No files matched your search

@@ -7,14 +7,16 @@ export interface Props {
value: boolean; value: boolean;
onChange: (v: boolean) => void; onChange: (v: boolean) => void;
disabled?: boolean; disabled?: boolean;
className?: string;
} }
export default function InputBoolean({ export default function InputBoolean({
label, label,
value = false, value = false,
onChange, onChange,
disabled = false, disabled = false,
className,
}: Props) { }: Props) {
return <FormGroup> return <FormGroup className={className}>
<FormControlLabel disabled={disabled} control={<Checkbox checked={value} onChange={() => onChange(!value)} />} label={label} /> <FormControlLabel disabled={disabled} control={<Checkbox checked={value} onChange={() => onChange(!value)} />} label={label} />
</FormGroup> </FormGroup>
} }
@@ -9,6 +9,7 @@ import { getDescriptionFromAutomationNode } from 'utils/formatting';
import { useHA } from 'haService'; import { useHA } from 'haService';
import { Generic } from './Generic'; import { Generic } from './Generic';
import { getNodeTypeAndValidate } from '../../../utils/automations'; import { getNodeTypeAndValidate } from '../../../utils/automations';
import InputBoolean from 'components/Inputs/InputBoolean';
type UseState = <S>(s: S) => [S, Dispatch<SetStateAction<S>>] type UseState = <S>(s: S) => [S, Dispatch<SetStateAction<S>>]
@@ -70,8 +71,13 @@ export const useEditorNodeState = (originalNode: AutomationNode, isErrored: bool
get data() { get data() {
return currentNode return currentNode
}, },
setEnabled(enabled: boolean) {
setState({
...currentNode,
enabled,
})
},
renderOptionList() { renderOptionList() {
console.log('rendering option list')
let aliasEditor = <></> let aliasEditor = <></>
if (nodeType === 'trigger') { if (nodeType === 'trigger') {
aliasEditor = <InputText aliasEditor = <InputText
@@ -8,6 +8,14 @@
margin-top: 0.5em; margin-top: 0.5em;
} }
.node-editor--root.disabled {
background-color: var(--secondary);
}
.node-editor--root.disabled .enabled-flag {
color: var(--secondary-accent);
}
.node-editor--root.modded { .node-editor--root.modded {
border: 1px solid var(--change); border: 1px solid var(--change);
border-radius: 5px; border-radius: 5px;
@@ -68,3 +76,15 @@
.node-editor--error>li { .node-editor--error>li {
text-align: left; text-align: left;
} }
.node-editor--body-flags {
padding-left: 1em;
display: flex;
flex-direction: column;
justify-content: space-evenly;
}
.node-editor--body-flags .MuiCheckbox-root {
margin: 0;
padding: 0 0 0 0;
}
+10 -2
View File
@@ -43,7 +43,12 @@ export const NodeEditor: FC<NodeEditorProps> = ({
// events // events
onFlags(isReady, isModified); onFlags(isReady, isModified);
// render // render
return <div className={["node-editor--root", isModified ? "modded" : "", (!isReady && isModified) ? 'not-ready' : ''].join(" ")}> return <div className={[
"node-editor--root",
isModified ? "modded" : "",
(!isReady && isModified) ? 'not-ready' : '',
state.data.enabled === false ? 'disabled' : 'enabled'
].join(" ")}>
<div className="node-editor--body"> <div className="node-editor--body">
<div className="node-editor--body-title"> <div className="node-editor--body-title">
{allowedTypes.length > 1 ? <InputList {allowedTypes.length > 1 ? <InputList
@@ -58,7 +63,10 @@ export const NodeEditor: FC<NodeEditorProps> = ({
options={state.subTypes} options={state.subTypes}
onChange={state.setSubType} onChange={state.setSubType}
/> : <></>} /> : <></>}
<InputBoolean label="Yaml" onChange={state.setYamlMode} value={state.yamlMode} disabled={state.isErrored} /> <div className="node-editor--body-flags">
<InputBoolean label="Yaml" onChange={state.setYamlMode} value={state.yamlMode} disabled={state.isErrored} />
<InputBoolean className="enabled-flag" label='Enabled' value={state.data.enabled ?? true} onChange={state.setEnabled} />
</div>
</div> </div>
{state.renderOptionList()} {state.renderOptionList()}
</div> </div>
@@ -3,6 +3,7 @@ import * as st from 'superstruct';
import * as v from "types/validators/conditions"; import * as v from "types/validators/conditions";
type AutomationConditionNodeBase<Name extends String, Data extends Object> = { type AutomationConditionNodeBase<Name extends String, Data extends Object> = {
condition: Name; condition: Name;
enabled?: boolean;
} & Data; } & Data;
export type LogicCondition = AutomationConditionNodeBase<'and' | 'or' | 'not', { export type LogicCondition = AutomationConditionNodeBase<'and' | 'or' | 'not', {
conditions: AutomationCondition[]; conditions: AutomationCondition[];
+1
View File
@@ -6,6 +6,7 @@ import { AutomationTrigger } from './triggers';
export const AutomationActionNodeBase = st.type({ export const AutomationActionNodeBase = st.type({
alias: st.optional(st.string()), alias: st.optional(st.string()),
variables: st.optional(st.record(st.string(), st.any())), variables: st.optional(st.record(st.string(), st.any())),
enabled: st.optional(st.boolean())
}) })
export const ServiceAction = st.intersection([ export const ServiceAction = st.intersection([
+3 -1
View File
@@ -2,7 +2,9 @@ import * as st from 'superstruct'
import { AutomationTime, EntityId } from './common'; import { AutomationTime, EntityId } from './common';
export const AutomationConditionNodeBase = st.type({}); export const AutomationConditionNodeBase = st.type({
enabled: st.optional(st.boolean())
});
export const LogicCondition = st.intersection([ export const LogicCondition = st.intersection([
AutomationConditionNodeBase, AutomationConditionNodeBase,
st.type({ st.type({