Skip to content

Commit fea64c3

Browse files
committed
fix: resolve redux store circular dependencies
1 parent 83f64a6 commit fea64c3

File tree

13 files changed

+37
-32
lines changed

13 files changed

+37
-32
lines changed

redisinsight/ui/src/services/apiService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { isNumber } from 'lodash'
77
import { sessionStorageService } from 'uiSrc/services'
88
import { BrowserStorageItem } from 'uiSrc/constants'
99
import { CLOUD_AUTH_API_ENDPOINTS, CustomHeaders } from 'uiSrc/constants/api'
10-
import { store } from 'uiSrc/slices/store'
10+
import { store } from 'uiSrc/slices/store-dynamic'
1111
import { logoutUserAction } from 'uiSrc/slices/oauth/cloud'
1212
import { setConnectivityError } from 'uiSrc/slices/app/connectivity'
1313
import { getConfig } from 'uiSrc/config'

redisinsight/ui/src/slices/app/context.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ import {
5252
RedisResponseBuffer,
5353
StateAppContext,
5454
} from '../interfaces'
55-
import { AppDispatch, RootState } from '../store'
55+
import type { AppDispatch, RootState } from '../store'
5656

5757
export const initialState: StateAppContext = {
5858
workspace:

redisinsight/ui/src/slices/browser/keys.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ import {
100100
SearchHistoryItem,
101101
SearchMode,
102102
} from '../interfaces/keys'
103-
import { AppDispatch, RootState } from '../store'
103+
import type { AppDispatch, RootState } from '../store'
104104
import { StreamViewType } from '../interfaces/stream'
105105
import { EditorType, RedisResponseBuffer, RedisString } from '../interfaces'
106106

redisinsight/ui/src/slices/instances/instances.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import { ExportDatabase } from 'apiSrc/modules/database/models/export-database'
2828

2929
import { fetchMastersSentinelAction } from './sentinel'
3030
import { fetchTags } from './tags'
31-
import { AppDispatch, RootState } from '../store'
31+
import type { AppDispatch, RootState } from '../store'
3232
import {
3333
addErrorNotification,
3434
addInfiniteNotification,
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/* eslint-disable global-require */
2+
import type { RootState, AppDispatch } from './store'
3+
4+
// Importing store methods dynamically to avoid circular dependencies
5+
6+
const getState = (): RootState => {
7+
const { store } = require('uiSrc/slices/store')
8+
return store.getState() as RootState
9+
}
10+
11+
const dispatch: AppDispatch = (action: any) => {
12+
const { store } = require('uiSrc/slices/store')
13+
return store.dispatch(action)
14+
}
15+
16+
const store = {
17+
getState,
18+
dispatch,
19+
}
20+
21+
export { store }
22+
23+
export { RootState, AppDispatch }

redisinsight/ui/src/slices/store.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,5 +151,6 @@ const store = configureStore({
151151

152152
export { store }
153153

154+
export type ReduxStore = typeof store
154155
export type RootState = ReturnType<typeof rootReducer>
155156
export type AppDispatch = typeof store.dispatch

redisinsight/ui/src/slices/tests/browser/rejson.setJsonDataAction.spec.ts

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,6 @@ import { EditorType } from 'uiSrc/slices/interfaces'
44

55
const mockStore = configureStore([thunk])
66

7-
const originalConsoleError = console.error
8-
9-
// Suppress Redux warnings about missing reducers
10-
beforeAll(() => {
11-
console.error = (...args: any[]) => {
12-
const message = args[0]
13-
if (
14-
typeof message === 'string' &&
15-
message.includes('No reducer provided for key')
16-
) {
17-
return
18-
}
19-
20-
originalConsoleError(...args)
21-
}
22-
})
23-
24-
afterAll(() => {
25-
console.error = originalConsoleError
26-
})
27-
287
describe('setReJSONDataAction', () => {
298
let store: any
309
let sendEventTelemetryMock: jest.Mock

redisinsight/ui/src/telemetry/checkAnalytics.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { get } from 'lodash'
2-
import { store } from 'uiSrc/slices/store'
2+
import { store } from 'uiSrc/slices/store-dynamic'
33

44
// Check is user give access to collect his events
55
export const checkIsAnalyticsGranted = (): boolean =>

redisinsight/ui/src/telemetry/telemetryUtils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
RedisModulesKeyType,
1515
} from 'uiSrc/telemetry/interfaces'
1616
import { apiService } from 'uiSrc/services'
17-
import { store } from 'uiSrc/slices/store'
17+
import { store } from 'uiSrc/slices/store-dynamic'
1818
import { getInstanceInfo } from 'uiSrc/services/database/instancesService'
1919
import { AdditionalRedisModule } from 'apiSrc/modules/database/models/additional.redis.module'
2020
import { IRedisModulesSummary, MatchType, RedisModules } from './interfaces'

redisinsight/ui/src/utils/capability.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { OAuthSocialSource, RedisDefaultModules } from 'uiSrc/slices/interfaces'
2-
import { store } from 'uiSrc/slices/store'
2+
import { store } from 'uiSrc/slices/store-dynamic'
33
import { Nullable } from 'uiSrc/utils'
44
import { findMarkdownPath } from 'uiSrc/utils/workbench'
55

0 commit comments

Comments
 (0)