Skip to content

Commit

Permalink
[Actions] fixes bug where severity is auto selected but not applied t…
Browse files Browse the repository at this point in the history
…o the action in PagerDuty (elastic#84891)

In this PR we ensure the EuiSelects in the PagerDuty params components don't auto select a value when the field doesn't have a default value.
  • Loading branch information
gmmorris committed Dec 4, 2020
1 parent a0be161 commit 7c0096c
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 5 deletions.
1 change: 0 additions & 1 deletion x-pack/plugins/translations/translations/ja-JP.json
Original file line number Diff line number Diff line change
Expand Up @@ -19635,7 +19635,6 @@
"xpack.triggersActionsUI.components.builtinActionTypes.pagerDutyAction.selectMessageText": "PagerDuty でイベントを送信します。",
"xpack.triggersActionsUI.components.builtinActionTypes.pagerDutyAction.severitySelectCriticalOptionLabel": "重大",
"xpack.triggersActionsUI.components.builtinActionTypes.pagerDutyAction.severitySelectErrorOptionLabel": "エラー",
"xpack.triggersActionsUI.components.builtinActionTypes.pagerDutyAction.severitySelectFieldLabel": "深刻度",
"xpack.triggersActionsUI.components.builtinActionTypes.pagerDutyAction.severitySelectInfoOptionLabel": "情報",
"xpack.triggersActionsUI.components.builtinActionTypes.pagerDutyAction.severitySelectWarningOptionLabel": "警告",
"xpack.triggersActionsUI.components.builtinActionTypes.pagerDutyAction.sourceTextFieldLabel": "ソース (任意)",
Expand Down
1 change: 0 additions & 1 deletion x-pack/plugins/translations/translations/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -19654,7 +19654,6 @@
"xpack.triggersActionsUI.components.builtinActionTypes.pagerDutyAction.selectMessageText": "在 PagerDuty 中发送事件。",
"xpack.triggersActionsUI.components.builtinActionTypes.pagerDutyAction.severitySelectCriticalOptionLabel": "紧急",
"xpack.triggersActionsUI.components.builtinActionTypes.pagerDutyAction.severitySelectErrorOptionLabel": "错误",
"xpack.triggersActionsUI.components.builtinActionTypes.pagerDutyAction.severitySelectFieldLabel": "严重性",
"xpack.triggersActionsUI.components.builtinActionTypes.pagerDutyAction.severitySelectInfoOptionLabel": "信息",
"xpack.triggersActionsUI.components.builtinActionTypes.pagerDutyAction.severitySelectWarningOptionLabel": "警告",
"xpack.triggersActionsUI.components.builtinActionTypes.pagerDutyAction.sourceTextFieldLabel": "源(可选)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,25 @@ describe('PagerDutyParamsFields renders', () => {
expect(wrapper.find('[data-test-subj="summaryInput"]').length > 0).toBeTruthy();
expect(wrapper.find('[data-test-subj="dedupKeyAddVariableButton"]').length > 0).toBeTruthy();
});

test('params select fields dont auto set values ', () => {
const actionParams = {};

const wrapper = mountWithIntl(
<PagerDutyParamsFields
actionParams={actionParams}
errors={{ summary: [], timestamp: [], dedupKey: [] }}
editAction={() => {}}
index={0}
/>
);
expect(wrapper.find('[data-test-subj="severitySelect"]').length > 0).toBeTruthy();
expect(wrapper.find('[data-test-subj="severitySelect"]').first().prop('value')).toStrictEqual(
undefined
);
expect(wrapper.find('[data-test-subj="eventActionSelect"]').length > 0).toBeTruthy();
expect(
wrapper.find('[data-test-subj="eventActionSelect"]').first().prop('value')
).toStrictEqual(undefined);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import React, { Fragment } from 'react';
import { EuiFlexGroup, EuiFlexItem, EuiFormRow, EuiSelect, EuiSpacer } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { isUndefined } from 'lodash';
import { ActionParamsProps } from '../../../../types';
import { PagerDutyActionParams } from '.././types';
import { TextFieldWithMessageVariables } from '../../text_field_with_message_variables';
Expand Down Expand Up @@ -106,14 +107,15 @@ const PagerDutyParamsFields: React.FunctionComponent<ActionParamsProps<PagerDuty
label={i18n.translate(
'xpack.triggersActionsUI.components.builtinActionTypes.pagerDutyAction.severitySelectFieldLabel',
{
defaultMessage: 'Severity',
defaultMessage: 'Severity (optional)',
}
)}
>
<EuiSelect
fullWidth
data-test-subj="severitySelect"
options={severityOptions}
hasNoInitialSelection={isUndefined(severity)}
value={severity}
onChange={(e) => {
editAction('severity', e.target.value, index);
Expand All @@ -135,6 +137,7 @@ const PagerDutyParamsFields: React.FunctionComponent<ActionParamsProps<PagerDuty
fullWidth
data-test-subj="eventActionSelect"
options={eventActionOptions}
hasNoInitialSelection={isUndefined(eventAction)}
value={eventAction}
onChange={(e) => {
editAction('eventAction', e.target.value, index);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

import { AlertActionParam, RecoveredActionGroup } from '../../../../alerts/common';
import { EventActionOptions } from '../components/builtin_action_types/types';
import { AlertProvidedActionVariables } from './action_variables';

export const getDefaultsForActionParams = (
Expand All @@ -15,10 +16,10 @@ export const getDefaultsForActionParams = (
case '.pagerduty':
const pagerDutyDefaults = {
dedupKey: `{{${AlertProvidedActionVariables.alertId}}}:{{${AlertProvidedActionVariables.alertInstanceId}}}`,
eventAction: 'trigger',
eventAction: EventActionOptions.TRIGGER,
};
if (actionGroupId === RecoveredActionGroup.id) {
pagerDutyDefaults.eventAction = 'resolve';
pagerDutyDefaults.eventAction = EventActionOptions.RESOLVE;
}
return pagerDutyDefaults;
}
Expand Down

0 comments on commit 7c0096c

Please sign in to comment.