From ab8ecfeefb4e6c907be11df71505335cf568b0d9 Mon Sep 17 00:00:00 2001 From: Ari Date: Fri, 17 Jun 2022 16:26:54 -0400 Subject: [PATCH] updated zone condition --- .../ConditionEditor/editorRender.tsx | 405 +++++++++++------- 1 file changed, 239 insertions(+), 166 deletions(-) diff --git a/webapp/src/components/ConditionEditor/editorRender.tsx b/webapp/src/components/ConditionEditor/editorRender.tsx index 3bef37a..1dd85d1 100644 --- a/webapp/src/components/ConditionEditor/editorRender.tsx +++ b/webapp/src/components/ConditionEditor/editorRender.tsx @@ -1,5 +1,14 @@ import { FC } from "react"; -import { AutomationCondition, LogicCondition, NumericCondition, StateCondition, TemplateCondition, TimeCondition, TriggerCondition, ZoneCondition } from 'types/automations/conditions'; +import { + AutomationCondition, + LogicCondition, + NumericCondition, + StateCondition, + TemplateCondition, + TimeCondition, + TriggerCondition, + ZoneCondition, +} from "types/automations/conditions"; import InputNumber from "components/Inputs/InputNumber"; import InputText from "components/Inputs/InputText"; import { InputEntity } from "components/Inputs/InputEntities"; @@ -8,209 +17,273 @@ import { genUpdateMethods } from "./nestedUpdater"; import { InputTime } from "components/Inputs/InputTime"; import InputYaml from "components/Inputs/InputYaml"; - -interface Editor extends FC<{ - condition: C, - onChange: (condition: C) => void; -}> { } - +interface Editor + extends FC<{ + condition: C; + onChange: (condition: C) => void; + }> {} export const getEditor = (condition: AutomationCondition): Editor => { switch (condition.condition) { - case 'template': + case "template": return TemplateEditor; - case 'and': + case "and": return LogicViewer; - case 'or': + case "or": return LogicViewer; - case 'not': + case "not": return LogicViewer; - case 'numeric_state': + case "numeric_state": return NumericStateEditor; - case 'state': + case "state": return StateEditor; - case 'time': + case "time": return TimeEditor; - case 'trigger': + case "trigger": return TriggerEditor; - case 'zone': + case "zone": return ZoneEditor; default: - return () =>
Not Ready
+ return () =>
Not Ready
; } -} +}; export const TemplateEditor: Editor = ({ onChange, condition, }) => { - return <> - onChange({ - ...condition, - value_template - })} /> - -} - + return ( + <> + + onChange({ + ...condition, + value_template, + }) + } + /> + + ); +}; export const NumericStateEditor: Editor = ({ onChange, condition, }) => { - return <> - onChange({ - ...condition, - entity_id - })} - /> - onChange({ - ...condition, - attribute - })} /> - onChange({ - ...condition, - above: above ? String(above) : undefined, - })} - /> - onChange({ - ...condition, - below: below ? String(below) : undefined, - })} - /> - onChange({ - ...condition, - value_template - })} /> - -} - + return ( + <> + + onChange({ + ...condition, + entity_id, + }) + } + /> + + onChange({ + ...condition, + attribute, + }) + } + /> + + onChange({ + ...condition, + above: above ? String(above) : undefined, + }) + } + /> + + onChange({ + ...condition, + below: below ? String(below) : undefined, + }) + } + /> + + onChange({ + ...condition, + value_template, + }) + } + /> + + ); +}; export const LogicViewer: Editor = ({ condition, onChange, }) => { - - return <> - {condition.conditions.map((c, i) => { - return - })} - -} - - + return ( + <> + {condition.conditions.map((c, i) => { + return ( + + ); + })} + + ); +}; export const StateEditor: Editor = ({ onChange, condition, }) => { - return <> - onChange({ - ...condition, - entity_id - })} - /> - onChange({ - ...condition, - attribute - })} /> - onChange({ - ...condition, - state, - })} - /> - onChange({ - ...condition, - for: _for, - })} - /> - -} + return ( + <> + + onChange({ + ...condition, + entity_id, + }) + } + /> + + onChange({ + ...condition, + attribute, + }) + } + /> + + onChange({ + ...condition, + state, + }) + } + /> + + onChange({ + ...condition, + for: _for, + }) + } + /> + + ); +}; -export const TimeEditor: Editor = ({ - onChange, - condition, -}) => { - return <> - onChange({ - ...condition, - after, - })} - /> - onChange({ - ...condition, - before, - })} - /> - Weekday not support for no, use yaml for now {condition.weekday} - -} +export const TimeEditor: Editor = ({ onChange, condition }) => { + return ( + <> + + onChange({ + ...condition, + after, + }) + } + /> + + onChange({ + ...condition, + before, + }) + } + /> + Weekday not support for no, use yaml for now {condition.weekday} + + ); +}; export const TriggerEditor: Editor = ({ onChange, condition, }) => { - return <> - onChange({ - ...condition, - id - })} /> - -} + return ( + <> + + onChange({ + ...condition, + id, + }) + } + /> + + ); +}; -export const ZoneEditor: Editor = ({ - onChange, - condition, -}) => { - return <> - onChange({ - ...condition, - zone - })} /> - onChange({ - ...condition, - entity_id - })} - /> - onChange({ - ...condition, - state, - })} - /> - -} \ No newline at end of file +export const ZoneEditor: Editor = ({ onChange, condition }) => { + return ( + <> + + onChange({ + ...condition, + zone: zone ?? "", + }) + } + restrictToDomain={["zone"]} + /> + + onChange({ + ...condition, + entity_id, + }) + } + restrictToDomain={["person", "device_tracker"]} + /> + + onChange({ + ...condition, + state, + }) + } + /> + + ); +};