Feat: Add Edit Label button to Agent Actions
This commit is contained in:
1 parent
3524588e42
commit
19197ea9fa
3 files changed
+35
-2
No files matched your search
@@ -4,7 +4,7 @@ import { Column } from "@/components/ui/DataTable";
|
|||||||
import { Agent } from "@/lib/actions/agentsCore";
|
import { Agent } from "@/lib/actions/agentsCore";
|
||||||
import { Badge } from "@/components/ui/Badge";
|
import { Badge } from "@/components/ui/Badge";
|
||||||
import { resolveAgentLabel, type ManagedUser } from "@/lib/admin-api";
|
import { resolveAgentLabel, type ManagedUser } from "@/lib/admin-api";
|
||||||
import { Loader2, Trash2, CheckCircle2, XCircle, ChevronRight, UserCog, Eye, MapPin, Network } from "lucide-react";
|
import { Loader2, Trash2, CheckCircle2, XCircle, ChevronRight, UserCog, Eye, MapPin, Network, Edit2 } from "lucide-react";
|
||||||
|
|
||||||
interface GetColumnsProps {
|
interface GetColumnsProps {
|
||||||
role: string | null;
|
role: string | null;
|
||||||
@@ -18,6 +18,7 @@ interface GetColumnsProps {
|
|||||||
handleViewAs: (uuid: string, label: string) => void;
|
handleViewAs: (uuid: string, label: string) => void;
|
||||||
openDelete: (agent: Agent) => void;
|
openDelete: (agent: Agent) => void;
|
||||||
handleEditLocation?: (agentUuid: string, agentLabel: string) => void;
|
handleEditLocation?: (agentUuid: string, agentLabel: string) => void;
|
||||||
|
handleEditLabel?: (agentUuid: string, currentLabel: string) => void;
|
||||||
handleEditSubnet?: (agentUuid: string, agentLabel: string) => void;
|
handleEditSubnet?: (agentUuid: string, agentLabel: string) => void;
|
||||||
/** Set of agent UUIDs that already have a location saved */
|
/** Set of agent UUIDs that already have a location saved */
|
||||||
locationUuids?: Set<string>;
|
locationUuids?: Set<string>;
|
||||||
@@ -35,6 +36,7 @@ export function getAgentColumns({
|
|||||||
handleViewAs,
|
handleViewAs,
|
||||||
openDelete,
|
openDelete,
|
||||||
handleEditLocation,
|
handleEditLocation,
|
||||||
|
handleEditLabel,
|
||||||
handleEditSubnet,
|
handleEditSubnet,
|
||||||
locationUuids = new Set(),
|
locationUuids = new Set(),
|
||||||
}: GetColumnsProps): Column<Agent>[] {
|
}: GetColumnsProps): Column<Agent>[] {
|
||||||
@@ -128,6 +130,15 @@ export function getAgentColumns({
|
|||||||
</button>
|
</button>
|
||||||
{(role === 'SUPER_ADMIN' || role === 'TENANT_ADMIN') && (
|
{(role === 'SUPER_ADMIN' || role === 'TENANT_ADMIN') && (
|
||||||
<>
|
<>
|
||||||
|
{handleEditLabel && (
|
||||||
|
<button
|
||||||
|
onClick={(e) => { e.stopPropagation(); handleEditLabel(uuid, agentLabel); }}
|
||||||
|
className="p-1 text-blue-400 hover:text-blue-300 hover:bg-blue-950/30 rounded transition-colors"
|
||||||
|
title="Edit Label Agent"
|
||||||
|
>
|
||||||
|
<Edit2 className="w-4 h-4" />
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
<button
|
<button
|
||||||
onClick={(e) => { e.stopPropagation(); setAccountModalAgent({ uuid, label: agentLabel }); setAccountModalOpen(true); }}
|
onClick={(e) => { e.stopPropagation(); setAccountModalAgent({ uuid, label: agentLabel }); setAccountModalOpen(true); }}
|
||||||
className="p-1 text-emerald-400 hover:text-emerald-300 hover:bg-emerald-950/30 rounded transition-colors"
|
className="p-1 text-emerald-400 hover:text-emerald-300 hover:bg-emerald-950/30 rounded transition-colors"
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ export default function AgentsPage() {
|
|||||||
handleViewAs,
|
handleViewAs,
|
||||||
openDelete,
|
openDelete,
|
||||||
handleEditLocation,
|
handleEditLocation,
|
||||||
|
handleEditLabel,
|
||||||
} = useAgentsData();
|
} = useAgentsData();
|
||||||
|
|
||||||
const [subnetModalOpen, setSubnetModalOpen] = useState(false);
|
const [subnetModalOpen, setSubnetModalOpen] = useState(false);
|
||||||
@@ -82,6 +83,7 @@ export default function AgentsPage() {
|
|||||||
handleViewAs,
|
handleViewAs,
|
||||||
openDelete,
|
openDelete,
|
||||||
handleEditLocation,
|
handleEditLocation,
|
||||||
|
handleEditLabel,
|
||||||
handleEditSubnet,
|
handleEditSubnet,
|
||||||
locationUuids: new Set(locations.map((l: any) => l.agent_uuid)),
|
locationUuids: new Set(locations.map((l: any) => l.agent_uuid)),
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
import { useState, useEffect } from "react";
|
import { useState, useEffect } from "react";
|
||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
import { getAgents } from "@/lib/actions/agents";
|
import { getAgents, updateAgent } from "@/lib/actions/agents";
|
||||||
import { Agent } from "@/lib/actions/agentsCore";
|
import { Agent } from "@/lib/actions/agentsCore";
|
||||||
import { getAdminUsers, startViewAs, getViewAsHeaders, type ManagedUser } from "@/lib/admin-api";
|
import { getAdminUsers, startViewAs, getViewAsHeaders, type ManagedUser } from "@/lib/admin-api";
|
||||||
import { useTimeFilter } from "@/contexts/TimeFilterContext";
|
import { useTimeFilter } from "@/contexts/TimeFilterContext";
|
||||||
@@ -194,6 +194,25 @@ export function useAgentsData() {
|
|||||||
setIsLocModalOpen(true);
|
setIsLocModalOpen(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleEditLabel = async (agentUuid: string, currentLabel: string) => {
|
||||||
|
const newLabel = window.prompt("Masukkan label baru untuk agent ini:", currentLabel);
|
||||||
|
if (newLabel !== null && newLabel.trim() !== "" && newLabel !== currentLabel) {
|
||||||
|
try {
|
||||||
|
const result = await updateAgent(agentUuid, newLabel.trim());
|
||||||
|
if (result.success) {
|
||||||
|
// Update local state without waiting for full refresh to feel snappy
|
||||||
|
setAgents(prev => prev.map(a =>
|
||||||
|
(a.uuid === agentUuid || a.serial === agentUuid) ? { ...a, label: newLabel.trim() } : a
|
||||||
|
));
|
||||||
|
} else {
|
||||||
|
window.alert("Gagal mengubah label: " + result.message);
|
||||||
|
}
|
||||||
|
} catch (err: any) {
|
||||||
|
window.alert("Terjadi kesalahan: " + err.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
role,
|
role,
|
||||||
agents,
|
agents,
|
||||||
@@ -236,5 +255,6 @@ export function useAgentsData() {
|
|||||||
handleViewAs,
|
handleViewAs,
|
||||||
openDelete,
|
openDelete,
|
||||||
handleEditLocation,
|
handleEditLocation,
|
||||||
|
handleEditLabel,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user