1
1
import React from 'react' ;
2
2
3
- import { Dialog , Link as ExternalLink , Flex , TextInput , Tooltip } from '@gravity-ui/uikit' ;
3
+ import { Button , Dialog , Flex , TextInput , Tooltip } from '@gravity-ui/uikit' ;
4
4
import { zodResolver } from '@hookform/resolvers/zod' ;
5
5
import { Controller , useForm } from 'react-hook-form' ;
6
6
@@ -18,9 +18,10 @@ import {
18
18
useTypedDispatch ,
19
19
useTypedSelector ,
20
20
} from '../../../../utils/hooks' ;
21
- import { querySettingsValidationSchema } from '../../../../utils/query' ;
21
+ import { QUERY_MODES , querySettingsValidationSchema } from '../../../../utils/query' ;
22
22
23
23
import { QuerySettingsSelect } from './QuerySettingsSelect' ;
24
+ import { QuerySettingsTimeout } from './QuerySettingsTimeout' ;
24
25
import { QUERY_SETTINGS_FIELD_SETTINGS } from './constants' ;
25
26
import i18n from './i18n' ;
26
27
@@ -73,6 +74,8 @@ function QuerySettingsForm({initialValues, onSubmit, onClose}: QuerySettingsForm
73
74
const {
74
75
control,
75
76
handleSubmit,
77
+ setValue,
78
+ watch,
76
79
formState : { errors} ,
77
80
} = useForm < QuerySettings > ( {
78
81
defaultValues : initialValues ,
@@ -82,6 +85,9 @@ function QuerySettingsForm({initialValues, onSubmit, onClose}: QuerySettingsForm
82
85
const [ useShowPlanToSvg ] = useSetting < boolean > ( USE_SHOW_PLAN_SVG_KEY ) ;
83
86
const enableTracingLevel = useTracingLevelOptionAvailable ( ) ;
84
87
88
+ const timeout = watch ( 'timeout' ) ;
89
+ const queryMode = watch ( 'queryMode' ) ;
90
+
85
91
return (
86
92
< form onSubmit = { handleSubmit ( onSubmit ) } >
87
93
< Dialog . Body className = { b ( 'dialog-body' ) } >
@@ -97,42 +103,21 @@ function QuerySettingsForm({initialValues, onSubmit, onClose}: QuerySettingsForm
97
103
< QuerySettingsSelect
98
104
id = "queryMode"
99
105
setting = { field . value }
100
- onUpdateSetting = { field . onChange }
106
+ onUpdateSetting = { ( mode ) => {
107
+ field . onChange ( mode ) ;
108
+
109
+ if ( mode !== 'query' && timeout === null ) {
110
+ setValue ( 'timeout' , '' ) ;
111
+ } else if ( mode === 'query' ) {
112
+ setValue ( 'timeout' , null ) ;
113
+ }
114
+ } }
101
115
settingOptions = { QUERY_SETTINGS_FIELD_SETTINGS . queryMode . options }
102
116
/>
103
117
) }
104
118
/>
105
119
</ div >
106
120
</ Flex >
107
- < Flex direction = "row" alignItems = "flex-start" className = { b ( 'dialog-row' ) } >
108
- < label htmlFor = "timeout" className = { b ( 'field-title' ) } >
109
- { QUERY_SETTINGS_FIELD_SETTINGS . timeout . title }
110
- </ label >
111
- < div className = { b ( 'control-wrapper' ) } >
112
- < Controller
113
- name = "timeout"
114
- control = { control }
115
- render = { ( { field} ) => (
116
- < React . Fragment >
117
- < TextInput
118
- id = "timeout"
119
- type = "number"
120
- { ...field }
121
- value = { field . value ?. toString ( ) }
122
- className = { b ( 'timeout' ) }
123
- placeholder = "60"
124
- validationState = { errors . timeout ? 'invalid' : undefined }
125
- errorMessage = { errors . timeout ?. message }
126
- errorPlacement = "inside"
127
- />
128
- < span className = { b ( 'timeout-suffix' ) } >
129
- { i18n ( 'form.timeout.seconds' ) }
130
- </ span >
131
- </ React . Fragment >
132
- ) }
133
- />
134
- </ div >
135
- </ Flex >
136
121
{ enableTracingLevel && (
137
122
< Flex direction = "row" alignItems = "flex-start" className = { b ( 'dialog-row' ) } >
138
123
< label htmlFor = "tracingLevel" className = { b ( 'field-title' ) } >
@@ -225,11 +210,33 @@ function QuerySettingsForm({initialValues, onSubmit, onClose}: QuerySettingsForm
225
210
validationState = { errors . limitRows ? 'invalid' : undefined }
226
211
errorMessage = { errors . limitRows ?. message }
227
212
errorPlacement = "inside"
213
+ endContent = {
214
+ < span className = { b ( 'postfix' ) } >
215
+ { i18n ( 'form.limit.rows' ) }
216
+ </ span >
217
+ }
228
218
/>
229
219
) }
230
220
/>
231
221
</ div >
232
222
</ Flex >
223
+ < Flex direction = "row" alignItems = "flex-start" className = { b ( 'dialog-row' ) } >
224
+ < Controller
225
+ name = "timeout"
226
+ control = { control }
227
+ render = { ( { field} ) => (
228
+ < QuerySettingsTimeout
229
+ id = "timeout"
230
+ value = { typeof field . value === 'string' ? undefined : field . value }
231
+ onChange = { field . onChange }
232
+ onToggle = { ( enabled ) => field . onChange ( enabled ? '' : null ) }
233
+ validationState = { errors . timeout ? 'invalid' : undefined }
234
+ errorMessage = { errors . timeout ?. message }
235
+ isDisabled = { queryMode !== QUERY_MODES . query }
236
+ />
237
+ ) }
238
+ />
239
+ </ Flex >
233
240
</ Dialog . Body >
234
241
< Dialog . Footer
235
242
textButtonApply = { i18n ( 'button-done' ) }
@@ -240,13 +247,14 @@ function QuerySettingsForm({initialValues, onSubmit, onClose}: QuerySettingsForm
240
247
} }
241
248
renderButtons = { ( buttonApply , buttonCancel ) => (
242
249
< div className = { b ( 'buttons-container' ) } >
243
- < ExternalLink
250
+ < Button
244
251
href = "https://ydb.tech/docs"
245
252
target = "_blank"
246
- className = { b ( 'documentation-link' ) }
253
+ view = "outlined"
254
+ size = "l"
247
255
>
248
256
{ i18n ( 'docs' ) }
249
- </ ExternalLink >
257
+ </ Button >
250
258
< div className = { b ( 'main-buttons' ) } >
251
259
{ buttonCancel }
252
260
{ buttonApply }
0 commit comments