-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #98 from Tauffer-Consulting/feature/nodes-orientation
Feature/Nodes orientation
- Loading branch information
Showing
12 changed files
with
453 additions
and
411 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 0 additions & 50 deletions
50
frontend/src/components/WorkflowPanel/DefaultNode/Handle.tsx
This file was deleted.
Oops, something went wrong.
270 changes: 138 additions & 132 deletions
270
frontend/src/components/WorkflowPanel/DefaultNode/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,148 +1,154 @@ | ||
import { Paper, Typography } from "@mui/material"; | ||
import theme from "providers/theme.config"; | ||
import React, { type CSSProperties, memo, useMemo, useState } from "react"; | ||
import { Handle, type Position } from "reactflow"; | ||
import { getUuidSlice } from "utils"; | ||
import React, { type CSSProperties, memo, useMemo } from "react"; | ||
import { Handle, Position } from "reactflow"; | ||
import { getUuidSlice, useMouseProximity } from "utils"; | ||
|
||
import { type DefaultNodeProps } from "../types"; | ||
|
||
export const CustomNode = memo<DefaultNodeProps>( | ||
({ id, sourcePosition, targetPosition, data, selected }) => { | ||
const [hovered, setHovered] = useState(false); | ||
export const CustomNode = memo<DefaultNodeProps>(({ id, data, selected }) => { | ||
const [isNear, ElementRef] = useMouseProximity(150); | ||
|
||
const handleStyle = useMemo( | ||
() => | ||
hovered | ||
? { | ||
border: 0, | ||
borderRadius: "16px", | ||
backgroundColor: theme.palette.grey[400], | ||
transition: "ease 100", | ||
zIndex: 2, | ||
} | ||
: { | ||
border: 0, | ||
borderRadius: "16px", | ||
backgroundColor: "transparent", | ||
transition: "ease 100", | ||
zIndex: 2, | ||
}, | ||
[hovered], | ||
); | ||
const handleStyle = useMemo<CSSProperties>( | ||
() => | ||
isNear | ||
? { | ||
border: 0, | ||
borderRadius: "16px", | ||
backgroundColor: theme.palette.info.main, | ||
transition: "ease 100", | ||
zIndex: 2, | ||
width: "12px", | ||
height: "12px", | ||
} | ||
: { | ||
border: 0, | ||
borderRadius: "16px", | ||
backgroundColor: "transparent", | ||
transition: "ease 100", | ||
zIndex: 2, | ||
}, | ||
[isNear], | ||
); | ||
|
||
const extendedClassExt = useMemo<"input" | "default" | "output">(() => { | ||
const dominoReactflowClassTypeMap = Object.freeze({ | ||
source: "input", | ||
default: "default", | ||
sink: "output", | ||
}); | ||
if ( | ||
!data?.style.nodeType || | ||
!["default", "source", "sink"].includes(data?.style.nodeType) | ||
) { | ||
return "default"; | ||
} else { | ||
return dominoReactflowClassTypeMap[data.style.nodeType]; | ||
} | ||
}, [data]); | ||
const extendedClassExt = useMemo<"input" | "default" | "output">(() => { | ||
const dominoReactflowClassTypeMap = Object.freeze({ | ||
source: "input", | ||
default: "default", | ||
sink: "output", | ||
}); | ||
if ( | ||
!data?.style.nodeType || | ||
!["default", "source", "sink"].includes(data?.style.nodeType) | ||
) { | ||
return "default"; | ||
} else { | ||
return dominoReactflowClassTypeMap[data.style.nodeType]; | ||
} | ||
}, [data]); | ||
|
||
const nodeTypeRenderHandleMap = useMemo( | ||
() => ({ | ||
input: { | ||
renderTargetHandle: false, | ||
renderSourceHandle: true, | ||
}, | ||
output: { | ||
renderTargetHandle: true, | ||
renderSourceHandle: false, | ||
}, | ||
default: { | ||
renderTargetHandle: true, | ||
renderSourceHandle: true, | ||
}, | ||
}), | ||
[], | ||
); | ||
const nodeTypeRenderHandleMap = useMemo( | ||
() => ({ | ||
input: { | ||
renderTargetHandle: false, | ||
renderSourceHandle: true, | ||
}, | ||
output: { | ||
renderTargetHandle: true, | ||
renderSourceHandle: false, | ||
}, | ||
default: { | ||
renderTargetHandle: true, | ||
renderSourceHandle: true, | ||
}, | ||
}), | ||
[], | ||
); | ||
|
||
const nodeStyle = useMemo<CSSProperties>(() => { | ||
return { | ||
...data.style.nodeStyle, | ||
display: "flex", | ||
flexDirection: "row", | ||
justifyContent: "center", | ||
alignItems: "center", | ||
const nodeStyle = useMemo<CSSProperties>(() => { | ||
return { | ||
...data.style.nodeStyle, | ||
display: "flex", | ||
flexDirection: "row", | ||
justifyContent: "center", | ||
alignItems: "center", | ||
|
||
position: "relative", | ||
width: 150, | ||
height: 70, | ||
lineHeight: "60px", | ||
border: selected ? "2px" : "", | ||
borderStyle: selected ? "solid" : "", | ||
borderColor: selected ? theme.palette.info.dark : "", | ||
borderRadius: selected ? "3px" : "", | ||
...(data.validationError && { | ||
backgroundColor: theme.palette.error.light, | ||
color: theme.palette.error.contrastText, | ||
}), | ||
}; | ||
}, [data, selected]); | ||
position: "relative", | ||
width: 150, | ||
height: 70, | ||
lineHeight: "60px", | ||
border: selected ? "2px" : "", | ||
borderStyle: selected ? "solid" : "", | ||
borderColor: selected ? theme.palette.info.dark : "", | ||
borderRadius: selected ? "3px" : "", | ||
...(data.validationError && { | ||
backgroundColor: theme.palette.error.light, | ||
color: theme.palette.error.contrastText, | ||
}), | ||
}; | ||
}, [data, selected]); | ||
|
||
return ( | ||
<> | ||
{nodeTypeRenderHandleMap[extendedClassExt].renderSourceHandle && ( | ||
<Handle | ||
type="source" | ||
position={sourcePosition as Position} | ||
id={`source-${id}`} | ||
style={handleStyle} | ||
/> | ||
)} | ||
{nodeTypeRenderHandleMap[extendedClassExt].renderTargetHandle && ( | ||
<Handle | ||
type="target" | ||
position={targetPosition as Position} | ||
id={`target-${id}`} | ||
style={handleStyle} | ||
/> | ||
)} | ||
<Paper | ||
elevation={selected ? 12 : 3} | ||
onMouseEnter={() => { | ||
setHovered(true); | ||
}} | ||
onMouseLeave={() => { | ||
setHovered(false); | ||
const { sourcePosition, targetPosition } = useMemo( | ||
() => ({ | ||
...(data.orientation === "horizontal" | ||
? { | ||
targetPosition: Position.Left, | ||
sourcePosition: Position.Right, | ||
} | ||
: { | ||
targetPosition: Position.Top, | ||
sourcePosition: Position.Bottom, | ||
}), | ||
}), | ||
[data], | ||
); | ||
|
||
return ( | ||
<> | ||
{nodeTypeRenderHandleMap[extendedClassExt].renderSourceHandle && ( | ||
<Handle | ||
type="source" | ||
position={sourcePosition} | ||
id={`source-${id}`} | ||
style={handleStyle} | ||
/> | ||
)} | ||
{nodeTypeRenderHandleMap[extendedClassExt].renderTargetHandle && ( | ||
<Handle | ||
type="target" | ||
position={targetPosition} | ||
id={`target-${id}`} | ||
style={handleStyle} | ||
/> | ||
)} | ||
<Paper elevation={selected ? 12 : 3} sx={nodeStyle} ref={ElementRef}> | ||
<div | ||
style={{ | ||
display: "flex", | ||
flexDirection: "column", | ||
alignItems: "center", | ||
justifyContent: "center", | ||
}} | ||
sx={nodeStyle} | ||
> | ||
<div | ||
style={{ | ||
display: "flex", | ||
flexDirection: "column", | ||
alignItems: "center", | ||
justifyContent: "center", | ||
}} | ||
<Typography | ||
component="div" | ||
variant="h5" | ||
style={{ fontSize: 12 }} | ||
fontWeight={500} | ||
> | ||
{data?.style?.label ? data?.style?.label : data?.name} | ||
</Typography> | ||
<Typography | ||
variant="subtitle1" | ||
color="text.secondary" | ||
style={{ fontSize: 10 }} | ||
> | ||
<Typography | ||
component="div" | ||
variant="h5" | ||
style={{ fontSize: 12 }} | ||
fontWeight={500} | ||
> | ||
{data?.style?.label ? data?.style?.label : data?.name} | ||
</Typography> | ||
<Typography | ||
variant="subtitle1" | ||
color="text.secondary" | ||
style={{ fontSize: 10 }} | ||
> | ||
{getUuidSlice(id)} | ||
</Typography> | ||
</div> | ||
</Paper> | ||
</> | ||
); | ||
}, | ||
); | ||
{getUuidSlice(id)} | ||
</Typography> | ||
</div> | ||
</Paper> | ||
</> | ||
); | ||
}); | ||
|
||
CustomNode.displayName = "CustomNode"; |
Oops, something went wrong.