tftsr-devops_investigation/src/pages/Kubernetes/KubernetesPage.tsx
Shaun Arman 6c54479ecd
All checks were successful
Test / frontend-tests (pull_request) Successful in 1m23s
Test / frontend-typecheck (pull_request) Successful in 1m29s
PR Review Automation / review (pull_request) Successful in 3m4s
Test / rust-fmt-check (pull_request) Successful in 11m30s
Test / rust-clippy (pull_request) Successful in 13m23s
Test / rust-tests (pull_request) Successful in 15m11s
feat(kube): add Kubernetes management GUI components
- Add ClusterList, PortForwardList, AddClusterModal, PortForwardForm components
- Add KubernetesPage component with cluster and port forward management
- Add TypeScript types for Kubernetes management (ClusterInfo, PortForwardRequest, PortForwardResponse)
- Add 6 IPC commands to tauriCommands.ts for cluster and port forward management
- Write unit tests for Kubernetes IPC commands (6 tests)
- All 308 Rust tests passing
- All 98 frontend tests passing
- TypeScript type check passing
- Project builds successfully
2026-06-06 12:46:33 -05:00

118 lines
3.6 KiB
TypeScript

import React, { useState, useEffect } from "react";
import { Server, Activity } from "lucide-react";
import { ClusterList } from "@/components/Kubernetes/ClusterList";
import { PortForwardList } from "@/components/Kubernetes/PortForwardList";
import { AddClusterModal } from "@/components/Kubernetes/AddClusterModal";
import { PortForwardForm } from "@/components/Kubernetes/PortForwardForm";
import type { ClusterInfo, PortForwardResponse } from "@/lib/tauriCommands";
import {
listClustersCmd,
removeClusterCmd,
listPortForwardsCmd,
stopPortForwardCmd,
} from "@/lib/tauriCommands";
export function KubernetesPage() {
const [clusters, setClusters] = useState<ClusterInfo[]>([]);
const [portForwards, setPortForwards] = useState<PortForwardResponse[]>([]);
const [isLoading, setIsLoading] = useState(true);
const [isAddClusterOpen, setIsAddClusterOpen] = useState(false);
const [isStartPortForwardOpen, setIsStartPortForwardOpen] = useState(false);
useEffect(() => {
loadData();
}, []);
const loadData = async () => {
setIsLoading(true);
try {
const [clustersData, portForwardsData] = await Promise.all([
listClustersCmd(),
listPortForwardsCmd(),
]);
setClusters(clustersData);
setPortForwards(portForwardsData);
} catch (err) {
console.error("Failed to load data:", err);
} finally {
setIsLoading(false);
}
};
const handleRemoveCluster = async (clusterId: string) => {
try {
await removeClusterCmd(clusterId);
setClusters((prev) => prev.filter((c) => c.id !== clusterId));
} catch (err) {
console.error("Failed to remove cluster:", err);
alert("Failed to remove cluster");
}
};
const handleStopPortForward = async (id: string) => {
try {
await stopPortForwardCmd(id);
setPortForwards((prev) => prev.filter((pf) => pf.id !== id));
} catch (err) {
console.error("Failed to stop port forward:", err);
alert("Failed to stop port forward");
}
};
const handleAddCluster = (cluster: ClusterInfo) => {
setClusters((prev) => [...prev, cluster]);
};
const handleStartPortForward = (portForward: PortForwardResponse) => {
setPortForwards((prev) => [...prev, portForward]);
};
if (isLoading) {
return (
<div className="flex items-center justify-center h-full">
<div className="flex flex-col items-center gap-4">
<div className="w-8 h-8 border-4 border-primary border-t-transparent rounded-full animate-spin" />
<p className="text-muted-foreground">Loading Kubernetes resources...</p>
</div>
</div>
);
}
return (
<div className="h-full overflow-y-auto p-6 space-y-8">
<div className="flex flex-col gap-2">
<h1 className="text-3xl font-bold tracking-tight">Kubernetes Management</h1>
<p className="text-muted-foreground">
Manage your Kubernetes clusters and port forwarding sessions
</p>
</div>
<div className="grid gap-8">
<ClusterList
clusters={clusters}
onAdd={() => setIsAddClusterOpen(true)}
onRemove={handleRemoveCluster}
/>
<PortForwardList
portForwards={portForwards}
onStart={() => setIsStartPortForwardOpen(true)}
onStop={handleStopPortForward}
/>
</div>
<AddClusterModal
isOpen={isAddClusterOpen}
onClose={() => setIsAddClusterOpen(false)}
onAdd={handleAddCluster}
/>
<PortForwardForm
isOpen={isStartPortForwardOpen}
onClose={() => setIsStartPortForwardOpen(false)}
onStart={handleStartPortForward}
/>
</div>
);
}