SkillDetailDrawer.tsx
3.06 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
import { useEffect, useState } from 'react';
import { useNavigate } from 'react-router-dom';
import { Button, Drawer, StatePlaceholder } from '../../../packages/ui/src';
import { getSkillDetail, type SkillDetail } from '../../api';
import { SkillMarkdown } from './SkillMarkdown';
import { buildSkillListSearch, type SkillListRouteState } from './skillRouteState';
export function SkillDetailDrawer({ routeState, skillCode }: { routeState: SkillListRouteState; skillCode?: string }) {
const navigate = useNavigate();
const [loading, setLoading] = useState(false);
const [loadError, setLoadError] = useState(false);
const [detail, setDetail] = useState<SkillDetail | null>(null);
useEffect(() => {
if (!skillCode) return;
setLoading(true);
setLoadError(false);
setDetail(null);
getSkillDetail(skillCode)
.then((data) => {
setDetail(data);
setLoading(false);
})
.catch(() => {
setLoadError(true);
setLoading(false);
});
}, [skillCode]);
const closeDrawer = () => {
navigate(`/skills${buildSkillListSearch({ keyword: routeState.keyword, detail: undefined })}`);
};
if (!skillCode) {
return null;
}
return (
<Drawer
open
title="Skill详情"
width={560}
onClose={closeDrawer}
footer={
<div className="flex items-center justify-end gap-3">
<Button variant="outline" onClick={closeDrawer}>关闭</Button>
</div>
}
>
{loading ? (
<StatePlaceholder state="empty" title="加载中" description="正在加载 Skill 详情" />
) : loadError ? (
<StatePlaceholder state="error" title="详情加载失败" description="当前 Skill 详情无法展示" />
) : detail ? (
<div className="flex h-[calc(100vh-220px)] flex-col gap-4 overflow-y-auto pr-1 text-sm" data-testid="skill-drawer-scroll">
<section className="grid content-start gap-3">
<div className="grid grid-cols-[100px_1fr] items-start gap-2">
<span className="text-[var(--gl-color-text-secondary)]">Skill编码:</span>
<span>{detail.skill_code}</span>
</div>
<div className="grid grid-cols-[100px_1fr] items-start gap-2">
<span className="text-[var(--gl-color-text-secondary)]">Skill名称:</span>
<span>{detail.skill_name}</span>
</div>
<div className="grid grid-cols-[100px_1fr] items-start gap-2">
<span className="text-[var(--gl-color-text-secondary)]">说明:</span>
<span>{detail.description || '-'}</span>
</div>
</section>
<section className="grid content-start gap-2">
<strong>使用说明</strong>
{detail.doc_markdown ? (
<SkillMarkdown markdown={detail.doc_markdown} />
) : (
<StatePlaceholder state="empty" title="暂无使用说明" description="当前 Skill 还没有可展示的 Markdown 内容" />
)}
</section>
</div>
) : null}
</Drawer>
);
}