From 3b94530d46dd2ee63cb56170ad01f1c10f1f0ac3 Mon Sep 17 00:00:00 2001 From: Yuliia Naumenko Date: Fri, 13 Mar 2020 19:31:09 -0700 Subject: [PATCH 1/5] Added variables button for text fields in Pagerduty component. Fixed bugs mentioned in https://github.com/elastic/kibana/issues/60067 --- .../builtin_action_types/pagerduty.test.tsx | 1 + .../builtin_action_types/pagerduty.tsx | 241 +++++++++++++++++- 2 files changed, 232 insertions(+), 10 deletions(-) diff --git a/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/pagerduty.test.tsx b/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/pagerduty.test.tsx index 31a69f9fd94acd..bb06f7961b20bb 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/pagerduty.test.tsx +++ b/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/pagerduty.test.tsx @@ -183,5 +183,6 @@ describe('PagerDutyParamsFields renders', () => { expect(wrapper.find('[data-test-subj="groupInput"]').length > 0).toBeTruthy(); expect(wrapper.find('[data-test-subj="sourceInput"]').length > 0).toBeTruthy(); expect(wrapper.find('[data-test-subj="pagerdutySummaryInput"]').length > 0).toBeTruthy(); + expect(wrapper.find('[data-test-subj="dedupKeyAddVariableButton"]').length > 0).toBeTruthy(); }); }); diff --git a/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/pagerduty.tsx b/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/pagerduty.tsx index 3c1b1d258cfe22..041d2456a1779e 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/pagerduty.tsx +++ b/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/pagerduty.tsx @@ -3,7 +3,7 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ -import React, { Fragment } from 'react'; +import React, { Fragment, useState } from 'react'; import { EuiFieldText, EuiFlexGroup, @@ -11,6 +11,10 @@ import { EuiFormRow, EuiSelect, EuiLink, + EuiContextMenuItem, + EuiPopover, + EuiButtonIcon, + EuiContextMenuPanel, } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n/react'; @@ -158,6 +162,7 @@ const PagerDutyParamsFields: React.FunctionComponent { const { @@ -171,8 +176,8 @@ const PagerDutyParamsFields: React.FunctionComponent>({ + dedupKey: false, + summary: false, + source: false, + timestamp: false, + component: false, + group: false, + class: false, + }); + // TODO: replace this button with a proper Eui component, when it will be ready + const getMessageVariables = (paramsProperty: string) => + messageVariables?.map((variable: string, i: number) => ( + { + editAction( + paramsProperty, + ((actionParams as any)[paramsProperty] ?? '').concat(` {{${variable}}}`), + index + ); + setIsVariablesPopoverOpen({ ...isVariablesPopoverOpen, [paramsProperty]: false }); + }} + > + {`{{${variable}}}`} + + )); return ( @@ -190,7 +222,7 @@ const PagerDutyParamsFields: React.FunctionComponent @@ -211,7 +243,7 @@ const PagerDutyParamsFields: React.FunctionComponent @@ -237,6 +269,33 @@ const PagerDutyParamsFields: React.FunctionComponent + setIsVariablesPopoverOpen({ ...isVariablesPopoverOpen, dedupKey: true }) + } + iconType="indexOpen" + aria-label={i18n.translate( + 'xpack.triggersActionsUI.components.builtinActionTypes.pagerDutyAction.addVariablePopoverButton1', + { + defaultMessage: 'Add variable', + } + )} + /> + } + isOpen={isVariablesPopoverOpen.dedupKey} + closePopover={() => + setIsVariablesPopoverOpen({ ...isVariablesPopoverOpen, dedupKey: false }) + } + panelPaddingSize="none" + anchorPosition="downLeft" + > + + + } > { - if (!index) { + if (!dedupKey) { editAction('dedupKey', '', index); } }} @@ -263,6 +322,33 @@ const PagerDutyParamsFields: React.FunctionComponent + setIsVariablesPopoverOpen({ ...isVariablesPopoverOpen, timestamp: true }) + } + iconType="indexOpen" + aria-label={i18n.translate( + 'xpack.triggersActionsUI.components.builtinActionTypes.pagerDutyAction.addVariablePopoverButton2', + { + defaultMessage: 'Add variable', + } + )} + /> + } + isOpen={isVariablesPopoverOpen.timestamp} + closePopover={() => + setIsVariablesPopoverOpen({ ...isVariablesPopoverOpen, timestamp: false }) + } + panelPaddingSize="none" + anchorPosition="downLeft" + > + + + } > { - if (!index) { + if (!timestamp) { editAction('timestamp', '', index); } }} @@ -289,6 +375,33 @@ const PagerDutyParamsFields: React.FunctionComponent + setIsVariablesPopoverOpen({ ...isVariablesPopoverOpen, component: true }) + } + iconType="indexOpen" + aria-label={i18n.translate( + 'xpack.triggersActionsUI.components.builtinActionTypes.pagerDutyAction.addVariablePopoverButton3', + { + defaultMessage: 'Add variable', + } + )} + /> + } + isOpen={isVariablesPopoverOpen.component} + closePopover={() => + setIsVariablesPopoverOpen({ ...isVariablesPopoverOpen, component: false }) + } + panelPaddingSize="none" + anchorPosition="downLeft" + > + + + } > { - if (!index) { + if (!component) { editAction('component', '', index); } }} @@ -313,6 +426,33 @@ const PagerDutyParamsFields: React.FunctionComponent + setIsVariablesPopoverOpen({ ...isVariablesPopoverOpen, group: true }) + } + iconType="indexOpen" + aria-label={i18n.translate( + 'xpack.triggersActionsUI.components.builtinActionTypes.pagerDutyAction.addVariablePopoverButton4', + { + defaultMessage: 'Add variable', + } + )} + /> + } + isOpen={isVariablesPopoverOpen.group} + closePopover={() => + setIsVariablesPopoverOpen({ ...isVariablesPopoverOpen, group: false }) + } + panelPaddingSize="none" + anchorPosition="downLeft" + > + + + } > { - if (!index) { + if (!group) { editAction('group', '', index); } }} @@ -337,6 +477,33 @@ const PagerDutyParamsFields: React.FunctionComponent + setIsVariablesPopoverOpen({ ...isVariablesPopoverOpen, source: true }) + } + iconType="indexOpen" + aria-label={i18n.translate( + 'xpack.triggersActionsUI.components.builtinActionTypes.pagerDutyAction.addVariablePopoverButton5', + { + defaultMessage: 'Add variable', + } + )} + /> + } + isOpen={isVariablesPopoverOpen.source} + closePopover={() => + setIsVariablesPopoverOpen({ ...isVariablesPopoverOpen, source: false }) + } + panelPaddingSize="none" + anchorPosition="downLeft" + > + + + } > { - if (!index) { + if (!source) { editAction('source', '', index); } }} @@ -364,6 +531,33 @@ const PagerDutyParamsFields: React.FunctionComponent + setIsVariablesPopoverOpen({ ...isVariablesPopoverOpen, summary: true }) + } + iconType="indexOpen" + aria-label={i18n.translate( + 'xpack.triggersActionsUI.components.builtinActionTypes.pagerDutyAction.addVariablePopoverButton6', + { + defaultMessage: 'Add variable', + } + )} + /> + } + isOpen={isVariablesPopoverOpen.summary} + closePopover={() => + setIsVariablesPopoverOpen({ ...isVariablesPopoverOpen, summary: false }) + } + panelPaddingSize="none" + anchorPosition="downLeft" + > + + + } > + setIsVariablesPopoverOpen({ ...isVariablesPopoverOpen, class: true }) + } + iconType="indexOpen" + aria-label={i18n.translate( + 'xpack.triggersActionsUI.components.builtinActionTypes.pagerDutyAction.addVariablePopoverButton7', + { + defaultMessage: 'Add variable', + } + )} + /> + } + isOpen={isVariablesPopoverOpen.class} + closePopover={() => + setIsVariablesPopoverOpen({ ...isVariablesPopoverOpen, class: false }) + } + panelPaddingSize="none" + anchorPosition="downLeft" + > + + + } > Date: Mon, 16 Mar 2020 11:23:57 -0700 Subject: [PATCH 2/5] Fixed due to comments --- .../builtin_action_types/pagerduty.tsx | 226 +++--------------- 1 file changed, 36 insertions(+), 190 deletions(-) diff --git a/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/pagerduty.tsx b/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/pagerduty.tsx index 041d2456a1779e..9017ff50410a5a 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/pagerduty.tsx +++ b/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/pagerduty.tsx @@ -197,7 +197,7 @@ const PagerDutyParamsFields: React.FunctionComponent - messageVariables?.map((variable: string, i: number) => ( + messageVariables?.map((variable: string) => ( )); + + const getAddVariableComponent = (paramsProperty: string, buttonName: string) => { + return ( + setIsVariablesPopoverOpen({ ...isVariablesPopoverOpen, dedupKey: true })} + iconType="indexOpen" + aria-label={i18n.translate( + `xpack.triggersActionsUI.components.builtinActionTypes.pagerDutyAction.${buttonName}`, + { + defaultMessage: 'Add variable', + } + )} + /> + } + isOpen={isVariablesPopoverOpen[paramsProperty]} + closePopover={() => + setIsVariablesPopoverOpen({ ...isVariablesPopoverOpen, [paramsProperty]: false }) + } + panelPaddingSize="none" + anchorPosition="downLeft" + > + + + ); + }; return ( @@ -269,33 +297,7 @@ const PagerDutyParamsFields: React.FunctionComponent - setIsVariablesPopoverOpen({ ...isVariablesPopoverOpen, dedupKey: true }) - } - iconType="indexOpen" - aria-label={i18n.translate( - 'xpack.triggersActionsUI.components.builtinActionTypes.pagerDutyAction.addVariablePopoverButton1', - { - defaultMessage: 'Add variable', - } - )} - /> - } - isOpen={isVariablesPopoverOpen.dedupKey} - closePopover={() => - setIsVariablesPopoverOpen({ ...isVariablesPopoverOpen, dedupKey: false }) - } - panelPaddingSize="none" - anchorPosition="downLeft" - > - - - } + labelAppend={getAddVariableComponent('dedupKey', 'addVariablePopoverButton1')} > - setIsVariablesPopoverOpen({ ...isVariablesPopoverOpen, timestamp: true }) - } - iconType="indexOpen" - aria-label={i18n.translate( - 'xpack.triggersActionsUI.components.builtinActionTypes.pagerDutyAction.addVariablePopoverButton2', - { - defaultMessage: 'Add variable', - } - )} - /> - } - isOpen={isVariablesPopoverOpen.timestamp} - closePopover={() => - setIsVariablesPopoverOpen({ ...isVariablesPopoverOpen, timestamp: false }) - } - panelPaddingSize="none" - anchorPosition="downLeft" - > - - - } + labelAppend={getAddVariableComponent('timestamp', 'addVariablePopoverButton2')} > - setIsVariablesPopoverOpen({ ...isVariablesPopoverOpen, component: true }) - } - iconType="indexOpen" - aria-label={i18n.translate( - 'xpack.triggersActionsUI.components.builtinActionTypes.pagerDutyAction.addVariablePopoverButton3', - { - defaultMessage: 'Add variable', - } - )} - /> - } - isOpen={isVariablesPopoverOpen.component} - closePopover={() => - setIsVariablesPopoverOpen({ ...isVariablesPopoverOpen, component: false }) - } - panelPaddingSize="none" - anchorPosition="downLeft" - > - - - } + labelAppend={getAddVariableComponent('component', 'addVariablePopoverButton7')} > - setIsVariablesPopoverOpen({ ...isVariablesPopoverOpen, group: true }) - } - iconType="indexOpen" - aria-label={i18n.translate( - 'xpack.triggersActionsUI.components.builtinActionTypes.pagerDutyAction.addVariablePopoverButton4', - { - defaultMessage: 'Add variable', - } - )} - /> - } - isOpen={isVariablesPopoverOpen.group} - closePopover={() => - setIsVariablesPopoverOpen({ ...isVariablesPopoverOpen, group: false }) - } - panelPaddingSize="none" - anchorPosition="downLeft" - > - - - } + labelAppend={getAddVariableComponent('group', 'addVariablePopoverButton3')} > - setIsVariablesPopoverOpen({ ...isVariablesPopoverOpen, source: true }) - } - iconType="indexOpen" - aria-label={i18n.translate( - 'xpack.triggersActionsUI.components.builtinActionTypes.pagerDutyAction.addVariablePopoverButton5', - { - defaultMessage: 'Add variable', - } - )} - /> - } - isOpen={isVariablesPopoverOpen.source} - closePopover={() => - setIsVariablesPopoverOpen({ ...isVariablesPopoverOpen, source: false }) - } - panelPaddingSize="none" - anchorPosition="downLeft" - > - - - } + labelAppend={getAddVariableComponent('source', 'addVariablePopoverButton6')} > - setIsVariablesPopoverOpen({ ...isVariablesPopoverOpen, summary: true }) - } - iconType="indexOpen" - aria-label={i18n.translate( - 'xpack.triggersActionsUI.components.builtinActionTypes.pagerDutyAction.addVariablePopoverButton6', - { - defaultMessage: 'Add variable', - } - )} - /> - } - isOpen={isVariablesPopoverOpen.summary} - closePopover={() => - setIsVariablesPopoverOpen({ ...isVariablesPopoverOpen, summary: false }) - } - panelPaddingSize="none" - anchorPosition="downLeft" - > - - - } + labelAppend={getAddVariableComponent('summary', 'addVariablePopoverButton4')} > - setIsVariablesPopoverOpen({ ...isVariablesPopoverOpen, class: true }) - } - iconType="indexOpen" - aria-label={i18n.translate( - 'xpack.triggersActionsUI.components.builtinActionTypes.pagerDutyAction.addVariablePopoverButton7', - { - defaultMessage: 'Add variable', - } - )} - /> - } - isOpen={isVariablesPopoverOpen.class} - closePopover={() => - setIsVariablesPopoverOpen({ ...isVariablesPopoverOpen, class: false }) - } - panelPaddingSize="none" - anchorPosition="downLeft" - > - - - } + labelAppend={getAddVariableComponent('class', 'addVariablePopoverButton5')} > Date: Mon, 16 Mar 2020 14:19:18 -0700 Subject: [PATCH 3/5] fixed language check issue --- .../builtin_action_types/pagerduty.tsx | 79 +++++++++++++++---- 1 file changed, 65 insertions(+), 14 deletions(-) diff --git a/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/pagerduty.tsx b/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/pagerduty.tsx index 9017ff50410a5a..f7432b504b6c09 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/pagerduty.tsx +++ b/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/pagerduty.tsx @@ -219,15 +219,10 @@ const PagerDutyParamsFields: React.FunctionComponent setIsVariablesPopoverOpen({ ...isVariablesPopoverOpen, dedupKey: true })} iconType="indexOpen" - aria-label={i18n.translate( - `xpack.triggersActionsUI.components.builtinActionTypes.pagerDutyAction.${buttonName}`, - { - defaultMessage: 'Add variable', - } - )} + aria-label={buttonName} /> } isOpen={isVariablesPopoverOpen[paramsProperty]} @@ -297,7 +292,15 @@ const PagerDutyParamsFields: React.FunctionComponent Date: Mon, 16 Mar 2020 17:39:21 -0700 Subject: [PATCH 4/5] Fixed tests --- .../application/components/builtin_action_types/pagerduty.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/pagerduty.tsx b/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/pagerduty.tsx index f7432b504b6c09..769ff26a2b6874 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/pagerduty.tsx +++ b/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/pagerduty.tsx @@ -219,7 +219,7 @@ const PagerDutyParamsFields: React.FunctionComponent setIsVariablesPopoverOpen({ ...isVariablesPopoverOpen, dedupKey: true })} iconType="indexOpen" aria-label={buttonName} From ff35ccd3f4c9f362497763b400b0105b6e3964a6 Mon Sep 17 00:00:00 2001 From: Yuliia Naumenko Date: Mon, 16 Mar 2020 17:48:32 -0700 Subject: [PATCH 5/5] Fixed due to comments --- .../builtin_action_types/pagerduty.tsx | 74 +++++++++++++++++-- 1 file changed, 66 insertions(+), 8 deletions(-) diff --git a/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/pagerduty.tsx b/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/pagerduty.tsx index 769ff26a2b6874..7666129e4abdc3 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/pagerduty.tsx +++ b/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/pagerduty.tsx @@ -176,15 +176,71 @@ const PagerDutyParamsFields: React.FunctionComponent>({ dedupKey: false, @@ -220,7 +276,9 @@ const PagerDutyParamsFields: React.FunctionComponent setIsVariablesPopoverOpen({ ...isVariablesPopoverOpen, dedupKey: true })} + onClick={() => + setIsVariablesPopoverOpen({ ...isVariablesPopoverOpen, [paramsProperty]: true }) + } iconType="indexOpen" aria-label={buttonName} />