remove condition nodes

This commit is contained in:
ari committed 2021-12-16 15:47:59 -05:00
1 parent 49bb35717f
commit fff15f65ce
3 files changed
+31 -10

No files matched your search

+3 -2
View File
@@ -21,7 +21,8 @@ export const DAGCircle = ({
}: AddProps) => { }: AddProps) => {
const { classes } = useCircleStyles({ const { classes } = useCircleStyles({
size: size * 0.9, size: size * 0.9,
hasOnFunction: !!onEdit || !!onAdd hasOnFunction: !!onEdit || !!onAdd,
hasRemoveFunction: !!onRemove,
}); });
return <> return <>
<foreignObject x={x} y={y} width={size} height={size}> <foreignObject x={x} y={y} width={size} height={size}>
@@ -38,7 +39,7 @@ export const DAGCircle = ({
onClick={onAdd} onClick={onAdd}
/> />
: "else"} : "else"}
{onRemove ? <TrashIcon className={classes.trashIcon} /> : <></>} {onRemove ? <TrashIcon className={classes.trashIcon} onClick={onRemove} /> : <></>}
</div> </div>
</foreignObject> </foreignObject>
</> </>
+11 -8
View File
@@ -152,15 +152,16 @@ export const useNodeStyles = createAppUseStyles<{
export const useCircleStyles = createAppUseStyles<{ export const useCircleStyles = createAppUseStyles<{
size: number, size: number,
hasOnFunction: boolean, hasOnFunction: boolean,
hasRemoveFunction: boolean,
}>(theme => ({ }>(theme => ({
root: ({size, hasOnFunction}) => ({ root: ({size, hasOnFunction, hasRemoveFunction}) => ({
backgroundColor: Color(theme.primary).set('rgb.g', 100).hex(), backgroundColor: Color(theme.primary).set('rgb.g', 100).hex(),
borderRadius: 500, borderRadius: hasRemoveFunction ? 10 : 500,
height: size, height: size,
width: size, width: size,
cursor: hasOnFunction ? "pointer" : 'default', cursor: hasOnFunction ? "pointer" : 'default',
"&:hover": { "&:hover": {
backgroundColor: hasOnFunction ? backgroundColor: (hasOnFunction && !hasRemoveFunction) ?
Color(theme.primary).set('rgb.g', 150).hex() : Color(theme.primary).set('rgb.g', 150).hex() :
Color(theme.primary).set('rgb.g', 100).hex(), Color(theme.primary).set('rgb.g', 100).hex(),
}, },
@@ -170,14 +171,16 @@ export const useCircleStyles = createAppUseStyles<{
alignItems: 'center', alignItems: 'center',
}), }),
icon: { icon: {
padding: "15%", "&:hover": {
borderRadius: 500,
background: Color(theme.primary).set('rgb.g', 150).hex(),
}
}, },
trashIcon: { trashIcon: {
position: 'absolute', padding: 1,
top: 0,
left: 0,
"&:hover": { "&:hover": {
fill: theme.secondary, borderRadius: 500,
background: Color(theme.primary).set('rgb.g', 150).hex(),
cursor: 'pointer', cursor: 'pointer',
} }
} }
@@ -45,6 +45,7 @@ function* dealWithNested(
sequence: AutomationSequenceNode[], sequence: AutomationSequenceNode[],
openModal: UpdateModalState, openModal: UpdateModalState,
onEdit?: () => void, onEdit?: () => void,
onRemove?: () => void,
): Generator<DAGElement> { ): Generator<DAGElement> {
const np = offsetPoint(innerStartLoc, [0.5, 0]); const np = offsetPoint(innerStartLoc, [0.5, 0]);
yield { yield {
@@ -53,18 +54,21 @@ function* dealWithNested(
p2: innerStartLoc, p2: innerStartLoc,
direction: '1->2', direction: '1->2',
} }
console.log(onRemove)
if (onEdit) { if (onEdit) {
yield { yield {
type: 'circle', type: 'circle',
loc: innerStartLoc, loc: innerStartLoc,
icon: 'edit', icon: 'edit',
onEdit, onEdit,
onRemove,
} }
} else { } else {
yield { yield {
type: 'circle', type: 'circle',
loc: innerStartLoc, loc: innerStartLoc,
icon: 'blank', icon: 'blank',
onRemove,
} }
} }
yield { yield {
@@ -109,6 +113,7 @@ function* dealWithChoose(
node.action_data, node.action_data,
updateData, updateData,
), ),
createOnRemoveForChooseNode(node.action_data, updateData, j)
)) { )) {
yield elm yield elm
if (elm.type === 'node') { if (elm.type === 'node') {
@@ -238,3 +243,15 @@ export const onModalOpenForConditions = (
] ]
}), }),
}) })
const createOnRemoveForChooseNode = (
data: ChooseAction['action_data'],
updateData: (data: ChooseAction['action_data']) => void,
j: number
) => () => updateData({
...data,
choose: [
...data.choose.slice(0, j),
...data.choose.slice(j+1),
]
})