Skip to content

Commit

Permalink
[chore](KnowledgeGraph): Add reset clickedNode state on focus and cha…
Browse files Browse the repository at this point in the history
…nge events
  • Loading branch information
LZS911 committed Feb 27, 2025
1 parent 95a7ed4 commit 78aba92
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
10 changes: 7 additions & 3 deletions packages/sqle/src/page/Knowledge/Graph/components/LoadGraph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
useSetSettings,
useSigma
} from '@react-sigma/core';
import { FC, useEffect, useState } from 'react';
import { Dispatch, FC, SetStateAction, useEffect } from 'react';
import useGraph from '../hooks/useGraph';
import { EdgeType, NodeType } from '../index.type';
import {
Expand All @@ -20,12 +20,16 @@ type props = {
};
hoveredNode: string | null;
setHoveredNode: (node: string | null) => void;
clickedNode: string | null;
setClickedNode: Dispatch<SetStateAction<string | null>>;
onLoaded?: () => void;
};
const LoadGraph: FC<props> = ({
graphData,
hoveredNode,
setHoveredNode,
clickedNode,
setClickedNode,
onLoaded
}) => {
const { createGraph } = useGraph();
Expand All @@ -34,7 +38,6 @@ const LoadGraph: FC<props> = ({
const setSettings = useSetSettings<NodeType, EdgeType>();
const loadGraph = useLoadGraph<NodeType, EdgeType>();
const { sharedTheme } = useThemeStyleData();
const [clickedNode, setClickedNode] = useState<string | null>(null);

useEffect(() => {
if (graphData) {
Expand Down Expand Up @@ -69,7 +72,8 @@ const LoadGraph: FC<props> = ({
registerEvents,
setHoveredNode,
sigma,
onLoaded
onLoaded,
setClickedNode
]);

useEffect(() => {
Expand Down
5 changes: 5 additions & 0 deletions packages/sqle/src/page/Knowledge/Graph/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,15 @@ const KnowledgeGraph: React.FC<KnowledgeGraphProp> = ({ graphData }) => {
const [isFullScreen, setIsFullScreen] = useState(false);
const [hoveredNode, setHoveredNode] = useState<string | null>(null);
const [isLoading, setIsLoading] = useState(true);
const [clickedNode, setClickedNode] = useState<string | null>(null);

const onFocus = useCallback((value: GraphSearchOption | null) => {
if (value === null) {
setFocusNode(null);
} else if (value.type === 'nodes') {
setFocusNode(value.id);
}
setClickedNode(null);
}, []);

const onChange = useCallback((value: GraphSearchOption | null) => {
Expand All @@ -81,6 +83,7 @@ const KnowledgeGraph: React.FC<KnowledgeGraphProp> = ({ graphData }) => {
} else if (value.type === 'nodes') {
setSelectedNode(value.id);
}
setClickedNode(null);
}, []);

const handleGraphLoaded = useCallback(() => {
Expand Down Expand Up @@ -132,6 +135,8 @@ const KnowledgeGraph: React.FC<KnowledgeGraphProp> = ({ graphData }) => {
hoveredNode={hoveredNode}
setHoveredNode={setHoveredNode}
onLoaded={handleGraphLoaded}
clickedNode={clickedNode}
setClickedNode={setClickedNode}
/>
<FocusOnNode
node={focusNode ?? selectedNode}
Expand Down

0 comments on commit 78aba92

Please sign in to comment.