Skip to content

Commit

Permalink
[8.13] [Actions] [ServiceNow] Add required UI validation for correlat…
Browse files Browse the repository at this point in the history
…ion_id when recovered action (elastic#177422) (elastic#177550)

# Backport

This will backport the following commits from `main` to `8.13`:
- [[Actions] [ServiceNow] Add required UI validation for correlation_id
when recovered action
(elastic#177422)](elastic#177422)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Janki
Salvi","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-02-22T08:21:31Z","message":"[Actions]
[ServiceNow] Add required UI validation for correlation_id when
recovered action (elastic#177422)\n\n## Summary\r\n\r\nThis PR adds UI
validation for `correlation_id` field in case of\r\nRecovered
action.\r\n\r\n<img width=\"503\"
alt=\"image\"\r\nsrc=\"https://github.com/elastic/kibana/assets/117571355/60731f81-1dc5-4d34-b9f8-4a3488df244f\">\r\n\r\n###
Checklist\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios","sha":"401f79c335c8a0c4e3afb531a76bb27630e834ea","branchLabelMapping":{"^v8.14.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","release_note:skip","Feature:Actions","Team:ResponseOps","v8.13.0","v8.14.0"],"title":"[Actions]
[ServiceNow] Add required UI validation for correlation_id when
recovered
action","number":177422,"url":"https://github.com/elastic/kibana/pull/177422","mergeCommit":{"message":"[Actions]
[ServiceNow] Add required UI validation for correlation_id when
recovered action (elastic#177422)\n\n## Summary\r\n\r\nThis PR adds UI
validation for `correlation_id` field in case of\r\nRecovered
action.\r\n\r\n<img width=\"503\"
alt=\"image\"\r\nsrc=\"https://github.com/elastic/kibana/assets/117571355/60731f81-1dc5-4d34-b9f8-4a3488df244f\">\r\n\r\n###
Checklist\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios","sha":"401f79c335c8a0c4e3afb531a76bb27630e834ea"}},"sourceBranch":"main","suggestedTargetBranches":["8.13"],"targetPullRequestStates":[{"branch":"8.13","label":"v8.13.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.14.0","branchLabelMappingKey":"^v8.14.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/177422","number":177422,"mergeCommit":{"message":"[Actions]
[ServiceNow] Add required UI validation for correlation_id when
recovered action (elastic#177422)\n\n## Summary\r\n\r\nThis PR adds UI
validation for `correlation_id` field in case of\r\nRecovered
action.\r\n\r\n<img width=\"503\"
alt=\"image\"\r\nsrc=\"https://github.com/elastic/kibana/assets/117571355/60731f81-1dc5-4d34-b9f8-4a3488df244f\">\r\n\r\n###
Checklist\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios","sha":"401f79c335c8a0c4e3afb531a76bb27630e834ea"}}]}]
BACKPORT-->

Co-authored-by: Janki Salvi <[email protected]>
  • Loading branch information
kibanamachine and js-jankisalvi authored Feb 22, 2024
1 parent fc82311 commit f91e5cb
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -339,5 +339,27 @@ describe('ServiceNowITSMParamsFields renders', () => {
incident: { correlation_id: 'updated correlation id' },
});
});

test('throws error if correlation_id is null and sub action is recovered', () => {
const newProps = {
...defaultProps,
actionParams: {
subAction: 'closeIncident',
subActionParams: {
incident: {
...defaultProps.actionParams.subActionParams.incident,
correlation_id: null,
},
comments: null,
},
},
errors: { 'subActionParams.incident.correlation_id': ['correlation_id_error'] },
selectedActionGroupId: ACTION_GROUP_RECOVERED,
};

const wrapper = mountWithIntl(<ServiceNowITSMParamsFields {...newProps} />);

expect(wrapper.find('.euiFormErrorText').text()).toBe('correlation_id_error');
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,31 @@ const defaultFields: Fields = {
};

const CorrelationIdField: React.FunctionComponent<
Pick<ActionParamsProps<ServiceNowITSMActionParams>, 'index' | 'messageVariables'> & {
Pick<ActionParamsProps<ServiceNowITSMActionParams>, 'index' | 'messageVariables' | 'errors'> & {
correlationId: string | null;
selectedActionGroupId?: string;
editSubActionProperty: (key: string, value: any) => void;
}
> = ({ index, messageVariables, correlationId, editSubActionProperty }) => {
> = ({
index,
messageVariables,
correlationId,
editSubActionProperty,
selectedActionGroupId,
errors,
}) => {
const { docLinks } = useKibana().services;
return (
<EuiFormRow
fullWidth
label={i18n.CORRELATION_ID}
error={errors['subActionParams.incident.correlation_id']}
isInvalid={
errors['subActionParams.incident.correlation_id'] !== undefined &&
errors['subActionParams.incident.correlation_id'].length > 0 &&
!correlationId &&
selectedActionGroupId === ACTION_GROUP_RECOVERED
}
helpText={
<EuiLink href={docLinks.links.alerting.serviceNowAction} target="_blank">
<FormattedMessage
Expand All @@ -65,7 +80,9 @@ const CorrelationIdField: React.FunctionComponent<
}
labelAppend={
<EuiText size="xs" color="subdued">
{i18n.OPTIONAL_LABEL}
{selectedActionGroupId !== ACTION_GROUP_RECOVERED
? i18n.OPTIONAL_LABEL
: i18n.REQUIRED_LABEL}
</EuiText>
}
>
Expand All @@ -75,6 +92,7 @@ const CorrelationIdField: React.FunctionComponent<
messageVariables={messageVariables}
paramsProperty={'correlation_id'}
inputTargetValue={correlationId ?? undefined}
errors={errors['subActionParams.incident.correlation_id'] as string[]}
/>
</EuiFormRow>
);
Expand Down Expand Up @@ -297,6 +315,8 @@ const ServiceNowParamsFields: React.FunctionComponent<
messageVariables={messageVariables}
correlationId={incident.correlation_id}
editSubActionProperty={editSubActionProperty}
selectedActionGroupId={selectedActionGroupId}
errors={errors}
/>
</EuiFlexItem>
<EuiFlexItem>
Expand Down Expand Up @@ -374,6 +394,8 @@ const ServiceNowParamsFields: React.FunctionComponent<
messageVariables={messageVariables}
correlationId={incident.correlation_id}
editSubActionProperty={editSubActionProperty}
selectedActionGroupId={selectedActionGroupId}
errors={errors}
/>
)}
</>
Expand Down

0 comments on commit f91e5cb

Please sign in to comment.