import { AutomationData } from "~/automations/types"; import { AutomationTrigger } from "~/automations/types/triggers"; import { getDescriptionFromAutomationNode } from "~/automations/utils"; import useWindowSize from "~/utils/useWindowSize"; import AutoInfoBox from "./AutoInfoBox"; import { NODE_HEIGHT, NODE_WIDTH } from "./constants"; import DAGEdge from "./DAGEdge"; import DAGNode from "./DAGNode"; import { SequenceNodes } from "./SequenceNodes"; import { useEditorStyles } from "./styles"; import { Point } from "./types"; import { AutomationSequenceNode } from '../../automations/types/index'; interface Props { automation: AutomationData; onUpdate: (auto: AutomationData) => void; } export default function AutomationEditor({ automation, onUpdate, }: Props) { // state const { ratioWbh } = useWindowSize(); const { classes, theme } = useEditorStyles({}); // alias const nHDF = 1.5 // node horizontal distance factor (aspect ratio) const graphHeight = 300; const graphWidth = Math.round(graphHeight * ratioWbh); const pointTrigToCond: Point = [NODE_WIDTH * nHDF, NODE_HEIGHT / 2] const updateSequence = (i: number, node: AutomationSequenceNode | null) => { const update = (sequence: AutomationSequenceNode[]) => onUpdate({ ...automation, sequence, }) if (node === null) { update([ ...automation.sequence.slice(0, i), ...automation.sequence.slice(i + 1), ]) } else { update([ ...automation.sequence.slice(0, i), node, ...automation.sequence.slice(i + 1), ]) } }; // render funcs const renderTrigger = (trigger: AutomationTrigger, i: number) => { const nodeLoc: Point = [0, i * NODE_HEIGHT]; return <> { onUpdate({ ...automation, trigger: [ ...automation.trigger.slice(0, i), ...automation.trigger.slice(i + 1), ] }) }} /> } // render return
= 0.75 ? 'row' : 'column' }}> onUpdate({ ...automation, metadata })} />
{automation.trigger.map(renderTrigger)}
}