Skip to content

Commit 216f649

Browse files
authored
feat: Fixed the issue where the page reports an error when the graph returned by the interface is empty infiniflow#162 (infiniflow#1795)
…returned by the interface is empty infiniflow#162 ### What problem does this PR solve? feat: Fixed the issue where the page reports an error when the graph returned by the interface is empty infiniflow#162 ### Type of change - [x] New Feature (non-breaking change which adds functionality)
1 parent f60a249 commit 216f649

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

web/src/pages/add-knowledge/components/knowledge-chunk/components/knowledge-graph/force-graph.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { ElementDatum, Graph, IElementEvent } from '@antv/g6';
2+
import isEmpty from 'lodash/isEmpty';
23
import { useCallback, useEffect, useMemo, useRef } from 'react';
34
import { buildNodesAndCombos } from './util';
45

@@ -20,7 +21,7 @@ const ForceGraph = ({ data, show }: IProps) => {
2021
const graphRef = useRef<Graph | null>(null);
2122

2223
const nextData = useMemo(() => {
23-
if (data) {
24+
if (!isEmpty(data)) {
2425
const graphData = data;
2526
const mi = buildNodesAndCombos(graphData.nodes);
2627
return { edges: graphData.links, ...mi };
@@ -116,7 +117,7 @@ const ForceGraph = ({ data, show }: IProps) => {
116117
}, [nextData]);
117118

118119
useEffect(() => {
119-
if (data) {
120+
if (!isEmpty(data)) {
120121
render();
121122
}
122123
}, [data, render]);

web/src/pages/add-knowledge/components/knowledge-chunk/components/knowledge-graph/util.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { isEmpty } from 'lodash';
2+
13
class KeyGenerator {
24
idx = 0;
35
chars: string[] = [];
@@ -55,7 +57,9 @@ export class Converter {
5557
}
5658

5759
export const isDataExist = (data: any) => {
58-
return data?.data && typeof data?.data !== 'boolean';
60+
return (
61+
data?.data && typeof data?.data !== 'boolean' && !isEmpty(data?.data?.graph)
62+
);
5963
};
6064

6165
export const buildNodesAndCombos = (nodes: any[]) => {

0 commit comments

Comments
 (0)