Fix linting

This commit is contained in:
yangdx
2025-03-14 00:03:45 +08:00
parent 1a92d46bff
commit 55d796c669
13 changed files with 167 additions and 167 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -8,8 +8,8 @@
<link rel="icon" type="image/svg+xml" href="./logo.png" /> <link rel="icon" type="image/svg+xml" href="./logo.png" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Lightrag</title> <title>Lightrag</title>
<script type="module" crossorigin src="./assets/index-DbL6qA5M.js"></script> <script type="module" crossorigin src="./assets/index-CKDgttI2.js"></script>
<link rel="stylesheet" crossorigin href="./assets/index-CRQxBxm4.css"> <link rel="stylesheet" crossorigin href="./assets/index-ban2VJxS.css">
</head> </head>
<body> <body>
<div id="root"></div> <div id="root"></div>

View File

@@ -11,23 +11,23 @@ const GraphLabels = () => {
const label = useSettingsStore.use.queryLabel() const label = useSettingsStore.use.queryLabel()
const allDatabaseLabels = useGraphStore.use.allDatabaseLabels() const allDatabaseLabels = useGraphStore.use.allDatabaseLabels()
const labelsLoadedRef = useRef(false) const labelsLoadedRef = useRef(false)
// Track if a fetch is in progress to prevent multiple simultaneous fetches // Track if a fetch is in progress to prevent multiple simultaneous fetches
const fetchInProgressRef = useRef(false) const fetchInProgressRef = useRef(false)
// Fetch labels once on component mount, using global flag to prevent duplicates // Fetch labels once on component mount, using global flag to prevent duplicates
useEffect(() => { useEffect(() => {
// Check if we've already attempted to fetch labels in this session // Check if we've already attempted to fetch labels in this session
const labelsFetchAttempted = useGraphStore.getState().labelsFetchAttempted const labelsFetchAttempted = useGraphStore.getState().labelsFetchAttempted
// Only fetch if we haven't attempted in this session and no fetch is in progress // Only fetch if we haven't attempted in this session and no fetch is in progress
if (!labelsFetchAttempted && !fetchInProgressRef.current) { if (!labelsFetchAttempted && !fetchInProgressRef.current) {
fetchInProgressRef.current = true fetchInProgressRef.current = true
// Set global flag to indicate we've attempted to fetch in this session // Set global flag to indicate we've attempted to fetch in this session
useGraphStore.getState().setLabelsFetchAttempted(true) useGraphStore.getState().setLabelsFetchAttempted(true)
console.log('Fetching graph labels (once per session)...') console.log('Fetching graph labels (once per session)...')
useGraphStore.getState().fetchAllDatabaseLabels() useGraphStore.getState().fetchAllDatabaseLabels()
.then(() => { .then(() => {
labelsLoadedRef.current = true labelsLoadedRef.current = true
@@ -103,22 +103,22 @@ const GraphLabels = () => {
if (newLabel === '...') { if (newLabel === '...') {
newLabel = '*' newLabel = '*'
} }
// Reset the fetch attempted flag to force a new data fetch // Reset the fetch attempted flag to force a new data fetch
useGraphStore.getState().setGraphDataFetchAttempted(false) useGraphStore.getState().setGraphDataFetchAttempted(false)
// Clear current graph data to ensure complete reload when label changes // Clear current graph data to ensure complete reload when label changes
if (newLabel !== currentLabel) { if (newLabel !== currentLabel) {
const graphStore = useGraphStore.getState(); const graphStore = useGraphStore.getState();
graphStore.clearSelection(); graphStore.clearSelection();
// Reset the graph state but preserve the instance // Reset the graph state but preserve the instance
if (graphStore.sigmaGraph) { if (graphStore.sigmaGraph) {
const nodes = Array.from(graphStore.sigmaGraph.nodes()); const nodes = Array.from(graphStore.sigmaGraph.nodes());
nodes.forEach(node => graphStore.sigmaGraph?.dropNode(node)); nodes.forEach(node => graphStore.sigmaGraph?.dropNode(node));
} }
} }
if (newLabel === currentLabel && newLabel !== '*') { if (newLabel === currentLabel && newLabel !== '*') {
// 选择相同标签时切换到'*' // 选择相同标签时切换到'*'
useSettingsStore.getState().setQueryLabel('*') useSettingsStore.getState().setQueryLabel('*')

View File

@@ -18,7 +18,7 @@ const TabContent: React.FC<TabContentProps> = ({ tabId, children, className = ''
// Register this tab with the context when mounted // Register this tab with the context when mounted
useEffect(() => { useEffect(() => {
setTabVisibility(tabId, true); setTabVisibility(tabId, true);
// Cleanup when unmounted // Cleanup when unmounted
return () => { return () => {
setTabVisibility(tabId, false); setTabVisibility(tabId, false);

View File

@@ -14,7 +14,7 @@ interface TabVisibilityProviderProps {
export const TabVisibilityProvider: React.FC<TabVisibilityProviderProps> = ({ children }) => { export const TabVisibilityProvider: React.FC<TabVisibilityProviderProps> = ({ children }) => {
// Get current tab from settings store // Get current tab from settings store
const currentTab = useSettingsStore.use.currentTab(); const currentTab = useSettingsStore.use.currentTab();
// Initialize visibility state with current tab as visible // Initialize visibility state with current tab as visible
const [visibleTabs, setVisibleTabs] = useState<Record<string, boolean>>(() => ({ const [visibleTabs, setVisibleTabs] = useState<Record<string, boolean>>(() => ({
[currentTab]: true [currentTab]: true

View File

@@ -8,10 +8,10 @@ import { TabVisibilityContextType } from './types';
*/ */
export const useTabVisibility = (): TabVisibilityContextType => { export const useTabVisibility = (): TabVisibilityContextType => {
const context = useContext(TabVisibilityContext); const context = useContext(TabVisibilityContext);
if (!context) { if (!context) {
throw new Error('useTabVisibility must be used within a TabVisibilityProvider'); throw new Error('useTabVisibility must be used within a TabVisibilityProvider');
} }
return context; return context;
}; };

View File

@@ -8,20 +8,20 @@ export default function ApiSite() {
const { isTabVisible } = useTabVisibility() const { isTabVisible } = useTabVisibility()
const isApiTabVisible = isTabVisible('api') const isApiTabVisible = isTabVisible('api')
const [iframeLoaded, setIframeLoaded] = useState(false) const [iframeLoaded, setIframeLoaded] = useState(false)
// Load the iframe once on component mount // Load the iframe once on component mount
useEffect(() => { useEffect(() => {
if (!iframeLoaded) { if (!iframeLoaded) {
setIframeLoaded(true) setIframeLoaded(true)
} }
}, [iframeLoaded]) }, [iframeLoaded])
// Use CSS to hide content when tab is not visible // Use CSS to hide content when tab is not visible
return ( return (
<div className={`size-full ${isApiTabVisible ? '' : 'hidden'}`}> <div className={`size-full ${isApiTabVisible ? '' : 'hidden'}`}>
{iframeLoaded ? ( {iframeLoaded ? (
<iframe <iframe
src={backendBaseUrl + '/docs'} src={backendBaseUrl + '/docs'}
className="size-full w-full h-full" className="size-full w-full h-full"
style={{ width: '100%', height: '100%', border: 'none' }} style={{ width: '100%', height: '100%', border: 'none' }}
// Use key to ensure iframe doesn't reload // Use key to ensure iframe doesn't reload

View File

@@ -76,7 +76,7 @@ export default function DocumentManager() {
if (!isDocumentsTabVisible || !health) { if (!isDocumentsTabVisible || !health) {
return return
} }
const interval = setInterval(async () => { const interval = setInterval(async () => {
try { try {
await fetchDocuments() await fetchDocuments()
@@ -84,7 +84,7 @@ export default function DocumentManager() {
toast.error(t('documentPanel.documentManager.errors.scanProgressFailed', { error: errorMessage(err) })) toast.error(t('documentPanel.documentManager.errors.scanProgressFailed', { error: errorMessage(err) }))
} }
}, 5000) }, 5000)
return () => clearInterval(interval) return () => clearInterval(interval)
}, [health, fetchDocuments, t, isDocumentsTabVisible]) }, [health, fetchDocuments, t, isDocumentsTabVisible])

View File

@@ -115,7 +115,7 @@ const GraphViewer = () => {
const moveToSelectedNode = useGraphStore.use.moveToSelectedNode() const moveToSelectedNode = useGraphStore.use.moveToSelectedNode()
const isFetching = useGraphStore.use.isFetching() const isFetching = useGraphStore.use.isFetching()
const shouldRender = useGraphStore.use.shouldRender() // Rendering control state const shouldRender = useGraphStore.use.shouldRender() // Rendering control state
// Get tab visibility // Get tab visibility
const { isTabVisible } = useTabVisibility() const { isTabVisible } = useTabVisibility()
const isGraphTabVisible = isTabVisible('knowledge-graph') const isGraphTabVisible = isTabVisible('knowledge-graph')
@@ -137,7 +137,7 @@ const GraphViewer = () => {
initAttemptedRef.current = true initAttemptedRef.current = true
console.log('Graph viewer initialized') console.log('Graph viewer initialized')
} }
// Cleanup function when component unmounts // Cleanup function when component unmounts
return () => { return () => {
// Only log cleanup, don't actually clean up the WebGL context // Only log cleanup, don't actually clean up the WebGL context

View File

@@ -148,7 +148,7 @@ const createSigmaGraph = (rawGraph: RawGraph | null) => {
seedrandom(rawNode.id + Date.now().toString(), { global: true }) seedrandom(rawNode.id + Date.now().toString(), { global: true })
const x = Math.random() const x = Math.random()
const y = Math.random() const y = Math.random()
graph.addNode(rawNode.id, { graph.addNode(rawNode.id, {
label: rawNode.labels.join(', '), label: rawNode.labels.join(', '),
color: rawNode.color, color: rawNode.color,
@@ -178,20 +178,20 @@ const useLightrangeGraph = () => {
const maxQueryDepth = useSettingsStore.use.graphQueryMaxDepth() const maxQueryDepth = useSettingsStore.use.graphQueryMaxDepth()
const minDegree = useSettingsStore.use.graphMinDegree() const minDegree = useSettingsStore.use.graphMinDegree()
const isFetching = useGraphStore.use.isFetching() const isFetching = useGraphStore.use.isFetching()
// Get tab visibility // Get tab visibility
const { isTabVisible } = useTabVisibility() const { isTabVisible } = useTabVisibility()
const isGraphTabVisible = isTabVisible('knowledge-graph') const isGraphTabVisible = isTabVisible('knowledge-graph')
// Track previous parameters to detect actual changes // Track previous parameters to detect actual changes
const prevParamsRef = useRef({ queryLabel, maxQueryDepth, minDegree }) const prevParamsRef = useRef({ queryLabel, maxQueryDepth, minDegree })
// Use ref to track if data has been loaded and initial load // Use ref to track if data has been loaded and initial load
const dataLoadedRef = useRef(false) const dataLoadedRef = useRef(false)
const initialLoadRef = useRef(false) const initialLoadRef = useRef(false)
// Check if parameters have changed // Check if parameters have changed
const paramsChanged = const paramsChanged =
prevParamsRef.current.queryLabel !== queryLabel || prevParamsRef.current.queryLabel !== queryLabel ||
prevParamsRef.current.maxQueryDepth !== maxQueryDepth || prevParamsRef.current.maxQueryDepth !== maxQueryDepth ||
prevParamsRef.current.minDegree !== minDegree prevParamsRef.current.minDegree !== minDegree
@@ -212,14 +212,14 @@ const useLightrangeGraph = () => {
// Track if a fetch is in progress to prevent multiple simultaneous fetches // Track if a fetch is in progress to prevent multiple simultaneous fetches
const fetchInProgressRef = useRef(false) const fetchInProgressRef = useRef(false)
// Data fetching logic - simplified but preserving TAB visibility check // Data fetching logic - simplified but preserving TAB visibility check
useEffect(() => { useEffect(() => {
// Skip if fetch is already in progress // Skip if fetch is already in progress
if (fetchInProgressRef.current) { if (fetchInProgressRef.current) {
return return
} }
// If there's no query label, reset the graph // If there's no query label, reset the graph
if (!queryLabel) { if (!queryLabel) {
if (rawGraph !== null || sigmaGraph !== null) { if (rawGraph !== null || sigmaGraph !== null) {
@@ -233,25 +233,25 @@ const useLightrangeGraph = () => {
initialLoadRef.current = false initialLoadRef.current = false
return return
} }
// Check if parameters have changed // Check if parameters have changed
if (!isFetching && !fetchInProgressRef.current && if (!isFetching && !fetchInProgressRef.current &&
(paramsChanged || !useGraphStore.getState().graphDataFetchAttempted)) { (paramsChanged || !useGraphStore.getState().graphDataFetchAttempted)) {
// Only fetch data if the Graph tab is visible // Only fetch data if the Graph tab is visible
if (!isGraphTabVisible) { if (!isGraphTabVisible) {
console.log('Graph tab not visible, skipping data fetch'); console.log('Graph tab not visible, skipping data fetch');
return; return;
} }
// Set flags // Set flags
fetchInProgressRef.current = true fetchInProgressRef.current = true
useGraphStore.getState().setGraphDataFetchAttempted(true) useGraphStore.getState().setGraphDataFetchAttempted(true)
const state = useGraphStore.getState() const state = useGraphStore.getState()
state.setIsFetching(true) state.setIsFetching(true)
state.setShouldRender(false) // Disable rendering during data loading state.setShouldRender(false) // Disable rendering during data loading
// Clear selection and highlighted nodes before fetching new graph // Clear selection and highlighted nodes before fetching new graph
state.clearSelection() state.clearSelection()
if (state.sigmaGraph) { if (state.sigmaGraph) {
@@ -259,32 +259,32 @@ const useLightrangeGraph = () => {
state.sigmaGraph?.setNodeAttribute(node, 'highlighted', false) state.sigmaGraph?.setNodeAttribute(node, 'highlighted', false)
}) })
} }
// Update parameter reference // Update parameter reference
prevParamsRef.current = { queryLabel, maxQueryDepth, minDegree } prevParamsRef.current = { queryLabel, maxQueryDepth, minDegree }
console.log('Fetching graph data...') console.log('Fetching graph data...')
// Use a local copy of the parameters // Use a local copy of the parameters
const currentQueryLabel = queryLabel const currentQueryLabel = queryLabel
const currentMaxQueryDepth = maxQueryDepth const currentMaxQueryDepth = maxQueryDepth
const currentMinDegree = minDegree const currentMinDegree = minDegree
// Fetch graph data // Fetch graph data
fetchGraph(currentQueryLabel, currentMaxQueryDepth, currentMinDegree).then((data) => { fetchGraph(currentQueryLabel, currentMaxQueryDepth, currentMinDegree).then((data) => {
const state = useGraphStore.getState() const state = useGraphStore.getState()
// Reset state // Reset state
state.reset() state.reset()
// Create and set new graph directly // Create and set new graph directly
const newSigmaGraph = createSigmaGraph(data) const newSigmaGraph = createSigmaGraph(data)
data?.buildDynamicMap() data?.buildDynamicMap()
// Set new graph data // Set new graph data
state.setSigmaGraph(newSigmaGraph) state.setSigmaGraph(newSigmaGraph)
state.setRawGraph(data) state.setRawGraph(data)
// Extract labels from current graph data // Extract labels from current graph data
if (data) { if (data) {
const labelSet = new Set<string>() const labelSet = new Set<string>()
@@ -303,21 +303,21 @@ const useLightrangeGraph = () => {
} else { } else {
state.setGraphLabels(['*']) state.setGraphLabels(['*'])
} }
// Update flags // Update flags
dataLoadedRef.current = true dataLoadedRef.current = true
initialLoadRef.current = true initialLoadRef.current = true
fetchInProgressRef.current = false fetchInProgressRef.current = false
// Reset camera view // Reset camera view
state.setMoveToSelectedNode(true) state.setMoveToSelectedNode(true)
// Enable rendering if the tab is visible // Enable rendering if the tab is visible
state.setShouldRender(isGraphTabVisible) state.setShouldRender(isGraphTabVisible)
state.setIsFetching(false) state.setIsFetching(false)
}).catch((error) => { }).catch((error) => {
console.error('Error fetching graph data:', error) console.error('Error fetching graph data:', error)
// Reset state on error // Reset state on error
const state = useGraphStore.getState() const state = useGraphStore.getState()
state.setIsFetching(false) state.setIsFetching(false)
@@ -328,7 +328,7 @@ const useLightrangeGraph = () => {
}) })
} }
}, [queryLabel, maxQueryDepth, minDegree, isFetching, paramsChanged, isGraphTabVisible, rawGraph, sigmaGraph]) }, [queryLabel, maxQueryDepth, minDegree, isFetching, paramsChanged, isGraphTabVisible, rawGraph, sigmaGraph])
// Update rendering state and handle tab visibility changes // Update rendering state and handle tab visibility changes
useEffect(() => { useEffect(() => {
// When tab becomes visible // When tab becomes visible
@@ -337,7 +337,7 @@ const useLightrangeGraph = () => {
if (rawGraph) { if (rawGraph) {
useGraphStore.getState().setShouldRender(true) useGraphStore.getState().setShouldRender(true)
} }
// We no longer reset the fetch attempted flag here to prevent continuous API calls // We no longer reset the fetch attempted flag here to prevent continuous API calls
} else { } else {
// When tab becomes invisible, disable rendering // When tab becomes invisible, disable rendering
@@ -350,7 +350,7 @@ const useLightrangeGraph = () => {
if (sigmaGraph) { if (sigmaGraph) {
return sigmaGraph as Graph<NodeType, EdgeType> return sigmaGraph as Graph<NodeType, EdgeType>
} }
// If no graph exists yet, create a new one and store it // If no graph exists yet, create a new one and store it
console.log('Creating new Sigma graph instance') console.log('Creating new Sigma graph instance')
const graph = new DirectedGraph() const graph = new DirectedGraph()

View File

@@ -72,7 +72,7 @@ interface GraphState {
moveToSelectedNode: boolean moveToSelectedNode: boolean
isFetching: boolean isFetching: boolean
shouldRender: boolean shouldRender: boolean
// Global flags to track data fetching attempts // Global flags to track data fetching attempts
graphDataFetchAttempted: boolean graphDataFetchAttempted: boolean
labelsFetchAttempted: boolean labelsFetchAttempted: boolean
@@ -94,7 +94,7 @@ interface GraphState {
fetchAllDatabaseLabels: () => Promise<void> fetchAllDatabaseLabels: () => Promise<void>
setIsFetching: (isFetching: boolean) => void setIsFetching: (isFetching: boolean) => void
setShouldRender: (shouldRender: boolean) => void setShouldRender: (shouldRender: boolean) => void
// Methods to set global flags // Methods to set global flags
setGraphDataFetchAttempted: (attempted: boolean) => void setGraphDataFetchAttempted: (attempted: boolean) => void
setLabelsFetchAttempted: (attempted: boolean) => void setLabelsFetchAttempted: (attempted: boolean) => void
@@ -109,7 +109,7 @@ const useGraphStoreBase = create<GraphState>()((set, get) => ({
moveToSelectedNode: false, moveToSelectedNode: false,
isFetching: false, isFetching: false,
shouldRender: false, shouldRender: false,
// Initialize global flags // Initialize global flags
graphDataFetchAttempted: false, graphDataFetchAttempted: false,
labelsFetchAttempted: false, labelsFetchAttempted: false,
@@ -147,13 +147,13 @@ const useGraphStoreBase = create<GraphState>()((set, get) => ({
reset: () => { reset: () => {
// Get the existing graph // Get the existing graph
const existingGraph = get().sigmaGraph; const existingGraph = get().sigmaGraph;
// If we have an existing graph, clear it by removing all nodes // If we have an existing graph, clear it by removing all nodes
if (existingGraph) { if (existingGraph) {
const nodes = Array.from(existingGraph.nodes()); const nodes = Array.from(existingGraph.nodes());
nodes.forEach(node => existingGraph.dropNode(node)); nodes.forEach(node => existingGraph.dropNode(node));
} }
set({ set({
selectedNode: null, selectedNode: null,
focusedNode: null, focusedNode: null,
@@ -195,7 +195,7 @@ const useGraphStoreBase = create<GraphState>()((set, get) => ({
}, },
setMoveToSelectedNode: (moveToSelectedNode?: boolean) => set({ moveToSelectedNode }), setMoveToSelectedNode: (moveToSelectedNode?: boolean) => set({ moveToSelectedNode }),
// Methods to set global flags // Methods to set global flags
setGraphDataFetchAttempted: (attempted: boolean) => set({ graphDataFetchAttempted: attempted }), setGraphDataFetchAttempted: (attempted: boolean) => set({ graphDataFetchAttempted: attempted }),
setLabelsFetchAttempted: (attempted: boolean) => set({ labelsFetchAttempted: attempted }) setLabelsFetchAttempted: (attempted: boolean) => set({ labelsFetchAttempted: attempted })