Fix: graph label not set on grapview initial mount
This commit is contained in:
@@ -189,19 +189,10 @@ const useLightrangeGraph = () => {
|
||||
const nodeToExpand = useGraphStore.use.nodeToExpand()
|
||||
const nodeToPrune = useGraphStore.use.nodeToPrune()
|
||||
|
||||
// Track previous parameters to detect actual changes
|
||||
const prevParamsRef = useRef({ queryLabel, maxQueryDepth, minDegree })
|
||||
|
||||
// Use ref to track if data has been loaded and initial load
|
||||
const dataLoadedRef = useRef(false)
|
||||
const initialLoadRef = useRef(false)
|
||||
|
||||
// Check if parameters have changed
|
||||
const paramsChanged =
|
||||
prevParamsRef.current.queryLabel !== queryLabel ||
|
||||
prevParamsRef.current.maxQueryDepth !== maxQueryDepth ||
|
||||
prevParamsRef.current.minDegree !== minDegree
|
||||
|
||||
const getNode = useCallback(
|
||||
(nodeId: string) => {
|
||||
return rawGraph?.getNode(nodeId) || null
|
||||
@@ -219,30 +210,27 @@ const useLightrangeGraph = () => {
|
||||
// Track if a fetch is in progress to prevent multiple simultaneous fetches
|
||||
const fetchInProgressRef = useRef(false)
|
||||
|
||||
// Data fetching logic - simplified but preserving TAB visibility check
|
||||
// Reset graph when query label is cleared
|
||||
useEffect(() => {
|
||||
// Skip if fetch is already in progress
|
||||
if (fetchInProgressRef.current) {
|
||||
return
|
||||
}
|
||||
|
||||
// If there's no query label, reset the graph
|
||||
if (!queryLabel) {
|
||||
if (rawGraph !== null || sigmaGraph !== null) {
|
||||
const state = useGraphStore.getState()
|
||||
state.reset()
|
||||
state.setGraphDataFetchAttempted(false)
|
||||
state.setLabelsFetchAttempted(false)
|
||||
}
|
||||
if (!queryLabel && (rawGraph !== null || sigmaGraph !== null)) {
|
||||
const state = useGraphStore.getState()
|
||||
state.reset()
|
||||
state.setGraphDataFetchAttempted(false)
|
||||
state.setLabelsFetchAttempted(false)
|
||||
dataLoadedRef.current = false
|
||||
initialLoadRef.current = false
|
||||
}
|
||||
}, [queryLabel, rawGraph, sigmaGraph])
|
||||
|
||||
// Data fetching logic
|
||||
useEffect(() => {
|
||||
// Skip if fetch is already in progress or no query label
|
||||
if (fetchInProgressRef.current || !queryLabel) {
|
||||
return
|
||||
}
|
||||
|
||||
// Check if parameters have changed
|
||||
if (!isFetching && !fetchInProgressRef.current &&
|
||||
(paramsChanged || !useGraphStore.getState().graphDataFetchAttempted)) {
|
||||
|
||||
// Only fetch data when graphDataFetchAttempted is false
|
||||
if (!isFetching && !useGraphStore.getState().graphDataFetchAttempted) {
|
||||
// Set flags
|
||||
fetchInProgressRef.current = true
|
||||
useGraphStore.getState().setGraphDataFetchAttempted(true)
|
||||
@@ -258,9 +246,6 @@ const useLightrangeGraph = () => {
|
||||
})
|
||||
}
|
||||
|
||||
// Update parameter reference
|
||||
prevParamsRef.current = { queryLabel, maxQueryDepth, minDegree }
|
||||
|
||||
console.log('Fetching graph data...')
|
||||
|
||||
// Use a local copy of the parameters
|
||||
@@ -283,8 +268,6 @@ const useLightrangeGraph = () => {
|
||||
state.setSigmaGraph(newSigmaGraph)
|
||||
state.setRawGraph(data)
|
||||
|
||||
// No longer need to extract labels from graph data
|
||||
|
||||
// Update flags
|
||||
dataLoadedRef.current = true
|
||||
initialLoadRef.current = true
|
||||
@@ -305,7 +288,7 @@ const useLightrangeGraph = () => {
|
||||
state.setGraphDataFetchAttempted(false)
|
||||
})
|
||||
}
|
||||
}, [queryLabel, maxQueryDepth, minDegree, isFetching, paramsChanged, rawGraph, sigmaGraph])
|
||||
}, [queryLabel, maxQueryDepth, minDegree, isFetching])
|
||||
|
||||
// Handle node expansion
|
||||
useEffect(() => {
|
||||
|
Reference in New Issue
Block a user