Skip to content

Commit a174b12

Browse files
committed
change node ids to number
1 parent 4f4a6ec commit a174b12

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

app/api/repo/[graph]/neighbors/route.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ import { NextRequest, NextResponse } from "next/server";
22

33
export async function POST(request: NextRequest, { params }: { params: { graph: string } }) {
44

5-
const { nodeIds } = await request.json();
5+
const nodeIds = (await request.json()).nodeIds.map((id: string) => Number(id));
66
const graphId = params.graph;
77
try {
8-
8+
console.log(nodeIds, graphId);
9+
910
const result = await fetch(`${process.env.BACKEND_URL}/get_neighbors`, {
1011
method: 'POST',
1112
body: JSON.stringify({ node_ids: nodeIds, repo: graphId }),

app/components/code-graph.tsx

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ export function CodeGraph({
261261
const type = "category" in element.data
262262

263263
if (element.data.expand) {
264-
deleteNeighbors(element.data, chart)
264+
deleteNeighbors([element.data], chart)
265265
}
266266

267267
graph.Elements.splice(index, 1);
@@ -296,7 +296,9 @@ export function CodeGraph({
296296

297297
if (!graphNode) return
298298

299-
if (!graphNode.data.expand) {
299+
const expand = !graphNode.data.expand
300+
301+
if (expand) {
300302
const elements = await onFetchNode([node.id])
301303

302304
if (elements.length === 0) {
@@ -312,7 +314,9 @@ export function CodeGraph({
312314
deleteNeighbors([node], chart);
313315
}
314316

315-
graphNode.data.expand = !graphNode.data.expand
317+
const element = chart.elements(`#${node.id}`)
318+
element.data('expand', expand)
319+
graphNode.data.expand = expand
316320

317321
setSelectedObj(undefined)
318322
chart.elements().layout(LAYOUT).run();
@@ -336,20 +340,26 @@ export function CodeGraph({
336340
}
337341

338342
chart.add(elements);
343+
chart.elements().layout(LAYOUT).run();
339344
} else {
340-
deleteNeighbors(nodes, chart);
345+
const deleteNodes = nodes.filter(n => n.expand === true)
346+
if (deleteNodes.length > 0) {
347+
deleteNeighbors(deleteNodes, chart);
348+
chart.elements().layout(LAYOUT).run();
349+
}
341350
}
342351

343352
nodes.forEach((node) => {
344353
const graphNode = graph.Elements.find(e => e.data.id === node.id)
354+
const element = chart.elements(`#${node.id}`)
345355

346356
if (!graphNode) return
347357

358+
element.data("expand", expand)
348359
graphNode.data.expand = expand
349360
})
350361

351362
setSelectedObj(undefined)
352-
chart.elements().layout(LAYOUT).run();
353363
}
354364

355365
const handelSearchSubmit = (node: any) => {

0 commit comments

Comments
 (0)