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:
parent
9f685ef2a4
commit
4913677f5f
|
@ -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');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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 })) : []),
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue