33 * SPDX-License-Identifier: Apache-2.0
44 */
55
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' ;
816import { useVisualizationType } from '../utils/use' ;
917import './side_nav.scss' ;
1018import { useOpenSearchDashboards } from '../../../../opensearch_dashboards_react/public' ;
1119import { WizardServices } from '../../types' ;
1220import { setActiveVisualization , useTypedDispatch } from '../utils/state_management' ;
1321
1422export const RightNav = ( ) => {
23+ const [ newVisType , setNewVisType ] = useState < string > ( ) ;
1524 const {
1625 services : { types } ,
1726 } = useOpenSearchDashboards < WizardServices > ( ) ;
@@ -23,6 +32,7 @@ export const RightNav = () => {
2332 value : name ,
2433 inputDisplay : < OptionItem icon = { icon } title = { title } /> ,
2534 dropdownDisplay : < OptionItem icon = { icon } title = { title } /> ,
35+ 'data-test-subj' : `visType-${ name } ` ,
2636 } ) ) ;
2737
2838 return (
@@ -32,19 +42,48 @@ export const RightNav = () => {
3242 options = { options }
3343 valueOfSelected = { activeVisName }
3444 onChange = { ( name ) => {
35- dispatch (
36- setActiveVisualization ( {
37- name,
38- style : types . get ( name ) ?. ui . containerConfig . style . defaults ,
39- } )
40- ) ;
45+ setNewVisType ( name ) ;
4146 } }
4247 fullWidth
48+ data-test-subj = "chartPicker"
4349 />
4450 </ div >
4551 < div className = "wizSidenav__style" >
4652 < StyleSection />
4753 </ 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+ ) }
4887 </ section >
4988 ) ;
5089} ;
0 commit comments