import "./DAGNode.css"; import { PencilIcon } from "components/Icons"; import { NodeColor } from "types/graphs"; import { useNodeStyles } from "./styles"; import { Handle, Position } from "react-flow-renderer"; import { FC, ReactNode, useState } from "react"; import ClickAwayListener from "@mui/material/ClickAwayListener"; import IconButton from "@mui/material/IconButton"; import DeleteForeverIcon from "@mui/icons-material/DeleteForever"; import SettingsOutlinedIcon from "@mui/icons-material/SettingsOutlined"; import ArrowBackIcon from "@mui/icons-material/ArrowBack"; import { createToNodeMakerFunction } from "./helpers"; export type DAGNodeOnMove = Record< Direction, () => void >; export type DAGNodeOnMoveEvents = Partial< DAGNodeOnMove<"up" | "down" | "left" | "right"> >; export interface DAGNodeDataProps { onXClick?: () => void; onEditClick?: () => void; onMove?: DAGNodeOnMoveEvents; color: NodeColor; label: ReactNode; hasInput?: boolean; accentBackground?: boolean; } export interface DAGNodeProps extends DAGNodeDataProps { height: number; width: number; flipped: boolean; } export const makeConditionPoint = createToNodeMakerFunction< { totalConditions: number; onEditClick: () => void; }, DAGNodeProps >((pre, { conditionWidth, conditionHeight, flipped }) => ({ color: "lblue", accentBackground: true, label: `${pre.totalConditions} Condition${ pre.totalConditions !== 1 ? "s" : "" }`, height: conditionHeight, width: conditionWidth, hasInput: true, onEditClick: pre.onEditClick, flipped, })); export const makeActionPoint = createToNodeMakerFunction< DAGNodeDataProps, DAGNodeProps >((pre, { nodeHeight, nodeWidth, flipped }) => ({ ...pre, height: nodeHeight, width: nodeWidth, flipped, })); export const DAGNode: FC = ({ label, height, width, onXClick, onEditClick = () => {}, onMove = {}, color, hasInput = false, accentBackground = false, flipped, }) => { const { classes, theme } = useNodeStyles({ color, nodeHeight: height, nodeWidth: width, accentBackground, }); const [open, setOpen] = useState(false); return ( <> {hasInput && ( )}
setOpen(false)}>
setOpen(!open)} onMouseEnter={() => setOpen(true)} >
{Object.entries(onMove).map(([key, action]) => ( ))}
{label}
); };