MCPcopy
hub / github.com/HKUDS/LightRAG / GraphLabels

Function GraphLabels

lightrag_webui/src/components/graph/GraphLabels.tsx:18–318  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

16import { getPopularLabels, searchLabels } from '@/api/lightrag'
17
18const GraphLabels = () => {
19 const { t } = useTranslation()
20 const label = useSettingsStore.use.queryLabel()
21 const dropdownRefreshTrigger = useSettingsStore.use.searchLabelDropdownRefreshTrigger()
22 const [isRefreshing, setIsRefreshing] = useState(false)
23 const [refreshTrigger, setRefreshTrigger] = useState(0)
24 const [selectKey, setSelectKey] = useState(0)
25
26 // Pipeline state monitoring
27 const pipelineBusy = useBackendState.use.pipelineBusy()
28 const prevPipelineBusy = useRef<boolean | undefined>(undefined)
29 const shouldRefreshPopularLabelsRef = useRef(false)
30
31 // Dynamic tooltip based on current label state
32 const getRefreshTooltip = useCallback(() => {
33 if (isRefreshing) {
34 return t('graphPanel.graphLabels.refreshingTooltip')
35 }
36
37 if (!label || label === '*') {
38 return t('graphPanel.graphLabels.refreshGlobalTooltip')
39 } else {
40 return t('graphPanel.graphLabels.refreshCurrentLabelTooltip', { label })
41 }
42 }, [label, t, isRefreshing])
43
44 // Initialize search history on component mount
45 useEffect(() => {
46 const initializeHistory = async () => {
47 const history = SearchHistoryManager.getHistory()
48
49 if (history.length === 0) {
50 // If no history exists, fetch popular labels and initialize
51 try {
52 const popularLabels = await getPopularLabels(popularLabelsDefaultLimit)
53 await SearchHistoryManager.initializeWithDefaults(popularLabels)
54 } catch (error) {
55 console.error('Failed to initialize search history:', error)
56 // No fallback needed, API is the source of truth
57 }
58 }
59 }
60
61 initializeHistory()
62 }, [])
63
64 // Force AsyncSelect to re-render when label or dropdownRefreshTrigger changes.
65 // Uses render-time previous-value comparison to avoid cascading renders from
66 // setState-in-useEffect, while still bumping the key on external changes.
67 const [previousLabel, setPreviousLabel] = useState(label)
68 const [previousDropdownTrigger, setPreviousDropdownTrigger] = useState(dropdownRefreshTrigger)
69 if (label !== previousLabel) {
70 setPreviousLabel(label)
71 setSelectKey(prev => prev + 1)
72 }
73 if (dropdownRefreshTrigger !== previousDropdownTrigger) {
74 setPreviousDropdownTrigger(dropdownRefreshTrigger)
75 if (dropdownRefreshTrigger > 0) {

Callers

nothing calls this directly

Calls 12

getPopularLabelsFunction · 0.90
searchLabelsFunction · 0.90
tFunction · 0.85
initializeHistoryFunction · 0.85
clearHistoryMethod · 0.80
getHistoryLabelsMethod · 0.80
getHistoryMethod · 0.80
addToHistoryMethod · 0.80
mapMethod · 0.45
filterMethod · 0.45
includesMethod · 0.45

Tested by

no test coverage detected