yangdx
commited on
Commit
·
5cfaefc
1
Parent(s):
18c85b7
Add label validation in GraphLabels component
Browse files- Validate queryLabel against available labels
- Reset to default if label not found
- Log warning when resetting label
lightrag_webui/src/components/graph/GraphLabels.tsx
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
import { useCallback } from 'react'
|
2 |
import { AsyncSelect } from '@/components/ui/AsyncSelect'
|
3 |
import { useSettingsStore } from '@/stores/settings'
|
4 |
import { useGraphStore } from '@/stores/graph'
|
@@ -56,6 +56,23 @@ const GraphLabels = () => {
|
|
56 |
[getSearchEngine]
|
57 |
)
|
58 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
const handleRefresh = useCallback(() => {
|
60 |
// Reset fetch status flags
|
61 |
useGraphStore.getState().setLabelsFetchAttempted(false)
|
|
|
1 |
+
import { useCallback, useEffect } from 'react'
|
2 |
import { AsyncSelect } from '@/components/ui/AsyncSelect'
|
3 |
import { useSettingsStore } from '@/stores/settings'
|
4 |
import { useGraphStore } from '@/stores/graph'
|
|
|
56 |
[getSearchEngine]
|
57 |
)
|
58 |
|
59 |
+
// Validate if current queryLabel exists in allDatabaseLabels
|
60 |
+
useEffect(() => {
|
61 |
+
// Only update label when all conditions are met:
|
62 |
+
// 1. allDatabaseLabels is loaded (length > 1, as it has at least '*' by default)
|
63 |
+
// 2. Current label is not the default '*'
|
64 |
+
// 3. Current label doesn't exist in allDatabaseLabels
|
65 |
+
if (
|
66 |
+
allDatabaseLabels.length > 1 &&
|
67 |
+
label &&
|
68 |
+
label !== '*' &&
|
69 |
+
!allDatabaseLabels.includes(label)
|
70 |
+
) {
|
71 |
+
console.log(`Label "${label}" not found in available labels, resetting to default`);
|
72 |
+
useSettingsStore.getState().setQueryLabel('*');
|
73 |
+
}
|
74 |
+
}, [allDatabaseLabels, label]);
|
75 |
+
|
76 |
const handleRefresh = useCallback(() => {
|
77 |
// Reset fetch status flags
|
78 |
useGraphStore.getState().setLabelsFetchAttempted(false)
|