From d824a93695a1c9aee2b7dda46063b50b2581730b Mon Sep 17 00:00:00 2001 From: Ari Date: Sun, 12 Jun 2022 22:23:30 -0400 Subject: [PATCH] delay fixes --- .../components/NodeEditor/OptionManager/ActionWait.tsx | 3 +-- .../NodeEditor/OptionManager/getOptionManager.ts | 2 ++ webapp/src/types/automations/actions.ts | 2 +- webapp/src/utils/automations.ts | 10 ++++++---- webapp/src/utils/formatting.ts | 3 +++ 5 files changed, 13 insertions(+), 7 deletions(-) diff --git a/webapp/src/components/NodeEditor/OptionManager/ActionWait.tsx b/webapp/src/components/NodeEditor/OptionManager/ActionWait.tsx index 37f5712..3a75868 100644 --- a/webapp/src/components/NodeEditor/OptionManager/ActionWait.tsx +++ b/webapp/src/components/NodeEditor/OptionManager/ActionWait.tsx @@ -7,13 +7,12 @@ import { InputTime } from "components/Inputs/InputTime"; import { useState } from "react"; import { DelayAction, WaitAction } from "types/automations/actions"; import { OptionManager, updateActionData } from './OptionManager'; -import { getNodeSubType } from 'utils/automations'; import InputYaml from "components/Inputs/InputYaml"; type ThisAction = WaitAction | DelayAction; type Option = 'delay' | 'template' | 'trigger' const getCurrentOption = (node: ThisAction): Option => { - if (getNodeSubType(node) === 'delay') { + if ('delay' in node) { return 'delay' } else { return 'template' diff --git a/webapp/src/components/NodeEditor/OptionManager/getOptionManager.ts b/webapp/src/components/NodeEditor/OptionManager/getOptionManager.ts index 95a526b..4d97a4b 100644 --- a/webapp/src/components/NodeEditor/OptionManager/getOptionManager.ts +++ b/webapp/src/components/NodeEditor/OptionManager/getOptionManager.ts @@ -40,6 +40,8 @@ export const getOptionManager = ( return ActionCallServiceState; case "wait": return ActionWaitState; + case "delay": + return ActionWaitState; } } if (nodeType === 'condition') { diff --git a/webapp/src/types/automations/actions.ts b/webapp/src/types/automations/actions.ts index 80761ee..4c725fa 100644 --- a/webapp/src/types/automations/actions.ts +++ b/webapp/src/types/automations/actions.ts @@ -28,6 +28,7 @@ export type AutomationAction = | ServiceAction | RepeatAction | WaitAction + | DelayAction | FireEventAction | DeviceAction | ChooseAction @@ -36,7 +37,6 @@ export type ActionType = | 'service' | 'repeat' | 'wait' - | 'delay' | 'event' | 'device' | 'choose' diff --git a/webapp/src/utils/automations.ts b/webapp/src/utils/automations.ts index ee80e88..3dd8c2e 100644 --- a/webapp/src/utils/automations.ts +++ b/webapp/src/utils/automations.ts @@ -5,6 +5,7 @@ import { MiniFailure } from "types/validators/helper"; import { getFailures } from '../types/validators/helper'; import { ActionType } from "types/automations/actions"; import { ConditionType } from "types/automations/conditions"; +import * as st from 'superstruct'; export const getNodeTypeAndValidate = (node: AutomationNode, allowedTypes: AutomationNodeTypes[]) => { const nodeType = getNodeType(node); @@ -31,7 +32,6 @@ export const getSubTypeList = (nodeType: T): Auto "service", "repeat", "wait", - "delay", "device", "choose", ] as any @@ -113,7 +113,7 @@ export const getNodeSubType = ( } else if ('choose' in node) { return 'choose' as any } else if ('delay' in node) { - return 'delay' as any + return 'wait' as any } else { throw new Error("Invalid node type!") } @@ -140,8 +140,10 @@ const ActionValidators: Record = { "event": v.actions.FireEventAction, "repeat": v.actions.RepeatAction, "service": v.actions.ServiceAction, - "wait": v.actions.WaitAction, - "delay": v.actions.DelayAction, + "wait": st.union([ + v.actions.DelayAction, + v.actions.WaitAction + ]), } const ConditionValidators: Record = { diff --git a/webapp/src/utils/formatting.ts b/webapp/src/utils/formatting.ts index 623e50d..e3db4c9 100644 --- a/webapp/src/utils/formatting.ts +++ b/webapp/src/utils/formatting.ts @@ -107,6 +107,9 @@ export const getDescriptionFromAutomationNode = ( if ('repeat' in node) { return 'Repeat ' + node.repeat.count } + if ('delay' in node) { + return `Wait for ${convertTimeToString(node.delay)}` + } if ('wait_template' in node) { let out = 'Wait on ' + node.wait_template; if (node.timeout) {