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
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
169 lines
5.1 KiB
TypeScript
169 lines
5.1 KiB
TypeScript
import React from "react";
|
|
import {
|
|
Dialog,
|
|
DialogContent,
|
|
DialogHeader,
|
|
DialogTitle,
|
|
DialogFooter,
|
|
} from "@/components/ui";
|
|
import { Button } from "@/components/ui";
|
|
import { Input } from "@/components/ui";
|
|
import { Label } from "@/components/ui";
|
|
import {
|
|
Select,
|
|
SelectContent,
|
|
SelectItem,
|
|
SelectTrigger,
|
|
SelectValue,
|
|
} from "@/components/ui";
|
|
import { Tabs, TabsList, TabsTrigger, TabsContent } from "@/components/ui";
|
|
import { YamlEditor } from "./YamlEditor";
|
|
import { editResourceCmd } from "@/lib/tauriCommands";
|
|
import { Loader2 } from "lucide-react";
|
|
|
|
interface EditResourceModalProps {
|
|
isOpen: boolean;
|
|
clusterId: string;
|
|
namespace: string;
|
|
resourceType: string;
|
|
resourceName: string;
|
|
initialYaml?: string;
|
|
onClose?: () => void;
|
|
}
|
|
|
|
export function EditResourceModal({
|
|
isOpen,
|
|
clusterId,
|
|
namespace,
|
|
resourceType,
|
|
resourceName,
|
|
initialYaml = "",
|
|
onClose,
|
|
}: EditResourceModalProps) {
|
|
const [activeTab, setActiveTab] = React.useState("yaml");
|
|
const [name, setName] = React.useState(resourceName);
|
|
const [currentNamespace, setCurrentNamespace] = React.useState(namespace);
|
|
const [yamlContent, setYamlContent] = React.useState(initialYaml);
|
|
const [isLoading, setIsLoading] = React.useState(false);
|
|
const [error, setError] = React.useState<string | null>(null);
|
|
|
|
React.useEffect(() => {
|
|
setName(resourceName);
|
|
setCurrentNamespace(namespace);
|
|
setYamlContent(initialYaml);
|
|
}, [resourceName, namespace, initialYaml]);
|
|
|
|
const handleSubmit = async () => {
|
|
setIsLoading(true);
|
|
setError(null);
|
|
try {
|
|
await editResourceCmd(
|
|
clusterId,
|
|
currentNamespace,
|
|
resourceType,
|
|
name,
|
|
yamlContent
|
|
);
|
|
onClose?.();
|
|
} catch (err) {
|
|
setError(err instanceof Error ? err.message : String(err));
|
|
} finally {
|
|
setIsLoading(false);
|
|
}
|
|
};
|
|
|
|
return (
|
|
<Dialog open={isOpen} onOpenChange={() => onClose?.()}>
|
|
<DialogContent className="max-w-3xl">
|
|
<DialogHeader>
|
|
<DialogTitle>Edit Kubernetes Resource</DialogTitle>
|
|
</DialogHeader>
|
|
|
|
<Tabs value={activeTab} onValueChange={setActiveTab}>
|
|
<TabsList className="grid grid-cols-2 mb-4">
|
|
<TabsTrigger value="form">Form</TabsTrigger>
|
|
<TabsTrigger value="yaml">YAML</TabsTrigger>
|
|
</TabsList>
|
|
|
|
<div className="max-h-[60vh] overflow-y-auto">
|
|
<TabsContent value="form" className="space-y-4">
|
|
<div className="grid grid-cols-2 gap-4">
|
|
<div className="space-y-2">
|
|
<Label htmlFor="name">Name</Label>
|
|
<Input
|
|
id="name"
|
|
value={name}
|
|
onChange={(e) => setName(e.target.value)}
|
|
placeholder="Enter resource name"
|
|
/>
|
|
</div>
|
|
|
|
<div className="space-y-2">
|
|
<Label htmlFor="namespace">Namespace</Label>
|
|
<Select
|
|
value={currentNamespace}
|
|
onValueChange={setCurrentNamespace}
|
|
>
|
|
<SelectTrigger>
|
|
<SelectValue placeholder="Select namespace" />
|
|
</SelectTrigger>
|
|
<SelectContent>
|
|
<SelectItem value="default">default</SelectItem>
|
|
<SelectItem value="kube-system">kube-system</SelectItem>
|
|
<SelectItem value="kube-public">kube-public</SelectItem>
|
|
</SelectContent>
|
|
</Select>
|
|
</div>
|
|
</div>
|
|
|
|
<div className="p-4 bg-muted rounded-md">
|
|
<h4 className="text-sm font-medium mb-2">Resource Details</h4>
|
|
<div className="space-y-2 text-sm text-muted-foreground">
|
|
<p>Name: {name || "not specified"}</p>
|
|
<p>Namespace: {currentNamespace}</p>
|
|
<p>Type: {resourceType}</p>
|
|
</div>
|
|
</div>
|
|
</TabsContent>
|
|
|
|
<TabsContent value="yaml">
|
|
<div className="space-y-2">
|
|
<Label>Resource YAML</Label>
|
|
<YamlEditor
|
|
height="300px"
|
|
showControls={false}
|
|
content={yamlContent}
|
|
onChange={setYamlContent}
|
|
/>
|
|
</div>
|
|
</TabsContent>
|
|
</div>
|
|
|
|
{error && (
|
|
<p className="text-sm text-destructive mt-2">{error}</p>
|
|
)}
|
|
|
|
<DialogFooter>
|
|
<Button variant="outline" onClick={onClose} disabled={isLoading}>
|
|
Cancel
|
|
</Button>
|
|
<Button
|
|
onClick={handleSubmit}
|
|
disabled={isLoading || !name}
|
|
>
|
|
{isLoading ? (
|
|
<>
|
|
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
|
|
Saving...
|
|
</>
|
|
) : (
|
|
"Save Changes"
|
|
)}
|
|
</Button>
|
|
</DialogFooter>
|
|
</Tabs>
|
|
</DialogContent>
|
|
</Dialog>
|
|
);
|
|
}
|