Skip to content

Commit

Permalink
feat: Fixed the issue where the page reports an error when the graph …
Browse files Browse the repository at this point in the history
…returned by the interface is empty infiniflow#162
  • Loading branch information
cike8899 committed Aug 2, 2024
1 parent f60a249 commit 767b253
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ElementDatum, Graph, IElementEvent } from '@antv/g6';
import isEmpty from 'lodash/isEmpty';
import { useCallback, useEffect, useMemo, useRef } from 'react';
import { buildNodesAndCombos } from './util';

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

const nextData = useMemo(() => {
if (data) {
if (!isEmpty(data)) {
const graphData = data;
const mi = buildNodesAndCombos(graphData.nodes);
return { edges: graphData.links, ...mi };
Expand Down Expand Up @@ -116,7 +117,7 @@ const ForceGraph = ({ data, show }: IProps) => {
}, [nextData]);

useEffect(() => {
if (data) {
if (!isEmpty(data)) {
render();
}
}, [data, render]);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { isEmpty } from 'lodash';

class KeyGenerator {
idx = 0;
chars: string[] = [];
Expand Down Expand Up @@ -55,7 +57,9 @@ export class Converter {
}

export const isDataExist = (data: any) => {
return data?.data && typeof data?.data !== 'boolean';
return (
data?.data && typeof data?.data !== 'boolean' && !isEmpty(data?.data?.graph)
);
};

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

0 comments on commit 767b253

Please sign in to comment.