import "./index.css"; import "./index.mobile.css"; import { AutomationEditor } from "components/AutomationEditor"; import { FC, ReactNode, useState } from "react"; import { AutomationData } from "types/automations"; import { defaultAutomation } from 'utils/defaults'; import { ArrowIcon } from "components/Icons"; import { ButtonIcon } from "components/Icons/ButtonIcons"; import { ApiService } from "apiService/core"; import { AutomationListBox } from "./AutomationListBox"; import { DAGAutomationFlowDims } from 'components/DAGFlow/types'; import useWindowSize from "utils/useWindowSize"; import { makeTagDB } from "./TagDB"; import LinearProgress from "@mui/material/LinearProgress"; import CircularProgress from "@mui/material/CircularProgress"; interface AutomationListParams { automations: AutomationData[]; onUpdate: (i: number, auto: AutomationData) => void; onAdd: (auto: AutomationData) => void; onRemove: (i: number) => void; dims: DAGAutomationFlowDims; children?: ReactNode; } export const AutomationList: FC = ({ automations, onUpdate, onAdd, onRemove, dims, children, }) => { // state const [hideList, setHideList] = useState(false); const [current, setCurrent] = useState(0); const { isMobile } = useWindowSize(); // alias const currentAuto = automations.length > 0 ? automations[current] : null; const tagDB = makeTagDB(automations); // render return
{ onAdd(defaultAutomation(String(Date.now()))); setCurrent(automations.length) }} onSelectAutomation={i => { setCurrent(i); if (isMobile) { setHideList(true) } }} selected={current} onRemove={onRemove} /> setHideList(!hideList)} className="automation-list--list-hide" Icon={ArrowIcon} />
{currentAuto ? onUpdate(current, a)} dims={dims} tagDB={tagDB} /> : <>}
{children}
} interface ConnectedAutomationListParams { dims: DAGAutomationFlowDims; api: ApiService; } export const ConnectedAutomationList: FC = ({ api: { state: { automations, }, removeAutomation, updateAutomation, }, dims }) => { if (!automations.ready) { return
} if (!automations.ok) { return Error {automations.error} } return updateAutomation({ auto, index: automations.data.totalItems + 1 })} onRemove={index => removeAutomation({ index })} onUpdate={(index, auto) => updateAutomation({ index, auto })} /> }