From b30f4ed59ab3a3ea1557f35ef1ae013e9ffc3aea Mon Sep 17 00:00:00 2001 From: Ari Date: Sun, 12 Jun 2022 21:55:32 -0400 Subject: [PATCH] enabled flag --- webapp/src/components/Inputs/InputBoolean.tsx | 4 +++- .../NodeEditor/OptionManager/index.tsx | 8 +++++++- webapp/src/components/NodeEditor/index.css | 20 +++++++++++++++++++ webapp/src/components/NodeEditor/index.tsx | 12 +++++++++-- webapp/src/types/automations/conditions.ts | 1 + webapp/src/types/validators/actions.ts | 1 + webapp/src/types/validators/conditions.ts | 4 +++- 7 files changed, 45 insertions(+), 5 deletions(-) diff --git a/webapp/src/components/Inputs/InputBoolean.tsx b/webapp/src/components/Inputs/InputBoolean.tsx index 85ab51c..d3accfb 100644 --- a/webapp/src/components/Inputs/InputBoolean.tsx +++ b/webapp/src/components/Inputs/InputBoolean.tsx @@ -7,14 +7,16 @@ export interface Props { value: boolean; onChange: (v: boolean) => void; disabled?: boolean; + className?: string; } export default function InputBoolean({ label, value = false, onChange, disabled = false, + className, }: Props) { - return + return onChange(!value)} />} label={label} /> } diff --git a/webapp/src/components/NodeEditor/OptionManager/index.tsx b/webapp/src/components/NodeEditor/OptionManager/index.tsx index 295f34a..8319975 100644 --- a/webapp/src/components/NodeEditor/OptionManager/index.tsx +++ b/webapp/src/components/NodeEditor/OptionManager/index.tsx @@ -9,6 +9,7 @@ import { getDescriptionFromAutomationNode } from 'utils/formatting'; import { useHA } from 'haService'; import { Generic } from './Generic'; import { getNodeTypeAndValidate } from '../../../utils/automations'; +import InputBoolean from 'components/Inputs/InputBoolean'; type UseState = (s: S) => [S, Dispatch>] @@ -70,8 +71,13 @@ export const useEditorNodeState = (originalNode: AutomationNode, isErrored: bool get data() { return currentNode }, + setEnabled(enabled: boolean) { + setState({ + ...currentNode, + enabled, + }) + }, renderOptionList() { - console.log('rendering option list') let aliasEditor = <> if (nodeType === 'trigger') { aliasEditor = li { 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; } \ No newline at end of file diff --git a/webapp/src/components/NodeEditor/index.tsx b/webapp/src/components/NodeEditor/index.tsx index 5a306b0..64cee59 100644 --- a/webapp/src/components/NodeEditor/index.tsx +++ b/webapp/src/components/NodeEditor/index.tsx @@ -43,7 +43,12 @@ export const NodeEditor: FC = ({ // events onFlags(isReady, isModified); // render - return
+ return
{allowedTypes.length > 1 ? = ({ options={state.subTypes} onChange={state.setSubType} /> : <>} - +
+ + +
{state.renderOptionList()}
diff --git a/webapp/src/types/automations/conditions.ts b/webapp/src/types/automations/conditions.ts index aac3037..e45b680 100644 --- a/webapp/src/types/automations/conditions.ts +++ b/webapp/src/types/automations/conditions.ts @@ -3,6 +3,7 @@ import * as st from 'superstruct'; import * as v from "types/validators/conditions"; type AutomationConditionNodeBase = { condition: Name; + enabled?: boolean; } & Data; export type LogicCondition = AutomationConditionNodeBase<'and' | 'or' | 'not', { conditions: AutomationCondition[]; diff --git a/webapp/src/types/validators/actions.ts b/webapp/src/types/validators/actions.ts index 807ceea..af587e9 100644 --- a/webapp/src/types/validators/actions.ts +++ b/webapp/src/types/validators/actions.ts @@ -6,6 +6,7 @@ import { AutomationTrigger } from './triggers'; export const AutomationActionNodeBase = st.type({ alias: st.optional(st.string()), variables: st.optional(st.record(st.string(), st.any())), + enabled: st.optional(st.boolean()) }) export const ServiceAction = st.intersection([ diff --git a/webapp/src/types/validators/conditions.ts b/webapp/src/types/validators/conditions.ts index fd15635..2ab66bc 100644 --- a/webapp/src/types/validators/conditions.ts +++ b/webapp/src/types/validators/conditions.ts @@ -2,7 +2,9 @@ import * as st from 'superstruct' 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([ AutomationConditionNodeBase, st.type({