yangdx
commited on
Commit
·
75d0b6d
1
Parent(s):
ae19f4a
Set queryLabel after query on page first load
Browse files
lightrag_webui/src/components/graph/GraphLabels.tsx
CHANGED
@@ -12,7 +12,8 @@ const GraphLabels = () => {
|
|
12 |
const { t } = useTranslation()
|
13 |
const label = useSettingsStore.use.queryLabel()
|
14 |
const allDatabaseLabels = useGraphStore.use.allDatabaseLabels()
|
15 |
-
|
|
|
16 |
// Remove initial label fetch effect as it's now handled by fetchGraph based on lastSuccessfulQueryLabel
|
17 |
|
18 |
const getSearchEngine = useCallback(() => {
|
@@ -56,22 +57,25 @@ const GraphLabels = () => {
|
|
56 |
[getSearchEngine]
|
57 |
)
|
58 |
|
59 |
-
//
|
60 |
useEffect(() => {
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
|
|
|
|
73 |
}
|
74 |
-
|
|
|
75 |
|
76 |
const handleRefresh = useCallback(() => {
|
77 |
// Reset fetch status flags
|
|
|
12 |
const { t } = useTranslation()
|
13 |
const label = useSettingsStore.use.queryLabel()
|
14 |
const allDatabaseLabels = useGraphStore.use.allDatabaseLabels()
|
15 |
+
const labelsFetchAttempted = useGraphStore.use.labelsFetchAttempted()
|
16 |
+
|
17 |
// Remove initial label fetch effect as it's now handled by fetchGraph based on lastSuccessfulQueryLabel
|
18 |
|
19 |
const getSearchEngine = useCallback(() => {
|
|
|
57 |
[getSearchEngine]
|
58 |
)
|
59 |
|
60 |
+
// Show queryLabel validation status
|
61 |
useEffect(() => {
|
62 |
+
|
63 |
+
if (labelsFetchAttempted) {
|
64 |
+
if (allDatabaseLabels.length > 1) {
|
65 |
+
if (label && label !== '*' && !allDatabaseLabels.includes(label)) {
|
66 |
+
console.log(`Label "${label}" not in available labels`);
|
67 |
+
// useSettingsStore.getState().setQueryLabel('*');
|
68 |
+
} else {
|
69 |
+
console.log(`Label "${label}" is valid`);
|
70 |
+
}
|
71 |
+
} else if (allDatabaseLabels.length <= 1 && label && label !== '*') {
|
72 |
+
console.log('Available labels list is empty');
|
73 |
+
// useSettingsStore.getState().setQueryLabel('');
|
74 |
+
}
|
75 |
+
useGraphStore.getState().setLabelsFetchAttempted(false)
|
76 |
}
|
77 |
+
|
78 |
+
}, [allDatabaseLabels, label, labelsFetchAttempted]);
|
79 |
|
80 |
const handleRefresh = useCallback(() => {
|
81 |
// Reset fetch status flags
|
lightrag_webui/src/hooks/useLightragGraph.tsx
CHANGED
@@ -119,6 +119,10 @@ const fetchGraph = async (label: string, maxDepth: number, maxNodes: number) =>
|
|
119 |
// Continue with graph fetch even if labels fetch fails
|
120 |
}
|
121 |
}
|
|
|
|
|
|
|
|
|
122 |
|
123 |
// If label is empty, use default label '*'
|
124 |
const queryLabel = label || '*';
|
@@ -339,6 +343,7 @@ const useLightrangeGraph = () => {
|
|
339 |
}
|
340 |
|
341 |
// Only fetch data when graphDataFetchAttempted is false (avoids re-fetching on vite dev mode)
|
|
|
342 |
if (!isFetching && !useGraphStore.getState().graphDataFetchAttempted) {
|
343 |
// Set flags
|
344 |
fetchInProgressRef.current = true
|
@@ -445,6 +450,13 @@ const useLightrangeGraph = () => {
|
|
445 |
state.setRawGraph(data);
|
446 |
state.setGraphIsEmpty(false);
|
447 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
448 |
// Update last successful query label
|
449 |
state.setLastSuccessfulQueryLabel(currentQueryLabel);
|
450 |
|
|
|
119 |
// Continue with graph fetch even if labels fetch fails
|
120 |
}
|
121 |
}
|
122 |
+
|
123 |
+
// Trigger GraphLabels component to check if the label is valid
|
124 |
+
// console.log('Setting labelsFetchAttempted to true');
|
125 |
+
useGraphStore.getState().setLabelsFetchAttempted(true)
|
126 |
|
127 |
// If label is empty, use default label '*'
|
128 |
const queryLabel = label || '*';
|
|
|
343 |
}
|
344 |
|
345 |
// Only fetch data when graphDataFetchAttempted is false (avoids re-fetching on vite dev mode)
|
346 |
+
// GraphDataFetchAttempted must set to false when queryLabel is changed
|
347 |
if (!isFetching && !useGraphStore.getState().graphDataFetchAttempted) {
|
348 |
// Set flags
|
349 |
fetchInProgressRef.current = true
|
|
|
450 |
state.setRawGraph(data);
|
451 |
state.setGraphIsEmpty(false);
|
452 |
|
453 |
+
// ensusre GraphLabels show the current label on first load
|
454 |
+
const lastSuccessfulQueryLabel = useGraphStore.getState().lastSuccessfulQueryLabel;
|
455 |
+
if (!lastSuccessfulQueryLabel){
|
456 |
+
useSettingsStore.getState().setQueryLabel('');
|
457 |
+
useSettingsStore.getState().setQueryLabel(queryLabel);
|
458 |
+
console.log('Set queryLabel after query on page first load');
|
459 |
+
}
|
460 |
// Update last successful query label
|
461 |
state.setLastSuccessfulQueryLabel(currentQueryLabel);
|
462 |
|