1- import React , { useState , useRef } from 'react' ;
1+ import React , { useState } from 'react' ;
22import _ from 'lodash' ;
33import cn from 'bem-cn-lite' ;
44import { useDispatch , useSelector } from 'react-redux' ;
5- import { Dialog , DropdownMenu , Popup , TextInput , Button } from '@yandex-cloud/uikit' ;
5+ import { Dialog , DropdownMenu , TextInput , Button } from '@yandex-cloud/uikit' ;
66
7- import Icon from '../../../../components/Icon/Icon' ;
87import { setQueryNameToEdit } from '../../../../store/reducers/saveQuery' ;
98
109import './SaveQuery.scss' ;
1110
1211const b = cn ( 'kv-save-query' ) ;
1312
14- const EMBEDDED_VERSION_WARNING =
15- 'Please be aware: after cookies delete your saved queries will be lost.' ;
16-
1713function SaveQuery ( { savedQueries, onSaveQuery, saveButtonDisabled} ) {
1814 const singleClusterMode = useSelector ( ( state ) => state . singleClusterMode ) ;
1915 const [ isDialogVisible , setIsDialogVisible ] = useState ( false ) ;
20- const [ isEmbeddedWarningVisible , setIsEmbeddedWarningVisible ] = useState ( false ) ;
2116 const [ queryName , setQueryName ] = useState ( '' ) ;
2217 const [ validationError , setValidationError ] = useState ( null ) ;
2318
2419 const queryNameToEdit = useSelector ( ( state ) => state . saveQuery ) ;
2520 const dispatch = useDispatch ( ) ;
2621
27- const warningRef = useRef ( ) ;
28-
2922 const onSaveQueryClick = ( ) => {
3023 setIsDialogVisible ( true ) ;
3124 dispatch ( setQueryNameToEdit ( null ) ) ;
@@ -42,13 +35,6 @@ function SaveQuery({savedQueries, onSaveQuery, saveButtonDisabled}) {
4235 setValidationError ( validateQueryName ( value ) ) ;
4336 } ;
4437
45- const onEmbeddedWarningOpen = ( ) => {
46- setIsEmbeddedWarningVisible ( true ) ;
47- } ;
48- const onEmbeddedWarningClose = ( ) => {
49- setIsEmbeddedWarningVisible ( false ) ;
50- } ;
51-
5238 const validateQueryName = ( value ) => {
5339 if ( _ . some ( savedQueries , ( q ) => q . name . toLowerCase ( ) === value . trim ( ) . toLowerCase ( ) ) ) {
5440 return 'This name already exists' ;
@@ -73,15 +59,28 @@ function SaveQuery({savedQueries, onSaveQuery, saveButtonDisabled}) {
7359 < Dialog open = { isDialogVisible } hasCloseButton = { false } size = "s" onClose = { onCloseDialog } >
7460 < Dialog . Header caption = "Save query" />
7561 < Dialog . Body className = { b ( 'dialog-body' ) } >
76- < span className = { b ( 'field-title' , 'required' ) } > Query name</ span >
77- < div className = { b ( 'control-wrapper' ) } >
78- < TextInput
79- placeholder = "Enter query name"
80- text = { queryName }
81- onUpdate = { onQueryNameChange }
82- hasClear
83- />
84- < span className = { b ( 'error' ) } > { validationError } </ span >
62+ { singleClusterMode && (
63+ < div className = { b ( 'dialog-row' ) } >
64+ The query will be saved in your browser
65+ </ div >
66+ ) }
67+ < div className = { b ( 'dialog-row' ) } >
68+ < label
69+ htmlFor = "queryName"
70+ className = { b ( 'field-title' , 'required' ) }
71+ >
72+ Query name
73+ </ label >
74+ < div className = { b ( 'control-wrapper' ) } >
75+ < TextInput
76+ id = "queryName"
77+ placeholder = "Enter query name"
78+ text = { queryName }
79+ onUpdate = { onQueryNameChange }
80+ hasClear
81+ />
82+ < span className = { b ( 'error' ) } > { validationError } </ span >
83+ </ div >
8584 </ div >
8685 </ Dialog . Body >
8786 < Dialog . Footer
@@ -121,36 +120,10 @@ function SaveQuery({savedQueries, onSaveQuery, saveButtonDisabled}) {
121120 ) ;
122121 } ;
123122
124- const renderEmbeddedVersionWarning = ( ) => {
125- return (
126- < React . Fragment >
127- < Popup
128- className = { b ( 'embedded-popup' ) }
129- anchorRef = { warningRef }
130- placement = { [ 'top' ] }
131- open = { isEmbeddedWarningVisible }
132- hasArrow
133- >
134- { EMBEDDED_VERSION_WARNING }
135- </ Popup >
136- < div
137- className = { b ( 'embedded-tooltip' ) }
138- ref = { warningRef }
139- onMouseEnter = { onEmbeddedWarningOpen }
140- onMouseLeave = { onEmbeddedWarningClose }
141- >
142- < Icon name = "question" height = { 18 } width = { 18 } viewBox = "0 0 24 24" />
143- </ div >
144- </ React . Fragment >
145- ) ;
146- } ;
147-
148123 return (
149124 < React . Fragment >
150125 { queryNameToEdit ? renderSaveDropdownMenu ( ) : renderSaveButton ( onSaveQueryClick ) }
151126 { isDialogVisible && renderDialog ( ) }
152-
153- { singleClusterMode && renderEmbeddedVersionWarning ( ) }
154127 </ React . Fragment >
155128 ) ;
156129}
0 commit comments