Spaces:
Sleeping
Sleeping
Upload index.tsx
Browse files
aworld/cmd/web/webui/src/pages/components/Drawer/index.tsx
ADDED
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import React, { useEffect, useRef } from 'react';
|
2 |
+
import mermaid from 'mermaid';
|
3 |
+
import './index.less'
|
4 |
+
|
5 |
+
interface TraceProps {
|
6 |
+
sessionId: string;
|
7 |
+
}
|
8 |
+
|
9 |
+
const Trace: React.FC<TraceProps> = ({ sessionId }) => {
|
10 |
+
const diagramRef = useRef<HTMLDivElement>(null);
|
11 |
+
|
12 |
+
useEffect(() => {
|
13 |
+
const initializeMermaid = async () => {
|
14 |
+
try {
|
15 |
+
await mermaid.initialize({
|
16 |
+
startOnLoad: false,
|
17 |
+
theme: 'default',
|
18 |
+
fontFamily: 'Arial',
|
19 |
+
securityLevel: 'loose'
|
20 |
+
});
|
21 |
+
|
22 |
+
if (diagramRef.current) {
|
23 |
+
await mermaid.run({
|
24 |
+
nodes: [diagramRef.current]
|
25 |
+
});
|
26 |
+
}
|
27 |
+
} catch (err) {
|
28 |
+
console.error('Mermaid initialization error:', err);
|
29 |
+
}
|
30 |
+
};
|
31 |
+
|
32 |
+
initializeMermaid();
|
33 |
+
}, []);
|
34 |
+
|
35 |
+
return (
|
36 |
+
<div className='tracebox'>
|
37 |
+
<div ref={diagramRef} className="mermaid">
|
38 |
+
{`graph TD
|
39 |
+
A[会话开始] --> B[初始化环境]
|
40 |
+
B --> C[加载配置]
|
41 |
+
C --> D[执行任务]
|
42 |
+
D --> E{成功?}
|
43 |
+
E -->|是| F[保存结果]
|
44 |
+
E -->|否| G[错误处理]
|
45 |
+
F --> H[会话结束]
|
46 |
+
G --> H`}
|
47 |
+
</div>
|
48 |
+
<p style={{textAlign:'center'}}>Session ID: {sessionId}</p>
|
49 |
+
</div>
|
50 |
+
);
|
51 |
+
};
|
52 |
+
|
53 |
+
export default Trace;
|