Skip to content

Commit 9e420e1

Browse files
#RI-4880 - update condition
1 parent ca2d44c commit 9e420e1

File tree

2 files changed

+72
-61
lines changed

2 files changed

+72
-61
lines changed

redisinsight/ui/src/utils/redistack.ts

Lines changed: 34 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,63 @@
1-
import { isArray, map, concat } from 'lodash'
1+
import { isArray, map, concat, remove, find } from 'lodash'
22
import { Instance, RedisDefaultModules } from 'uiSrc/slices/interfaces'
33
import { isVersionHigherOrEquals, Nullable } from 'uiSrc/utils'
44

5-
const REDISTACK_LOW_VERSION = '6.2.6'
6-
const REDISTACK_HIGH_VERSION = '7.1'
5+
const REDISTACK_VERSION = '6.2.5'
76

8-
const REDISTACK_LOW_VERSION_REQUIRE_MODULES: Array<string | Array<string>> = [
9-
RedisDefaultModules.ReJSON,
10-
RedisDefaultModules.Bloom,
11-
RedisDefaultModules.Graph,
12-
[RedisDefaultModules.Search, RedisDefaultModules.SearchLight],
13-
RedisDefaultModules.TimeSeries,
14-
]
15-
16-
const REDISTACK_HIGH_VERSION_REQUIRE_MODULES: Array<string | Array<string>> = [
7+
const REDISTACK_REQUIRE_MODULES: Array<string | Array<string>> = [
178
RedisDefaultModules.ReJSON,
189
RedisDefaultModules.Bloom,
1910
[RedisDefaultModules.Search, RedisDefaultModules.SearchLight],
2011
RedisDefaultModules.TimeSeries,
2112
]
2213

23-
const REDISTACK_HIGH_VERSION_OPTIONAL_MODULES: Array<string[]> = [
14+
const REDISTACK_OPTIONAL_MODULES: Array<string | Array<string>> = [
15+
RedisDefaultModules.Graph,
2416
[RedisDefaultModules.RedisGears, RedisDefaultModules.RedisGears2]
2517
]
2618

27-
const checkRediStackModules = (modules: any[], required: any[], optional: any[] = []) => {
19+
const checkRediStackModules = (modules: any[]) => {
2820
if (!modules?.length) return false
21+
const moduleNames = map(modules, 'name').sort()
2922

30-
if (modules.length === required.length) {
31-
return map(modules, 'name')
32-
.sort()
33-
.every((m, index) => (isArray(required[index])
34-
? (required[index] as Array<string>).some((rm) => rm === m)
35-
: required[index] === m))
23+
if (modules.length === REDISTACK_REQUIRE_MODULES.length) {
24+
return moduleNames
25+
.every((m, index) => (isArray(REDISTACK_REQUIRE_MODULES[index])
26+
? (REDISTACK_REQUIRE_MODULES[index] as Array<string>).some((rm) => rm === m)
27+
: REDISTACK_REQUIRE_MODULES[index] === m))
3628
}
3729

38-
if (modules.length === (required.length + optional.length)) {
39-
const rediStackModules = concat(required, optional).sort()
40-
return map(modules, 'name')
41-
.sort()
42-
.every((m, index) => (isArray(rediStackModules[index])
43-
? (rediStackModules[index] as Array<string>).some((rm) => rm === m)
44-
: rediStackModules[index] === m))
30+
if (modules.length > REDISTACK_REQUIRE_MODULES.length
31+
&& modules.length <= (REDISTACK_REQUIRE_MODULES.length + REDISTACK_OPTIONAL_MODULES.length)) {
32+
let isCustomModule = false
33+
const rediStackModules = concat(REDISTACK_REQUIRE_MODULES, REDISTACK_OPTIONAL_MODULES).sort()
34+
35+
const diff = rediStackModules.reduce((acc: Array<string>, current: string | Array<string>) => {
36+
const moduleName = isArray(current)
37+
? (current as Array<string>).find((item) => find(moduleNames, (m) => item === m))
38+
: find(moduleNames, (name) => name === current)
39+
40+
if (moduleName) {
41+
remove(acc, (name) => moduleName === name)
42+
return acc
43+
}
44+
isCustomModule = true
45+
return acc
46+
}, moduleNames)
47+
48+
return isCustomModule && !diff.length
4549
}
4650

4751
return false
4852
}
4953

5054
const isRediStack = (modules: any[], version?: Nullable<string>): boolean => {
5155
if (!version) {
52-
return checkRediStackModules(modules, REDISTACK_LOW_VERSION_REQUIRE_MODULES)
53-
}
54-
55-
if (isVersionHigherOrEquals(version, REDISTACK_HIGH_VERSION)) {
56-
return checkRediStackModules(
57-
modules,
58-
REDISTACK_HIGH_VERSION_REQUIRE_MODULES,
59-
REDISTACK_HIGH_VERSION_OPTIONAL_MODULES
60-
)
56+
return checkRediStackModules(modules)
6157
}
6258

63-
if (isVersionHigherOrEquals(version, REDISTACK_LOW_VERSION)) {
64-
return checkRediStackModules(modules, REDISTACK_LOW_VERSION_REQUIRE_MODULES)
59+
if (isVersionHigherOrEquals(version, REDISTACK_VERSION)) {
60+
return checkRediStackModules(modules)
6561
}
6662

6763
return false

redisinsight/ui/src/utils/tests/redistack.spec.ts

Lines changed: 38 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,45 @@ import { isRediStack } from 'uiSrc/utils'
44
const unmapWithName = (arr: any[]) => arr.map((item) => ({ name: item }))
55

66
const isRediStackTests = [
7-
{ input: [unmapWithName(['bf', 'timeseries', 'ReJSON', 'searchlight', 'graph', 'custom']), '6.2.6'], expected: false },
8-
{ input: [unmapWithName(['bf', 'timeseries', 'ReJSON', 'search', 'graph', 'custom']), '6.2.6'], expected: false },
9-
{ input: [unmapWithName(['bf', 'timeseries', 'ReJSON', 'searchlight', 'graph']), '6.2.6'], expected: true },
10-
{ input: [unmapWithName(['bf', 'timeseries', 'ReJSON', 'searchlight', 'graph'])], expected: true },
7+
{ input: [unmapWithName(['bf', 'timeseries', 'ReJSON', 'searchlight']), '6.2.5'], expected: true },
8+
{ input: [unmapWithName(['bf', 'timeseries', 'ReJSON', 'search']), '6.2.5'], expected: true },
9+
{ input: [unmapWithName(['bf', 'timeseries', 'ReJSON', 'search', 'searchlight']), '6.2.5'], expected: false },
10+
{ input: [unmapWithName(['bf', 'timeseries', 'ReJSON', 'searchlight', 'graph']), '6.2.5'], expected: true },
11+
{ input: [unmapWithName(['bf', 'timeseries', 'ReJSON', 'search', 'graph']), '6.2.5'], expected: true },
12+
{ input: [unmapWithName(['bf', 'timeseries', 'ReJSON', 'search', 'redisgears']), '6.2.5'], expected: true },
13+
{ input: [unmapWithName(['bf', 'timeseries', 'ReJSON', 'searchlight', 'redisgears']), '6.2.5'], expected: true },
14+
{ input: [unmapWithName(['bf', 'timeseries', 'ReJSON', 'search', 'redisgears_2']), '6.2.5'], expected: true },
15+
{ input: [unmapWithName(['bf', 'timeseries', 'ReJSON', 'searchlight', 'redisgears_2']), '6.2.5'], expected: true },
16+
{ input: [unmapWithName(['bf', 'timeseries', 'ReJSON', 'searchlight', 'search', 'redisgears_2']), '6.2.5'], expected: false },
17+
{ input: [unmapWithName(['bf', 'timeseries', 'ReJSON', 'searchlight', 'graph', 'redisgears_2']), '6.2.5'], expected: false },
18+
{ input: [unmapWithName(['bf', 'timeseries', 'ReJSON', 'search', 'graph', 'redisgears_2']), '6.2.5'], expected: false },
19+
{ input: [unmapWithName(['bf', 'timeseries', 'ReJSON', 'searchlight', 'graph', 'redisgears']), '6.2.5'], expected: false },
20+
{ input: [unmapWithName(['bf', 'timeseries', 'ReJSON', 'search', 'graph', 'redisgears']), '6.2.5'], expected: false },
21+
{ input: [unmapWithName(['bf', 'timeseries', 'ReJSON', 'search', 'graph', 'redisgears', 'redisgears_2']), '6.2.5'], expected: false },
22+
{ input: [unmapWithName(['bf', 'timeseries', 'ReJSON', 'searchlight', 'custom']), '6.2.5'], expected: false },
23+
{ input: [unmapWithName(['bf', 'timeseries', 'ReJSON', 'searchlight', 'graph', 'custom']), '6.2.5'], expected: false },
24+
{ input: [unmapWithName(['bf', 'timeseries', 'ReJSON', 'searchlight', 'graph', 'redisgears', 'custom']), '6.2.5'], expected: false },
25+
26+
{ input: [unmapWithName(['bf', 'timeseries', 'ReJSON', 'searchlight']), null], expected: true },
27+
{ input: [unmapWithName(['bf', 'timeseries', 'ReJSON', 'search']), null], expected: true },
28+
{ input: [unmapWithName(['bf', 'timeseries', 'ReJSON', 'search', 'searchlight']), null], expected: false },
1129
{ input: [unmapWithName(['bf', 'timeseries', 'ReJSON', 'searchlight', 'graph']), null], expected: true },
12-
{ input: [unmapWithName(['bf', 'timeseries', 'ReJSON', 'search']), null], expected: false },
13-
{ input: [unmapWithName(['bf', 'timeseries', 'ReJSON', 'rg', 'search'])], expected: false },
14-
{ input: [unmapWithName(['bf', 'timeseries', 'ReJSON', 'search', 'graph']), '6.2.6'], expected: true },
15-
{ input: [unmapWithName(['bf', 'timeseries', 'ReJSON', 'searchlight', 'graph']), '6.2.5'], expected: false },
16-
{ input: [unmapWithName(['bf', 'timeseries', 'ReJSON', 'search', 'graph']), '6.2.5'], expected: false },
17-
{ input: [unmapWithName(['bf', 'timeseries', 'ReJSON', 'searchlight', 'graph']), '7.1'], expected: false },
18-
{ input: [unmapWithName(['bf', 'timeseries', 'ReJSON', 'search', 'graph']), '7.1'], expected: false },
19-
{ input: [unmapWithName(['bf', 'timeseries', 'ReJSON', 'redisgears', 'searchlight']), '7.1'], expected: true },
20-
{ input: [unmapWithName(['bf', 'timeseries', 'ReJSON', 'redisgears', 'search']), '7.1'], expected: true },
21-
{ input: [unmapWithName(['bf', 'timeseries', 'ReJSON', 'redisgears_2', 'searchlight']), '7.1'], expected: true },
22-
{ input: [unmapWithName(['bf', 'timeseries', 'ReJSON', 'redisgears_2', 'search']), '7.1'], expected: true },
23-
{ input: [unmapWithName(['bf', 'timeseries', 'ReJSON', 'rg', 'searchlight']), '7.1'], expected: false },
24-
{ input: [unmapWithName(['bf', 'timeseries', 'ReJSON', 'rg', 'search']), '7.1'], expected: false },
25-
{ input: [unmapWithName(['bf', 'timeseries', 'ReJSON', 'redisgears_2', 'redisgears', 'search']), '7.1'], expected: false },
26-
{ input: [unmapWithName(['bf', 'timeseries', 'ReJSON', 'searchlight']), '7.1'], expected: true },
27-
{ input: [unmapWithName(['bf', 'timeseries', 'ReJSON', 'search']), '7.1'], expected: true },
28-
{ input: [unmapWithName(['bf', 'timeseries', 'ReJSON', 'search']), '7.1'], expected: true },
29-
{ input: [unmapWithName(['bf', 'timeseries', 'ReJSON', 'search', 'custom']), '7.1'], expected: false },
30-
{ input: [unmapWithName(['bf', 'timeseries', 'ReJSON', 'seasearchlightrch', 'custom']), '7.1'], expected: false },
30+
{ input: [unmapWithName(['bf', 'timeseries', 'ReJSON', 'search', 'graph']), null], expected: true },
31+
{ input: [unmapWithName(['bf', 'timeseries', 'ReJSON', 'search', 'redisgears']), null], expected: true },
32+
{ input: [unmapWithName(['bf', 'timeseries', 'ReJSON', 'searchlight', 'redisgears']), null], expected: true },
33+
{ input: [unmapWithName(['bf', 'timeseries', 'ReJSON', 'search', 'redisgears_2']), null], expected: true },
34+
{ input: [unmapWithName(['bf', 'timeseries', 'ReJSON', 'searchlight', 'redisgears_2']), null], expected: true },
35+
{ input: [unmapWithName(['bf', 'timeseries', 'ReJSON', 'searchlight', 'search', 'redisgears_2']), null], expected: false },
36+
{ input: [unmapWithName(['bf', 'timeseries', 'ReJSON', 'searchlight', 'graph', 'redisgears_2']), null], expected: false },
37+
{ input: [unmapWithName(['bf', 'timeseries', 'ReJSON', 'search', 'graph', 'redisgears_2']), null], expected: false },
38+
{ input: [unmapWithName(['bf', 'timeseries', 'ReJSON', 'searchlight', 'graph', 'redisgears']), null], expected: false },
39+
{ input: [unmapWithName(['bf', 'timeseries', 'ReJSON', 'search', 'graph', 'redisgears']), null], expected: false },
40+
{ input: [unmapWithName(['bf', 'timeseries', 'ReJSON', 'search', 'graph', 'redisgears', 'redisgears_2']), null], expected: false },
41+
{ input: [unmapWithName(['bf', 'timeseries', 'ReJSON', 'searchlight', 'custom']), null], expected: false },
42+
{ input: [unmapWithName(['bf', 'timeseries', 'ReJSON', 'searchlight', 'graph', 'custom']), null], expected: false },
43+
{ input: [unmapWithName(['bf', 'timeseries', 'ReJSON', 'searchlight', 'graph', 'redisgears', 'custom']), null], expected: false },
44+
45+
{ input: [unmapWithName(['bf', 'timeseries', 'ReJSON', 'searchlight']), '6.2.4'], expected: false },
3146
]
3247

3348
describe('isRediStack', () => {

0 commit comments

Comments
 (0)