mirror of
https://git.mirrors.martin98.com/https://github.com/infiniflow/ragflow.git
synced 2025-06-01 08:06:15 +08:00
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:
parent
f60a249fe1
commit
216f6495c4
@ -1,4 +1,5 @@
|
|||||||
import { ElementDatum, Graph, IElementEvent } from '@antv/g6';
|
import { ElementDatum, Graph, IElementEvent } from '@antv/g6';
|
||||||
|
import isEmpty from 'lodash/isEmpty';
|
||||||
import { useCallback, useEffect, useMemo, useRef } from 'react';
|
import { useCallback, useEffect, useMemo, useRef } from 'react';
|
||||||
import { buildNodesAndCombos } from './util';
|
import { buildNodesAndCombos } from './util';
|
||||||
|
|
||||||
@ -20,7 +21,7 @@ const ForceGraph = ({ data, show }: IProps) => {
|
|||||||
const graphRef = useRef<Graph | null>(null);
|
const graphRef = useRef<Graph | null>(null);
|
||||||
|
|
||||||
const nextData = useMemo(() => {
|
const nextData = useMemo(() => {
|
||||||
if (data) {
|
if (!isEmpty(data)) {
|
||||||
const graphData = data;
|
const graphData = data;
|
||||||
const mi = buildNodesAndCombos(graphData.nodes);
|
const mi = buildNodesAndCombos(graphData.nodes);
|
||||||
return { edges: graphData.links, ...mi };
|
return { edges: graphData.links, ...mi };
|
||||||
@ -116,7 +117,7 @@ const ForceGraph = ({ data, show }: IProps) => {
|
|||||||
}, [nextData]);
|
}, [nextData]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (data) {
|
if (!isEmpty(data)) {
|
||||||
render();
|
render();
|
||||||
}
|
}
|
||||||
}, [data, render]);
|
}, [data, render]);
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
import { isEmpty } from 'lodash';
|
||||||
|
|
||||||
class KeyGenerator {
|
class KeyGenerator {
|
||||||
idx = 0;
|
idx = 0;
|
||||||
chars: string[] = [];
|
chars: string[] = [];
|
||||||
@ -55,7 +57,9 @@ export class Converter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const isDataExist = (data: any) => {
|
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[]) => {
|
export const buildNodesAndCombos = (nodes: any[]) => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user