Przeglądaj źródła

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)
tags/v0.9.0
balibabu 1 rok temu
rodzic
commit
216f6495c4
No account linked to committer's email address

+ 3
- 2
web/src/pages/add-knowledge/components/knowledge-chunk/components/knowledge-graph/force-graph.tsx Wyświetl plik

@@ -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]);

+ 5
- 1
web/src/pages/add-knowledge/components/knowledge-chunk/components/knowledge-graph/util.ts Wyświetl plik

@@ -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[]) => {

Ładowanie…
Anuluj
Zapisz