From 649c1fbdeb9430d4be9404de98a5195bac6ab030 Mon Sep 17 00:00:00 2001 From: Ari Date: Sun, 10 Jul 2022 14:13:31 -0400 Subject: [PATCH] add in tooltip --- .../components/DAGGraph/elements/constants.ts | 2 +- .../src/components/DAGGraph/elements/index.ts | 7 ++--- .../nodes/SequenceNode/SequenceNode.css | 7 +++++ .../SequenceNode/SequenceNode.stories.tsx | 6 +++++ .../SequenceNode/SequenceNodeElement.tsx | 23 ++++++++++++---- .../DAGGraph/nodes/SequenceNode/types.ts | 1 + .../src/components/DAGGraph/updater/index.ts | 26 +++++++++++++++---- 7 files changed, 58 insertions(+), 14 deletions(-) diff --git a/webapp/src/components/DAGGraph/elements/constants.ts b/webapp/src/components/DAGGraph/elements/constants.ts index 5a92372..094e120 100644 --- a/webapp/src/components/DAGGraph/elements/constants.ts +++ b/webapp/src/components/DAGGraph/elements/constants.ts @@ -22,7 +22,7 @@ export const DEFAULT_DIMS: DAGDims = { width: CIRCLE_SIZE, }, distanceFactor: { - node: 2, + node: 1.5, collection: 1.25, }, position: { diff --git a/webapp/src/components/DAGGraph/elements/index.ts b/webapp/src/components/DAGGraph/elements/index.ts index 0485bdd..52dded8 100644 --- a/webapp/src/components/DAGGraph/elements/index.ts +++ b/webapp/src/components/DAGGraph/elements/index.ts @@ -15,6 +15,7 @@ import { import { AutomationCondition } from "types/automations/conditions"; import { CollectionNodeMaker } from "../nodes/CollectionNode"; import { SequenceNodeMaker } from "../nodes/SequenceNode"; +import { getNodeType } from "utils/automations"; export const makeAutomationNodes = ( automation: AutomationActionData, @@ -70,7 +71,7 @@ export const makeTriggerNodes: ElementMaker = ( CollectionNodeMaker.makeElement({ id: nodeId, position }, dims, { ...dims.trigger, color: "red", - onAddNode: () => stateUpdater.basic.trigger.addNode(), + onAddNode: () => stateUpdater.basic.trigger.addNode(null), nodes: nodes.map((node, index) => ({ enabled: node.enabled ?? true, label: getDescriptionFromAutomationNode(node, namer, true), @@ -97,7 +98,7 @@ export const makeConditionNodes: ElementMaker = ( ...dims.condition, color: "blue", hasInput: !!lastNodeId, - onAddNode: stateUpdater.basic.condition.addNode, + onAddNode: () => stateUpdater.basic.condition.addNode(null), nodes: nodes.map((node, index) => ({ enabled: node.enabled ?? true, label: getDescriptionFromAutomationNode(node, namer, true), @@ -142,7 +143,7 @@ export const makeSequenceNodes: ElementMaker = ( }, dims, { - color: "green", + color: getNodeType(node) === "action" ? "green" : "blue", enabled: node.enabled ?? true, hasInput: true, label: getDescriptionFromAutomationNode(node, namer, true), diff --git a/webapp/src/components/DAGGraph/nodes/SequenceNode/SequenceNode.css b/webapp/src/components/DAGGraph/nodes/SequenceNode/SequenceNode.css index 32ed811..a9daef0 100644 --- a/webapp/src/components/DAGGraph/nodes/SequenceNode/SequenceNode.css +++ b/webapp/src/components/DAGGraph/nodes/SequenceNode/SequenceNode.css @@ -84,6 +84,13 @@ border-radius: 20px; } +.sequence-node--actions--move .icon-2 { + position: absolute; + bottom: 10%; + left: 60%; + font-size: 0.75em; +} + .sequence-node--actions--move.right { transform: rotate(180deg); } diff --git a/webapp/src/components/DAGGraph/nodes/SequenceNode/SequenceNode.stories.tsx b/webapp/src/components/DAGGraph/nodes/SequenceNode/SequenceNode.stories.tsx index b092430..f8b9875 100644 --- a/webapp/src/components/DAGGraph/nodes/SequenceNode/SequenceNode.stories.tsx +++ b/webapp/src/components/DAGGraph/nodes/SequenceNode/SequenceNode.stories.tsx @@ -91,4 +91,10 @@ OnMoveAllDirections.args = { left: console.log, right: console.log, }, + onAdd: { + up: console.log, + down: console.log, + left: console.log, + right: console.log, + }, }; diff --git a/webapp/src/components/DAGGraph/nodes/SequenceNode/SequenceNodeElement.tsx b/webapp/src/components/DAGGraph/nodes/SequenceNode/SequenceNodeElement.tsx index 05eacfc..dcac7d8 100644 --- a/webapp/src/components/DAGGraph/nodes/SequenceNode/SequenceNodeElement.tsx +++ b/webapp/src/components/DAGGraph/nodes/SequenceNode/SequenceNodeElement.tsx @@ -17,6 +17,7 @@ import { ButtonIcon } from "components/Icons/ButtonIcons"; import { SpeedDial } from "components/SpeedDial"; import { SequenceNodeElementProps } from "./types"; import { useSequenceNodeColor } from "./util"; +import { AddOutlined } from "@mui/icons-material"; export const SequenceNodeElement: FC< PropsWithChildren @@ -26,7 +27,7 @@ export const SequenceNodeElement: FC< width, onXClick, onEditClick = () => {}, - onAddNode, + onAdd = {}, onMove = {}, color, flipped, @@ -38,6 +39,7 @@ export const SequenceNodeElement: FC< const confirm = useConfirm(); const snackbr = useSnackbar(); const nodeColor = useSequenceNodeColor(color); + console.log({ onAdd }); return ( <>
{Object.entries(onMove).map(([key, action]) => ( - + + + ))} + {Object.entries(onAdd).map(([key, action]) => ( + + + ))} {onXClick && ( @@ -129,11 +142,11 @@ export const SequenceNodeElement: FC< {typeof label === "string" ? {label} : label}
- {onAddNode && ( + {/* {onAddNode && (
} onClick={onAddNode} />
- )} + )} */} ); diff --git a/webapp/src/components/DAGGraph/nodes/SequenceNode/types.ts b/webapp/src/components/DAGGraph/nodes/SequenceNode/types.ts index 9faf536..b922c70 100644 --- a/webapp/src/components/DAGGraph/nodes/SequenceNode/types.ts +++ b/webapp/src/components/DAGGraph/nodes/SequenceNode/types.ts @@ -11,6 +11,7 @@ export type SequenceNodeActions = { onSetEnabled: () => void; onAddNode: () => void; onMove: SequenceNodeOnMoveEvents; + onAdd: SequenceNodeOnMoveEvents; }; export type SequenceNodeOnMoveEvents = Partial< SequenceNodeOnMove<"up" | "down" | "left" | "right"> diff --git a/webapp/src/components/DAGGraph/updater/index.ts b/webapp/src/components/DAGGraph/updater/index.ts index 0f1e1f1..e80e3b6 100644 --- a/webapp/src/components/DAGGraph/updater/index.ts +++ b/webapp/src/components/DAGGraph/updater/index.ts @@ -36,12 +36,22 @@ export const createBasicUpdater = ...args[k].data.slice(i + 1), ]), - addNode: () => + addNode: (afterIndex: number | null) => args.openModal({ allowedTypes: mapAutoActionKeyToNodeType(k), saveBtnCreateText: true, node: JSON.parse(JSON.stringify(defaultNode)), - update: (n) => args[k].onUpdate([...args[k].data, n]), + update: (n) => { + if (afterIndex !== null) { + args[k].onUpdate([ + ...args[k].data.slice(0, afterIndex), + n, + ...args[k].data.slice(afterIndex), + ]); + } else { + args[k].onUpdate([...args[k].data, n]); + } + }, }), onMove: (i: number, direction: "back" | "forward") => { if (direction === "back" && i > 0) { @@ -121,9 +131,15 @@ export const createUpdater = ( } } // build add - let onAddNode: (() => void) | undefined = undefined; + let onAdd: SequenceNodeActions["onAdd"] = {}; if (flags.includeAdd) { - onAddNode = basic[k].addNode; + if (!flags.flipped) { + onAdd["left"] = () => basic[k].addNode(i); + onAdd["right"] = () => basic[k].addNode(i + 1); + } else { + onAdd["up"] = () => basic[k].addNode(i); + onAdd["down"] = () => basic[k].addNode(i + 1); + } } return { @@ -136,7 +152,7 @@ export const createUpdater = ( }), onXClick: () => basic[k].deleteNode(i), onSetEnabled: () => basic[k].setEnabled(i), - onAddNode, + onAdd, onMove, }; },