feat(kube): add YAML edit action to NamespaceList
Namespaces had a read-only table with no actions. Adds an edit button per row that fetches the namespace YAML via getResourceYamlCmd (cluster-scoped, empty namespace param) and opens EditResourceModal.
This commit is contained in:
parent
f8e29769ce
commit
3afa97b517
@ -1,6 +1,9 @@
|
|||||||
import React from "react";
|
import React, { useState } from "react";
|
||||||
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, Badge } from "@/components/ui";
|
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, Badge, Button } from "@/components/ui";
|
||||||
|
import { Pencil } from "lucide-react";
|
||||||
import type { NamespaceResourceInfo } from "@/lib/tauriCommands";
|
import type { NamespaceResourceInfo } from "@/lib/tauriCommands";
|
||||||
|
import { getResourceYamlCmd } from "@/lib/tauriCommands";
|
||||||
|
import { EditResourceModal } from "./EditResourceModal";
|
||||||
|
|
||||||
interface NamespaceListProps {
|
interface NamespaceListProps {
|
||||||
items: NamespaceResourceInfo[];
|
items: NamespaceResourceInfo[];
|
||||||
@ -14,21 +17,46 @@ function statusVariant(status: string): "success" | "destructive" | "secondary"
|
|||||||
return "secondary";
|
return "secondary";
|
||||||
}
|
}
|
||||||
|
|
||||||
export function NamespaceList({ items }: NamespaceListProps) {
|
export function NamespaceList({ items, clusterId }: NamespaceListProps) {
|
||||||
|
const [editState, setEditState] = useState<{
|
||||||
|
open: boolean;
|
||||||
|
name: string;
|
||||||
|
yaml: string;
|
||||||
|
} | null>(null);
|
||||||
|
const [editError, setEditError] = useState<string | null>(null);
|
||||||
|
|
||||||
|
const openEdit = async (ns: NamespaceResourceInfo) => {
|
||||||
|
setEditError(null);
|
||||||
|
try {
|
||||||
|
// Namespaces are cluster-scoped — pass empty string for namespace param
|
||||||
|
const yaml = await getResourceYamlCmd(clusterId, "namespaces", "", ns.name);
|
||||||
|
setEditState({ open: true, name: ns.name, yaml });
|
||||||
|
} catch (err) {
|
||||||
|
setEditError(err instanceof Error ? err.message : String(err));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="overflow-x-auto">
|
<div className="overflow-x-auto">
|
||||||
|
{editError && (
|
||||||
|
<div className="mb-2 rounded-md border border-destructive/50 bg-destructive/10 px-3 py-2 text-sm text-destructive">
|
||||||
|
{editError}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
<Table>
|
<Table>
|
||||||
<TableHeader>
|
<TableHeader>
|
||||||
<TableRow>
|
<TableRow>
|
||||||
<TableHead>Name</TableHead>
|
<TableHead>Name</TableHead>
|
||||||
<TableHead>Status</TableHead>
|
<TableHead>Status</TableHead>
|
||||||
<TableHead>Age</TableHead>
|
<TableHead>Age</TableHead>
|
||||||
|
<TableHead className="w-16 text-right">Actions</TableHead>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
</TableHeader>
|
</TableHeader>
|
||||||
<TableBody>
|
<TableBody>
|
||||||
{items.length === 0 ? (
|
{items.length === 0 ? (
|
||||||
<TableRow>
|
<TableRow>
|
||||||
<TableCell colSpan={3} className="text-center text-muted-foreground">
|
<TableCell colSpan={4} className="text-center text-muted-foreground">
|
||||||
No namespaces found
|
No namespaces found
|
||||||
</TableCell>
|
</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
@ -40,11 +68,35 @@ export function NamespaceList({ items }: NamespaceListProps) {
|
|||||||
<Badge variant={statusVariant(ns.status)}>{ns.status}</Badge>
|
<Badge variant={statusVariant(ns.status)}>{ns.status}</Badge>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell className="text-sm text-muted-foreground">{ns.age}</TableCell>
|
<TableCell className="text-sm text-muted-foreground">{ns.age}</TableCell>
|
||||||
|
<TableCell className="text-right">
|
||||||
|
<Button
|
||||||
|
size="sm"
|
||||||
|
variant="ghost"
|
||||||
|
className="h-7 w-7 p-0"
|
||||||
|
title="Edit YAML"
|
||||||
|
onClick={() => void openEdit(ns)}
|
||||||
|
>
|
||||||
|
<Pencil className="h-3.5 w-3.5" />
|
||||||
|
<span className="sr-only">Edit</span>
|
||||||
|
</Button>
|
||||||
|
</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
))
|
))
|
||||||
)}
|
)}
|
||||||
</TableBody>
|
</TableBody>
|
||||||
</Table>
|
</Table>
|
||||||
|
|
||||||
|
{editState && (
|
||||||
|
<EditResourceModal
|
||||||
|
isOpen={editState.open}
|
||||||
|
clusterId={clusterId}
|
||||||
|
namespace=""
|
||||||
|
resourceType="namespaces"
|
||||||
|
resourceName={editState.name}
|
||||||
|
initialYaml={editState.yaml}
|
||||||
|
onClose={() => setEditState(null)}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user