AgentDetailDrawer.tsx
2.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import { useNavigate } from 'react-router-dom';
import { Button, Drawer, StatePlaceholder, Tag } from '../../../packages/ui/src';
import { getAgentDetail } from '../../../packages/contracts/agent-editor-mock';
import { findSavedAgent } from './agentLocalStore';
import { buildAgentListSearch, type AgentListRouteState } from './agentRouteState';
export function AgentDetailDrawer({ agentId, routeState }: { agentId?: string; routeState: AgentListRouteState }) {
const navigate = useNavigate();
const detail = findSavedAgent(agentId) ?? getAgentDetail(agentId);
const closeDrawer = () => {
navigate(`/agents${buildAgentListSearch({ ...routeState, detail: undefined })}`);
};
if (!agentId) {
return null;
}
return (
<Drawer
open
title="Agent详情"
width={520}
onClose={closeDrawer}
footer={
<div className="flex items-center justify-end gap-3">
<Button variant="outline" onClick={closeDrawer}>关闭</Button>
<Button variant="primary" onClick={() => navigate(`/agents/${agentId}/edit${buildAgentListSearch(routeState)}`)}>编辑</Button>
</div>
}
>
{!detail ? (
<StatePlaceholder state="error" title="详情加载失败" description="当前 Agent 详情无法展示" />
) : (
<div className="grid gap-4 text-sm">
<section className="grid gap-2">
<strong className="text-base">{detail.name}</strong>
<span className="text-[var(--gl-color-text-secondary)]">ID: {detail.agent_id}</span>
</section>
<div className="grid gap-3">
<div className="grid grid-cols-[100px_1fr] gap-2 items-start">
<span className="text-[var(--gl-color-text-secondary)]">所属岗位</span>
<div className="flex flex-wrap gap-2">
{detail.is_manager ? <Tag status="info">系统调度</Tag> : detail.positions.map((position) => <Tag key={position.id}>{position.name}</Tag>)}
</div>
</div>
<div className="grid grid-cols-[100px_1fr] gap-2 items-start">
<span className="text-[var(--gl-color-text-secondary)]">托管企微员工</span>
<span>{detail.employee_name}</span>
</div>
<div className="grid grid-cols-[100px_1fr] gap-2 items-start">
<span className="text-[var(--gl-color-text-secondary)]">Agent描述</span>
<span>{detail.description}</span>
</div>
<div className="grid grid-cols-[100px_1fr] gap-2 items-start">
<span className="text-[var(--gl-color-text-secondary)]">状态</span>
<div className="flex flex-wrap gap-2">
<Tag status={detail.status === 'enable' ? 'success' : 'warning'}>{detail.status === 'enable' ? '已上架' : '已停用'}</Tag>
</div>
</div>
</div>
</div>
)}
</Drawer>
);
}