Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added message variables button for Webhook body form field #60174

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ describe('WebhookParamsFields renders', () => {
.first()
.prop('value')
).toStrictEqual('test message');
expect(wrapper.find('[data-test-subj="webhookAddVariableButton"]').length > 0).toBeTruthy();
});

test('params validation fails when body is not valid', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ import {
EuiCodeEditor,
EuiSwitch,
EuiButtonEmpty,
EuiContextMenuItem,
EuiPopover,
EuiContextMenuPanel,
} from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import {
Expand Down Expand Up @@ -454,10 +457,24 @@ const WebhookParamsFields: React.FunctionComponent<ActionParamsProps<WebhookActi
actionParams,
editAction,
index,
messageVariables,
errors,
}) => {
const { body } = actionParams;

const [isVariablesPopoverOpen, setIsVariablesPopoverOpen] = useState<boolean>(false);
const messageVariablesItems = messageVariables?.map((variable: string, i: number) => (
<EuiContextMenuItem
key={variable}
data-test-subj={`variableMenuButton-${i}`}
icon="empty"
onClick={() => {
editAction('body', (body ?? '').concat(` {{${variable}}}`), index);
setIsVariablesPopoverOpen(false);
}}
>
{`{{${variable}}}`}
</EuiContextMenuItem>
));
return (
<Fragment>
<EuiFormRow
Expand All @@ -471,6 +488,30 @@ const WebhookParamsFields: React.FunctionComponent<ActionParamsProps<WebhookActi
isInvalid={errors.body.length > 0 && body !== undefined}
fullWidth
error={errors.body}
labelAppend={
// TODO: replace this button with a proper Eui component, when it will be ready
<EuiPopover
button={
<EuiButtonIcon
data-test-subj="webhookAddVariableButton"
onClick={() => setIsVariablesPopoverOpen(true)}
iconType="indexOpen"
aria-label={i18n.translate(
'xpack.triggersActionsUI.components.builtinActionTypes.webhookAction.addVariablePopoverButton',
{
defaultMessage: 'Add variable',
}
)}
/>
}
isOpen={isVariablesPopoverOpen}
closePopover={() => setIsVariablesPopoverOpen(false)}
panelPaddingSize="none"
anchorPosition="downLeft"
>
<EuiContextMenuPanel items={messageVariablesItems} />
</EuiPopover>
}
>
<EuiCodeEditor
mode="json"
Expand Down