1
1
import React , { useState } from 'react'
2
- import { useDispatch , useSelector } from 'react-redux'
2
+ import { useSelector } from 'react-redux'
3
3
import cx from 'classnames'
4
4
import {
5
- EuiButton ,
6
- EuiButtonIcon ,
7
- EuiPopover ,
8
5
EuiText ,
9
- EuiToolTip ,
10
6
EuiFlexGroup ,
11
- EuiIcon ,
12
- EuiLink ,
13
7
} from '@elastic/eui'
14
8
import { userSettingsConfigSelector } from 'uiSrc/slices/user/user-settings'
15
- import { putRecommendationVote } from 'uiSrc/slices/analytics/dbAnalysis'
16
- import { IRecommendationsStatic } from 'uiSrc/slices/interfaces/recommendations'
17
- import { sendEventTelemetry , TelemetryEvent } from 'uiSrc/telemetry'
18
- import { EXTERNAL_LINKS } from 'uiSrc/constants/links'
19
9
import { Vote } from 'uiSrc/constants/recommendations'
20
- import _content from 'uiSrc/constants/dbAnalysisRecommendations.json'
21
- import { ReactComponent as LikeIcon } from 'uiSrc/assets/img/icons/like.svg'
22
- import { ReactComponent as DoubleLikeIcon } from 'uiSrc/assets/img/icons/double_like.svg'
23
- import { ReactComponent as DislikeIcon } from 'uiSrc/assets/img/icons/dislike.svg'
24
- import GithubSVG from 'uiSrc/assets/img/sidebar/github.svg'
25
- import { updateLiveRecommendation } from 'uiSrc/slices/recommendations/recommendations'
26
10
import { Nullable } from 'uiSrc/utils'
27
11
28
- import { connectedInstanceSelector } from 'uiSrc/slices/instances/instances '
12
+ import VoteOption from './components/vote-option '
29
13
import styles from './styles.module.scss'
30
14
31
15
export interface Props {
@@ -36,43 +20,9 @@ export interface Props {
36
20
containerClass ?: string
37
21
}
38
22
39
- const recommendationsContent = _content as IRecommendationsStatic
40
-
41
23
const RecommendationVoting = ( { vote, name, id = '' , live = false , containerClass = '' } : Props ) => {
42
24
const config = useSelector ( userSettingsConfigSelector )
43
- const { id : instanceId = '' , provider } = useSelector ( connectedInstanceSelector )
44
- const [ isPopoverOpen , setIsPopoverOpen ] = useState ( false )
45
- const dispatch = useDispatch ( )
46
-
47
- const onSuccessVoted = ( { vote, name } : { name : string , vote : Nullable < Vote > } ) => {
48
- sendEventTelemetry ( {
49
- event : live
50
- ? TelemetryEvent . INSIGHTS_RECOMMENDATION_VOTED
51
- : TelemetryEvent . DATABASE_ANALYSIS_RECOMMENDATIONS_VOTED ,
52
- eventData : {
53
- databaseId : instanceId ,
54
- name : recommendationsContent [ name ] ?. telemetryEvent ?? name ,
55
- vote,
56
- provider
57
- }
58
- } )
59
- }
60
-
61
- const handleClick = ( name : string , vote : Vote ) => {
62
- if ( vote === Vote . Dislike ) {
63
- setIsPopoverOpen ( true )
64
- }
65
-
66
- if ( live ) {
67
- dispatch ( updateLiveRecommendation ( id , { vote } , onSuccessVoted ) )
68
- } else {
69
- dispatch ( putRecommendationVote ( name , vote , onSuccessVoted ) )
70
- }
71
- }
72
-
73
- const getTooltipContent = ( recommendationsContent : string ) => ( config ?. agreements ?. analytics
74
- ? recommendationsContent
75
- : 'Enable Analytics on the Settings page to vote for a recommendation' )
25
+ const [ popover , setPopover ] = useState < string > ( '' )
76
26
77
27
return (
78
28
< EuiFlexGroup
@@ -81,97 +31,21 @@ const RecommendationVoting = ({ vote, name, id = '', live = false, containerClas
81
31
gutterSize = { live ? 'none' : 'l' }
82
32
data-testid = "recommendation-voting"
83
33
>
84
- < EuiText size = "m" > Rate Recommendation </ EuiText >
34
+ < EuiText size = "m" > Is this useful? </ EuiText >
85
35
< div className = "voteContent" >
86
- < EuiToolTip
87
- content = { getTooltipContent ( 'Very Useful' ) }
88
- position = "bottom"
89
- data-testid = "very-useful-vote-tooltip"
90
- >
91
- < EuiButtonIcon
92
- disabled = { ! ! vote || ! config ?. agreements ?. analytics }
93
- iconType = { DoubleLikeIcon }
94
- className = { cx ( 'vote__btn' , { selected : vote === Vote . DoubleLike } ) }
95
- aria-label = "vote very useful"
96
- data-testid = "very-useful-vote-btn"
97
- onClick = { ( ) => handleClick ( name , Vote . DoubleLike ) }
98
- />
99
- </ EuiToolTip >
100
- < EuiToolTip
101
- content = { getTooltipContent ( 'Useful' ) }
102
- position = "bottom"
103
- data-testid = "useful-vote-tooltip"
104
- >
105
- < EuiButtonIcon
106
- disabled = { ! ! vote || ! config ?. agreements ?. analytics }
107
- iconType = { LikeIcon }
108
- className = { cx ( 'vote__btn' , { selected : vote === Vote . Like } ) }
109
- aria-label = "vote useful"
110
- data-testid = "useful-vote-btn"
111
- onClick = { ( ) => handleClick ( name , Vote . Like ) }
36
+ { Object . values ( Vote ) . map ( ( option ) => (
37
+ < VoteOption
38
+ key = { option }
39
+ voteOption = { option }
40
+ vote = { vote }
41
+ popover = { popover }
42
+ isAnalyticsEnable = { config ?. agreements ?. analytics }
43
+ setPopover = { setPopover }
44
+ name = { name }
45
+ id = { id }
46
+ live = { live }
112
47
/>
113
- </ EuiToolTip >
114
- < EuiToolTip
115
- content = { getTooltipContent ( 'Not Useful' ) }
116
- position = "bottom"
117
- data-testid = "not-useful-vote-tooltip"
118
- >
119
- < EuiPopover
120
- initialFocus = { false }
121
- anchorPosition = "rightCenter"
122
- isOpen = { isPopoverOpen }
123
- closePopover = { ( ) => setIsPopoverOpen ( false ) }
124
- anchorClassName = { styles . popoverAnchor }
125
- panelClassName = { cx ( 'euiToolTip' , 'popoverLikeTooltip' , styles . popover ) }
126
- button = { (
127
- < EuiButtonIcon
128
- disabled = { ! ! vote || ! config ?. agreements ?. analytics }
129
- iconType = { DislikeIcon }
130
- className = { cx ( 'vote__btn' , { selected : vote === Vote . Dislike } ) }
131
- aria-label = "vote not useful"
132
- data-testid = "not-useful-vote-btn"
133
- onClick = { ( ) => handleClick ( name , Vote . Dislike ) }
134
- />
135
- ) }
136
- >
137
- < div >
138
- Thank you for your feedback, Tell us how we can improve
139
- < EuiButton
140
- aria-label = "recommendation feedback"
141
- fill
142
- data-testid = "recommendation-feedback-btn"
143
- className = { styles . feedbackBtn }
144
- color = "secondary"
145
- size = "s"
146
- >
147
- < EuiLink
148
- external = { false }
149
- className = { styles . link }
150
- href = { EXTERNAL_LINKS . recommendationFeedback }
151
- target = "_blank"
152
- data-test-subj = "github-repo-link"
153
- >
154
- < EuiIcon
155
- className = { styles . githubIcon }
156
- aria-label = "redis insight github issues"
157
- type = { GithubSVG }
158
- data-testid = "github-repo-icon"
159
- />
160
- To Github
161
- </ EuiLink >
162
- </ EuiButton >
163
- < EuiButtonIcon
164
- iconType = "cross"
165
- color = "primary"
166
- id = "close-monitor"
167
- aria-label = "close popover"
168
- data-testid = "close-popover"
169
- className = { styles . icon }
170
- onClick = { ( ) => setIsPopoverOpen ( false ) }
171
- />
172
- </ div >
173
- </ EuiPopover >
174
- </ EuiToolTip >
48
+ ) ) }
175
49
</ div >
176
50
</ EuiFlexGroup >
177
51
)
0 commit comments