From 5d80c698550bccb1e4dba8ee13ce3859d86a0789 Mon Sep 17 00:00:00 2001 From: yangdx Date: Sat, 5 Apr 2025 04:39:42 +0800 Subject: [PATCH] Add label validation in GraphLabels component - Validate queryLabel against available labels - Reset to default if label not found - Log warning when resetting label --- .../src/components/graph/GraphLabels.tsx | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) 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)