Skip to content

Commit

Permalink
fix priority reset bug (#113626)
Browse files Browse the repository at this point in the history
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
semd and kibanamachine authored Oct 4, 2021
1 parent 3d0da7f commit 59b15df
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ describe('JiraParamsFields renders', () => {
description: { allowedValues: [], defaultValue: {} },
},
};
const useGetFieldsByIssueTypeResponseLoading = {
isLoading: true,
fields: {},
};

beforeEach(() => {
jest.clearAllMocks();
Expand Down Expand Up @@ -421,5 +425,19 @@ describe('JiraParamsFields renders', () => {
expect(editAction.mock.calls[0][1].incident.priority).toEqual('Medium');
expect(editAction.mock.calls[1][1].incident.priority).toEqual(null);
});

test('Preserve priority when the issue type fields are loading and hasPriority becomes stale', () => {
useGetFieldsByIssueTypeMock
.mockReturnValueOnce(useGetFieldsByIssueTypeResponseLoading)
.mockReturnValue(useGetFieldsByIssueTypeResponse);
const wrapper = mount(<JiraParamsFields {...defaultProps} />);

expect(editAction).not.toBeCalled();

wrapper.setProps({ ...defaultProps }); // just to force component call useGetFieldsByIssueType again

expect(editAction).toBeCalledTimes(1);
expect(editAction.mock.calls[0][1].incident.priority).toEqual('Medium');
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,11 @@ const JiraParamsFields: React.FunctionComponent<ActionParamsProps<JiraActionPara
}, [editSubActionProperty, fields, incident.issueType, incident.priority]);

useEffect(() => {
if (!hasPriority && incident.priority != null) {
if (!isLoadingFields && !hasPriority && incident.priority != null) {
editSubActionProperty('priority', null);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [hasPriority]);
}, [hasPriority, isLoadingFields]);

const labelOptions = useMemo(
() => (incident.labels ? incident.labels.map((label: string) => ({ label })) : []),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ export const useGetFieldsByIssueType = ({
});

if (!didCancel) {
setIsLoading(false);
setFields(res.data ?? {});
setIsLoading(false);
if (res.status && res.status === 'error') {
toastNotifications.addDanger({
title: i18n.FIELDS_API_ERROR,
Expand Down

0 comments on commit 59b15df

Please sign in to comment.