Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: enhance visualization of connectors #257

Merged
merged 8 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 36 additions & 16 deletions packages/otelbin/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/otelbin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"dependencies": {
"@clerk/nextjs": "^4.27.1",
"@clerk/themes": "^1.7.6",
"@dagrejs/dagre": "^1.0.4",
"@jest/globals": "^29.7.0",
"@monaco-editor/react": "^4.6.0",
"@radix-ui/react-accordion": "^1.1.2",
Expand Down
61 changes: 61 additions & 0 deletions packages/otelbin/src/components/react-flow/CyclicErrorEdge.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// SPDX-FileCopyrightText: 2023 Dash0 Inc.
// SPDX-License-Identifier: Apache-2.0

import { type EdgeProps, BaseEdge, getSmoothStepPath, EdgeLabelRenderer } from "reactflow";

interface CyclicErrorEdgeProps extends EdgeProps {
pathOptions?: {
centerX: number;
centerY: number;
offset?: number;
borderRadius?: number;
};
}

export default function CyclicErrorEdge({
id,
sourceX,
sourceY,
sourcePosition,
targetX,
targetY,
targetPosition,
pathOptions,
style,
...props
}: CyclicErrorEdgeProps) {
const [edgePath, labelX, labelY] = getSmoothStepPath({
sourceX,
sourceY,
sourcePosition,
targetX,
targetY,
targetPosition,
...pathOptions,
});

return (
<>
<BaseEdge
id={id}
path={edgePath}
{...props}
style={{
...style,
}}
/>
<EdgeLabelRenderer>
<span
style={{
position: "absolute",
transform: `translate(50%, -100%) translate(${labelX}px, ${labelY}px)`,
pointerEvents: "all",
...style,
}}
>
connector cycle
</span>
</EdgeLabelRenderer>
</>
);
}
23 changes: 17 additions & 6 deletions packages/otelbin/src/components/react-flow/ReactFlow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import type { IItem, Document } from "../monaco-editor/parseYaml";
import ExportersNode from "./node-types/ExportersNode";
import ReceiversNode from "./node-types/ReceiversNode";
import ProcessorsNode from "./node-types/ProcessorsNode";
import { useLayout } from "./layout/useLayout";
import CyclicErrorEdge from "./CyclicErrorEdge";

type EditorRefType = RefObject<editor.IStandaloneCodeEditor | null>;

Expand All @@ -46,9 +48,11 @@ export default function Flow({
return docService?.value.items.find((item: IItem) => item.key?.source === "pipelines");
}, [value]);
const initNodes = useNodes(jsonData);
const [nodes, setNodes] = useNodesState(initNodes !== undefined ? initNodes : []);
const initEdges = useEdgeCreator(nodes);
const [edges, setEdges] = useEdgesState(initEdges);
const initEdges = useEdgeCreator(initNodes ?? []);
const { nodes: layoutedNodes, edges: layoutedEdges } = useLayout(initNodes ?? [], initEdges);

const [nodes, setNodes] = useNodesState(layoutedNodes !== undefined ? layoutedNodes : []);
const [edges, setEdges] = useEdgesState(layoutedEdges);
const widthSelector = (state: { width: number }) => state.width;
const reactFlowWidth = useStore(widthSelector);

Expand All @@ -58,15 +62,15 @@ export default function Flow({

useEffect(() => {
if (jsonData) {
setEdges(initEdges);
setNodes(initNodes !== undefined ? initNodes : []);
setEdges(layoutedEdges);
setNodes(layoutedNodes !== undefined ? layoutedNodes : []);
reactFlowInstance.fitView();
} else {
setNodes(EmptyStateNodeData);
setEdges([]);
reactFlowInstance.fitView();
}
}, [initNodes, initEdges, value, jsonData, setEdges, setNodes, reactFlowInstance]);
}, [layoutedNodes, layoutedEdges, value, jsonData, setEdges, setNodes, reactFlowInstance]);

const nodeTypes = useMemo(
() => ({
Expand All @@ -77,6 +81,12 @@ export default function Flow({
}),
[]
);
const edgeTypes = useMemo(
() => ({
cyclicErrorEdge: CyclicErrorEdge,
}),
[]
);
const EmptyStateNodeType = useMemo(() => ({ emptyState: EmptyStateNode }), []);
const { setCenter } = useReactFlow();
const nodeInfo = reactFlowInstance.getNodes();
Expand Down Expand Up @@ -220,6 +230,7 @@ export default function Flow({
edges={edges}
defaultEdgeOptions={edgeOptions}
nodeTypes={jsonData.service ? nodeTypes : EmptyStateNodeType}
edgeTypes={edgeTypes}
fitView
className="disable-attribution bg-default"
proOptions={{
Expand Down
Loading
Loading