Ver código fonte

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 ano atrás
pai
commit
216f6495c4
Nenhuma conta vinculada ao e-mail do autor do commit

+ 3
- 2
web/src/pages/add-knowledge/components/knowledge-chunk/components/knowledge-graph/force-graph.tsx Ver arquivo

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';


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 };
}, [nextData]); }, [nextData]);


useEffect(() => { useEffect(() => {
if (data) {
if (!isEmpty(data)) {
render(); render();
} }
}, [data, render]); }, [data, render]);

+ 5
- 1
web/src/pages/add-knowledge/components/knowledge-chunk/components/knowledge-graph/util.ts Ver arquivo

import { isEmpty } from 'lodash';

class KeyGenerator { class KeyGenerator {
idx = 0; idx = 0;
chars: string[] = []; chars: string[] = [];
} }


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

Carregando…
Cancelar
Salvar