AgentDetailDrawer.tsx
3.49 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import { useEffect, useState } from 'react';
import { useNavigate } from 'react-router-dom';
import { Button, Drawer, StatePlaceholder, Tag } from '../../../packages/ui/src';
import { getAgentDetail, type AgentDetail } from '../../api';
import { buildAgentListSearch, type AgentListRouteState } from './agentRouteState';
export function AgentDetailDrawer({ agentId, routeState }: { agentId?: string; routeState: AgentListRouteState }) {
const navigate = useNavigate();
const [loading, setLoading] = useState(false);
const [loadError, setLoadError] = useState(false);
const [detail, setDetail] = useState<AgentDetail | null>(null);
useEffect(() => {
if (!agentId) return;
setLoading(true);
setLoadError(false);
setDetail(null);
getAgentDetail(Number(agentId))
.then((data) => {
setDetail(data);
setLoading(false);
})
.catch(() => {
setLoadError(true);
setLoading(false);
});
}, [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>
}
>
{loading ? (
<StatePlaceholder state="empty" title="加载中" description="正在加载 Agent 详情" />
) : loadError ? (
<StatePlaceholder state="error" title="详情加载失败" description="当前 Agent 详情无法展示" />
) : detail ? (
<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.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)]">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 className="grid grid-cols-[100px_1fr] gap-2 items-start">
<span className="text-[var(--gl-color-text-secondary)]">绑定 Skill</span>
<div className="flex flex-wrap gap-2">
{detail.skills.map((skill) => <Tag key={skill.skill_code}>{skill.skill_name}</Tag>)}
</div>
</div>
</div>
</div>
) : null}
</Drawer>
);
}