diff --git a/lightrag_webui/src/components/graph/GraphLabels.tsx b/lightrag_webui/src/components/graph/GraphLabels.tsx index b89c2e74..fb91bfb9 100644 --- a/lightrag_webui/src/components/graph/GraphLabels.tsx +++ b/lightrag_webui/src/components/graph/GraphLabels.tsx @@ -1,4 +1,4 @@ -import { useCallback } from 'react' +import { useCallback, useEffect } from 'react' import { AsyncSelect } from '@/components/ui/AsyncSelect' import { useSettingsStore } from '@/stores/settings' import { useGraphStore } from '@/stores/graph' @@ -56,6 +56,23 @@ const GraphLabels = () => { [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(() => { // Reset fetch status flags useGraphStore.getState().setLabelsFetchAttempted(false)