Skip to content

Commit 05c0ca9

Browse files
committed
Added message variables button for Webhook body form field
1 parent 4b2231d commit 05c0ca9

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/webhook.test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ describe('WebhookActionConnectorFields renders', () => {
130130
expect(wrapper.find('[data-test-subj="webhookUrlText"]').length > 0).toBeTruthy();
131131
expect(wrapper.find('[data-test-subj="webhookUserInput"]').length > 0).toBeTruthy();
132132
expect(wrapper.find('[data-test-subj="webhookPasswordInput"]').length > 0).toBeTruthy();
133+
expect(wrapper.find('[data-test-subj="webhookAddVariableButton"]').length > 0).toBeTruthy();
133134
});
134135
});
135136

x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/webhook.tsx

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ import {
2222
EuiCodeEditor,
2323
EuiSwitch,
2424
EuiButtonEmpty,
25+
EuiContextMenuItem,
26+
EuiPopover,
27+
EuiContextMenuPanel,
2528
} from '@elastic/eui';
2629
import { i18n } from '@kbn/i18n';
2730
import {
@@ -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

Comments
 (0)