added dial

This commit is contained in:
ari committed 2022-08-05 22:54:17 -04:00
1 parent f1b99cad1c
commit 14649ac1fd
4 files changed
+80 -32

No files matched your search

@@ -3,15 +3,19 @@ import "./index.mobile.css";
import { FC, useState } from "react";
import { useCookies } from "react-cookie";
import { ControlButton } from "react-flow-renderer";
import Skeleton from "@mui/material/Skeleton";
import LinearProgress from "@mui/material/LinearProgress";
import SpeedDial from "@mui/material/SpeedDial";
import SpeedDialAction from "@mui/material/SpeedDialAction";
import SpeedDialIcon from "@mui/icons-material/SettingsRounded";
import Edit from "@mui/icons-material/Edit";
import Icon from "@mui/material/Icon";
import ModeEditOutlineTwoToneIcon from "@mui/icons-material/ModeEditOutlineTwoTone";
import EditIcon from "@mui/icons-material/ModeEditOutlineTwoTone";
import DeleteIcon from "@mui/icons-material/DeleteForever";
import { CheckMarkIcon } from "components/Icons";
import RunIcon from "@mui/icons-material/RunCircleOutlined";
import { Modal } from "components/Modal";
import { Button } from "components/Inputs/Buttons/Button";
@@ -32,6 +36,8 @@ interface Props {
automation?: AutomationData;
dims: DAGDims;
onUpdate: (auto: AutomationData) => void;
onTrigger: () => void;
onDelete: () => void;
tagDB: TagDB;
isNew?: boolean;
}
@@ -39,6 +45,8 @@ export const AutomationEditor: FC<Props> = ({
dims,
automation: propsAutos,
onUpdate: propsOnUpdate,
onDelete,
onTrigger,
tagDB,
isNew,
}) => {
@@ -198,12 +206,6 @@ export const AutomationEditor: FC<Props> = ({
Flip
</Button>
)}
<Button
className={"automation-editor--flow-wrapper--toolbar--edit-btn"}
onClick={() => setInfoBox(!infoBoxOpen)}
>
Metadata <Edit />
</Button>
<Button
className={"automation-editor--flow-wrapper--toolbar--save-btn"}
onClick={save}
@@ -220,12 +222,31 @@ export const AutomationEditor: FC<Props> = ({
onTriggerUpdate={updateTrigger}
onConditionUpdate={updateCondition}
isFlipped={flipped}
additionalControls={
<ControlButton onClick={() => setInfoBox(!infoBoxOpen)}>
<ModeEditOutlineTwoToneIcon />
</ControlButton>
}
/>
<SpeedDial
ariaLabel="options label"
sx={{ position: "absolute", bottom: 16, right: 16 }}
icon={<SpeedDialIcon />}
>
<SpeedDialAction
tooltipOpen
icon={<RunIcon />}
tooltipTitle={"Trigger"}
onClick={onTrigger}
/>
<SpeedDialAction
tooltipOpen
icon={<DeleteIcon />}
tooltipTitle={"Delete"}
onClick={onDelete}
/>
<SpeedDialAction
tooltipOpen
icon={<EditIcon />}
tooltipTitle={"Metadata"}
onClick={() => setInfoBox(!infoBoxOpen)}
/>
</SpeedDial>
</div>
</div>
);
@@ -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");
}