Skip to content

Commit 6a1a914

Browse files
committed
fix(ui): auto-clear connection error indicator when Redis reconnects
- Clear connectivity error on successful API response, avoiding stale closure issues where the callback captures an outdated value - Remove unused handleRefreshClick callback since loadData() is already called via onRefresh Fixes: #RI-7761
1 parent f7ba473 commit 6a1a914

File tree

4 files changed

+12
-28
lines changed

4 files changed

+12
-28
lines changed

redisinsight/ui/src/components/database-overview/DatabaseOverview.spec.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ const defaultMockHook = () => ({
3535
usedMemoryPercent: undefined,
3636
handleEnableAutoRefresh: jest.fn(),
3737
handleRefresh: jest.fn(),
38-
handleRefreshClick: jest.fn(),
3938
})
4039

4140
describe('DatabaseOverview', () => {

redisinsight/ui/src/components/database-overview/DatabaseOverview.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ const DatabaseOverview = () => {
3030
isBdbPackages,
3131
lastRefreshTime,
3232
handleEnableAutoRefresh,
33-
handleRefreshClick,
3433
handleRefresh,
3534
} = useDatabaseOverview()
3635

@@ -102,7 +101,6 @@ const DatabaseOverview = () => {
102101
DATABASE_OVERVIEW_MINIMUM_REFRESH_INTERVAL,
103102
)}
104103
onRefresh={handleRefresh}
105-
onRefreshClicked={handleRefreshClick}
106104
onEnableAutoRefresh={handleEnableAutoRefresh}
107105
/>
108106
</FlexItem>

redisinsight/ui/src/components/database-overview/hooks/useDatabaseOverview.spec.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
renderHook,
77
} from 'uiSrc/utils/test-utils'
88
import { getDatabaseConfigInfo } from 'uiSrc/slices/instances/instances'
9-
import { setConnectivityError } from 'uiSrc/slices/app/connectivity'
109
import { sendEventTelemetry, TelemetryEvent } from 'uiSrc/telemetry'
1110
import { useDatabaseOverview } from './useDatabaseOverview'
1211

@@ -97,7 +96,6 @@ describe('useDatabaseOverview', () => {
9796
expect(data.isBdbPackages).toBeUndefined()
9897
expect(data.usedMemoryPercent).toBeUndefined()
9998
expect(typeof data.handleRefresh).toBe('function')
100-
expect(typeof data.handleRefreshClick).toBe('function')
10199
expect(typeof data.handleEnableAutoRefresh).toBe('function')
102100
})
103101

@@ -158,19 +156,6 @@ describe('useDatabaseOverview', () => {
158156
expect(actions).toContainEqual(getDatabaseConfigInfo())
159157
})
160158

161-
it('should handle refresh click correctly', () => {
162-
// Clear previous actions
163-
mockedStore.clearActions()
164-
165-
const data = renderHelper(mockedStore)
166-
act(() => {
167-
data.handleRefreshClick()
168-
})
169-
170-
const actions = mockedStore.getActions()
171-
expect(actions).toContainEqual(setConnectivityError(null))
172-
})
173-
174159
it('should send telemetry event when auto-refresh is enabled', () => {
175160
const data = renderHelper(mockedStore)
176161
act(() => {

redisinsight/ui/src/components/database-overview/hooks/useDatabaseOverview.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,16 @@ export const useDatabaseOverview = () => {
4848
} = {},
4949
} = overview
5050

51-
const loadData = (forceDataReload = false) => {
52-
if (connectedInstanceId && (!connectivityError || forceDataReload)) {
53-
dispatch(getDatabaseConfigInfoAction(connectedInstanceId))
51+
const loadData = () => {
52+
if (connectedInstanceId) {
53+
dispatch(
54+
getDatabaseConfigInfoAction(connectedInstanceId, () => {
55+
// Clear connectivity error on successful API call.
56+
// Always dispatch to avoid stale closure issues - dispatching null
57+
// when there's no error is a safe no-op.
58+
dispatch(setConnectivityError(null))
59+
}),
60+
)
5461
setLastRefreshTime(Date.now())
5562
}
5663
}
@@ -75,12 +82,8 @@ export const useDatabaseOverview = () => {
7582
},
7683
})
7784

78-
const handleRefresh = (forceRefresh?: boolean) => {
79-
loadData(forceRefresh)
80-
}
81-
const handleRefreshClick = () => {
82-
// clear error, if connectivity is broken, the interceptor will set it again
83-
dispatch(setConnectivityError(null))
85+
const handleRefresh = () => {
86+
loadData()
8487
}
8588
const usedMemoryPercent = getUsedMemoryPercent(
8689
planMemoryLimit,
@@ -109,6 +112,5 @@ export const useDatabaseOverview = () => {
109112
usedMemoryPercent,
110113
handleEnableAutoRefresh,
111114
handleRefresh,
112-
handleRefreshClick,
113115
}
114116
}

0 commit comments

Comments
 (0)