import { useEffect, useState } from "react"; import { Drawer, Descriptions, Tag, Spin, Empty, message } from "antd"; import type { RelationVO } from "../knowledge-graph.model"; import { ENTITY_TYPE_LABELS, ENTITY_TYPE_COLORS, DEFAULT_ENTITY_COLOR, RELATION_TYPE_LABELS, } from "../knowledge-graph.const"; import * as api from "../knowledge-graph.api"; interface RelationDetailProps { graphId: string; relationId: string | null; open: boolean; onClose: () => void; onEntityNavigate: (entityId: string) => void; } export default function RelationDetail({ graphId, relationId, open, onClose, onEntityNavigate, }: RelationDetailProps) { const [relation, setRelation] = useState(null); const [loading, setLoading] = useState(false); useEffect(() => { if (!relationId || !graphId) { setRelation(null); return; } if (!open) return; setLoading(true); api .getRelation(graphId, relationId) .then((data) => setRelation(data)) .catch(() => message.error("加载关系详情失败")) .finally(() => setLoading(false)); }, [graphId, relationId, open]); return ( {relation ? (
{RELATION_TYPE_LABELS[relation.relationType] ?? relation.relationType}
{ENTITY_TYPE_LABELS[relation.sourceEntityType] ?? relation.sourceEntityType} onEntityNavigate(relation.sourceEntityId)} > {relation.sourceEntityName}
{ENTITY_TYPE_LABELS[relation.targetEntityType] ?? relation.targetEntityType} onEntityNavigate(relation.targetEntityId)} > {relation.targetEntityName}
{relation.weight != null && ( {relation.weight} )} {relation.confidence != null && ( {(relation.confidence * 100).toFixed(0)}% )} {relation.createdAt && ( {relation.createdAt} )}
{relation.properties && Object.keys(relation.properties).length > 0 && ( <>

扩展属性

{Object.entries(relation.properties).map(([key, value]) => ( {String(value)} ))} )}
) : !loading ? ( ) : null}
); }