Skip to content

Commit

Permalink
feat(Knowledge Graph): adding clear and render graph results events
Browse files Browse the repository at this point in the history
  • Loading branch information
MO-Elmu committed Jun 6, 2023
1 parent c711db8 commit 5479a51
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export interface KnowledgeGraphInterface extends HTMLAttributes<HTMLDivElement>
onRelationshipSelected?: (e: EdgeData) => void;
onEntityUnSelected?: (e: NodeData) => void;
onRelationshipUnSelected?: (e: EdgeData) => void;
onGraphResultChange?: (nodes: NodeData[], edges?: EdgeData[]) => void;
onClearGraph?: (nodes: NodeData[], edges?: EdgeData[]) => void;
queryData?: IQueryData;
}
export const ZOOM_INTERVAL = 0.1;
Expand All @@ -32,6 +34,8 @@ export const KnowledgeGraphContainer: React.FC<KnowledgeGraphInterface> = ({
onRelationshipSelected,
onEntityUnSelected,
onRelationshipUnSelected,
onGraphResultChange,
onClearGraph,
queryData,
...props
}) => {
Expand Down Expand Up @@ -123,6 +127,14 @@ export const KnowledgeGraphContainer: React.FC<KnowledgeGraphInterface> = ({
};
}, [cy.current]);

useEffect(() => {
if (onGraphResultChange && nodeData) {
edgeData
? onGraphResultChange([...nodeData.values()], [...edgeData.values()])
: onGraphResultChange([...nodeData.values()]);
}
}, [queryResult]);

const knowledgeGraphQueryClient = useMemo(() => {
return createKnowledgeGraphQueryClient(kgDataSource, setQueryResult);
}, [kgDataSource, setQueryResult]);
Expand All @@ -140,8 +152,11 @@ export const KnowledgeGraphContainer: React.FC<KnowledgeGraphInterface> = ({
}, [selectedGraphNodeEntityId, knowledgeGraphQueryClient]);

const onClearClicked = useCallback(() => {
if (onClearGraph && nodeData) {
edgeData ? onClearGraph([...nodeData.values()], [...edgeData.values()]) : onClearGraph([...nodeData.values()]);
}
clearGraphResults(true);
}, [clearGraphResults]);
}, [clearGraphResults, onClearGraph, nodeData, edgeData]);

useEffect(() => {
if (queryData?.entityId) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export { KnowledgeGraph } from './KnowledgeGraphPanel';
export type { NodeData, EdgeData } from './graph/types';
export type { IQueryData } from './interfaces';

0 comments on commit 5479a51

Please sign in to comment.