generated from Luis/nextjs-python-web-template
fixed height issue, fixed code for grouping in diagram
This commit is contained in:
@@ -154,6 +154,8 @@ export default function Client({
|
|||||||
setSnackbarOpen(false);
|
setSnackbarOpen(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
console.log("entity", entity);
|
||||||
|
|
||||||
if (services_loading) return <Skeleton height={500} />;
|
if (services_loading) return <Skeleton height={500} />;
|
||||||
if (!services) return <Alert severity="error">Client not found</Alert>;
|
if (!services) return <Alert severity="error">Client not found</Alert>;
|
||||||
|
|
||||||
@@ -193,7 +195,7 @@ export default function Client({
|
|||||||
IP: <code>{entity?.ip}</code>
|
IP: <code>{entity?.ip}</code>
|
||||||
</Typography>
|
</Typography>
|
||||||
<Typography color="text.primary" gutterBottom>
|
<Typography color="text.primary" gutterBottom>
|
||||||
Network: <code>{entity?.other?.network}</code>
|
Network: <code>{entity?.network}</code>
|
||||||
</Typography>
|
</Typography>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import {
|
|||||||
CssBaseline,
|
CssBaseline,
|
||||||
IconButton,
|
IconButton,
|
||||||
ThemeProvider,
|
ThemeProvider,
|
||||||
|
Tooltip,
|
||||||
useMediaQuery,
|
useMediaQuery,
|
||||||
} from "@mui/material";
|
} from "@mui/material";
|
||||||
import { StyledEngineProvider } from "@mui/material/styles";
|
import { StyledEngineProvider } from "@mui/material/styles";
|
||||||
@@ -84,6 +85,7 @@ export default function RootLayout({
|
|||||||
>
|
>
|
||||||
<div className="grid grid-cols-3">
|
<div className="grid grid-cols-3">
|
||||||
<div className="col-span-1">
|
<div className="col-span-1">
|
||||||
|
<Tooltip placement="right" title="Expand Sidebar">
|
||||||
<IconButton
|
<IconButton
|
||||||
style={{ padding: "12px" }}
|
style={{ padding: "12px" }}
|
||||||
hidden={true}
|
hidden={true}
|
||||||
@@ -91,6 +93,7 @@ export default function RootLayout({
|
|||||||
>
|
>
|
||||||
{!showSidebar && <MenuIcon />}
|
{!showSidebar && <MenuIcon />}
|
||||||
</IconButton>
|
</IconButton>
|
||||||
|
</Tooltip>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -1,51 +1,46 @@
|
|||||||
export const generateMermaidString = (data: any) => {
|
import { Eventmessage } from "@/api/model";
|
||||||
|
|
||||||
|
export const generateMermaidString = (data: Eventmessage[] | undefined) => {
|
||||||
if (!data || data.length === 0) return "";
|
if (!data || data.length === 0) return "";
|
||||||
|
|
||||||
// Extract unique participants
|
|
||||||
const participants = Array.from(
|
const participants = Array.from(
|
||||||
new Set(
|
new Set(data.flatMap((item) => [item.src_did, item.des_did])),
|
||||||
data
|
|
||||||
.map((item: any) => item.src_did)
|
|
||||||
.concat(data.map((item: any) => item.des_did)),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// Begin the sequence diagram definition
|
|
||||||
let mermaidString = "sequenceDiagram\n";
|
let mermaidString = "sequenceDiagram\n";
|
||||||
|
|
||||||
// Add participants to the diagram
|
|
||||||
participants.forEach((participant, index) => {
|
participants.forEach((participant, index) => {
|
||||||
mermaidString += ` participant ${String.fromCharCode(
|
mermaidString += ` participant ${String.fromCharCode(
|
||||||
65 + index,
|
65 + index,
|
||||||
)} as ${participant}\n`;
|
)} as ${participant}\n`;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Add messages to the diagram
|
let currentGroupId: number | null = null;
|
||||||
data.forEach((item: any, index: number) => {
|
|
||||||
|
data.forEach((item, index) => {
|
||||||
const srcParticipant = String.fromCharCode(
|
const srcParticipant = String.fromCharCode(
|
||||||
65 + participants.indexOf(item.src_did),
|
65 + participants.indexOf(item.src_did),
|
||||||
);
|
);
|
||||||
const desParticipant = String.fromCharCode(
|
const desParticipant = String.fromCharCode(
|
||||||
65 + participants.indexOf(item.des_did),
|
65 + participants.indexOf(item.des_did),
|
||||||
);
|
);
|
||||||
const timestamp = new Date(item.timestamp * 1000).toLocaleString(); // Convert Unix timestamp to readable date
|
const timestamp = new Date(item.timestamp * 1000).toLocaleString();
|
||||||
const message = item.msg.text || `Event message ${index + 1}`;
|
const message = item.msg.text || `Event message ${index + 1}`;
|
||||||
|
|
||||||
// If group_name or group_id exists, start an 'alt' block
|
if (item.group_id !== currentGroupId) {
|
||||||
if (item.group_id != null) {
|
if (currentGroupId !== null) {
|
||||||
mermaidString += ` alt ${item.group_name || item.group_id}\n`;
|
mermaidString += ` end\n`;
|
||||||
mermaidString += ` rect rgb(191, 223, 255)\n`;
|
}
|
||||||
|
mermaidString += ` alt Group ${item.group_id}\n`;
|
||||||
|
currentGroupId = item.group_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add the message interaction
|
|
||||||
mermaidString += ` ${srcParticipant}->>${desParticipant}: [${timestamp}] ${message}\n`;
|
mermaidString += ` ${srcParticipant}->>${desParticipant}: [${timestamp}] ${message}\n`;
|
||||||
|
});
|
||||||
|
|
||||||
// If there was an 'alt' block, close it
|
if (currentGroupId !== null) {
|
||||||
if (item.group_id != null) {
|
|
||||||
mermaidString += ` end\n`;
|
|
||||||
mermaidString += ` end\n`;
|
mermaidString += ` end\n`;
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
return mermaidString;
|
return mermaidString;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ const SequenceDiagram = () => {
|
|||||||
const mermaidRef: any = useRef(null);
|
const mermaidRef: any = useRef(null);
|
||||||
const [scale, setScale] = useState(1);
|
const [scale, setScale] = useState(1);
|
||||||
const hasData = eventMessagesData?.data && eventMessagesData?.data.length > 0;
|
const hasData = eventMessagesData?.data && eventMessagesData?.data.length > 0;
|
||||||
// const hasData = true;
|
|
||||||
|
|
||||||
const mermaidString = generateMermaidString(eventMessagesData?.data);
|
const mermaidString = generateMermaidString(eventMessagesData?.data);
|
||||||
|
|
||||||
@@ -51,7 +50,7 @@ const SequenceDiagram = () => {
|
|||||||
const svg = mermaidRef.current.querySelector("svg");
|
const svg = mermaidRef.current.querySelector("svg");
|
||||||
if (svg) {
|
if (svg) {
|
||||||
svg.style.transform = `scale(${scale})`;
|
svg.style.transform = `scale(${scale})`;
|
||||||
svg.style.transformOrigin = "top left"; // Set transform origin to top left
|
svg.style.transformOrigin = "top left";
|
||||||
mermaidRef.current.style.width = `${
|
mermaidRef.current.style.width = `${
|
||||||
svg.getBoundingClientRect().width * scale
|
svg.getBoundingClientRect().width * scale
|
||||||
}px`;
|
}px`;
|
||||||
@@ -131,10 +130,10 @@ const SequenceDiagram = () => {
|
|||||||
return <LoadingOverlay title="Loading Diagram" subtitle="Please wait..." />;
|
return <LoadingOverlay title="Loading Diagram" subtitle="Please wait..." />;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex w-full flex-col items-end">
|
<div className="flex flex-col items-end">
|
||||||
{hasData ? (
|
{hasData ? (
|
||||||
<>
|
<>
|
||||||
<div className="flex w-full justify-end gap-2.5 mb-5">
|
<div className="flex justify-end gap-2.5 mb-5">
|
||||||
<Tooltip placement="top" title="Refresh Diagram">
|
<Tooltip placement="top" title="Refresh Diagram">
|
||||||
<IconButton color="default" onClick={onRefresh}>
|
<IconButton color="default" onClick={onRefresh}>
|
||||||
<RefreshIcon />
|
<RefreshIcon />
|
||||||
@@ -166,7 +165,7 @@ const SequenceDiagram = () => {
|
|||||||
</IconButton>
|
</IconButton>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
</div>
|
</div>
|
||||||
<div className="w-full h-full overflow-auto p-2.5 box-border">
|
<div className="w-full p-2.5">
|
||||||
<div className="mermaid" ref={mermaidRef}></div>
|
<div className="mermaid" ref={mermaidRef}></div>
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import {
|
|||||||
ListItemButton,
|
ListItemButton,
|
||||||
ListItemIcon,
|
ListItemIcon,
|
||||||
ListItemText,
|
ListItemText,
|
||||||
|
Tooltip,
|
||||||
useMediaQuery,
|
useMediaQuery,
|
||||||
} from "@mui/material";
|
} from "@mui/material";
|
||||||
import Image from "next/image";
|
import Image from "next/image";
|
||||||
@@ -137,9 +138,14 @@ export function Sidebar(props: SidebarProps) {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="lg:absolute lg:right-0 lg:top-0">
|
<div className="lg:absolute lg:right-0 lg:top-0">
|
||||||
|
<Tooltip
|
||||||
|
placement="right"
|
||||||
|
title={collapseMenuOpen ? "Close Sidebar" : "Expand Sidebar"}
|
||||||
|
>
|
||||||
<IconButton size="large" className="text-white" onClick={onClose}>
|
<IconButton size="large" className="text-white" onClick={onClose}>
|
||||||
<ChevronLeftIcon fontSize="inherit" />
|
<ChevronLeftIcon fontSize="inherit" />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
|
</Tooltip>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<Divider
|
<Divider
|
||||||
|
|||||||
@@ -10,10 +10,6 @@ export const HomeTableConfig = [
|
|||||||
{
|
{
|
||||||
key: "network",
|
key: "network",
|
||||||
label: "Network",
|
label: "Network",
|
||||||
render: (value: any) => {
|
|
||||||
const renderedValue = typeof value === "object" ? value?.network : "-";
|
|
||||||
return renderedValue;
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: "ip",
|
key: "ip",
|
||||||
@@ -22,11 +18,6 @@ export const HomeTableConfig = [
|
|||||||
{
|
{
|
||||||
key: "roles",
|
key: "roles",
|
||||||
label: "Roles",
|
label: "Roles",
|
||||||
render: (value: any) => {
|
|
||||||
const renderedValue =
|
|
||||||
typeof value === "object" ? value?.roles?.join(", ") : "-";
|
|
||||||
return renderedValue;
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: "attached",
|
key: "attached",
|
||||||
|
|||||||
Reference in New Issue
Block a user