@@ -10,17 +10,21 @@ import { useFormikContext } from 'formik';
10
10
import {
11
11
EuiCodeEditor ,
12
12
EuiComboBox ,
13
+ EuiContextMenu ,
13
14
EuiEmptyPrompt ,
14
15
EuiFlexGroup ,
15
16
EuiFlexItem ,
17
+ EuiPopover ,
16
18
EuiSmallButton ,
17
19
EuiSmallButtonEmpty ,
18
20
EuiText ,
19
21
} from '@elastic/eui' ;
20
22
import {
21
23
CONFIG_STEP ,
22
24
customStringify ,
25
+ QUERY_PRESETS ,
23
26
QueryParam ,
27
+ QueryPreset ,
24
28
SearchResponse ,
25
29
SearchResponseVerbose ,
26
30
WorkflowFormValues ,
@@ -74,6 +78,9 @@ export function Query(props: QueryProps) {
74
78
const { loading } = useSelector ( ( state : AppState ) => state . opensearch ) ;
75
79
const { values } = useFormikContext < WorkflowFormValues > ( ) ;
76
80
81
+ // popover state
82
+ const [ popoverOpen , setPopoverOpen ] = useState < boolean > ( false ) ;
83
+
77
84
// state for if to execute search w/ or w/o any configured search pipeline.
78
85
// default based on if there is an available search pipeline or not.
79
86
const [ includePipeline , setIncludePipeline ] = useState < boolean > ( false ) ;
@@ -231,20 +238,63 @@ export function Query(props: QueryProps) {
231
238
< EuiFlexItem grow = { false } >
232
239
< EuiText size = "s" > Query</ EuiText >
233
240
</ EuiFlexItem >
234
- { props . selectedStep === CONFIG_STEP . SEARCH &&
235
- ! isEmpty ( values ?. search ?. request ) &&
236
- values ?. search ?. request !== props . queryRequest && (
237
- < EuiFlexItem grow = { false } style = { { marginBottom : '0px' } } >
238
- < EuiSmallButtonEmpty
239
- disabled = { false }
240
- onClick = { ( ) => {
241
- props . setQueryRequest ( values ?. search ?. request ) ;
242
- } }
241
+ < EuiFlexItem grow = { false } >
242
+ < EuiFlexGroup direction = "row" gutterSize = "s" >
243
+ { props . selectedStep === CONFIG_STEP . SEARCH &&
244
+ ! isEmpty ( values ?. search ?. request ) &&
245
+ values ?. search ?. request !== props . queryRequest && (
246
+ < EuiFlexItem
247
+ grow = { false }
248
+ style = { { marginBottom : '0px' } }
249
+ >
250
+ < EuiSmallButtonEmpty
251
+ disabled = { false }
252
+ onClick = { ( ) => {
253
+ props . setQueryRequest ( values ?. search ?. request ) ;
254
+ } }
255
+ >
256
+ Revert to original query
257
+ </ EuiSmallButtonEmpty >
258
+ </ EuiFlexItem >
259
+ ) }
260
+ < EuiFlexItem grow = { false } >
261
+ < EuiPopover
262
+ button = {
263
+ < EuiSmallButton
264
+ onClick = { ( ) => setPopoverOpen ( ! popoverOpen ) }
265
+ data-testid = "inspectorQueryPresetButton"
266
+ iconSide = "right"
267
+ iconType = "arrowDown"
268
+ >
269
+ Query samples
270
+ </ EuiSmallButton >
271
+ }
272
+ isOpen = { popoverOpen }
273
+ closePopover = { ( ) => setPopoverOpen ( false ) }
274
+ anchorPosition = "downLeft"
243
275
>
244
- Revert to original query
245
- </ EuiSmallButtonEmpty >
276
+ < EuiContextMenu
277
+ size = "s"
278
+ initialPanelId = { 0 }
279
+ panels = { [
280
+ {
281
+ id : 0 ,
282
+ items : QUERY_PRESETS . map (
283
+ ( preset : QueryPreset ) => ( {
284
+ name : preset . name ,
285
+ onClick : ( ) => {
286
+ props . setQueryRequest ( preset . query ) ;
287
+ setPopoverOpen ( false ) ;
288
+ } ,
289
+ } )
290
+ ) ,
291
+ } ,
292
+ ] }
293
+ />
294
+ </ EuiPopover >
246
295
</ EuiFlexItem >
247
- ) }
296
+ </ EuiFlexGroup >
297
+ </ EuiFlexItem >
248
298
</ EuiFlexGroup >
249
299
</ EuiFlexItem >
250
300
< EuiFlexItem grow = { true } >
0 commit comments