3
3
* SPDX-License-Identifier: Apache-2.0
4
4
*/
5
5
6
- import React from 'react' ;
7
- import { EuiSuperSelect , EuiSuperSelectOption , EuiIcon , IconType } from '@elastic/eui' ;
6
+ import React , { useState } from 'react' ;
7
+ import {
8
+ EuiSuperSelect ,
9
+ EuiSuperSelectOption ,
10
+ EuiIcon ,
11
+ IconType ,
12
+ EuiConfirmModal ,
13
+ } from '@elastic/eui' ;
14
+ import { i18n } from '@osd/i18n' ;
15
+ import { FormattedMessage } from '@osd/i18n/react' ;
8
16
import { useVisualizationType } from '../utils/use' ;
9
17
import './side_nav.scss' ;
10
18
import { useOpenSearchDashboards } from '../../../../opensearch_dashboards_react/public' ;
11
19
import { WizardServices } from '../../types' ;
12
20
import { setActiveVisualization , useTypedDispatch } from '../utils/state_management' ;
13
21
14
22
export const RightNav = ( ) => {
23
+ const [ newVisType , setNewVisType ] = useState < string > ( ) ;
15
24
const {
16
25
services : { types } ,
17
26
} = useOpenSearchDashboards < WizardServices > ( ) ;
@@ -23,6 +32,7 @@ export const RightNav = () => {
23
32
value : name ,
24
33
inputDisplay : < OptionItem icon = { icon } title = { title } /> ,
25
34
dropdownDisplay : < OptionItem icon = { icon } title = { title } /> ,
35
+ 'data-test-subj' : `visType-${ name } ` ,
26
36
} ) ) ;
27
37
28
38
return (
@@ -32,19 +42,48 @@ export const RightNav = () => {
32
42
options = { options }
33
43
valueOfSelected = { activeVisName }
34
44
onChange = { ( name ) => {
35
- dispatch (
36
- setActiveVisualization ( {
37
- name,
38
- style : types . get ( name ) ?. ui . containerConfig . style . defaults ,
39
- } )
40
- ) ;
45
+ setNewVisType ( name ) ;
41
46
} }
42
47
fullWidth
48
+ data-test-subj = "chartPicker"
43
49
/>
44
50
</ div >
45
51
< div className = "wizSidenav__style" >
46
52
< StyleSection />
47
53
</ div >
54
+ { newVisType && (
55
+ < EuiConfirmModal
56
+ title = { i18n . translate ( 'wizard.rightNav.changeVisType.modalTitle' , {
57
+ defaultMessage : 'Change visualization type' ,
58
+ } ) }
59
+ confirmButtonText = { i18n . translate ( 'wizard.rightNav.changeVisType.confirmText' , {
60
+ defaultMessage : 'Change type' ,
61
+ } ) }
62
+ cancelButtonText = { i18n . translate ( 'wizard.rightNav.changeVisType.cancelText' , {
63
+ defaultMessage : 'Cancel' ,
64
+ } ) }
65
+ onCancel = { ( ) => setNewVisType ( undefined ) }
66
+ onConfirm = { ( ) => {
67
+ dispatch (
68
+ setActiveVisualization ( {
69
+ name : newVisType ,
70
+ style : types . get ( newVisType ) ?. ui . containerConfig . style . defaults ,
71
+ } )
72
+ ) ;
73
+
74
+ setNewVisType ( undefined ) ;
75
+ } }
76
+ maxWidth = "300px"
77
+ data-test-subj = "confirmVisChangeModal"
78
+ >
79
+ < p >
80
+ < FormattedMessage
81
+ id = "wizard.rightNav.changeVisType.modalDescription"
82
+ defaultMessage = "Changing the visualization type will reset all field selections. Do you want to continue?"
83
+ />
84
+ </ p >
85
+ </ EuiConfirmModal >
86
+ ) }
48
87
</ section >
49
88
) ;
50
89
} ;
0 commit comments