feat: add delete functionality for namespace resources

This commit is contained in:
loveuer
2025-11-13 15:27:54 +08:00
parent 8ffb0eec09
commit 0536ce9755
3 changed files with 54 additions and 5 deletions

View File

@@ -198,6 +198,10 @@ export default function K8sResourceList() {
try {
let endpoint = '';
let kind = '';
let requestBody = {
name: deleteTarget.name,
namespace: deleteTarget.namespace
};
// Determine the correct endpoint based on the selected resource kind
switch (selectedKind.key) {
@@ -221,6 +225,12 @@ export default function K8sResourceList() {
endpoint = '/api/v1/k8s/configmap/delete'
kind = 'ConfigMap'
break
case 'namespace':
endpoint = '/api/v1/k8s/namespace/delete'
kind = 'Namespace'
// Namespace doesn't need namespace field
requestBody = { name: deleteTarget.name }
break
default:
throw new Error(`Unsupported resource kind: ${selectedKind.key}`)
}
@@ -228,10 +238,7 @@ export default function K8sResourceList() {
const res = await fetch(endpoint, {
method: 'DELETE',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
name: deleteTarget.name,
namespace: deleteTarget.namespace
}),
body: JSON.stringify(requestBody),
})
const result = await res.json()
@@ -381,7 +388,7 @@ export default function K8sResourceList() {
const getResourceColumns = () => {
switch (selectedKind.key) {
case 'namespace':
return ['Name', 'Status', 'Age']
return ['Name', 'Status', 'Age', 'Actions']
case 'deployment':
case 'statefulset':
return ['Name', 'Namespace', 'Replicas', 'Age', 'Actions']
@@ -421,6 +428,17 @@ export default function K8sResourceList() {
<TableCell>{metadata.name || '-'}</TableCell>
<TableCell>{status.phase || '-'}</TableCell>
<TableCell>{getAge(metadata.creationTimestamp)}</TableCell>
<TableCell>
<Tooltip title="删除">
<IconButton
size="small"
color="error"
onClick={() => openDeleteDialog(metadata.name, metadata.namespace)}
>
<DeleteIcon fontSize="small" />
</IconButton>
</Tooltip>
</TableCell>
</TableRow>
)
case 'deployment':