From 5108bb35602fa03ee203e3046ac52b803d354196 Mon Sep 17 00:00:00 2001 From: Steph Milovic Date: Thu, 7 Jan 2021 17:39:19 -0700 Subject: [PATCH] [Security Solution] [Case] Fix Jira connector test form (#87580) (#87655) --- .../jira/jira_params.test.tsx | 25 +++++++++++++ .../builtin_action_types/jira/jira_params.tsx | 36 ++++++++++++++----- 2 files changed, 53 insertions(+), 8 deletions(-) diff --git a/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/jira/jira_params.test.tsx b/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/jira/jira_params.test.tsx index 664f22a9da7b1..a1c714361af6e 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/jira/jira_params.test.tsx +++ b/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/jira/jira_params.test.tsx @@ -85,6 +85,14 @@ describe('JiraParamsFields renders', () => { }, }, }; + const useGetFieldsByIssueTypeResponseNoPriority = { + ...useGetFieldsByIssueTypeResponse, + fields: { + summary: { allowedValues: [], defaultValue: {} }, + labels: { allowedValues: [], defaultValue: {} }, + description: { allowedValues: [], defaultValue: {} }, + }, + }; beforeEach(() => { jest.clearAllMocks(); @@ -386,5 +394,22 @@ describe('JiraParamsFields renders', () => { expect(comments.simulate('change', emptyComment)); expect(editAction.mock.calls.length).toEqual(1); }); + test('Clears any left behind priority when issueType changes and hasPriority becomes false', () => { + useGetFieldsByIssueTypeMock + .mockReturnValueOnce(useGetFieldsByIssueTypeResponse) + .mockReturnValue(useGetFieldsByIssueTypeResponseNoPriority); + const wrapper = mount(); + wrapper.setProps({ + ...{ + ...defaultProps, + actionParams: { + ...defaultProps.actionParams, + incident: { issueType: '10001' }, + }, + }, + }); + expect(editAction.mock.calls[0][1].incident.priority).toEqual('Medium'); + expect(editAction.mock.calls[1][1].incident.priority).toEqual(null); + }); }); }); diff --git a/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/jira/jira_params.tsx b/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/jira/jira_params.tsx index 3774b790ff622..1770debc6afcf 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/jira/jira_params.tsx +++ b/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/jira/jira_params.tsx @@ -64,14 +64,27 @@ const JiraParamsFields: React.FunctionComponent { - const newProps = - key !== 'comments' - ? { - incident: { ...incident, [key]: value }, - comments, - } - : { incident, [key]: value }; - editAction('subActionParams', newProps, index); + if (key === 'issueType') { + return editAction( + 'subActionParams', + { + incident: { issueType: value }, + comments, + }, + index + ); + } + if (key === 'comments') { + return editAction('subActionParams', { incident, comments: value }, index); + } + return editAction( + 'subActionParams', + { + incident: { ...incident, [key]: value }, + comments, + }, + index + ); }, [comments, editAction, incident, index] ); @@ -114,6 +127,7 @@ const JiraParamsFields: React.FunctionComponent p.name === incident.priority); + if ((!incident.priority || !doesPriorityExist) && priorities.length > 0) { editSubActionProperty('priority', priorities[0].name ?? ''); } @@ -126,6 +140,12 @@ const JiraParamsFields: React.FunctionComponent { + if (!hasPriority && incident.priority != null) { + editSubActionProperty('priority', null); + } + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [hasPriority]); const labelOptions = useMemo( () => (incident.labels ? incident.labels.map((label: string) => ({ label })) : []),