1
- import React from 'react'
1
+ import React , { useContext } from 'react'
2
2
import { useSelector } from 'react-redux'
3
3
import { useParams } from 'react-router-dom'
4
- import { isNull } from 'lodash'
4
+ import { isNull , sortBy } from 'lodash'
5
5
import {
6
6
EuiAccordion ,
7
7
EuiPanel ,
8
8
EuiText ,
9
9
EuiFlexGroup ,
10
10
EuiFlexItem ,
11
+ EuiIcon ,
11
12
} from '@elastic/eui'
13
+ import { ThemeContext } from 'uiSrc/contexts/themeContext'
12
14
import { dbAnalysisSelector } from 'uiSrc/slices/analytics/dbAnalysis'
13
15
import recommendationsContent from 'uiSrc/constants/dbAnalysisRecommendations.json'
16
+ import { Theme } from 'uiSrc/constants'
14
17
import { sendEventTelemetry , TelemetryEvent } from 'uiSrc/telemetry'
18
+ import RediStackDarkMin from 'uiSrc/assets/img/modules/redistack/RediStackDark-min.svg'
19
+ import RediStackLightMin from 'uiSrc/assets/img/modules/redistack/RediStackLight-min.svg'
15
20
16
21
import { renderContent , renderBadges , renderBadgesLegend } from './utils'
17
22
import styles from './styles.module.scss'
@@ -20,6 +25,7 @@ const Recommendations = () => {
20
25
const { data, loading } = useSelector ( dbAnalysisSelector )
21
26
const { recommendations = [ ] } = data ?? { }
22
27
28
+ const { theme } = useContext ( ThemeContext )
23
29
const { instanceId } = useParams < { instanceId : string } > ( )
24
30
25
31
const handleToggle = ( isOpen : boolean , id : string ) => sendEventTelemetry ( {
@@ -32,6 +38,31 @@ const Recommendations = () => {
32
38
}
33
39
} )
34
40
41
+ const sortedRecommendations = sortBy ( recommendations , ( { name } ) =>
42
+ ( recommendationsContent [ name ] ?. redisStack ? - 1 : 0 ) )
43
+
44
+ const renderButtonContent = ( redisStack : boolean , title : string , badges : string [ ] ) => (
45
+ < EuiFlexGroup className = { styles . accordionButton } responsive = { false } alignItems = "center" justifyContent = "spaceBetween" >
46
+ < EuiFlexGroup alignItems = "center" >
47
+ < EuiFlexItem grow = { false } >
48
+ { redisStack && (
49
+ < EuiIcon
50
+ type = { theme === Theme . Dark ? RediStackDarkMin : RediStackLightMin }
51
+ className = { styles . redisStack }
52
+ data-testid = "redis-stack-icon"
53
+ />
54
+ ) }
55
+ </ EuiFlexItem >
56
+ < EuiFlexItem grow = { false } >
57
+ { title }
58
+ </ EuiFlexItem >
59
+ </ EuiFlexGroup >
60
+ < EuiFlexItem grow = { false } >
61
+ { renderBadges ( badges ) }
62
+ </ EuiFlexItem >
63
+ </ EuiFlexGroup >
64
+ )
65
+
35
66
if ( loading ) {
36
67
return (
37
68
< div className = { styles . loadingWrapper } data-testid = "recommendations-loader" />
@@ -51,37 +82,37 @@ const Recommendations = () => {
51
82
< div >
52
83
{ renderBadgesLegend ( ) }
53
84
</ div >
54
- { recommendations . map ( ( { name } ) => {
55
- const { id = '' , title = '' , content = '' , badges = [ ] } = recommendationsContent [ name ]
85
+ < div className = { styles . recommendationsContainer } >
86
+ { sortedRecommendations . map ( ( { name } ) => {
87
+ const {
88
+ id = '' ,
89
+ title = '' ,
90
+ content = '' ,
91
+ badges = [ ] ,
92
+ redisStack = false
93
+ } = recommendationsContent [ name ]
56
94
57
- const buttonContent = (
58
- < EuiFlexGroup className = { styles . accordionButton } responsive = { false } alignItems = "center" justifyContent = "spaceBetween" >
59
- < EuiFlexItem grow = { false } > { title } </ EuiFlexItem >
60
- < EuiFlexItem grow = { false } >
61
- { renderBadges ( badges ) }
62
- </ EuiFlexItem >
63
- </ EuiFlexGroup >
64
- )
65
- return (
66
- < div key = { id } className = { styles . recommendation } >
67
- < EuiAccordion
68
- id = { name }
69
- arrowDisplay = "right"
70
- buttonContent = { buttonContent }
71
- buttonClassName = { styles . accordionBtn }
72
- buttonProps = { { 'data-test-subj' : `${ id } -button` } }
73
- className = { styles . accordion }
74
- initialIsOpen
75
- onToggle = { ( isOpen ) => handleToggle ( isOpen , id ) }
76
- data-testid = { `${ id } -accordion` }
77
- >
78
- < EuiPanel className = { styles . accordionContent } color = "subdued" >
79
- { renderContent ( content ) }
80
- </ EuiPanel >
81
- </ EuiAccordion >
82
- </ div >
83
- )
84
- } ) }
95
+ return (
96
+ < div key = { id } className = { styles . recommendation } >
97
+ < EuiAccordion
98
+ id = { name }
99
+ arrowDisplay = "right"
100
+ buttonContent = { renderButtonContent ( redisStack , title , badges ) }
101
+ buttonClassName = { styles . accordionBtn }
102
+ buttonProps = { { 'data-test-subj' : `${ id } -button` } }
103
+ className = { styles . accordion }
104
+ initialIsOpen
105
+ onToggle = { ( isOpen ) => handleToggle ( isOpen , id ) }
106
+ data-testid = { `${ id } -accordion` }
107
+ >
108
+ < EuiPanel className = { styles . accordionContent } color = "subdued" >
109
+ { renderContent ( content ) }
110
+ </ EuiPanel >
111
+ </ EuiAccordion >
112
+ </ div >
113
+ )
114
+ } ) }
115
+ </ div >
85
116
</ div >
86
117
)
87
118
}
0 commit comments