Skip to content

Commit 9a80394

Browse files
Merge pull request #2505 from RedisInsight/fe/bugfix/RI-4880-redistack_icon
#RI-4880 - update condition
2 parents 6deeb04 + 6e178d7 commit 9a80394

File tree

2 files changed

+77
-61
lines changed

2 files changed

+77
-61
lines changed

redisinsight/ui/src/utils/redistack.ts

Lines changed: 39 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,68 @@
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 MIN_MODULES_LENGTH = REDISTACK_REQUIRE_MODULES.length
20+
const MAX_MODULES_LENGTH = REDISTACK_REQUIRE_MODULES.length + REDISTACK_OPTIONAL_MODULES.length
21+
22+
const checkRediStackModules = (modules: any[]) => {
2823
if (!modules?.length) return false
24+
const moduleNames = map(modules, 'name').sort()
2925

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))
26+
if (modules.length === MIN_MODULES_LENGTH) {
27+
return moduleNames
28+
.every((m, index) => (isArray(REDISTACK_REQUIRE_MODULES[index])
29+
? (REDISTACK_REQUIRE_MODULES[index] as Array<string>).some((rm) => rm === m)
30+
: REDISTACK_REQUIRE_MODULES[index] === m))
3631
}
3732

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))
33+
if (modules.length > MIN_MODULES_LENGTH
34+
&& modules.length <= (MAX_MODULES_LENGTH)) {
35+
let isCustomModule = false
36+
const rediStackModules = concat(REDISTACK_REQUIRE_MODULES, REDISTACK_OPTIONAL_MODULES).sort()
37+
38+
const diff = rediStackModules.reduce((acc: Array<string>, current: string | Array<string>) => {
39+
const moduleName = isArray(current)
40+
? (current as Array<string>).find((item) => find(moduleNames, (m) => item === m))
41+
: find(moduleNames, (name) => name === current)
42+
43+
if (moduleName) {
44+
remove(acc, (name) => moduleName === name)
45+
46+
return acc
47+
}
48+
isCustomModule = true
49+
50+
return acc
51+
}, moduleNames)
52+
53+
return isCustomModule && !diff.length
4554
}
4655

4756
return false
4857
}
4958

5059
const isRediStack = (modules: any[], version?: Nullable<string>): boolean => {
5160
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-
)
61+
return checkRediStackModules(modules)
6162
}
6263

63-
if (isVersionHigherOrEquals(version, REDISTACK_LOW_VERSION)) {
64-
return checkRediStackModules(modules, REDISTACK_LOW_VERSION_REQUIRE_MODULES)
64+
if (isVersionHigherOrEquals(version, REDISTACK_VERSION)) {
65+
return checkRediStackModules(modules)
6566
}
6667

6768
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)