yangdx commited on
Commit
f614610
·
1 Parent(s): 0e483e2

Fix merge conflicts

Browse files
lightrag_webui/src/hooks/useLightragGraph.tsx CHANGED
@@ -363,7 +363,7 @@ const useLightrangeGraph = () => {
363
  const currentMaxNodes = maxNodes
364
 
365
  // Declare a variable to store data promise
366
- let dataPromise: Promise<RawGraph | null>;
367
 
368
  // 1. If query label is not empty, use fetchGraph
369
  if (currentQueryLabel) {
@@ -376,28 +376,28 @@ const useLightrangeGraph = () => {
376
 
377
  // 3. Process data
378
  dataPromise.then((data) => {
 
 
 
379
  // Assign colors based on entity_type *after* fetching
380
- if (data && data.nodes) {
381
- data.nodes.forEach(node => {
382
  // Use entity_type instead of type
383
  const nodeEntityType = node.properties?.entity_type as string | undefined;
384
  node.color = getNodeColorByType(nodeEntityType);
385
  });
386
  }
387
 
388
- const state = useGraphStore.getState()
389
- const data = result?.rawGraph;
390
-
391
- // Check if data is truncated
392
- if (result?.is_truncated) {
393
  toast.info(t('graphPanel.dataIsTruncated', 'Graph data is truncated to Max Nodes'));
394
  }
395
 
396
  // Reset state
 
397
  state.reset()
398
 
399
  // Check if data is empty or invalid
400
- if (!data || !data.nodes || data.nodes.length === 0) {
401
  // Create a graph with a single "Graph Is Empty" node
402
  const emptyGraph = new DirectedGraph();
403
 
@@ -438,12 +438,12 @@ const useLightrangeGraph = () => {
438
  console.log(`Graph data is empty, created graph with empty graph node. Auth error: ${isAuthError}`);
439
  } else {
440
  // Create and set new graph
441
- const newSigmaGraph = createSigmaGraph(data);
442
- data.buildDynamicMap();
443
 
444
  // Set new graph data
445
  state.setSigmaGraph(newSigmaGraph);
446
- state.setRawGraph(data);
447
  state.setGraphIsEmpty(false);
448
 
449
  // Update last successful query label
@@ -460,7 +460,7 @@ const useLightrangeGraph = () => {
460
  state.setIsFetching(false)
461
 
462
  // Mark empty data as handled if data is empty and query label is empty
463
- if ((!data || !data.nodes || data.nodes.length === 0) && !currentQueryLabel) {
464
  emptyDataHandledRef.current = true;
465
  }
466
  }).catch((error) => {
 
363
  const currentMaxNodes = maxNodes
364
 
365
  // Declare a variable to store data promise
366
+ let dataPromise: Promise<{ rawGraph: RawGraph | null; is_truncated: boolean | undefined } | null>;
367
 
368
  // 1. If query label is not empty, use fetchGraph
369
  if (currentQueryLabel) {
 
376
 
377
  // 3. Process data
378
  dataPromise.then((data) => {
379
+ // 提取 rawGraph 数据
380
+ const rawGraphData = data?.rawGraph;
381
+
382
  // Assign colors based on entity_type *after* fetching
383
+ if (rawGraphData && rawGraphData.nodes) {
384
+ rawGraphData.nodes.forEach(node => {
385
  // Use entity_type instead of type
386
  const nodeEntityType = node.properties?.entity_type as string | undefined;
387
  node.color = getNodeColorByType(nodeEntityType);
388
  });
389
  }
390
 
391
+ if (data?.is_truncated) {
 
 
 
 
392
  toast.info(t('graphPanel.dataIsTruncated', 'Graph data is truncated to Max Nodes'));
393
  }
394
 
395
  // Reset state
396
+ const state = useGraphStore.getState()
397
  state.reset()
398
 
399
  // Check if data is empty or invalid
400
+ if (!rawGraphData || !rawGraphData.nodes || rawGraphData.nodes.length === 0) {
401
  // Create a graph with a single "Graph Is Empty" node
402
  const emptyGraph = new DirectedGraph();
403
 
 
438
  console.log(`Graph data is empty, created graph with empty graph node. Auth error: ${isAuthError}`);
439
  } else {
440
  // Create and set new graph
441
+ const newSigmaGraph = createSigmaGraph(rawGraphData);
442
+ rawGraphData.buildDynamicMap();
443
 
444
  // Set new graph data
445
  state.setSigmaGraph(newSigmaGraph);
446
+ state.setRawGraph(rawGraphData);
447
  state.setGraphIsEmpty(false);
448
 
449
  // Update last successful query label
 
460
  state.setIsFetching(false)
461
 
462
  // Mark empty data as handled if data is empty and query label is empty
463
+ if ((!rawGraphData || !rawGraphData.nodes || rawGraphData.nodes.length === 0) && !currentQueryLabel) {
464
  emptyDataHandledRef.current = true;
465
  }
466
  }).catch((error) => {