refactor(dashboard): restructure dashboard components and improve data handling

- Moved dashboard components (Donut, Gauge, Sparkline) to their own files for better organization.
- Created a new DashboardHeader component to manage the header state and display service status.
- Introduced a layout component for the dashboard to encapsulate common layout styles.
- Simplified the Dashboard component by utilizing new components and reducing inline logic.
- Added type definitions for dashboard data in a new types.ts file.
- Enhanced the visual representation of data with improved SVG elements and accessibility attributes.
- Removed redundant code and improved overall readability and maintainability.
This commit is contained in:
asepharyana
2026-07-23 15:02:53 +07:00
parent e529e8c2e6
commit 6b725f31b4
10 changed files with 906 additions and 655 deletions
+57
View File
@@ -0,0 +1,57 @@
export interface Service {
name: string;
state: string;
hasWeb: boolean;
}
export interface Trace {
service: string;
operation: string;
duration: number;
spans: number;
hasError: boolean;
}
export interface DashboardData {
services: Service[];
traces: Trace[];
node: {
cpu: number | null;
ram: number | null;
disk: number | null;
load1: number | null;
load5: number | null;
load15: number | null;
netIn: number | null;
netOut: number | null;
};
rps: number[];
latency: number[];
errors: number[];
traceVolume: number[];
links: { url: string; label: string }[];
}
export function safeDur(us: number): string {
if (us < 1000) return `${us}\u00b5s`;
if (us < 1_000_000) return `${(us / 1000).toFixed(1)}ms`;
return `${(us / 1_000_000).toFixed(2)}s`;
}
export function gaugeColor(v: number | null): string {
if (v === null) return "#3fb950";
if (v > 80) return "#f85149";
if (v > 60) return "#d29922";
return "#3fb950";
}
export function serviceIndicator(state: string): string {
switch (state) {
case "running":
return "bg-green-400";
case "jaeger":
return "bg-blue-400";
default:
return "bg-red-400";
}
}