fix priority reset bug (#113626) (#113789)

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>

Co-authored-by: Sergi Massaneda <sergi.massaneda@elastic.co>
This commit is contained in:
Kibana Machine 2021-10-04 14:20:03 -04:00 committed by GitHub
parent 9f685ef2a4
commit 4913677f5f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 3 deletions

View file

@ -95,6 +95,10 @@ describe('JiraParamsFields renders', () => {
description: { allowedValues: [], defaultValue: {} },
},
};
const useGetFieldsByIssueTypeResponseLoading = {
isLoading: true,
fields: {},
};
beforeEach(() => {
jest.clearAllMocks();
@ -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');
});
});
});

View file

@ -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 })) : []),

View file

@ -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,