(path: string | null, targetLine?: number)
| 1187 | }, [fileContents]); |
| 1188 | |
| 1189 | const onFileClick = (path: string | null, targetLine?: number) => { |
| 1190 | if (!path) { |
| 1191 | setSelectedFile(null); |
| 1192 | setFocusSet(null); |
| 1193 | setCodeContent(null); |
| 1194 | setCodeError(null); |
| 1195 | setHighlightLine(null); |
| 1196 | return; |
| 1197 | } |
| 1198 | |
| 1199 | setHighlightLine(targetLine || null); |
| 1200 | |
| 1201 | if (path !== selectedFile) { |
| 1202 | setSelectedFile(path); |
| 1203 | loadFileCode(path); |
| 1204 | } else if (targetLine) { |
| 1205 | setCodePanelTab('code'); |
| 1206 | setTimeout(() => { |
| 1207 | const el = codeBodyRef.current?.querySelector(`[data-line="${targetLine}"]`); |
| 1208 | el?.scrollIntoView({ behavior: 'smooth', block: 'center' }); |
| 1209 | }, 100); |
| 1210 | } |
| 1211 | |
| 1212 | const fileNode = data.nodes.find((n: any) => n.file === path && n.type === 'File'); |
| 1213 | if (fileNode) { |
| 1214 | if (fgRef.current) { |
| 1215 | fgRef.current.centerAt(fileNode.x, fileNode.y, 800); |
| 1216 | fgRef.current.zoom(2.5, 800); |
| 1217 | } |
| 1218 | |
| 1219 | const nodesInFocus = new Set<number>(); |
| 1220 | const linksInFocus = new Set<any>(); |
| 1221 | nodesInFocus.add(fileNode.id); |
| 1222 | |
| 1223 | data.links.forEach((l: any) => { |
| 1224 | const sId = typeof l.source === 'object' ? l.source.id : l.source; |
| 1225 | const tId = typeof l.target === 'object' ? l.target.id : l.target; |
| 1226 | if (sId === fileNode.id || tId === fileNode.id) { |
| 1227 | nodesInFocus.add(sId); |
| 1228 | nodesInFocus.add(tId); |
| 1229 | linksInFocus.add(l); |
| 1230 | } |
| 1231 | }); |
| 1232 | |
| 1233 | setFocusSet({ nodes: nodesInFocus, links: linksInFocus }); |
| 1234 | } |
| 1235 | }; |
| 1236 | |
| 1237 | const onGraphNodeClick = (node: any) => { |
| 1238 | if (isPathMode) { |
no test coverage detected