From 642d17b7740c8ea270c126e4b5986ccde6ae4f40 Mon Sep 17 00:00:00 2001 From: yangdx Date: Thu, 13 Mar 2025 09:44:51 +0800 Subject: [PATCH] Moved refreshLayout from settings to graph store. --- lightrag_webui/src/components/graph/Settings.tsx | 3 ++- lightrag_webui/src/stores/graph.ts | 14 +++++++++++++- lightrag_webui/src/stores/settings.ts | 12 ------------ 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/lightrag_webui/src/components/graph/Settings.tsx b/lightrag_webui/src/components/graph/Settings.tsx index 8d764a9c..a24c86e9 100644 --- a/lightrag_webui/src/components/graph/Settings.tsx +++ b/lightrag_webui/src/components/graph/Settings.tsx @@ -8,6 +8,7 @@ import Input from '@/components/ui/Input' import { controlButtonVariant } from '@/lib/constants' import { useSettingsStore } from '@/stores/settings' import { useBackendState } from '@/stores/state' +import { useGraphStore } from '@/stores/graph' import { SettingsIcon, RefreshCwIcon } from 'lucide-react' import { useTranslation } from 'react-i18next'; @@ -114,7 +115,7 @@ const LabeledNumberInput = ({ export default function Settings() { const [opened, setOpened] = useState(false) const [tempApiKey, setTempApiKey] = useState('') - const refreshLayout = useSettingsStore.use.refreshLayout() + const refreshLayout = useGraphStore.use.refreshLayout() const showPropertyPanel = useSettingsStore.use.showPropertyPanel() const showNodeSearchBar = useSettingsStore.use.showNodeSearchBar() diff --git a/lightrag_webui/src/stores/graph.ts b/lightrag_webui/src/stores/graph.ts index 3c4fe37e..b27a7f09 100644 --- a/lightrag_webui/src/stores/graph.ts +++ b/lightrag_webui/src/stores/graph.ts @@ -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()((set) => ({ +const useGraphStoreBase = create()((set, get) => ({ selectedNode: null, focusedNode: null, selectedEdge: null, @@ -103,6 +104,17 @@ const useGraphStoreBase = create()((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 }), diff --git a/lightrag_webui/src/stores/settings.ts b/lightrag_webui/src/stores/settings.ts index 100b665e..72df7351 100644 --- a/lightrag_webui/src/stores/settings.ts +++ b/lightrag_webui/src/stores/settings.ts @@ -3,7 +3,6 @@ import { persist, createJSONStorage } from 'zustand/middleware' import { createSelectors } from '@/lib/utils' import { defaultQueryLabel } from '@/lib/constants' import { Message, QueryRequest } from '@/api/lightrag' -import { useGraphStore } from '@/stores/graph' type Theme = 'dark' | 'light' | 'system' type Language = 'en' | 'zh' @@ -11,7 +10,6 @@ type Tab = 'documents' | 'knowledge-graph' | 'retrieval' | 'api' interface SettingsState { // Graph viewer settings - refreshLayout: () => void showPropertyPanel: boolean showNodeSearchBar: boolean @@ -64,16 +62,6 @@ const useSettingsStoreBase = create()( (set) => ({ theme: 'system', language: 'en', - refreshLayout: () => { - const graphState = useGraphStore.getState(); - const currentGraph = graphState.sigmaGraph; - graphState.clearSelection(); - graphState.setSigmaGraph(null); - setTimeout(() => { - graphState.setSigmaGraph(currentGraph); - }, 10); - }, - showPropertyPanel: true, showNodeSearchBar: true,