balibabu commited on
Commit
0e7a78d
·
1 Parent(s): 82c3a74

feat: Fixed the issue where the page reports an error when the graph returned by the interface is empty #162 (#1795)

Browse files

…returned by the interface is empty #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 #162

### Type of change


- [x] New Feature (non-breaking change which adds functionality)

web/src/pages/add-knowledge/components/knowledge-chunk/components/knowledge-graph/force-graph.tsx CHANGED
@@ -1,4 +1,5 @@
1
  import { ElementDatum, Graph, IElementEvent } from '@antv/g6';
 
2
  import { useCallback, useEffect, useMemo, useRef } from 'react';
3
  import { buildNodesAndCombos } from './util';
4
 
@@ -20,7 +21,7 @@ const ForceGraph = ({ data, show }: IProps) => {
20
  const graphRef = useRef<Graph | null>(null);
21
 
22
  const nextData = useMemo(() => {
23
- if (data) {
24
  const graphData = data;
25
  const mi = buildNodesAndCombos(graphData.nodes);
26
  return { edges: graphData.links, ...mi };
@@ -116,7 +117,7 @@ const ForceGraph = ({ data, show }: IProps) => {
116
  }, [nextData]);
117
 
118
  useEffect(() => {
119
- if (data) {
120
  render();
121
  }
122
  }, [data, render]);
 
1
  import { ElementDatum, Graph, IElementEvent } from '@antv/g6';
2
+ import isEmpty from 'lodash/isEmpty';
3
  import { useCallback, useEffect, useMemo, useRef } from 'react';
4
  import { buildNodesAndCombos } from './util';
5
 
 
21
  const graphRef = useRef<Graph | null>(null);
22
 
23
  const nextData = useMemo(() => {
24
+ if (!isEmpty(data)) {
25
  const graphData = data;
26
  const mi = buildNodesAndCombos(graphData.nodes);
27
  return { edges: graphData.links, ...mi };
 
117
  }, [nextData]);
118
 
119
  useEffect(() => {
120
+ if (!isEmpty(data)) {
121
  render();
122
  }
123
  }, [data, render]);
web/src/pages/add-knowledge/components/knowledge-chunk/components/knowledge-graph/util.ts CHANGED
@@ -1,3 +1,5 @@
 
 
1
  class KeyGenerator {
2
  idx = 0;
3
  chars: string[] = [];
@@ -55,7 +57,9 @@ export class Converter {
55
  }
56
 
57
  export const isDataExist = (data: any) => {
58
- return data?.data && typeof data?.data !== 'boolean';
 
 
59
  };
60
 
61
  export const buildNodesAndCombos = (nodes: any[]) => {
 
1
+ import { isEmpty } from 'lodash';
2
+
3
  class KeyGenerator {
4
  idx = 0;
5
  chars: string[] = [];
 
57
  }
58
 
59
  export const isDataExist = (data: any) => {
60
+ return (
61
+ data?.data && typeof data?.data !== 'boolean' && !isEmpty(data?.data?.graph)
62
+ );
63
  };
64
 
65
  export const buildNodesAndCombos = (nodes: any[]) => {