From 49bb35717f049b940885079aa4c75a44aa5e82cd Mon Sep 17 00:00:00 2001 From: Ari Sosnovsky Date: Thu, 16 Dec 2021 15:28:18 -0500 Subject: [PATCH] added trash icon --- webapp/src/components/DAGSvgs/DAGBoard.tsx | 35 ++++++++++++++----- .../components/DAGSvgs/DAGCircle.stories.tsx | 11 ++++++ webapp/src/components/DAGSvgs/DAGCircle.tsx | 5 ++- webapp/src/components/DAGSvgs/styles.ts | 9 +++++ webapp/src/components/Icons/index.stories.tsx | 3 +- webapp/src/components/Icons/index.tsx | 4 +++ .../src/components/SequenceNodes/positions.ts | 24 +++++++++---- 7 files changed, 73 insertions(+), 18 deletions(-) diff --git a/webapp/src/components/DAGSvgs/DAGBoard.tsx b/webapp/src/components/DAGSvgs/DAGBoard.tsx index 9715b23..0aa8585 100644 --- a/webapp/src/components/DAGSvgs/DAGBoard.tsx +++ b/webapp/src/components/DAGSvgs/DAGBoard.tsx @@ -6,15 +6,28 @@ import { DAGNode } from "./DAGNode"; import { DAGEdge } from "./DAGEdge"; import { AddButton } from "./AddButton"; import { IteratorWrap } from "utils/iter"; -import { DAGCircle } from "./DAGCircle"; +import { DAGCircle, AddProps } from "./DAGCircle"; import { getDescriptionFromAutomationNode } from "utils/formatting"; -export interface DAGCircleElm { +export type DAGCircleElm = { type: 'circle'; loc: Point; - onClick?: ['add', () => void] | ['edit', () => void]; -} +} & ( + { + icon: 'add', + onAdd: () => void; + } | + { + icon: 'edit', + onEdit: () => void; + onRemove?: () => void; + } | + { + icon: 'blank', + onRemove?: () => void; + } + ) export interface DAGNodeElm { type: 'node'; loc: Point; @@ -138,11 +151,15 @@ export function* mapDataToElements({ break case 'circle': const loc = mapWithNode(elm.loc, [0, st.nodeHeight / 2 - st.circleSize / 2]); - const clickProps = elm.onClick ? ( - elm.onClick[0] === 'add' ? - { onAdd: elm.onClick[1] } : - { onEdit: elm.onClick[1] } - ) : {} + const clickProps: Partial = {} + if (elm.icon === 'add') { + clickProps.onAdd = elm.onAdd; + } else if (elm.icon === 'edit') { + clickProps.onEdit = elm.onEdit + clickProps.onRemove = elm.onRemove + } else { + clickProps.onRemove = elm.onRemove + } yield = args => { loc={[args.loc[0] + 2 * args.size, args.loc[1]]} onEdit={args.onEdit} /> + + } diff --git a/webapp/src/components/DAGSvgs/DAGCircle.tsx b/webapp/src/components/DAGSvgs/DAGCircle.tsx index ee45463..50f5b99 100644 --- a/webapp/src/components/DAGSvgs/DAGCircle.tsx +++ b/webapp/src/components/DAGSvgs/DAGCircle.tsx @@ -1,6 +1,6 @@ // import "./DAGCircle.css"; import { Point } from "types/graphs"; -import { AddIcon, PencilIcon } from '../Icons/index'; +import { AddIcon, PencilIcon, TrashIcon } from '../Icons/index'; import { useCircleStyles } from './styles'; @@ -8,6 +8,7 @@ import { useCircleStyles } from './styles'; export interface AddProps { onEdit?: () => void; onAdd?: () => void; + onRemove?: () => void; loc: Point, size: number, } @@ -16,6 +17,7 @@ export const DAGCircle = ({ size, onEdit, onAdd, + onRemove, }: AddProps) => { const { classes } = useCircleStyles({ size: size * 0.9, @@ -36,6 +38,7 @@ export const DAGCircle = ({ onClick={onAdd} /> : "else"} + {onRemove ? : <>} diff --git a/webapp/src/components/DAGSvgs/styles.ts b/webapp/src/components/DAGSvgs/styles.ts index 77a176a..65b89b0 100644 --- a/webapp/src/components/DAGSvgs/styles.ts +++ b/webapp/src/components/DAGSvgs/styles.ts @@ -171,5 +171,14 @@ export const useCircleStyles = createAppUseStyles<{ }), icon: { padding: "15%", + }, + trashIcon: { + position: 'absolute', + top: 0, + left: 0, + "&:hover": { + fill: theme.secondary, + cursor: 'pointer', + } } })) diff --git a/webapp/src/components/Icons/index.stories.tsx b/webapp/src/components/Icons/index.stories.tsx index 6e70630..f3c0473 100644 --- a/webapp/src/components/Icons/index.stories.tsx +++ b/webapp/src/components/Icons/index.stories.tsx @@ -1,7 +1,7 @@ import { ComponentStory } from "@storybook/react"; import { usePageTheme } from "styles/page"; import { IconBase } from "./base"; -import { PencilIcon, CheckMarkIcon } from "."; +import { PencilIcon, CheckMarkIcon, TrashIcon } from "."; import { AddIcon } from './index'; export default { @@ -16,6 +16,7 @@ export const IconList: ComponentStory = (args) => { + } IconList.args = { diff --git a/webapp/src/components/Icons/index.tsx b/webapp/src/components/Icons/index.tsx index 12ac009..126a966 100644 --- a/webapp/src/components/Icons/index.tsx +++ b/webapp/src/components/Icons/index.tsx @@ -29,3 +29,7 @@ export const AddIcon: FC = props => + + +export const TrashIcon: FC = props => + diff --git a/webapp/src/components/SequenceNodes/positions.ts b/webapp/src/components/SequenceNodes/positions.ts index 48cc5a8..ca06ddf 100644 --- a/webapp/src/components/SequenceNodes/positions.ts +++ b/webapp/src/components/SequenceNodes/positions.ts @@ -53,10 +53,19 @@ function* dealWithNested( p2: innerStartLoc, direction: '1->2', } - yield { - type: 'circle', - loc: innerStartLoc, - onClick: onEdit ? ['edit', onEdit]: undefined, + if (onEdit) { + yield { + type: 'circle', + loc: innerStartLoc, + icon: 'edit', + onEdit, + } + } else { + yield { + type: 'circle', + loc: innerStartLoc, + icon: 'blank', + } } yield { type: 'edge', @@ -130,12 +139,13 @@ function* dealWithChoose( // add new conditions const newCondLoc = offsetPoint( nodeLoc, - [1, node.action_data.choose.length + 3 + offset.y], + [1, node.action_data.choose.length + 2.5 + offset.y], ); yield { type: 'circle', loc: newCondLoc, - onClick: ['add', () => updateData({ + icon: 'add', + onAdd: () => updateData({ ...node.action_data, choose: [ ...node.action_data.choose, @@ -144,7 +154,7 @@ function* dealWithChoose( sequence: [], } ] - })], + }), } }