mirror of
https://github.com/YuzuZensai/Minikura.git
synced 2026-09-13 10:49:21 +00:00
♻️ refactor: remove unused code
This commit is contained in:
@@ -1,83 +0,0 @@
|
||||
import type { TopologyEdge, TopologyNode } from "@/lib/topology-types";
|
||||
|
||||
const LAYOUT_CONFIG = {
|
||||
TIER_SPACING: 300,
|
||||
NODE_SPACING: 250,
|
||||
START_X: 150,
|
||||
START_Y: 100,
|
||||
} as const;
|
||||
|
||||
export function applyHierarchicalLayout(
|
||||
nodes: TopologyNode[],
|
||||
edges: TopologyEdge[]
|
||||
): { nodes: TopologyNode[]; edges: TopologyEdge[] } {
|
||||
const proxyNodes = nodes.filter((n) => n.data.type === "proxy");
|
||||
const serverNodes = nodes.filter((n) => n.data.type === "server");
|
||||
|
||||
const layoutedNodes: TopologyNode[] = [];
|
||||
|
||||
const maxNodesInTier = Math.max(proxyNodes.length, serverNodes.length);
|
||||
const tierWidth = maxNodesInTier * LAYOUT_CONFIG.NODE_SPACING;
|
||||
|
||||
const proxyOffsetX = (tierWidth - proxyNodes.length * LAYOUT_CONFIG.NODE_SPACING) / 2;
|
||||
proxyNodes.forEach((node, index) => {
|
||||
const x = LAYOUT_CONFIG.START_X + proxyOffsetX + index * LAYOUT_CONFIG.NODE_SPACING;
|
||||
const y = LAYOUT_CONFIG.START_Y;
|
||||
|
||||
layoutedNodes.push({
|
||||
...node,
|
||||
position: { x, y },
|
||||
});
|
||||
});
|
||||
|
||||
const serverOffsetX = (tierWidth - serverNodes.length * LAYOUT_CONFIG.NODE_SPACING) / 2;
|
||||
serverNodes.forEach((node, index) => {
|
||||
const x = LAYOUT_CONFIG.START_X + serverOffsetX + index * LAYOUT_CONFIG.NODE_SPACING;
|
||||
const y = LAYOUT_CONFIG.START_Y + LAYOUT_CONFIG.TIER_SPACING;
|
||||
|
||||
layoutedNodes.push({
|
||||
...node,
|
||||
position: { x, y },
|
||||
});
|
||||
});
|
||||
|
||||
return {
|
||||
nodes: layoutedNodes,
|
||||
edges,
|
||||
};
|
||||
}
|
||||
|
||||
export function applyGridLayout(
|
||||
nodes: TopologyNode[],
|
||||
edges: TopologyEdge[]
|
||||
): { nodes: TopologyNode[]; edges: TopologyEdge[] } {
|
||||
const columns = Math.ceil(Math.sqrt(nodes.length));
|
||||
|
||||
const layoutedNodes = nodes.map((node, index) => ({
|
||||
...node,
|
||||
position: {
|
||||
x: LAYOUT_CONFIG.START_X + (index % columns) * LAYOUT_CONFIG.NODE_SPACING,
|
||||
y: LAYOUT_CONFIG.START_Y + Math.floor(index / columns) * LAYOUT_CONFIG.TIER_SPACING,
|
||||
},
|
||||
}));
|
||||
|
||||
return {
|
||||
nodes: layoutedNodes,
|
||||
edges,
|
||||
};
|
||||
}
|
||||
|
||||
export function layoutTopologyGraph(
|
||||
nodes: TopologyNode[],
|
||||
edges: TopologyEdge[]
|
||||
): { nodes: TopologyNode[]; edges: TopologyEdge[] } {
|
||||
if (nodes.length === 0) {
|
||||
return { nodes: [], edges: [] };
|
||||
}
|
||||
|
||||
if (nodes.length < 20) {
|
||||
return applyHierarchicalLayout(nodes, edges);
|
||||
}
|
||||
|
||||
return applyGridLayout(nodes, edges);
|
||||
}
|
||||
@@ -9,24 +9,10 @@ import type {
|
||||
PodInfo,
|
||||
StatefulSetInfo,
|
||||
} from "@minikura/api";
|
||||
import { getErrorMessage } from "@minikura/shared/errors";
|
||||
import { useCallback, useEffect, useRef, useState } from "react";
|
||||
import { api } from "@/lib/api-client";
|
||||
|
||||
function getErrorMessage(error: unknown) {
|
||||
if (error instanceof Error) {
|
||||
return error.message;
|
||||
}
|
||||
|
||||
if (typeof error === "object" && error) {
|
||||
const value = "value" in error ? error.value : error;
|
||||
if (typeof value === "object" && value && "message" in value) {
|
||||
return String(value.message);
|
||||
}
|
||||
}
|
||||
|
||||
return "Failed to fetch Kubernetes resources";
|
||||
}
|
||||
|
||||
export function useK8sResources() {
|
||||
const [status, setStatus] = useState<K8sStatus | null>(null);
|
||||
const [pods, setPods] = useState<PodInfo[]>([]);
|
||||
|
||||
@@ -6,6 +6,9 @@ import type {
|
||||
ReverseProxyServer,
|
||||
} from "@minikura/api";
|
||||
import type { Edge, Node } from "@xyflow/react";
|
||||
import type { ResourceMetrics } from "./k8s-metrics";
|
||||
|
||||
export type { ResourceMetrics };
|
||||
|
||||
export type HealthStatus = "healthy" | "degraded" | "unhealthy" | "unknown";
|
||||
|
||||
@@ -13,13 +16,6 @@ export type NodeType = "server" | "proxy" | "k8s-node";
|
||||
|
||||
export type EdgeType = "proxy-to-server" | "pod-to-node";
|
||||
|
||||
export interface ResourceMetrics {
|
||||
cpuUsage?: string;
|
||||
memoryUsage?: string;
|
||||
cpuUsagePercent?: number;
|
||||
memoryUsagePercent?: number;
|
||||
}
|
||||
|
||||
export interface K8sNodeMetadata {
|
||||
node: K8sNodeSummary;
|
||||
podCount: number;
|
||||
|
||||
Reference in New Issue
Block a user