import "./index.css"; import "./index.mobile.css"; import { FC, useState } from "react"; import { useCookies } from "react-cookie"; 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 UndoIcon from "@mui/icons-material/UndoSharp"; import Icon from "@mui/material/Icon"; 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"; import InputYaml from "components/Inputs/Base/InputYaml"; import { TagDB } from "components/AutomationManager/TagDB"; import { DAGDims } from "components/DAGGraph/elements/types"; import { DAGAutomationGraph } from "components/DAGGraph"; import { InputList } from "components/Inputs/InputList"; import { InputTextView } from "components/Inputs/InputTextView"; import { AutomationData } from "types/automations"; import { MiniFailure } from "types/validators/helper"; import { AutoInfoBox } from "./AutoInfoBox"; import { useAutomatioEditorState, EditorData } from "./state"; interface Props { automation?: AutomationData; dims: DAGDims; onUpdate: (auto: AutomationData) => void; onTrigger: () => void; onDelete: () => void; tagDB: TagDB; isNew?: boolean; } export const AutomationEditor: FC = ({ dims, automation: propsAutos, onUpdate: propsOnUpdate, onDelete, onTrigger, tagDB, isNew, }) => { // state const { state, updateSequence, updateTrigger, updateMetadata, updateCondition, validate, save, saveAndUpdate, undo, } = useAutomatioEditorState(propsAutos, propsOnUpdate); const [infoBoxOpen, setInfoBox] = useState(false); const [ { ckFlipped }, setCookies, // eslint-disable-next-line _, ] = useCookies(["ckFlipped"]); // alias const flipped = dims.flipped ? true : ckFlipped === "1"; const setFlipped = (v: boolean) => setCookies("ckFlipped", v ? "1" : "0"); // render if (state.status === "loading") { return (
); } if (state.status === "invalid") { return ( ); } return (
{state.status === "saving" && ( )}
{state.data.id}
updateMetadata( { ...state.data, alias, }, state.data.tags ) } />
updateMetadata( { ...state.data, mode: id, }, state.data.tags ) } getKey={({ id }) => id} getDescription={({ label }) => label} options={[ { id: "single", label: "Do not start a new run. Issue a warning.", }, { id: "parallel", label: "Start a new, independent run in parallel with previous runs.", }, { id: "queued", label: "Start a new run after all previous runs complete. Runs are guaranteed to execute in the order they were queued.", }, { id: "restart", label: "Start a new run after first stopping previous run.", }, ]} /> updateMetadata( { ...state.data, description, }, state.data.tags ) } />
{!dims.flipped && ( )} {state.status === "changed" && ( )}
} > } tooltipTitle={"Trigger"} onClick={onTrigger} /> } tooltipTitle={"Delete"} onClick={onDelete} /> } tooltipTitle={"Metadata"} onClick={() => setInfoBox(!infoBoxOpen)} /> {state.status === "changed" && ( } tooltipTitle={"Undo"} onClick={undo} /> )}
); }; export const ValidationBox: FC<{ failures: MiniFailure[]; validate: (d: any) => MiniFailure[] | null; data: EditorData; onSave: (d: EditorData) => void; }> = (props) => { const [{ failures, data }, setState] = useState({ failures: props.failures, data: props.data, }); const onSave = (d: EditorData) => { const newData = { ...data, ...d, }; const newFails = props.validate(newData); if (newFails) { setState({ failures: newFails, data: newData, }); } else { setState({ failures: [], data: newData, }); } }; return (
    {failures.map((f, i) => ( <>
  • {f.path}:
      {f.message.map((m, j) => (
    • {m}
    • ))}
  • ))}
Please correct the automation file manually and then continue!
); };