added dial
This commit is contained in:
1 parent
f1b99cad1c
commit
14649ac1fd
4 files changed
+80
-32
No files matched your search
@@ -28,17 +28,13 @@ export const useAutomationDB = (
|
||||
return out;
|
||||
}
|
||||
},
|
||||
getAutomationData(autoId: string) {
|
||||
getAutomationData(
|
||||
autoId: string
|
||||
): null | [AutomationManagerAuto, AutomationData | null] {
|
||||
if (newAuto && newAuto[0].id === autoId) {
|
||||
return newAuto[1];
|
||||
return newAuto;
|
||||
}
|
||||
return (autoMap[autoId] ?? [null, null])[1];
|
||||
},
|
||||
getAutomationState(autoId: string): string | null {
|
||||
if (newAuto && newAuto[0].id === autoId) {
|
||||
return newAuto[0].state;
|
||||
}
|
||||
return (autoMap[autoId] ?? [{ state: null }, null])[0].state;
|
||||
return autoMap[autoId] ?? null;
|
||||
},
|
||||
isAutoNew(autoId: string) {
|
||||
return (newAuto && newAuto[0].id === autoId) ?? false;
|
||||
|
||||
@@ -9,14 +9,27 @@ import {
|
||||
UseAutomationManagerStateArgs,
|
||||
} from "./state";
|
||||
import Alert from "@mui/material/Alert";
|
||||
import { useConfirm } from "material-ui-confirm";
|
||||
|
||||
export type AutomationManagerLoadedProps = UseAutomationManagerStateArgs & {
|
||||
onAutomationDelete: (aid: string, eid: string) => void;
|
||||
};
|
||||
export const AutomationManagerLoaded: FC<
|
||||
PropsWithChildren<AutomationManagerLoadedProps>
|
||||
> = ({ children, onAutomationDelete, ...args }) => {
|
||||
> = ({ children, ...args }) => {
|
||||
const state = useAutomationManagerState(args);
|
||||
const confirm = useConfirm();
|
||||
|
||||
const onAutomationDelete = async (aid: string, eid: string) =>
|
||||
confirm({
|
||||
title: "Are you sure you want to delete this automation?",
|
||||
confirmationText: "Delete",
|
||||
})
|
||||
.then(() => {
|
||||
args.onAutomationDelete(aid, eid);
|
||||
state.setSelectedAutomationId(null);
|
||||
})
|
||||
.catch(() => {});
|
||||
|
||||
return (
|
||||
<div className="automation-manager">
|
||||
@@ -27,10 +40,7 @@ export const AutomationManagerLoaded: FC<
|
||||
selectedAutomationId={state.currentAutomationId}
|
||||
onSelectedAutomationId={state.setSelectedAutomationId}
|
||||
onAutomationAdd={() => state.addNew()}
|
||||
onAutomationDelete={(aid, eid) => {
|
||||
onAutomationDelete(aid, eid);
|
||||
state.setSelectedAutomationId(null);
|
||||
}}
|
||||
onAutomationDelete={onAutomationDelete}
|
||||
onAutomationUpdate={state.sideBarUpdateAutomation}
|
||||
onRun={args.onAutomationRun}
|
||||
/>
|
||||
@@ -44,6 +54,22 @@ export const AutomationManagerLoaded: FC<
|
||||
}}
|
||||
automation={state.currentAutomation}
|
||||
onUpdate={state.editorUpdateAutomation}
|
||||
onDelete={() => {
|
||||
if (
|
||||
state.currentAutomationId &&
|
||||
state.currentAutomationEntityId
|
||||
) {
|
||||
onAutomationDelete(
|
||||
state.currentAutomationId,
|
||||
state.currentAutomationEntityId
|
||||
);
|
||||
}
|
||||
}}
|
||||
onTrigger={() => {
|
||||
if (state.currentAutomationEntityId) {
|
||||
args.onAutomationRun(state.currentAutomationEntityId);
|
||||
}
|
||||
}}
|
||||
tagDB={state.tagsDB}
|
||||
isNew={state.currentAutomationIsNew}
|
||||
/>
|
||||
|
||||
@@ -66,12 +66,15 @@ export const useAutomationManagerState = ({
|
||||
get tagsDB() {
|
||||
return tagsDB;
|
||||
},
|
||||
get currentAutomation() {
|
||||
return currentAutomation;
|
||||
get currentAutomation(): AutomationData | null {
|
||||
return currentAutomation === null ? null : currentAutomation[1];
|
||||
},
|
||||
get currentAutomationIsNew() {
|
||||
return automationDB.isAutoNew(cookies.currentAutomationId ?? "");
|
||||
},
|
||||
get currentAutomationEntityId(): string | null {
|
||||
return currentAutomation === null ? null : currentAutomation[0].entityId;
|
||||
},
|
||||
async setSelectedAutomationId(i: string | null, force: boolean = false) {
|
||||
if (methods.currentAutomationIsNew && !force) {
|
||||
if (!(await stillHaveNewAreYouSure())) {
|
||||
@@ -102,8 +105,9 @@ export const useAutomationManagerState = ({
|
||||
aid: string,
|
||||
eid: string
|
||||
) {
|
||||
const previousAutoState = automationDB.getAutomationData(aid);
|
||||
if (previousAutoState) {
|
||||
const previousAuto = automationDB.getAutomationData(aid);
|
||||
if (previousAuto && previousAuto[1]) {
|
||||
const previousAutoState = previousAuto[1];
|
||||
if (
|
||||
previousAutoState.metadata.alias !== a.title ||
|
||||
previousAutoState.metadata.description !== a.description
|
||||
@@ -125,7 +129,8 @@ export const useAutomationManagerState = ({
|
||||
{ variant: "error" }
|
||||
);
|
||||
}
|
||||
const previousState = automationDB.getAutomationState(aid);
|
||||
const previousState =
|
||||
previousAuto === null ? null : previousAuto[0].state;
|
||||
if (previousState !== a.state) {
|
||||
onAutomationStateChange(eid, a.state === "on");
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user