[Cases] [108671] Fix faulty status api call, if selection is same (#118115) (#118263)

* [Cases] [108671] Fix faulty status api call, if selection is same

* Add unit test to ensure selecting same status message does not call api

Co-authored-by: Kristof-Pierre Cummings <kristofpierre.cummings@elastic.co>
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>

Co-authored-by: Kristof C <kpac.ja@gmail.com>
Co-authored-by: Kristof-Pierre Cummings <kristofpierre.cummings@elastic.co>
This commit is contained in:
Kibana Machine 2021-11-10 20:24:49 -05:00 committed by GitHub
parent b040096beb
commit f776be5e61
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 2 deletions

View file

@ -60,4 +60,15 @@ describe('SyncAlertsSwitch', () => {
expect(onStatusChanged).toHaveBeenCalledWith('in-progress');
});
it('it does not call onStatusChanged if selection is same as current status', async () => {
const wrapper = mount(
<StatusContextMenu currentStatus={CaseStatuses.open} onStatusChanged={onStatusChanged} />
);
wrapper.find(`[data-test-subj="case-view-status-dropdown"] button`).simulate('click');
wrapper.find(`[data-test-subj="case-view-status-dropdown-open"] button`).simulate('click');
expect(onStatusChanged).not.toHaveBeenCalled();
});
});

View file

@ -33,9 +33,11 @@ const StatusContextMenuComponent: React.FC<Props> = ({
const onContextMenuItemClick = useCallback(
(status: CaseStatuses) => {
closePopover();
onStatusChanged(status);
if (currentStatus !== status) {
onStatusChanged(status);
}
},
[closePopover, onStatusChanged]
[closePopover, currentStatus, onStatusChanged]
);
const panelItems = useMemo(