Skip to content

Commit 468575f

Browse files
authored
RI-7508: Fix compatibility resolving (#4985)
1 parent a51741c commit 468575f

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

redisinsight/ui/src/pages/vector-search/create-index/hooks/useRedisInstanceCompatibility.spec.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,33 @@ describe('useRedisInstanceCompatibility', () => {
2525
jest.clearAllMocks()
2626
})
2727

28+
it('returns undefineds when loading is undefined (not initialized yet)', () => {
29+
mockConnectedInstanceSelector.mockReturnValue({
30+
loading: undefined,
31+
modules: [{ name: 'search' }],
32+
version: '7.2.0',
33+
})
34+
35+
const hookResult = renderUseRedisInstanceCompatibility()
36+
expect(hookResult.loading).toBeUndefined()
37+
expect(hookResult.hasRedisearch).toBeUndefined()
38+
expect(hookResult.hasSupportedVersion).toBeUndefined()
39+
})
40+
41+
it('still returns hasRedisearch=undefined when modules is null even after init', () => {
42+
mockConnectedInstanceSelector.mockReturnValue({
43+
loading: false,
44+
modules: null,
45+
version: '7.2.0',
46+
})
47+
48+
const hookResult = renderUseRedisInstanceCompatibility()
49+
expect(hookResult.loading).toBe(false)
50+
// preserve prior behavior: null => unknown, not false
51+
expect(hookResult.hasRedisearch).toBeUndefined()
52+
expect(hookResult.hasSupportedVersion).toBe(true)
53+
})
54+
2855
it('returns loading=true when connectedInstanceSelector returns loading=true', () => {
2956
mockConnectedInstanceSelector.mockReturnValue({
3057
loading: true,

redisinsight/ui/src/pages/vector-search/create-index/hooks/useRedisInstanceCompatibility.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { useMemo } from 'react'
12
import { useSelector } from 'react-redux'
23
import { connectedInstanceSelector } from 'uiSrc/slices/instances/instances'
34
import { REDISEARCH_MODULES } from 'uiSrc/slices/interfaces'
@@ -20,15 +21,18 @@ const useRedisInstanceCompatibility =
2021
version,
2122
} = useSelector(connectedInstanceSelector)
2223

23-
const hasRedisearch = modules?.some((m) =>
24-
REDISEARCH_MODULE_SET.has(m.name),
24+
const isInitialized = loading !== undefined
25+
26+
const redisearchPresent = useMemo(
27+
() => modules?.some((m) => REDISEARCH_MODULE_SET.has(m.name)),
28+
[modules],
2529
)
2630

2731
return {
2832
loading,
29-
hasRedisearch: !loading ? hasRedisearch : undefined,
33+
hasRedisearch: isInitialized ? redisearchPresent : undefined,
3034
hasSupportedVersion:
31-
!loading && version
35+
isInitialized && version
3236
? isRedisVersionSupported(version, MIN_SUPPORTED_REDIS_VERSION)
3337
: undefined,
3438
}

0 commit comments

Comments
 (0)