Skip to content

Commit

Permalink
Merge pull request #98 from Tauffer-Consulting/feature/nodes-orientation
Browse files Browse the repository at this point in the history
Feature/Nodes orientation
  • Loading branch information
luiztauffer authored Oct 10, 2023
2 parents 38e75bd + 35b7138 commit 6de60aa
Show file tree
Hide file tree
Showing 12 changed files with 453 additions and 411 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ export const CustomConnectionLine: React.FC<ConnectionLineComponentProps> = ({
style={{
strokeWidth: 2,
}}
markerEnd={`url(#custom-arrow)`}
/>
</g>
);
Expand Down
50 changes: 0 additions & 50 deletions frontend/src/components/WorkflowPanel/DefaultNode/Handle.tsx

This file was deleted.

270 changes: 138 additions & 132 deletions frontend/src/components/WorkflowPanel/DefaultNode/index.tsx
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";
Loading

0 comments on commit 6de60aa

Please sign in to comment.