Skip to content

Commit

Permalink
[Actions UI] Changed PagerDuty action form UI to fill payload fields …
Browse files Browse the repository at this point in the history
…according to the API docs for Resolve and Acknowledge events. (#96363) (#96677)

* [Actions UI] Changed PagerDuty action form UI to fill payload fields according to the API docs for Resolve and Acknowledge events.

* fixed test

* fixed test

Co-authored-by: Kibana Machine <[email protected]>

Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
YulNaumenko and kibanamachine authored Apr 9, 2021
1 parent 45fc5be commit b89efdb
Show file tree
Hide file tree
Showing 4 changed files with 196 additions and 128 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
PagerDutyConfig,
PagerDutySecrets,
PagerDutyActionParams,
EventActionOptions,
} from '.././types';
import pagerDutySvg from './pagerduty.svg';
import { hasMustacheTokens } from '../../../lib/has_mustache_tokens';
Expand Down Expand Up @@ -88,7 +89,10 @@ export function getActionType(): ActionTypeModel<
)
);
}
if (!actionParams.summary?.length) {
if (
actionParams.eventAction === EventActionOptions.TRIGGER &&
!actionParams.summary?.length
) {
errors.summary.push(
i18n.translate(
'xpack.triggersActionsUI.components.builtinActionTypes.pagerDutyAction.error.requiredSummaryText',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,29 @@ describe('PagerDutyParamsFields renders', () => {
expect(wrapper.find('[data-test-subj="dedupKeyAddVariableButton"]').length > 0).toBeTruthy();
});

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

const wrapper = mountWithIntl(
<PagerDutyParamsFields
actionParams={actionParams}
errors={{ summary: [], timestamp: [], dedupKey: [] }}
editAction={() => {}}
index={0}
/>
);
expect(wrapper.find('[data-test-subj="eventActionSelect"]').length > 0).toBeTruthy();
expect(
wrapper.find('[data-test-subj="eventActionSelect"]').first().prop('value')
).toStrictEqual(undefined);
});

test('params select fields do not auto set values severitySelect', () => {
const actionParams = {
eventAction: EventActionOptions.TRIGGER,
dedupKey: 'test',
};

const wrapper = mountWithIntl(
<PagerDutyParamsFields
actionParams={actionParams}
Expand All @@ -72,9 +92,35 @@ describe('PagerDutyParamsFields renders', () => {
expect(wrapper.find('[data-test-subj="severitySelect"]').first().prop('value')).toStrictEqual(
undefined
);
});

test('only eventActionSelect is available as a payload params for PagerDuty Resolve event', () => {
const actionParams = {
eventAction: EventActionOptions.RESOLVE,
dedupKey: 'test',
};

const wrapper = mountWithIntl(
<PagerDutyParamsFields
actionParams={actionParams}
errors={{ summary: [], timestamp: [], dedupKey: [] }}
editAction={() => {}}
index={0}
/>
);
expect(wrapper.find('[data-test-subj="dedupKeyInput"]').length > 0).toBeTruthy();
expect(wrapper.find('[data-test-subj="dedupKeyInput"]').first().prop('value')).toStrictEqual(
'test'
);
expect(wrapper.find('[data-test-subj="eventActionSelect"]').length > 0).toBeTruthy();
expect(
wrapper.find('[data-test-subj="eventActionSelect"]').first().prop('value')
).toStrictEqual(undefined);
).toStrictEqual('resolve');
expect(wrapper.find('[data-test-subj="dedupKeyInput"]').length > 0).toBeTruthy();
expect(wrapper.find('[data-test-subj="timestampInput"]').length > 0).toBeFalsy();
expect(wrapper.find('[data-test-subj="componentInput"]').length > 0).toBeFalsy();
expect(wrapper.find('[data-test-subj="groupInput"]').length > 0).toBeFalsy();
expect(wrapper.find('[data-test-subj="sourceInput"]').length > 0).toBeFalsy();
expect(wrapper.find('[data-test-subj="summaryInput"]').length > 0).toBeFalsy();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -99,32 +99,11 @@ const PagerDutyParamsFields: React.FunctionComponent<ActionParamsProps<PagerDuty
];

const isDedupeKeyRequired = eventAction !== 'trigger';
const isTriggerPagerDutyEvent = eventAction === 'trigger';

return (
<Fragment>
<EuiFlexGroup>
<EuiFlexItem>
<EuiFormRow
fullWidth
label={i18n.translate(
'xpack.triggersActionsUI.components.builtinActionTypes.pagerDutyAction.severitySelectFieldLabel',
{
defaultMessage: 'Severity (optional)',
}
)}
>
<EuiSelect
fullWidth
data-test-subj="severitySelect"
options={severityOptions}
hasNoInitialSelection={isUndefined(severity)}
value={severity}
onChange={(e) => {
editAction('severity', e.target.value, index);
}}
/>
</EuiFormRow>
</EuiFlexItem>
<EuiFlexItem>
<EuiFormRow
fullWidth
Expand All @@ -148,29 +127,6 @@ const PagerDutyParamsFields: React.FunctionComponent<ActionParamsProps<PagerDuty
</EuiFormRow>
</EuiFlexItem>
</EuiFlexGroup>
<EuiSpacer size="m" />
<EuiFormRow
id="pagerDutySummary"
fullWidth
error={errors.summary}
isInvalid={errors.summary.length > 0 && summary !== undefined}
label={i18n.translate(
'xpack.triggersActionsUI.components.builtinActionTypes.pagerDutyAction.summaryFieldLabel',
{
defaultMessage: 'Summary',
}
)}
>
<TextFieldWithMessageVariables
index={index}
editAction={editAction}
messageVariables={messageVariables}
paramsProperty={'summary'}
inputTargetValue={summary}
errors={errors.summary as string[]}
/>
</EuiFormRow>
<EuiSpacer size="m" />
<EuiFlexGroup>
<EuiFlexItem>
<EuiFormRow
Expand Down Expand Up @@ -202,99 +158,150 @@ const PagerDutyParamsFields: React.FunctionComponent<ActionParamsProps<PagerDuty
/>
</EuiFormRow>
</EuiFlexItem>
<EuiFlexItem>
</EuiFlexGroup>
{isTriggerPagerDutyEvent ? (
<>
<EuiSpacer size="m" />
<EuiFormRow
id="pagerDutySummary"
fullWidth
error={errors.timestamp}
isInvalid={errors.timestamp.length > 0 && timestamp !== undefined}
error={errors.summary}
isInvalid={errors.summary.length > 0 && summary !== undefined}
label={i18n.translate(
'xpack.triggersActionsUI.components.builtinActionTypes.pagerDutyAction.timestampTextFieldLabel',
'xpack.triggersActionsUI.components.builtinActionTypes.pagerDutyAction.summaryFieldLabel',
{
defaultMessage: 'Timestamp (optional)',
defaultMessage: 'Summary',
}
)}
>
<TextFieldWithMessageVariables
index={index}
editAction={editAction}
messageVariables={messageVariables}
paramsProperty={'timestamp'}
inputTargetValue={timestamp}
errors={errors.timestamp as string[]}
paramsProperty={'summary'}
inputTargetValue={summary}
errors={errors.summary as string[]}
/>
</EuiFormRow>
</EuiFlexItem>
</EuiFlexGroup>
<EuiSpacer size="m" />
<EuiFormRow
fullWidth
label={i18n.translate(
'xpack.triggersActionsUI.components.builtinActionTypes.pagerDutyAction.componentTextFieldLabel',
{
defaultMessage: 'Component (optional)',
}
)}
>
<TextFieldWithMessageVariables
index={index}
editAction={editAction}
messageVariables={messageVariables}
paramsProperty={'component'}
inputTargetValue={component}
/>
</EuiFormRow>
<EuiFormRow
fullWidth
label={i18n.translate(
'xpack.triggersActionsUI.components.builtinActionTypes.pagerDutyAction.groupTextFieldLabel',
{
defaultMessage: 'Group (optional)',
}
)}
>
<TextFieldWithMessageVariables
index={index}
editAction={editAction}
messageVariables={messageVariables}
paramsProperty={'group'}
inputTargetValue={group}
/>
</EuiFormRow>
<EuiFormRow
fullWidth
label={i18n.translate(
'xpack.triggersActionsUI.components.builtinActionTypes.pagerDutyAction.sourceTextFieldLabel',
{
defaultMessage: 'Source (optional)',
}
)}
>
<TextFieldWithMessageVariables
index={index}
editAction={editAction}
messageVariables={messageVariables}
paramsProperty={'source'}
inputTargetValue={source}
/>
</EuiFormRow>
<EuiFormRow
id="pagerDutyClass"
fullWidth
label={i18n.translate(
'xpack.triggersActionsUI.components.builtinActionTypes.pagerDutyAction.classFieldLabel',
{
defaultMessage: 'Class (optional)',
}
)}
>
<TextFieldWithMessageVariables
index={index}
editAction={editAction}
messageVariables={messageVariables}
paramsProperty={'class'}
inputTargetValue={actionParams.class}
/>
</EuiFormRow>
<EuiSpacer size="m" />
<EuiFlexGroup>
<EuiFlexItem>
<EuiFormRow
fullWidth
label={i18n.translate(
'xpack.triggersActionsUI.components.builtinActionTypes.pagerDutyAction.severitySelectFieldLabel',
{
defaultMessage: 'Severity (optional)',
}
)}
>
<EuiSelect
fullWidth
data-test-subj="severitySelect"
options={severityOptions}
hasNoInitialSelection={isUndefined(severity)}
value={severity}
onChange={(e) => {
editAction('severity', e.target.value, index);
}}
/>
</EuiFormRow>
</EuiFlexItem>
<EuiFlexItem>
<EuiFormRow
fullWidth
error={errors.timestamp}
isInvalid={errors.timestamp.length > 0 && timestamp !== undefined}
label={i18n.translate(
'xpack.triggersActionsUI.components.builtinActionTypes.pagerDutyAction.timestampTextFieldLabel',
{
defaultMessage: 'Timestamp (optional)',
}
)}
>
<TextFieldWithMessageVariables
index={index}
editAction={editAction}
messageVariables={messageVariables}
paramsProperty={'timestamp'}
inputTargetValue={timestamp}
errors={errors.timestamp as string[]}
/>
</EuiFormRow>
</EuiFlexItem>
</EuiFlexGroup>
<EuiSpacer size="m" />
<EuiFormRow
fullWidth
label={i18n.translate(
'xpack.triggersActionsUI.components.builtinActionTypes.pagerDutyAction.componentTextFieldLabel',
{
defaultMessage: 'Component (optional)',
}
)}
>
<TextFieldWithMessageVariables
index={index}
editAction={editAction}
messageVariables={messageVariables}
paramsProperty={'component'}
inputTargetValue={component}
/>
</EuiFormRow>
<EuiFormRow
fullWidth
label={i18n.translate(
'xpack.triggersActionsUI.components.builtinActionTypes.pagerDutyAction.groupTextFieldLabel',
{
defaultMessage: 'Group (optional)',
}
)}
>
<TextFieldWithMessageVariables
index={index}
editAction={editAction}
messageVariables={messageVariables}
paramsProperty={'group'}
inputTargetValue={group}
/>
</EuiFormRow>
<EuiFormRow
fullWidth
label={i18n.translate(
'xpack.triggersActionsUI.components.builtinActionTypes.pagerDutyAction.sourceTextFieldLabel',
{
defaultMessage: 'Source (optional)',
}
)}
>
<TextFieldWithMessageVariables
index={index}
editAction={editAction}
messageVariables={messageVariables}
paramsProperty={'source'}
inputTargetValue={source}
/>
</EuiFormRow>
<EuiFormRow
id="pagerDutyClass"
fullWidth
label={i18n.translate(
'xpack.triggersActionsUI.components.builtinActionTypes.pagerDutyAction.classFieldLabel',
{
defaultMessage: 'Class (optional)',
}
)}
>
<TextFieldWithMessageVariables
index={index}
editAction={editAction}
messageVariables={messageVariables}
paramsProperty={'class'}
inputTargetValue={actionParams.class}
/>
</EuiFormRow>
</>
) : null}
</Fragment>
);
};
Expand Down
Loading

0 comments on commit b89efdb

Please sign in to comment.