From cdf67aa1a938923e9d18a552d04909ac0b427d6d Mon Sep 17 00:00:00 2001 From: Ari Date: Fri, 27 May 2022 12:02:25 -0400 Subject: [PATCH] fixed up alias issues --- .../ConditionEditor/editorRender.tsx | 25 ------------------- webapp/src/components/DAGFlow/updater.test.ts | 4 +-- .../OptionManager/TriggerDevice.tsx | 5 ++-- .../NodeEditor/OptionManager/TriggerEvent.tsx | 5 ++-- .../NodeEditor/OptionManager/TriggerHA.tsx | 6 ++--- .../NodeEditor/OptionManager/TriggerMQTT.tsx | 5 ++-- .../OptionManager/TriggerNumericState.tsx | 5 ++-- .../NodeEditor/OptionManager/TriggerState.tsx | 5 ++-- .../OptionManager/TriggerTemplate.tsx | 5 ++-- .../NodeEditor/OptionManager/TriggerTime.tsx | 5 ++-- .../OptionManager/TriggerTimePattern.tsx | 5 ++-- .../OptionManager/TriggerWebhook.tsx | 5 ++-- .../NodeEditor/OptionManager/TriggerZone.tsx | 5 ++-- .../NodeEditor/OptionManager/index.tsx | 25 ++++++++++++++++--- webapp/src/components/NodeEditor/index.tsx | 2 +- webapp/src/types/automations/conditions.ts | 1 - webapp/src/types/automations/triggers.ts | 4 --- webapp/src/types/validators/conditions.ts | 4 +-- webapp/src/types/validators/triggers.ts | 1 - webapp/src/utils/formatting.ts | 6 ++++- 20 files changed, 52 insertions(+), 76 deletions(-) diff --git a/webapp/src/components/ConditionEditor/editorRender.tsx b/webapp/src/components/ConditionEditor/editorRender.tsx index 79f98ed..e33f65d 100644 --- a/webapp/src/components/ConditionEditor/editorRender.tsx +++ b/webapp/src/components/ConditionEditor/editorRender.tsx @@ -1,6 +1,5 @@ import { FC } from "react"; import { AutomationCondition, LogicCondition, NumericCondition, StateCondition, TemplateCondition, TimeCondition, TriggerCondition, ZoneCondition } from 'types/automations/conditions'; -import { getDescriptionFromAutomationNode } from "utils/formatting"; import InputNumber from "components/Inputs/InputNumber"; import InputText from "components/Inputs/InputText"; import { InputEntity } from "components/Inputs/InputTextBubble"; @@ -46,10 +45,6 @@ export const TemplateEditor: Editor = ({ condition, }) => { return <> - onChange({ - ...condition, - alias - })} /> onChange({ ...condition, value_template @@ -63,10 +58,6 @@ export const NumericStateEditor: Editor = ({ condition, }) => { return <> - onChange({ - ...condition, - alias - })} /> onChange({ @@ -127,10 +118,6 @@ export const StateEditor: Editor = ({ condition, }) => { return <> - onChange({ - ...condition, - alias - })} /> onChange({ @@ -166,10 +153,6 @@ export const TimeEditor: Editor = ({ condition, }) => { return <> - onChange({ - ...condition, - alias - })} /> = ({ condition, }) => { return <> - onChange({ - ...condition, - alias - })} /> onChange({ ...condition, id @@ -211,10 +190,6 @@ export const ZoneEditor: Editor = ({ condition, }) => { return <> - onChange({ - ...condition, - alias - })} /> onChange({ ...condition, zone diff --git a/webapp/src/components/DAGFlow/updater.test.ts b/webapp/src/components/DAGFlow/updater.test.ts index 3b34271..99d6903 100644 --- a/webapp/src/components/DAGFlow/updater.test.ts +++ b/webapp/src/components/DAGFlow/updater.test.ts @@ -40,8 +40,8 @@ test("sequence updater updates nodes", () => { mock.updater.updateNode(0, { ...mock.state[0], alias: "Hello" - }) - expect(mock.state[0].alias).toBe("Hello") + } as any) + expect((mock.state[0] as any).alias).toBe("Hello") }) test('update conditions for node', () => { const mock = mockSequenceUpdater([ diff --git a/webapp/src/components/NodeEditor/OptionManager/TriggerDevice.tsx b/webapp/src/components/NodeEditor/OptionManager/TriggerDevice.tsx index 37a3b86..6bed0ce 100644 --- a/webapp/src/components/NodeEditor/OptionManager/TriggerDevice.tsx +++ b/webapp/src/components/NodeEditor/OptionManager/TriggerDevice.tsx @@ -6,7 +6,6 @@ import { InputEntity } from 'components/Inputs/InputTextBubble'; export const TriggerDevice: OptionManager = { defaultState: () => ({ - "alias": "", "platform": 'device', "domain": "", "type": "", @@ -14,8 +13,8 @@ export const TriggerDevice: OptionManager = { "device_id": "", "entity_id": "", }), - isReady: ({ alias }) => { - return (alias !== '') + isReady: ({ }) => { + return true }, renderOptionList: (state, setState) => { return <> diff --git a/webapp/src/components/NodeEditor/OptionManager/TriggerEvent.tsx b/webapp/src/components/NodeEditor/OptionManager/TriggerEvent.tsx index a285050..ca4a69b 100644 --- a/webapp/src/components/NodeEditor/OptionManager/TriggerEvent.tsx +++ b/webapp/src/components/NodeEditor/OptionManager/TriggerEvent.tsx @@ -6,14 +6,13 @@ import InputYaml from "components/Inputs/InputYaml"; export const TriggerEventState: OptionManager = { defaultState: () => ({ - "alias": "", "platform": "event", "event_type": "", "event_data": {}, "context": {}, }), - isReady: ({ alias, event_type }) => { - return (alias !== '') && (event_type !== "") + isReady: ({ event_type }) => { + return (event_type !== "") }, renderOptionList: (state, setState) => { return <> diff --git a/webapp/src/components/NodeEditor/OptionManager/TriggerHA.tsx b/webapp/src/components/NodeEditor/OptionManager/TriggerHA.tsx index d248cc7..25d14c2 100644 --- a/webapp/src/components/NodeEditor/OptionManager/TriggerHA.tsx +++ b/webapp/src/components/NodeEditor/OptionManager/TriggerHA.tsx @@ -5,12 +5,11 @@ import { InputList } from "components/Inputs/InputList"; export const TriggerHAState: OptionManager = { defaultState: () => ({ - "alias": "HA Starts", "platform": "homeassistant", "event": "start", }), - isReady: ({ alias }) => { - return (alias !== '') + isReady: ({ }) => { + return true }, renderOptionList: (state, setState) => { return <> @@ -20,7 +19,6 @@ export const TriggerHAState: OptionManager = { options={['start', 'shutdown']} onChange={event => setState({ ...state, event, - alias: event === 'shutdown' ? "HA Shutdown" : "HA Starts" })} /> diff --git a/webapp/src/components/NodeEditor/OptionManager/TriggerMQTT.tsx b/webapp/src/components/NodeEditor/OptionManager/TriggerMQTT.tsx index 3ffdfc9..b1961da 100644 --- a/webapp/src/components/NodeEditor/OptionManager/TriggerMQTT.tsx +++ b/webapp/src/components/NodeEditor/OptionManager/TriggerMQTT.tsx @@ -5,14 +5,13 @@ import InputText from 'components/Inputs/InputText'; export const TriggerMQTTState: OptionManager = { defaultState: () => ({ - "alias": "", "platform": "mqtt", "payload": "", "topic": "", "value_template": "" }), - isReady: ({ alias }) => { - return (alias !== '') + isReady: ({ }) => { + return true }, renderOptionList: (state, setState) => { return <> diff --git a/webapp/src/components/NodeEditor/OptionManager/TriggerNumericState.tsx b/webapp/src/components/NodeEditor/OptionManager/TriggerNumericState.tsx index 58d80ab..a69ea46 100644 --- a/webapp/src/components/NodeEditor/OptionManager/TriggerNumericState.tsx +++ b/webapp/src/components/NodeEditor/OptionManager/TriggerNumericState.tsx @@ -9,12 +9,11 @@ import InputYaml from 'components/Inputs/InputYaml'; export const TriggerNumericState: OptionManager = { defaultState: () => ({ - "alias": "", "platform": 'numeric_state', "entity_id": "", }), - isReady: ({ alias }) => { - return (alias !== '') + isReady: ({ }) => { + return true }, renderOptionList: (state, setState) => { return <> diff --git a/webapp/src/components/NodeEditor/OptionManager/TriggerState.tsx b/webapp/src/components/NodeEditor/OptionManager/TriggerState.tsx index 21b3966..e6654e5 100644 --- a/webapp/src/components/NodeEditor/OptionManager/TriggerState.tsx +++ b/webapp/src/components/NodeEditor/OptionManager/TriggerState.tsx @@ -7,12 +7,11 @@ import InputTime from 'components/Inputs/InputTime'; export const TriggerState: OptionManager = { defaultState: () => ({ - "alias": "", "platform": 'state', "entity_id": "", }), - isReady: ({ alias }) => { - return (alias !== '') + isReady: ({ }) => { + return true }, renderOptionList: (state, setState) => { return <> diff --git a/webapp/src/components/NodeEditor/OptionManager/TriggerTemplate.tsx b/webapp/src/components/NodeEditor/OptionManager/TriggerTemplate.tsx index 7c95d99..8ee979d 100644 --- a/webapp/src/components/NodeEditor/OptionManager/TriggerTemplate.tsx +++ b/webapp/src/components/NodeEditor/OptionManager/TriggerTemplate.tsx @@ -6,12 +6,11 @@ import InputTime from 'components/Inputs/InputTime'; export const TriggerTemplate: OptionManager = { defaultState: () => ({ - "alias": "", "platform": 'template', "value_template": "", }), - isReady: ({ alias }) => { - return (alias !== '') + isReady: ({ }) => { + return true }, renderOptionList: (state, setState) => { return <> diff --git a/webapp/src/components/NodeEditor/OptionManager/TriggerTime.tsx b/webapp/src/components/NodeEditor/OptionManager/TriggerTime.tsx index 630013f..73d1db9 100644 --- a/webapp/src/components/NodeEditor/OptionManager/TriggerTime.tsx +++ b/webapp/src/components/NodeEditor/OptionManager/TriggerTime.tsx @@ -6,12 +6,11 @@ import { convertObjectToAutomationTimeString } from 'utils/time'; export const TriggerTime: OptionManager = { defaultState: () => ({ - "alias": "", "platform": 'time', "at": "", }), - isReady: ({ alias }) => { - return (alias !== '') + isReady: ({ }) => { + return true }, renderOptionList: (state, setState) => { return <> diff --git a/webapp/src/components/NodeEditor/OptionManager/TriggerTimePattern.tsx b/webapp/src/components/NodeEditor/OptionManager/TriggerTimePattern.tsx index 585f399..e85cdc4 100644 --- a/webapp/src/components/NodeEditor/OptionManager/TriggerTimePattern.tsx +++ b/webapp/src/components/NodeEditor/OptionManager/TriggerTimePattern.tsx @@ -5,11 +5,10 @@ import InputText from 'components/Inputs/InputText'; export const TriggerTimePattern: OptionManager = { defaultState: () => ({ - "alias": "", "platform": 'time_pattern', }), - isReady: ({ alias }) => { - return (alias !== '') + isReady: ({ }) => { + return true }, renderOptionList: (state, setState) => { return <> diff --git a/webapp/src/components/NodeEditor/OptionManager/TriggerWebhook.tsx b/webapp/src/components/NodeEditor/OptionManager/TriggerWebhook.tsx index 892a24c..e98a4e7 100644 --- a/webapp/src/components/NodeEditor/OptionManager/TriggerWebhook.tsx +++ b/webapp/src/components/NodeEditor/OptionManager/TriggerWebhook.tsx @@ -5,12 +5,11 @@ import InputText from 'components/Inputs/InputText'; export const TriggerWebhook: OptionManager = { defaultState: () => ({ - "alias": "", "platform": 'webhook', "webhook_id": "", }), - isReady: ({ alias }) => { - return (alias !== '') + isReady: ({ }) => { + return true }, renderOptionList: (state, setState) => { return <> diff --git a/webapp/src/components/NodeEditor/OptionManager/TriggerZone.tsx b/webapp/src/components/NodeEditor/OptionManager/TriggerZone.tsx index 577d3c2..0f0c3d0 100644 --- a/webapp/src/components/NodeEditor/OptionManager/TriggerZone.tsx +++ b/webapp/src/components/NodeEditor/OptionManager/TriggerZone.tsx @@ -7,14 +7,13 @@ import { InputEntity } from 'components/Inputs/InputTextBubble'; export const TriggerZone: OptionManager = { defaultState: () => ({ - "alias": "", "platform": 'zone', "zone": "", "event": "enter", "entity_id": "", }), - isReady: ({ alias }) => { - return (alias !== '') + isReady: ({ }) => { + return true }, renderOptionList: (state, setState) => { return <> diff --git a/webapp/src/components/NodeEditor/OptionManager/index.tsx b/webapp/src/components/NodeEditor/OptionManager/index.tsx index 1340029..253362b 100644 --- a/webapp/src/components/NodeEditor/OptionManager/index.tsx +++ b/webapp/src/components/NodeEditor/OptionManager/index.tsx @@ -59,10 +59,27 @@ export const useEditorNodeState = (originalNode: AutomationNode, isErrored: bool return currentNode }, renderOptionList() { - const aliasEditor = setState({ - ...allState.node, - alias - })} /> + let aliasEditor = <> + if (nodeType === 'trigger') { + aliasEditor = setState({ + ...allState.node, + id + } as any)} + /> + } + if (nodeType === 'action') { + aliasEditor = setState({ + ...allState.node, + alias + } as any)} + /> + } if (yamlMode || allState.isErrored) { return <> {aliasEditor} diff --git a/webapp/src/components/NodeEditor/index.tsx b/webapp/src/components/NodeEditor/index.tsx index 2b6ab67..5fa1a47 100644 --- a/webapp/src/components/NodeEditor/index.tsx +++ b/webapp/src/components/NodeEditor/index.tsx @@ -52,7 +52,7 @@ export const NodeEditor: FC = ({ onChange={state.setNodeType} /> : <>} {state.nodeType !== 'condition' ? = { condition: Name; - alias?: string; } & Data; export type LogicCondition = AutomationConditionNodeBase<'and' | 'or' | 'not', { conditions: AutomationCondition[]; diff --git a/webapp/src/types/automations/triggers.ts b/webapp/src/types/automations/triggers.ts index 4656949..66e8289 100644 --- a/webapp/src/types/automations/triggers.ts +++ b/webapp/src/types/automations/triggers.ts @@ -1,10 +1,6 @@ import * as st from 'superstruct' import * as v from "types/validators/triggers"; -interface AutomationTriggerBase { - alias?: string; -} - export type AutomationTriggerEvent = st.Infer; export type AutomationTriggerHA = st.Infer; export type AutomationTriggerMQTT = st.Infer; diff --git a/webapp/src/types/validators/conditions.ts b/webapp/src/types/validators/conditions.ts index 5d2c4a5..fd15635 100644 --- a/webapp/src/types/validators/conditions.ts +++ b/webapp/src/types/validators/conditions.ts @@ -2,9 +2,7 @@ import * as st from 'superstruct' import { AutomationTime, EntityId } from './common'; -export const AutomationConditionNodeBase = st.type({ - alias: st.optional(st.string()), -}); +export const AutomationConditionNodeBase = st.type({}); export const LogicCondition = st.intersection([ AutomationConditionNodeBase, st.type({ diff --git a/webapp/src/types/validators/triggers.ts b/webapp/src/types/validators/triggers.ts index 1f8198e..75b153a 100644 --- a/webapp/src/types/validators/triggers.ts +++ b/webapp/src/types/validators/triggers.ts @@ -3,7 +3,6 @@ import { AutomationTimeString, AutomationTime, EntityId } from './common' const AutomationTriggerBase = { - alias: st.optional(st.string()), id: st.optional(st.string()), } diff --git a/webapp/src/utils/formatting.ts b/webapp/src/utils/formatting.ts index f2136e1..2945dad 100644 --- a/webapp/src/utils/formatting.ts +++ b/webapp/src/utils/formatting.ts @@ -16,10 +16,14 @@ export const convertTimeToString = (t: AutomationTime) => { } } export const getDescriptionFromAutomationNode = (node: AutomationNode): string => { - if (node.alias) { + if (('alias' in node) && node.alias) { return node.alias; } + if ('platform' in node) { + if (node.id) { + return node.id ?? ''; + } if (node.platform === 'time') { return node.at }