mirror of
https://github.com/openziti/zrok.git
synced 2025-01-09 15:38:21 +01:00
first round of custom nodes for visualizer (#799)
This commit is contained in:
parent
9f2a335ac5
commit
8582077990
17
ui100/AccountNode.tsx
Normal file
17
ui100/AccountNode.tsx
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import {Handle, Position} from "@xyflow/react";
|
||||||
|
import {Grid2} from "@mui/material";
|
||||||
|
import AccountIcon from "@mui/icons-material/Person4";
|
||||||
|
|
||||||
|
const AccountNode = ({ data }) => {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Handle type="source" position={Position.Bottom} />
|
||||||
|
<Grid2 container sx={{ flexGrow: 1, p: 1 }} alignItems="center">
|
||||||
|
<Grid2 display="flex"><AccountIcon sx={{ fontSize: 15, mr: 0.5 }}/></Grid2>
|
||||||
|
<Grid2 display="flex">{data.label}</Grid2>
|
||||||
|
</Grid2>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default AccountNode;
|
22
ui100/src/EnvironmentNode.tsx
Normal file
22
ui100/src/EnvironmentNode.tsx
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
import {Handle, Position} from "@xyflow/react";
|
||||||
|
import {Grid2} from "@mui/material";
|
||||||
|
import EnvironmentIcon from "@mui/icons-material/Computer";
|
||||||
|
|
||||||
|
const EnvironmentNode = ({ data }) => {
|
||||||
|
let shareHandle = <Handle type="source" position={Position.Bottom} />;
|
||||||
|
if(data.empty) {
|
||||||
|
shareHandle = <></>;
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Handle type="target" position={Position.Top} />
|
||||||
|
{shareHandle}
|
||||||
|
<Grid2 container sx={{ flexGrow: 1, p: 1 }} alignItems="center">
|
||||||
|
<Grid2 display="flex"><EnvironmentIcon sx={{ fontSize: 15, mr: 0.5 }}/></Grid2>
|
||||||
|
<Grid2 display="flex">{data.label}</Grid2>
|
||||||
|
</Grid2>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default EnvironmentNode;
|
17
ui100/src/ShareNode.tsx
Normal file
17
ui100/src/ShareNode.tsx
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import {Handle, Position} from "@xyflow/react";
|
||||||
|
import {Grid2} from "@mui/material";
|
||||||
|
import ShareIcon from "@mui/icons-material/Share";
|
||||||
|
|
||||||
|
const ShareNode = ({ data }) => {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Handle type="target" position={Position.Top} />
|
||||||
|
<Grid2 container sx={{ flexGrow: 1, p: 1 }} alignItems="center">
|
||||||
|
<Grid2 display="flex"><ShareIcon sx={{ fontSize: 15, mr: 0.5 }}/></Grid2>
|
||||||
|
<Grid2 display="flex">{data.label}</Grid2>
|
||||||
|
</Grid2>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default ShareNode;
|
@ -4,11 +4,16 @@ import {Background, Controls, ReactFlow, ReactFlowProvider, useEdgesState, useNo
|
|||||||
import {VisualOverview} from "./model/visualizer.ts";
|
import {VisualOverview} from "./model/visualizer.ts";
|
||||||
import {useEffect} from "react";
|
import {useEffect} from "react";
|
||||||
import {stratify, tree} from "d3-hierarchy";
|
import {stratify, tree} from "d3-hierarchy";
|
||||||
|
import ShareNode from "./ShareNode.tsx";
|
||||||
|
import EnvironmentNode from "./EnvironmentNode.tsx";
|
||||||
|
import AccountNode from "../AccountNode.tsx";
|
||||||
|
|
||||||
interface VisualizerProps {
|
interface VisualizerProps {
|
||||||
overview: VisualOverview;
|
overview: VisualOverview;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const nodeTypes = { account: AccountNode, environment: EnvironmentNode, share: ShareNode };
|
||||||
|
|
||||||
const Visualizer = ({ overview }: VisualizerProps) => {
|
const Visualizer = ({ overview }: VisualizerProps) => {
|
||||||
const [nodes, setNodes, onNodesChange] = useNodesState([]);
|
const [nodes, setNodes, onNodesChange] = useNodesState([]);
|
||||||
const [edges, setEdges, onEdgesChange] = useEdgesState([]);
|
const [edges, setEdges, onEdgesChange] = useEdgesState([]);
|
||||||
@ -43,6 +48,7 @@ const Visualizer = ({ overview }: VisualizerProps) => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<ReactFlow
|
<ReactFlow
|
||||||
|
nodeTypes={nodeTypes}
|
||||||
nodes={nodes}
|
nodes={nodes}
|
||||||
edges={edges}
|
edges={edges}
|
||||||
onNodesChange={onNodesChange}
|
onNodesChange={onNodesChange}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import {Overview} from "../api";
|
import {Overview} from "../api";
|
||||||
import {Edge, Node} from "@xyflow/react";
|
import {Edge, Node} from "@xyflow/react";
|
||||||
import ShareIcon from "@mui/icons-material/Share";
|
|
||||||
|
|
||||||
export class VisualOverview {
|
export class VisualOverview {
|
||||||
nodes: Node[];
|
nodes: Node[];
|
||||||
@ -10,7 +9,7 @@ export class VisualOverview {
|
|||||||
const buildVisualizerGraph = (overview: Overview): VisualOverview => {
|
const buildVisualizerGraph = (overview: Overview): VisualOverview => {
|
||||||
let out = new VisualOverview();
|
let out = new VisualOverview();
|
||||||
out.nodes = [
|
out.nodes = [
|
||||||
{ id: "0", position: { x: 0, y: 0 }, data: { label: "michael@quigley.com" }, type: "input" }
|
{ id: "0", position: { x: 0, y: 0 }, data: { label: "michael@quigley.com" }, type: "account" }
|
||||||
];
|
];
|
||||||
out.edges = [];
|
out.edges = [];
|
||||||
|
|
||||||
@ -19,8 +18,8 @@ const buildVisualizerGraph = (overview: Overview): VisualOverview => {
|
|||||||
let envNode = {
|
let envNode = {
|
||||||
id: env.environment.zId,
|
id: env.environment.zId,
|
||||||
position: { x: 0, y: 0 },
|
position: { x: 0, y: 0 },
|
||||||
data: { label: env.environment?.description! },
|
data: { label: env.environment?.description!, empty: true },
|
||||||
type: "output",
|
type: "environment",
|
||||||
}
|
}
|
||||||
out.nodes.push(envNode);
|
out.nodes.push(envNode);
|
||||||
out.edges.push({
|
out.edges.push({
|
||||||
@ -29,13 +28,13 @@ const buildVisualizerGraph = (overview: Overview): VisualOverview => {
|
|||||||
target: env.environment.zId
|
target: env.environment.zId
|
||||||
});
|
});
|
||||||
if(env.shares) {
|
if(env.shares) {
|
||||||
envNode.type = "default";
|
envNode.data.empty = false;
|
||||||
env.shares.forEach(shr => {
|
env.shares.forEach(shr => {
|
||||||
out.nodes.push({
|
out.nodes.push({
|
||||||
id: shr.token!,
|
id: shr.token!,
|
||||||
position: { x: 0, y: 0 },
|
position: { x: 0, y: 0 },
|
||||||
data: { label: shr.token! },
|
data: { label: shr.token! },
|
||||||
type: "output",
|
type: "share",
|
||||||
});
|
});
|
||||||
out.edges.push({
|
out.edges.push({
|
||||||
id: env.environment?.zId + "-" + shr.token!,
|
id: env.environment?.zId + "-" + shr.token!,
|
||||||
|
Loading…
Reference in New Issue
Block a user