Merge branch 'fix-query-label-missing'

This commit is contained in:
yangdx
2025-04-05 06:07:44 +08:00

View File

@@ -1,4 +1,4 @@
import { useCallback } from 'react' import { useCallback, useEffect } from 'react'
import { AsyncSelect } from '@/components/ui/AsyncSelect' import { AsyncSelect } from '@/components/ui/AsyncSelect'
import { useSettingsStore } from '@/stores/settings' import { useSettingsStore } from '@/stores/settings'
import { useGraphStore } from '@/stores/graph' import { useGraphStore } from '@/stores/graph'
@@ -56,6 +56,23 @@ const GraphLabels = () => {
[getSearchEngine] [getSearchEngine]
) )
// Validate if current queryLabel exists in allDatabaseLabels
useEffect(() => {
// Only update label when all conditions are met:
// 1. allDatabaseLabels is loaded (length > 1, as it has at least '*' by default)
// 2. Current label is not the default '*'
// 3. Current label doesn't exist in allDatabaseLabels
if (
allDatabaseLabels.length > 1 &&
label &&
label !== '*' &&
!allDatabaseLabels.includes(label)
) {
console.log(`Label "${label}" not found in available labels, resetting to default`);
useSettingsStore.getState().setQueryLabel('*');
}
}, [allDatabaseLabels, label]);
const handleRefresh = useCallback(() => { const handleRefresh = useCallback(() => {
// Reset fetch status flags // Reset fetch status flags
useGraphStore.getState().setLabelsFetchAttempted(false) useGraphStore.getState().setLabelsFetchAttempted(false)