[Security Solution] [Timelines] Refresh notes table in thunk when deleting (#187428)

## Summary

Fixes an issue where the table was not being properly updated upon
deletion.

![delete_count_update](efd1e463-266a-4ce3-b34b-2a963ce44ae4)


### Checklist


- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
This commit is contained in:
Kevin Qualters 2024-07-03 17:16:58 -04:00 committed by GitHub
parent 7ae1f7a7df
commit 0ec428bf9c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 24 additions and 12 deletions

View file

@ -27,7 +27,7 @@ export const DeleteConfirmModal = React.memo(() => {
}, [dispatch]);
const onConfirm = useCallback(() => {
dispatch(deleteNotes({ ids: pendingDeleteIds }));
dispatch(deleteNotes({ ids: pendingDeleteIds, refetch: true }));
}, [dispatch, pendingDeleteIds]);
return (

View file

@ -28,14 +28,13 @@ export const NotesUtilityBar = React.memo(() => {
const dispatch = useDispatch();
const pagination = useSelector(selectNotesPagination);
const sort = useSelector(selectNotesTableSort);
const totalItems = pagination.total ?? 0;
const selectedItems = useSelector(selectNotesTableSelectedIds);
const resultsCount = useMemo(() => {
const { perPage, page } = pagination;
const { perPage, page, total } = pagination;
const startOfCurrentPage = perPage * (page - 1) + 1;
const endOfCurrentPage = Math.min(perPage * page, totalItems);
return perPage === 0 ? 'All' : `${startOfCurrentPage}-${endOfCurrentPage} of ${totalItems}`;
}, [pagination, totalItems]);
const endOfCurrentPage = Math.min(perPage * page, total);
return perPage === 0 ? 'All' : `${startOfCurrentPage}-${endOfCurrentPage} of ${total}`;
}, [pagination]);
const deleteSelectedNotes = useCallback(() => {
dispatch(userSelectedBulkDelete());
}, [dispatch]);

View file

@ -72,7 +72,6 @@ export const NoteManagementPage = () => {
const notes = useSelector(selectAllNotes);
const pagination = useSelector(selectNotesPagination);
const sort = useSelector(selectNotesTableSort);
const totalItems = pagination.total ?? 0;
const notesSearch = useSelector(selectNotesTableSearch);
const pendingDeleteIds = useSelector(selectNotesTablePendingDeleteIds);
const isDeleteModalVisible = pendingDeleteIds.length > 0;
@ -160,10 +159,10 @@ export const NoteManagementPage = () => {
return {
pageIndex: pagination.page - 1,
pageSize: pagination.perPage,
totalItemCount: totalItems,
totalItemCount: pagination.total,
pageSizeOptions,
};
}, [pagination, totalItems]);
}, [pagination]);
const selection = useMemo(() => {
return {

View file

@ -127,11 +127,25 @@ export const createNote = createAsyncThunk<NormalizedEntity<Note>, { note: BareN
}
);
export const deleteNotes = createAsyncThunk<string[], { ids: string[] }, {}>(
export const deleteNotes = createAsyncThunk<string[], { ids: string[]; refetch?: boolean }, {}>(
'notes/deleteNotes',
async (args) => {
const { ids } = args;
async (args, { dispatch, getState }) => {
const { ids, refetch } = args;
await deleteNotesApi(ids);
if (refetch) {
const state = getState() as State;
const { search, pagination, sort } = state.notes;
dispatch(
fetchNotes({
page: pagination.page,
perPage: pagination.perPage,
sortField: sort.field,
sortOrder: sort.direction,
filter: '',
search,
})
);
}
return ids;
}
);