yangdx
commited on
Commit
·
6043dbd
1
Parent(s):
060e4af
Added data reload button to graph labels component
Browse files
lightrag_webui/src/components/graph/GraphLabels.tsx
CHANGED
@@ -2,14 +2,17 @@ import { useCallback, useEffect, useRef } from 'react'
|
|
2 |
import { AsyncSelect } from '@/components/ui/AsyncSelect'
|
3 |
import { useSettingsStore } from '@/stores/settings'
|
4 |
import { useGraphStore } from '@/stores/graph'
|
5 |
-
import { labelListLimit } from '@/lib/constants'
|
6 |
import MiniSearch from 'minisearch'
|
7 |
import { useTranslation } from 'react-i18next'
|
|
|
|
|
8 |
|
9 |
const GraphLabels = () => {
|
10 |
const { t } = useTranslation()
|
11 |
const label = useSettingsStore.use.queryLabel()
|
12 |
const allDatabaseLabels = useGraphStore.use.allDatabaseLabels()
|
|
|
13 |
const labelsLoadedRef = useRef(false)
|
14 |
|
15 |
// Track if a fetch is in progress to prevent multiple simultaneous fetches
|
@@ -83,47 +86,70 @@ const GraphLabels = () => {
|
|
83 |
[getSearchEngine]
|
84 |
)
|
85 |
|
86 |
-
|
87 |
-
|
88 |
-
className="ml-2"
|
89 |
-
triggerClassName="max-h-8"
|
90 |
-
searchInputClassName="max-h-8"
|
91 |
-
triggerTooltip={t('graphPanel.graphLabels.selectTooltip')}
|
92 |
-
fetcher={fetchData}
|
93 |
-
renderOption={(item) => <div>{item}</div>}
|
94 |
-
getOptionValue={(item) => item}
|
95 |
-
getDisplayValue={(item) => <div>{item}</div>}
|
96 |
-
notFound={<div className="py-6 text-center text-sm">No labels found</div>}
|
97 |
-
label={t('graphPanel.graphLabels.label')}
|
98 |
-
placeholder={t('graphPanel.graphLabels.placeholder')}
|
99 |
-
value={label !== null ? label : '*'}
|
100 |
-
onChange={(newLabel) => {
|
101 |
-
const currentLabel = useSettingsStore.getState().queryLabel
|
102 |
-
|
103 |
-
// select the last item means query all
|
104 |
-
if (newLabel === '...') {
|
105 |
-
newLabel = '*'
|
106 |
-
}
|
107 |
|
108 |
-
|
109 |
-
useGraphStore.getState().setGraphDataFetchAttempted(false)
|
110 |
|
111 |
-
|
112 |
-
if (newLabel !== currentLabel) {
|
113 |
-
const graphStore = useGraphStore.getState();
|
114 |
-
// Reset the all graph objects and status
|
115 |
-
graphStore.reset();
|
116 |
-
}
|
117 |
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
127 |
)
|
128 |
}
|
129 |
|
|
|
2 |
import { AsyncSelect } from '@/components/ui/AsyncSelect'
|
3 |
import { useSettingsStore } from '@/stores/settings'
|
4 |
import { useGraphStore } from '@/stores/graph'
|
5 |
+
import { labelListLimit, controlButtonVariant } from '@/lib/constants'
|
6 |
import MiniSearch from 'minisearch'
|
7 |
import { useTranslation } from 'react-i18next'
|
8 |
+
import { RefreshCw } from 'lucide-react'
|
9 |
+
import Button from '@/components/ui/Button'
|
10 |
|
11 |
const GraphLabels = () => {
|
12 |
const { t } = useTranslation()
|
13 |
const label = useSettingsStore.use.queryLabel()
|
14 |
const allDatabaseLabels = useGraphStore.use.allDatabaseLabels()
|
15 |
+
const rawGraph = useGraphStore.use.rawGraph()
|
16 |
const labelsLoadedRef = useRef(false)
|
17 |
|
18 |
// Track if a fetch is in progress to prevent multiple simultaneous fetches
|
|
|
86 |
[getSearchEngine]
|
87 |
)
|
88 |
|
89 |
+
const handleRefresh = useCallback(() => {
|
90 |
+
const currentLabel = useSettingsStore.getState().queryLabel
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
91 |
|
92 |
+
useGraphStore.getState().setGraphDataFetchAttempted(false)
|
|
|
93 |
|
94 |
+
useGraphStore.getState().reset()
|
|
|
|
|
|
|
|
|
|
|
95 |
|
96 |
+
useSettingsStore.getState().setQueryLabel(currentLabel)
|
97 |
+
}, [])
|
98 |
+
|
99 |
+
return (
|
100 |
+
<div className="flex items-center">
|
101 |
+
{rawGraph && (
|
102 |
+
<Button
|
103 |
+
size="icon"
|
104 |
+
variant={controlButtonVariant}
|
105 |
+
onClick={handleRefresh}
|
106 |
+
tooltip={t('graphPanel.graphLabels.refreshTooltip')}
|
107 |
+
className="mr-1"
|
108 |
+
>
|
109 |
+
<RefreshCw className="h-4 w-4" />
|
110 |
+
</Button>
|
111 |
+
)}
|
112 |
+
<AsyncSelect<string>
|
113 |
+
className="ml-2"
|
114 |
+
triggerClassName="max-h-8"
|
115 |
+
searchInputClassName="max-h-8"
|
116 |
+
triggerTooltip={t('graphPanel.graphLabels.selectTooltip')}
|
117 |
+
fetcher={fetchData}
|
118 |
+
renderOption={(item) => <div>{item}</div>}
|
119 |
+
getOptionValue={(item) => item}
|
120 |
+
getDisplayValue={(item) => <div>{item}</div>}
|
121 |
+
notFound={<div className="py-6 text-center text-sm">No labels found</div>}
|
122 |
+
label={t('graphPanel.graphLabels.label')}
|
123 |
+
placeholder={t('graphPanel.graphLabels.placeholder')}
|
124 |
+
value={label !== null ? label : '*'}
|
125 |
+
onChange={(newLabel) => {
|
126 |
+
const currentLabel = useSettingsStore.getState().queryLabel
|
127 |
+
|
128 |
+
// select the last item means query all
|
129 |
+
if (newLabel === '...') {
|
130 |
+
newLabel = '*'
|
131 |
+
}
|
132 |
+
|
133 |
+
// Reset the fetch attempted flag to force a new data fetch
|
134 |
+
useGraphStore.getState().setGraphDataFetchAttempted(false)
|
135 |
+
|
136 |
+
// Clear current graph data to ensure complete reload when label changes
|
137 |
+
if (newLabel !== currentLabel) {
|
138 |
+
const graphStore = useGraphStore.getState();
|
139 |
+
// Reset the all graph objects and status
|
140 |
+
graphStore.reset();
|
141 |
+
}
|
142 |
+
|
143 |
+
if (newLabel === currentLabel && newLabel !== '*') {
|
144 |
+
// reselect the same itme means qery all
|
145 |
+
useSettingsStore.getState().setQueryLabel('*')
|
146 |
+
} else {
|
147 |
+
useSettingsStore.getState().setQueryLabel(newLabel)
|
148 |
+
}
|
149 |
+
}}
|
150 |
+
clearable={false} // Prevent clearing value on reselect
|
151 |
+
/>
|
152 |
+
</div>
|
153 |
)
|
154 |
}
|
155 |
|
lightrag_webui/src/locales/en.json
CHANGED
@@ -182,7 +182,8 @@
|
|
182 |
"noLabels": "No labels found",
|
183 |
"label": "Label",
|
184 |
"placeholder": "Search labels...",
|
185 |
-
"andOthers": "And {count} others"
|
|
|
186 |
}
|
187 |
},
|
188 |
"retrievePanel": {
|
|
|
182 |
"noLabels": "No labels found",
|
183 |
"label": "Label",
|
184 |
"placeholder": "Search labels...",
|
185 |
+
"andOthers": "And {count} others",
|
186 |
+
"refreshTooltip": "Reload graph data"
|
187 |
}
|
188 |
},
|
189 |
"retrievePanel": {
|
lightrag_webui/src/locales/zh.json
CHANGED
@@ -179,7 +179,8 @@
|
|
179 |
"noLabels": "未找到标签",
|
180 |
"label": "标签",
|
181 |
"placeholder": "搜索标签...",
|
182 |
-
"andOthers": "还有 {count} 个"
|
|
|
183 |
}
|
184 |
},
|
185 |
"retrievePanel": {
|
|
|
179 |
"noLabels": "未找到标签",
|
180 |
"label": "标签",
|
181 |
"placeholder": "搜索标签...",
|
182 |
+
"andOthers": "还有 {count} 个",
|
183 |
+
"refreshTooltip": "重新加载图形数据"
|
184 |
}
|
185 |
},
|
186 |
"retrievePanel": {
|