diff --git a/webapp/src/components/AutomationList/index.tsx b/webapp/src/components/AutomationList/index.tsx index 966c87a..b224fed 100644 --- a/webapp/src/components/AutomationList/index.tsx +++ b/webapp/src/components/AutomationList/index.tsx @@ -3,20 +3,19 @@ import "./index.mobile.css"; import { AutomationEditor } from "components/AutomationEditor"; import { FC, ReactNode, useState } from "react"; import { AutomationData } from "types/automations"; -import { defaultAutomation } from 'utils/defaults'; +import { defaultAutomation } from "utils/defaults"; import { ArrowIcon } from "components/Icons"; import { ButtonIcon } from "components/Icons/ButtonIcons"; import { ApiService } from "apiService/core"; import { AutomationListBox } from "./AutomationListBox"; -import { DAGAutomationFlowDims } from 'components/DAGFlow/types'; +import { DAGAutomationFlowDims } from "components/DAGFlow/types"; import useWindowSize from "utils/useWindowSize"; import { makeTagDB } from "./TagDB"; import LinearProgress from "@mui/material/LinearProgress"; import CircularProgress from "@mui/material/CircularProgress"; -import { useCookies } from 'react-cookie'; +import { useCookies } from "react-cookie"; import { useHA } from "haService"; - interface AutomationListParams { automations: AutomationData[]; onUpdate: (i: number, auto: AutomationData) => void; @@ -31,12 +30,12 @@ export const useAutomationListState = () => { cookies, setCookies, // eslint-disable-next-line - _ - ] = useCookies(['alCurrent']); + _, + ] = useCookies(["alCurrent"]); let initialCurrent = 0; try { - initialCurrent = Number(cookies.alCurrent ?? '0'); - } catch (_) { } + initialCurrent = Number(cookies.alCurrent ?? "0"); + } catch (_) {} const [hideList, setHideList] = useState(false); const [current, setCurrent] = useState(initialCurrent); @@ -46,11 +45,11 @@ export const useAutomationListState = () => { setHideList, current, setCurrent(i: number) { - setCurrent(i) - setCookies('alCurrent', String(i)) - } - } -} + setCurrent(i); + setCookies("alCurrent", String(i)); + }, + }; +}; export const AutomationList: FC = ({ automations, @@ -61,49 +60,65 @@ export const AutomationList: FC = ({ children, }) => { // state - const { hideList, setHideList, current, setCurrent } = useAutomationListState(); + const { hideList, setHideList, current, setCurrent } = + useAutomationListState(); const { isMobile } = useWindowSize(); // alias const currentAuto = automations.length > 0 ? automations[current] : null; const tagDB = makeTagDB(automations); // render - return
-
- { - onAdd(defaultAutomation(String(Date.now()))); - setCurrent(automations.length) - }} - onSelectAutomation={i => { - setCurrent(i); - if (isMobile) { - setHideList(true) - } - }} - selected={current} - onRemove={onRemove} - /> - setHideList(!hideList)} - className="automation-list--list-hide" - Icon={ArrowIcon} - /> + return ( +
+
+ { + onAdd(defaultAutomation(String(Date.now()))); + setCurrent(automations.length); + if (isMobile) { + setHideList(true); + } + }} + onSelectAutomation={(i) => { + setCurrent(i); + if (isMobile) { + setHideList(true); + } + }} + selected={current} + onRemove={onRemove} + /> + setHideList(!hideList)} + className="automation-list--list-hide" + Icon={ArrowIcon} + /> +
+
+ {currentAuto ? ( + onUpdate(current, a)} + dims={{ + ...dims, + flipped: isMobile, + }} + tagDB={tagDB} + /> + ) : ( + <> + )} +
+ {children}
-
- {currentAuto ? onUpdate(current, a)} - dims={{ - ...dims, - flipped: isMobile - }} - tagDB={tagDB} - /> : <>} -
- {children} -
-} + ); +}; interface ConnectedAutomationListParams { dims: DAGAutomationFlowDims; @@ -111,40 +126,44 @@ interface ConnectedAutomationListParams { } export const ConnectedAutomationList: FC = ({ api: { - state: { - automations, - }, + state: { automations }, ...methods }, - dims + dims, }) => { const { reloadAutomations } = useHA(); const removeAutomation = async (args: any) => { - const resp = await methods.removeAutomation(args) + const resp = await methods.removeAutomation(args); await reloadAutomations(); - return resp - } + return resp; + }; const updateAutomation = async (args: any) => { - const resp = await methods.updateAutomation(args) + const resp = await methods.updateAutomation(args); await reloadAutomations(); - return resp - } + return resp; + }; if (!automations.ready) { - return
- -
- + return ( +
+ +
+ +
-
+ ); } if (!automations.ok) { - return Error {automations.error} + return Error {automations.error}; } - return updateAutomation({ auto, index: automations.data.totalItems + 1 })} - onRemove={index => removeAutomation({ index })} - onUpdate={(index, auto) => updateAutomation({ index, auto })} - /> -} + return ( + + updateAutomation({ auto, index: automations.data.totalItems + 1 }) + } + onRemove={(index) => removeAutomation({ index })} + onUpdate={(index, auto) => updateAutomation({ index, auto })} + /> + ); +}; diff --git a/webapp/src/utils/formatting.ts b/webapp/src/utils/formatting.ts index 3b874fc..89fb0d3 100644 --- a/webapp/src/utils/formatting.ts +++ b/webapp/src/utils/formatting.ts @@ -98,6 +98,8 @@ export const getDescriptionFromAutomationNode = ( return node.value_template; case "device": return getDescriptionForDeviceType(node, namer, true); + case "trigger": + return node.id; default: return JSON.stringify(node); }