Fetch all labels and graph data again on refresh

This commit is contained in:
yangdx
2025-03-20 01:16:48 +08:00
parent 0210170ecd
commit e9fc12042c
2 changed files with 20 additions and 4 deletions

View File

@@ -93,9 +93,25 @@ const GraphLabels = () => {
)
const handleRefresh = useCallback(() => {
// Re-set the same label to trigger a refresh through useEffect
const currentLabel = useSettingsStore.getState().queryLabel
useSettingsStore.getState().setQueryLabel(currentLabel)
// Reset labels fetch status to allow fetching labels again
useGraphStore.getState().setLabelsFetchAttempted(false)
// Reset graph data fetch status directly, not depending on allDatabaseLabels changes
useGraphStore.getState().setGraphDataFetchAttempted(false)
// Fetch all labels again
useGraphStore.getState().fetchAllDatabaseLabels()
.then(() => {
// Trigger a graph data reload by changing the query label back and forth
const currentLabel = useSettingsStore.getState().queryLabel
useSettingsStore.getState().setQueryLabel('')
setTimeout(() => {
useSettingsStore.getState().setQueryLabel(currentLabel)
}, 0)
})
.catch((error) => {
console.error('Failed to refresh labels:', error)
})
}, [])
return (

View File

@@ -229,7 +229,7 @@ const useLightrangeGraph = () => {
return
}
// Only fetch data when graphDataFetchAttempted is false
// Only fetch data when graphDataFetchAttempted is false (avoids re-fetching on vite dev mode)
if (!isFetching && !useGraphStore.getState().graphDataFetchAttempted) {
// Set flags
fetchInProgressRef.current = true