MainContent.tsx 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import { useMemo } from "react";
  2. import type { FC } from "react";
  3. import { FlowChart } from "../FlowChart/FlowChart";
  4. import { useTrace } from "../../hooks/useTrace";
  5. import { useFlowChartData } from "../FlowChart/hooks/useFlowChartData";
  6. import type { Goal } from "../../types/goal";
  7. import type { Edge } from "../../types/message";
  8. import styles from "./MainContent.module.css";
  9. interface MainContentProps {
  10. traceId: string | null;
  11. onNodeClick?: (node: Goal, edge?: Edge) => void;
  12. }
  13. export const MainContent: FC<MainContentProps> = ({ traceId, onNodeClick }) => {
  14. const { trace, loading } = useTrace(traceId);
  15. const initialGoals = useMemo(() => trace?.goal_tree?.goals ?? [], [trace]);
  16. const { goals, connected, msgGroups } = useFlowChartData(traceId, initialGoals);
  17. console.log("%c [ goals ]-19", "font-size:13px; background:pink; color:#bf2c9f;", goals);
  18. if (!traceId && !loading) {
  19. return (
  20. <div className={styles.main}>
  21. <div className={styles.header}>
  22. <div className={styles.title}>暂无 Trace</div>
  23. <div className={styles.status}>未连接</div>
  24. </div>
  25. <div className={styles.content}>
  26. <div className={styles.empty}>暂无可展示的数据</div>
  27. </div>
  28. </div>
  29. );
  30. }
  31. return (
  32. <div className={styles.main}>
  33. <div className={styles.header}>
  34. <div className={styles.title}></div>
  35. <div className={styles.headerRight}>
  36. <div className={styles.status}>{connected ? "WebSocket 已连接" : "WebSocket 未连接"}</div>
  37. <div className={styles.legend}>
  38. <div className={styles.legendItem}>
  39. <span
  40. className={styles.legendDot}
  41. style={{ background: "#00c853" }}
  42. />
  43. 已完成
  44. </div>
  45. <div className={styles.legendItem}>
  46. <span
  47. className={styles.legendDot}
  48. style={{ background: "#f44336" }}
  49. />
  50. 失败
  51. </div>
  52. <div className={styles.legendItem}>
  53. <span
  54. className={styles.legendDot}
  55. style={{ background: "#ff9800" }}
  56. />
  57. 运行中
  58. </div>
  59. <div className={styles.legendItem}>
  60. <span
  61. className={styles.legendDot}
  62. style={{ background: "#4e79a7" }}
  63. />
  64. 默认
  65. </div>
  66. </div>
  67. </div>
  68. </div>
  69. <div className={styles.content}>
  70. {loading ? (
  71. <div className={styles.empty}>加载中...</div>
  72. ) : goals.length === 0 ? (
  73. <div className={styles.empty}>暂无节点</div>
  74. ) : (
  75. <FlowChart
  76. goals={goals}
  77. msgGroups={msgGroups}
  78. onNodeClick={onNodeClick}
  79. />
  80. )}
  81. </div>
  82. </div>
  83. );
  84. };