Moved refreshLayout from settings to graph store.

This commit is contained in:
yangdx
2025-03-13 09:44:51 +08:00
parent 2bc41bebf8
commit 642d17b774
3 changed files with 15 additions and 14 deletions

View File

@@ -72,6 +72,7 @@ interface GraphState {
moveToSelectedNode: boolean
isFetching: boolean
refreshLayout: () => void
setSelectedNode: (nodeId: string | null, moveToSelectedNode?: boolean) => void
setFocusedNode: (nodeId: string | null) => void
setSelectedEdge: (edgeId: string | null) => void
@@ -89,7 +90,7 @@ interface GraphState {
setIsFetching: (isFetching: boolean) => void
}
const useGraphStoreBase = create<GraphState>()((set) => ({
const useGraphStoreBase = create<GraphState>()((set, get) => ({
selectedNode: null,
focusedNode: null,
selectedEdge: null,
@@ -103,6 +104,17 @@ const useGraphStoreBase = create<GraphState>()((set) => ({
graphLabels: ['*'],
allDatabaseLabels: ['*'],
refreshLayout: () => {
const currentGraph = get().sigmaGraph;
if (currentGraph) {
get().clearSelection();
get().setSigmaGraph(null);
setTimeout(() => {
get().setSigmaGraph(currentGraph);
}, 10);
}
},
setIsFetching: (isFetching: boolean) => set({ isFetching }),
setSelectedNode: (nodeId: string | null, moveToSelectedNode?: boolean) =>
set({ selectedNode: nodeId, moveToSelectedNode }),