MCPcopy Create free account
hub / github.com/Qinbf/groundmap / PreviewPanel

Function PreviewPanel

tools/debug-console/components/PreviewPanel.tsx:55–269  ·  view source on GitHub ↗
({ refData, nodeData, workspace, onClose, onOpenRef }: Props)

Source from the content-addressed store, hash-verified

53 };
54
55export function PreviewPanel({ refData, nodeData, workspace, onClose, onOpenRef }: Props) {
56 const t = useT();
57 // 决定是否需要 fetch(refData 模式 或 nodeData 模式且 kind 是含 path 的 file/ghost/result)
58 const fetchTarget: { tool: string; args: Record<string, unknown> } | null = (() => {
59 if (refData) return refToToolCall(refData);
60 if (
61 nodeData &&
62 (nodeData.kind === "file" || nodeData.kind === "ghost") &&
63 nodeData.path
64 ) {
65 const ref: WikiRef = {
66 path: nodeData.path,
67 anchor: nodeData.anchor || null,
68 isBlock: !!nodeData.isBlock,
69 alias: null,
70 };
71 return refToToolCall(ref);
72 }
73 return null;
74 })();
75
76 // 显示用的 ref(顶栏路径 / 打开按钮)
77 const displayRef: WikiRef | null = refData
78 ? refData
79 : nodeData?.path
80 ? {
81 path: nodeData.path,
82 anchor: nodeData.anchor || null,
83 isBlock: !!nodeData.isBlock,
84 alias: null,
85 }
86 : null;
87
88 const [state, setState] = useState<FetchState>(
89 fetchTarget ? { kind: "loading" } : { kind: "ok", rendered: { body: "" } },
90 );
91
92 useEffect(() => {
93 if (!fetchTarget) {
94 setState({ kind: "ok", rendered: { body: "" } });
95 return;
96 }
97 let cancelled = false;
98 setState({ kind: "loading" });
99
100 const post = (tool: string, args: Record<string, unknown>) =>
101 fetch("/api/preview", {
102 method: "POST",
103 headers: { "Content-Type": "application/json" },
104 body: JSON.stringify({ tool, args, workspace: workspace || undefined }),
105 }).then((r) => r.json());
106
107 const path = typeof fetchTarget.args.path === "string" ? fetchTarget.args.path : "";
108 const anchor = typeof fetchTarget.args.anchor === "string" ? fetchTarget.args.anchor : "";
109 const hadAnchor = fetchTarget.tool !== "read_page" && !!anchor;
110
111 (async () => {
112 try {

Callers

nothing calls this directly

Calls 8

useTFunction · 0.90
refToToolCallFunction · 0.90
refToAdminUrlFunction · 0.90
postFunction · 0.85
renderToolResultFunction · 0.85
kindBadgeClassFunction · 0.70
kindLabelFunction · 0.70
tFunction · 0.50

Tested by

no test coverage detected