diff --git a/webapp/src/components/AutomationManager/Loaded/index.tsx b/webapp/src/components/AutomationManager/Loaded/index.tsx index 6afd56b..21c1772 100644 --- a/webapp/src/components/AutomationManager/Loaded/index.tsx +++ b/webapp/src/components/AutomationManager/Loaded/index.tsx @@ -10,10 +10,12 @@ import { } from "./state"; import Alert from "@mui/material/Alert"; -export type AutomationManagerLoadedProps = UseAutomationManagerStateArgs & {}; +export type AutomationManagerLoadedProps = UseAutomationManagerStateArgs & { + onAutomationDelete: (aid: string) => void; +}; export const AutomationManagerLoaded: FC< PropsWithChildren -> = ({ children, ...args }) => { +> = ({ children, onAutomationDelete, ...args }) => { const state = useAutomationManagerState(args); return ( @@ -25,7 +27,7 @@ export const AutomationManagerLoaded: FC< selectedAutomationId={state.currentAutomationId} onSelectedAutomationId={state.setSelectedAutomationId} onAutomationAdd={() => state.addNew()} - onAutomationDelete={() => {}} + onAutomationDelete={onAutomationDelete} onAutomationUpdate={() => {}} />
diff --git a/webapp/src/components/AutomationManager/Loaded/state.ts b/webapp/src/components/AutomationManager/Loaded/state.ts index 04be66e..d68e1c8 100644 --- a/webapp/src/components/AutomationManager/Loaded/state.ts +++ b/webapp/src/components/AutomationManager/Loaded/state.ts @@ -10,7 +10,6 @@ export type UseAutomationManagerStateArgs = { configAutomations: AutomationData[]; hassEntities: HassEntities; onUpdateTags: (aid: string, tags: Record) => void; - // onAutomationDelete: (aid: string) => void; onAutomationAdd: (auto: AutomationData) => void; }; export const useAutomationManagerState = ({ diff --git a/webapp/src/components/AutomationManager/index.stories.tsx b/webapp/src/components/AutomationManager/index.stories.tsx index 7283515..45d552a 100644 --- a/webapp/src/components/AutomationManager/index.stories.tsx +++ b/webapp/src/components/AutomationManager/index.stories.tsx @@ -71,3 +71,23 @@ export const One = make({ entitySource: {}, }, }); +export const MissingAutoInConfig = make({ + automations: [], + haProps: { + loading: false, + entities: { + [`automation.${auto1.metadata.id}`]: { + entity_id: `automation.${auto1.metadata.id}`, + attributes: { + id: auto1.metadata.id, + friendly_name: auto1.metadata.alias, + }, + context: { id: "", parent_id: null, user_id: null }, + last_changed: "", + last_updated: "", + state: "on", + }, + }, + entitySource: {}, + }, +}); diff --git a/webapp/src/components/AutomationManager/index.tsx b/webapp/src/components/AutomationManager/index.tsx index e7f5752..cdd24a6 100644 --- a/webapp/src/components/AutomationManager/index.tsx +++ b/webapp/src/components/AutomationManager/index.tsx @@ -59,6 +59,13 @@ export const AutomationManager: FC = ({ auto, }) } + onAutomationDelete={(aid) => + api.removeAutomation({ + index: configAutomations.data.findIndex( + ({ metadata }) => metadata.id === aid + ), + }) + } onUpdateTags={async (aid, t) => { setIsSaving(true); await api.updateTags({