import "./index.css"; import { AutomationEditor } from "components/AutomationEditor"; import { FC, 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'; interface AutomationListParams { automations: AutomationData[]; onUpdate: (i: number, auto: AutomationData) => void; onAdd: (auto: AutomationData) => void; onRemove: (i: number) => void; dims: DAGAutomationFlowDims; } export const AutomationList: FC = ({ automations, onUpdate, onAdd, onRemove, dims, children, }) => { // state const [hideList, setHideList] = useState(false); const [current, setCurrent] = useState(0); // alias const currentAuto = automations.length > 0 ? automations[current] : null; const automationListListCls = "automation-list--list" + (hideList ? " hide" : " show") // render return
{ onAdd(defaultAutomation(`shortu-${automations.length}`)); setCurrent(automations.length) }} onSelectAutomation={setCurrent} onRemove={onRemove} /> setHideList(!hideList)} className="automation-list--list-hide" > {ArrowIcon}
{currentAuto ? onUpdate(current, a)} dims={dims} /> : <>}
{children}
} interface ConnectedAutomationListParams { dims: DAGAutomationFlowDims; api: ApiService; } export const ConnectedAutomationList: FC = ({ api: { state: { automations, }, removeAutomation, updateAutomation, }, dims }) => { if (!automations.ready) { return Loading... } 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 })} /> }