@@ -22,6 +22,9 @@ import {
2222 EuiCodeEditor ,
2323 EuiSwitch ,
2424 EuiButtonEmpty ,
25+ EuiContextMenuItem ,
26+ EuiPopover ,
27+ EuiContextMenuPanel ,
2528} from '@elastic/eui' ;
2629import { i18n } from '@kbn/i18n' ;
2730import {
@@ -454,10 +457,24 @@ const WebhookParamsFields: React.FunctionComponent<ActionParamsProps<WebhookActi
454457 actionParams,
455458 editAction,
456459 index,
460+ messageVariables,
457461 errors,
458462} ) => {
459463 const { body } = actionParams ;
460-
464+ const [ isVariablesPopoverOpen , setIsVariablesPopoverOpen ] = useState < boolean > ( false ) ;
465+ const messageVariablesItems = messageVariables ?. map ( ( variable : string , i : number ) => (
466+ < EuiContextMenuItem
467+ key = { variable }
468+ data-test-subj = { `variableMenuButton-${ i } ` }
469+ icon = "empty"
470+ onClick = { ( ) => {
471+ editAction ( 'body' , ( body ?? '' ) . concat ( ` {{${ variable } }}` ) , index ) ;
472+ setIsVariablesPopoverOpen ( false ) ;
473+ } }
474+ >
475+ { `{{${ variable } }}` }
476+ </ EuiContextMenuItem >
477+ ) ) ;
461478 return (
462479 < Fragment >
463480 < EuiFormRow
@@ -471,6 +488,30 @@ const WebhookParamsFields: React.FunctionComponent<ActionParamsProps<WebhookActi
471488 isInvalid = { errors . body . length > 0 && body !== undefined }
472489 fullWidth
473490 error = { errors . body }
491+ labelAppend = {
492+ // TODO: replace this button with a proper Eui component, when it will be ready
493+ < EuiPopover
494+ button = {
495+ < EuiButtonIcon
496+ data-test-subj = "webhookAddVariableButton"
497+ onClick = { ( ) => setIsVariablesPopoverOpen ( true ) }
498+ iconType = "indexOpen"
499+ aria-label = { i18n . translate (
500+ 'xpack.triggersActionsUI.components.builtinActionTypes.webhookAction.addVariablePopoverButton' ,
501+ {
502+ defaultMessage : 'Add variable' ,
503+ }
504+ ) }
505+ />
506+ }
507+ isOpen = { isVariablesPopoverOpen }
508+ closePopover = { ( ) => setIsVariablesPopoverOpen ( false ) }
509+ panelPaddingSize = "none"
510+ anchorPosition = "downLeft"
511+ >
512+ < EuiContextMenuPanel items = { messageVariablesItems } />
513+ </ EuiPopover >
514+ }
474515 >
475516 < EuiCodeEditor
476517 mode = "json"
0 commit comments