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

…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)
This commit is contained in:
balibabu 2024-08-03 06:42:48 +08:00 committed by GitHub
parent f60a249fe1
commit 216f6495c4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 3 deletions

View File

@ -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';
@ -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 };
@ -116,7 +117,7 @@ const ForceGraph = ({ data, show }: IProps) => {
}, [nextData]);
useEffect(() => {
if (data) {
if (!isEmpty(data)) {
render();
}
}, [data, render]);

View File

@ -1,3 +1,5 @@
import { isEmpty } from 'lodash';
class KeyGenerator {
idx = 0;
chars: string[] = [];
@ -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[]) => {