fixed up deletes

This commit is contained in:
ari committed 2022-07-29 15:38:37 -04:00
1 parent e4af85cdfa
commit 957b6a66fe
9 files changed
+33 -12

No files matched your search

@@ -14,7 +14,7 @@ export type ListBoxGroupProps = AutomationManagerItem & {
aid: string,
eid: string
) => void;
onAutomationDelete: (aid: string) => void;
onAutomationDelete: (aid: string, eid: string) => void;
onSelect: (aid: string) => void;
initialOpenState?: boolean;
tagsDB: TagDB;
@@ -64,7 +64,9 @@ export const ListBoxGroup: FC<ListBoxGroupProps> = ({
key={`${i}-${auto.id}`}
{...auto}
tagsDB={tagsDB}
onDelete={() => events.onAutomationDelete(auto.id)}
onDelete={() =>
events.onAutomationDelete(auto.id, auto.entityId)
}
onSelect={() => events.onSelect(auto.id)}
onDescriptionUpdate={(description) =>
events.onAutomationUpdate(
@@ -11,7 +11,7 @@ import {
import Alert from "@mui/material/Alert";
export type AutomationManagerLoadedProps = UseAutomationManagerStateArgs & {
onAutomationDelete: (aid: string) => void;
onAutomationDelete: (aid: string, eid: string) => void;
};
export const AutomationManagerLoaded: FC<
PropsWithChildren<AutomationManagerLoadedProps>
@@ -27,7 +27,10 @@ export const AutomationManagerLoaded: FC<
selectedAutomationId={state.currentAutomationId}
onSelectedAutomationId={state.setSelectedAutomationId}
onAutomationAdd={() => state.addNew()}
onAutomationDelete={onAutomationDelete}
onAutomationDelete={(aid, eid) => {
onAutomationDelete(aid, eid);
state.setSelectedAutomationId(null);
}}
onAutomationUpdate={state.sideBarUpdateAutomation}
/>
<div className={["automation-manager--editor"].join(" ")}>
@@ -13,7 +13,6 @@ import { ButtonIcon } from "components/Icons/ButtonIcons";
import { AutomationManagerAuto } from "../types";
import { Tags } from "./Tags";
import { TagDB } from "../TagDB";
import useWindowSize from "utils/useWindowSize";
export type MetadataBoxProps = AutomationManagerAuto & {
onDelete: () => void;
@@ -37,8 +37,8 @@ const story = makeStory({
args.onSelectedAutomationId(aid);
setSelAutoId(aid);
}}
onAutomationDelete={(aid) => {
args.onAutomationDelete(aid);
onAutomationDelete={(aid, eid) => {
args.onAutomationDelete(aid, eid);
setAutomations(automations.filter(({ id }) => id !== aid));
}}
onAutomationUpdate={(a, aid, eid) => {
@@ -28,7 +28,7 @@ export type AutomationManagerSidebarProps = {
aid: string,
eid: string
) => void;
onAutomationDelete: (aid: string) => void;
onAutomationDelete: (aid: string, eid: string) => void;
onAutomationAdd: () => void;
onSelectedAutomationId: (aid: string) => void;
};
@@ -20,6 +20,7 @@ const { make, componentMeta } = makeStory({
api={useMockApiService(args.automations ?? [], !args.automations)}
haEntities={useMockHAEntities(haEntities)}
refreshAutomations={() => {}}
forceDeleteAutomation={() => {}}
onAutomationStateChange={(eid, on) => {
if (!haEntities.loading && !haEntities.error) {
setHAE({
@@ -13,6 +13,7 @@ import { useSnackbar } from "notistack";
export type AutomationManagerProps = {
onAutomationStateChange: (eid: string, on: boolean) => void;
refreshAutomations: () => void;
forceDeleteAutomation: (eid: string) => void;
haEntities: HAEntitiesState;
api: ApiService;
};
@@ -22,6 +23,7 @@ export const AutomationManager: FC<AutomationManagerProps> = ({
haEntities,
onAutomationStateChange,
refreshAutomations,
forceDeleteAutomation,
}) => {
const snackbr = useSnackbar();
const [isSaving, setIsSaving] = useState(false);
@@ -80,16 +82,23 @@ export const AutomationManager: FC<AutomationManagerProps> = ({
});
refreshAutomations();
}}
onAutomationDelete={(aid) => {
onAutomationDelete={(aid, eid) => {
const index = configAutomations.data.findIndex(
({ metadata }) => metadata.id === aid
);
let deleteSent = false;
if (index >= 0) {
api.removeAutomation({
index,
});
refreshAutomations();
} else {
deleteSent = true;
}
const hassAuto = hassEntities[eid];
if (hassAuto) {
forceDeleteAutomation(eid);
deleteSent = true;
}
if (!deleteSent) {
snackbr.enqueueSnackbar(
"Failed to delete automation, this may be resolved by a refresh or reboot of Home Assistant",
{
@@ -97,6 +106,7 @@ export const AutomationManager: FC<AutomationManagerProps> = ({
}
);
}
// refreshAutomations();
}}
onAutomationUpdate={(aid, auto) => {
const index = configAutomations.data.findIndex(
@@ -29,7 +29,7 @@ export const InputTextView: FC<PropsWithChildren<InputTextViewProps>> = (
return (
<div
className={className}
onClick={() => !!props.disabled && setViewMode(false)}
onClick={() => !props.disabled && setViewMode(false)}
>
{!!props.value ? (
<span>{props.value}</span>
+6
View File
@@ -11,6 +11,12 @@ export const AutomationRoute: FC<{ api: ApiService }> = ({ api }) => {
<AutomationManager
api={api}
refreshAutomations={() => ha.callService("automation", "reload")}
forceDeleteAutomation={(eid) =>
ha.callHA({
entity_id: eid,
type: "config/entity_registry/remove",
})
}
onAutomationStateChange={(eid, on) => {
ha.callService(
"automation",