tftsr-devops_investigation/src/components/Kubernetes/DeploymentDetail.tsx
Shaun Arman 3f4869af01
Some checks failed
PR Review Automation / review (pull_request) Has been cancelled
Test / frontend-typecheck (pull_request) Has been cancelled
Test / rust-clippy (pull_request) Has been cancelled
Test / frontend-tests (pull_request) Has been cancelled
Test / rust-fmt-check (pull_request) Has been cancelled
Test / rust-tests (pull_request) Has been cancelled
feat(kubernetes): implement Lens Desktop v5 feature-parity UI
Complete overhaul of the Kubernetes management page from a basic config
panel into a full Lens-style IDE shell with 26 resource types, real-time
data, and a comprehensive test suite.

Layout & navigation:
- Rewrite KubernetesPage as a Lens v5-style shell: collapsible sidebar
  (Workloads / Services & Networking / Config & Storage / Access Control /
  Cluster), top hotbar with cluster+namespace selectors, Ctrl+K command
  palette
- All 26 resource types now accessible via sidebar navigation (previously 5)

New resource types (Rust + TypeScript + React):
- StorageClasses, NetworkPolicies, ResourceQuotas, LimitRanges
- 4 new Tauri commands registered in generate_handler![]

Component implementations (replacing stubs with real IPC):
- Terminal: full xterm.js with multi-tab sessions and exec_pod IPC
- YamlEditor: Monaco editor with YAML syntax highlighting
- MetricsChart: recharts LineChart/BarChart
- ClusterOverview: live node/pod/deployment/namespace counts
- ClusterDetails: real kubeconfig + node data
- PodDetail, DeploymentDetail, ServiceDetail, ConfigMapDetail, SecretDetail:
  all connected to real IPC data, zero hardcoded values
- CreateResourceModal, EditResourceModal: wired to createResourceCmd /
  editResourceCmd
- RbacViewer: live data from 4 RBAC IPC commands
- RbacEditor: create roles/cluster-roles via YAML editor
- CommandPalette: 12 real navigation commands, keyboard nav

Dependencies added: xterm@5, xterm-addon-fit, xterm-addon-web-links,
@monaco-editor/react@4, recharts@2

Tooling:
- Replace eslint-plugin-react (incompatible with ESLint 10) with
  @eslint-react/eslint-plugin; fix eslint.config.js for flat config
- Fix pre-existing hoisting lint errors in Security.tsx, PortForwardForm.tsx
- Fix eventBus.ts: replace all `any` generics with `unknown`

Tests: 251 passing across 35 test files (was 94/19)
- 16 new test files covering all new and fixed components (TDD)
- npx tsc --noEmit: 0 errors
- cargo clippy -- -D warnings: 0 warnings
- cargo fmt --check: passes
- eslint src/ --max-warnings 0: 0 issues
2026-06-07 16:41:28 -05:00

275 lines
11 KiB
TypeScript

import React from "react";
import { Card, CardHeader, CardTitle, CardContent } from "@/components/ui";
import { Badge } from "@/components/ui";
import { Tabs, TabsList, TabsTrigger, TabsContent } from "@/components/ui";
import { Button } from "@/components/ui";
import { X, Loader2 } from "lucide-react";
import { YamlEditor } from "./YamlEditor";
import { scaleDeploymentCmd, restartDeploymentCmd, rollbackDeploymentCmd } from "@/lib/tauriCommands";
import type { DeploymentInfo } from "@/lib/tauriCommands";
interface DeploymentDetailProps {
clusterId: string;
namespace: string;
deployment: DeploymentInfo;
onClose?: () => void;
}
export function DeploymentDetail({ clusterId, namespace, deployment, onClose }: DeploymentDetailProps) {
const [activeTab, setActiveTab] = React.useState("overview");
const [replicaCount, setReplicaCount] = React.useState(deployment.replicas);
const [scaleLoading, setScaleLoading] = React.useState(false);
const [scaleError, setScaleError] = React.useState<string | null>(null);
const [scaleSuccess, setScaleSuccess] = React.useState(false);
const [restartLoading, setRestartLoading] = React.useState(false);
const [restartError, setRestartError] = React.useState<string | null>(null);
const [rollbackLoading, setRollbackLoading] = React.useState(false);
const [rollbackError, setRollbackError] = React.useState<string | null>(null);
const handleScale = async () => {
setScaleLoading(true);
setScaleError(null);
setScaleSuccess(false);
try {
await scaleDeploymentCmd(clusterId, namespace, deployment.name, replicaCount);
setScaleSuccess(true);
} catch (err) {
setScaleError(err instanceof Error ? err.message : String(err));
} finally {
setScaleLoading(false);
}
};
const handleRestart = async () => {
setRestartLoading(true);
setRestartError(null);
try {
await restartDeploymentCmd(clusterId, namespace, deployment.name);
} catch (err) {
setRestartError(err instanceof Error ? err.message : String(err));
} finally {
setRestartLoading(false);
}
};
const handleRollback = async () => {
setRollbackLoading(true);
setRollbackError(null);
try {
await rollbackDeploymentCmd(clusterId, namespace, deployment.name);
} catch (err) {
setRollbackError(err instanceof Error ? err.message : String(err));
} finally {
setRollbackLoading(false);
}
};
return (
<div className="h-full flex flex-col">
<div className="flex items-center justify-between mb-4">
<div className="flex items-center gap-2">
<h2 className="text-xl font-semibold">Deployment: {deployment.name}</h2>
<Badge variant="outline">{namespace}</Badge>
</div>
<Button variant="ghost" size="sm" onClick={onClose}>
<X className="w-4 h-4" />
</Button>
</div>
<Tabs value={activeTab} onValueChange={setActiveTab}>
<TabsList className="grid grid-cols-3 mb-4">
<TabsTrigger value="overview">Overview</TabsTrigger>
<TabsTrigger value="actions">Actions</TabsTrigger>
<TabsTrigger value="yaml">YAML</TabsTrigger>
</TabsList>
<div className="flex-1 overflow-hidden">
<TabsContent value="overview" className="h-full overflow-y-auto">
<div className="grid grid-cols-1 lg:grid-cols-2 gap-4">
<Card>
<CardHeader>
<CardTitle>Deployment Information</CardTitle>
</CardHeader>
<CardContent className="space-y-2">
<div className="flex items-center justify-between">
<span className="text-sm text-muted-foreground">Name</span>
<span className="font-mono">{deployment.name}</span>
</div>
<div className="flex items-center justify-between">
<span className="text-sm text-muted-foreground">Namespace</span>
<span className="font-mono">{namespace}</span>
</div>
<div className="flex items-center justify-between">
<span className="text-sm text-muted-foreground">Ready</span>
<span className="font-mono">{deployment.ready}</span>
</div>
<div className="flex items-center justify-between">
<span className="text-sm text-muted-foreground">Replicas</span>
<span>{deployment.replicas}</span>
</div>
<div className="flex items-center justify-between">
<span className="text-sm text-muted-foreground">Up-to-date</span>
<span>{deployment.up_to_date}</span>
</div>
<div className="flex items-center justify-between">
<span className="text-sm text-muted-foreground">Available</span>
<span>{deployment.available}</span>
</div>
<div className="flex items-center justify-between">
<span className="text-sm text-muted-foreground">Age</span>
<span className="text-sm">{deployment.age}</span>
</div>
</CardContent>
</Card>
{Object.keys(deployment.labels).length > 0 && (
<Card>
<CardHeader>
<CardTitle>Labels</CardTitle>
</CardHeader>
<CardContent>
<div className="flex flex-wrap gap-2">
{Object.entries(deployment.labels).map(([k, v]) => (
<Badge key={k} variant="secondary">
{k}={v}
</Badge>
))}
</div>
</CardContent>
</Card>
)}
</div>
</TabsContent>
<TabsContent value="actions" className="h-full overflow-y-auto">
<div className="space-y-4">
<Card>
<CardHeader>
<CardTitle>Scale</CardTitle>
</CardHeader>
<CardContent className="space-y-3">
<div className="flex items-center gap-3">
<label htmlFor="replica-input" className="text-sm text-muted-foreground">
Replicas
</label>
<input
id="replica-input"
type="number"
min={0}
value={replicaCount}
onChange={(e) => setReplicaCount(Number(e.target.value))}
className="w-24 border rounded px-2 py-1 text-sm bg-background"
/>
<Button
data-testid="scale-button"
size="sm"
onClick={() => void handleScale()}
disabled={scaleLoading}
>
{scaleLoading ? (
<>
<Loader2 className="w-4 h-4 mr-2 animate-spin" />
Scaling
</>
) : (
"Scale"
)}
</Button>
</div>
{scaleLoading && (
<div data-testid="scale-loading" className="flex items-center gap-2 text-sm text-muted-foreground">
<Loader2 className="w-4 h-4 animate-spin" />
Scaling deployment
</div>
)}
{scaleError && (
<div data-testid="scale-error" className="text-sm text-red-500">
Scale failed: {scaleError}
</div>
)}
{scaleSuccess && (
<div className="text-sm text-green-500">
Scaled to {replicaCount} replica{replicaCount !== 1 ? "s" : ""}.
</div>
)}
</CardContent>
</Card>
<Card>
<CardHeader>
<CardTitle>Restart</CardTitle>
</CardHeader>
<CardContent className="space-y-3">
<p className="text-sm text-muted-foreground">
Performs a rolling restart of all pods in this deployment.
</p>
<Button
data-testid="restart-button"
variant="outline"
size="sm"
onClick={() => void handleRestart()}
disabled={restartLoading}
>
{restartLoading ? (
<>
<Loader2 className="w-4 h-4 mr-2 animate-spin" />
Restarting
</>
) : (
"Restart Deployment"
)}
</Button>
{restartError && (
<div className="text-sm text-red-500">Restart failed: {restartError}</div>
)}
</CardContent>
</Card>
<Card>
<CardHeader>
<CardTitle>Rollback</CardTitle>
</CardHeader>
<CardContent className="space-y-3">
<p className="text-sm text-muted-foreground">
Roll back to the previous revision of this deployment.
</p>
<Button
data-testid="rollback-button"
variant="destructive"
size="sm"
onClick={() => void handleRollback()}
disabled={rollbackLoading}
>
{rollbackLoading ? (
<>
<Loader2 className="w-4 h-4 mr-2 animate-spin" />
Rolling back
</>
) : (
"Rollback Deployment"
)}
</Button>
{rollbackError && (
<div className="text-sm text-red-500">Rollback failed: {rollbackError}</div>
)}
</CardContent>
</Card>
</div>
</TabsContent>
<TabsContent value="yaml" className="h-full">
<YamlEditor
readOnly
showControls={false}
content={JSON.stringify(deployment, null, 2)}
/>
</TabsContent>
</div>
</Tabs>
</div>
);
}