Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Cases] Show toast when a case is updated from the cases list #123357

Merged
merged 5 commits into from
Jan 20, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,15 @@ import { UpdateKey } from './types';
import { allCases, basicCase } from './mock';
import * as api from './api';
import { TestProviders } from '../common/mock';
import { useToasts } from '../common/lib/kibana';

jest.mock('./api');
jest.mock('../common/lib/kibana');

describe('useGetCases', () => {
const abortCtrl = new AbortController();
const addSuccess = jest.fn();
(useToasts as jest.Mock).mockReturnValue({ addSuccess, addError: jest.fn() });

beforeEach(() => {
jest.clearAllMocks();
Expand Down Expand Up @@ -113,6 +116,9 @@ describe('useGetCases', () => {
abortCtrl.signal
);
});
expect(addSuccess).toHaveBeenCalledWith({
title: `Updated "${basicCase.title}"`,
});
});

it('refetch cases', async () => {
Expand Down
13 changes: 11 additions & 2 deletions x-pack/plugins/cases/public/containers/use_get_cases.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ export const useGetCases = (

const dispatchUpdateCaseProperty = useCallback(
async ({ updateKey, updateValue, caseId, refetchCasesStatus, version }: UpdateCase) => {
const caseData = state.data.cases.find((el) => el.id === caseId);
academo marked this conversation as resolved.
Show resolved Hide resolved
try {
didCancelUpdateCases.current = false;
abortCtrlUpdateCases.current.abort();
Expand All @@ -230,6 +231,15 @@ export const useGetCases = (
dispatch({ type: 'FETCH_UPDATE_CASE_SUCCESS' });
fetchCases(state.filterOptions, state.queryParams);
refetchCasesStatus();
if (caseData) {
toasts.addSuccess({
title: i18n.UPDATED_CASE(caseData.title),
text:
updateKey === 'status' && caseData.totalAlerts > 0
? i18n.STATUS_CHANGED_TOASTER_TEXT
academo marked this conversation as resolved.
Show resolved Hide resolved
: undefined,
});
}
}
} catch (error) {
if (!didCancelUpdateCases.current) {
Expand All @@ -240,8 +250,7 @@ export const useGetCases = (
}
}
},
// eslint-disable-next-line react-hooks/exhaustive-deps
[state.filterOptions, state.queryParams]
[fetchCases, state.data, state.filterOptions, state.queryParams, toasts]
);

const refetchCases = useCallback(() => {
Expand Down