Skip to content

Commit

Permalink
[Alerting] Reload the Alerts List when alerts are deleted (#73715)
Browse files Browse the repository at this point in the history
Reloads the entire Alerts list when alerts are deleted through the UI.
  • Loading branch information
gmmorris authored Aug 5, 2020
1 parent 47b9aba commit 41e3128
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ export const AlertsList: React.FunctionComponent = () => {
data: alertsResponse.data,
totalItemCount: alertsResponse.total,
});

if (!alertsResponse.data?.length && page.index > 0) {
setPage({ ...page, index: 0 });
}
} catch (e) {
toastNotifications.addDanger({
title: i18n.translate(
Expand Down Expand Up @@ -399,18 +403,9 @@ export const AlertsList: React.FunctionComponent = () => {
return (
<section data-test-subj="alertsList">
<DeleteModalConfirmation
onDeleted={(deleted: string[]) => {
if (selectedIds.length === 0 || selectedIds.length === deleted.length) {
const updatedAlerts = alertsState.data.filter(
(alert) => alert.id && !alertsToDelete.includes(alert.id)
);
setAlertsState({
isLoading: false,
data: updatedAlerts,
totalItemCount: alertsState.totalItemCount - deleted.length,
});
setSelectedIds([]);
}
onDeleted={async (deleted: string[]) => {
loadAlertsData();
setSelectedIds([]);
setAlertsToDelete([]);
}}
onErrors={async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

import uuid from 'uuid';
import { times } from 'lodash';
import expect from '@kbn/expect';
import { FtrProviderContext } from '../../ftr_provider_context';

Expand Down Expand Up @@ -361,11 +362,22 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
});

it('should delete all selection', async () => {
const createdAlert = await createAlert();
const namePrefix = generateUniqueKey();
let count = 0;
const createdAlertsFirstPage = await Promise.all(
times(10, () => createAlert({ name: `${namePrefix}-0${count++}` }))
);

const createdAlertsSecondPage = await Promise.all(
times(2, () => createAlert({ name: `${namePrefix}-1${count++}` }))
);

await pageObjects.common.navigateToApp('triggersActions');
await pageObjects.triggersActionsUI.searchAlerts(createdAlert.name);
await pageObjects.triggersActionsUI.searchAlerts(namePrefix);

await testSubjects.click(`checkboxSelectRow-${createdAlert.id}`);
for (const createdAlert of createdAlertsFirstPage) {
await testSubjects.click(`checkboxSelectRow-${createdAlert.id}`);
}

await testSubjects.click('bulkAction');

Expand All @@ -377,9 +389,11 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
await pageObjects.common.closeToast();

await pageObjects.common.navigateToApp('triggersActions');
await pageObjects.triggersActionsUI.searchAlerts(createdAlert.name);
await pageObjects.triggersActionsUI.searchAlerts(namePrefix);
const searchResultsAfterDelete = await pageObjects.triggersActionsUI.getAlertsList();
expect(searchResultsAfterDelete.length).to.eql(0);
expect(searchResultsAfterDelete).to.have.length(2);
expect(searchResultsAfterDelete[0].name).to.eql(createdAlertsSecondPage[0].name);
expect(searchResultsAfterDelete[1].name).to.eql(createdAlertsSecondPage[1].name);
});
});
};

0 comments on commit 41e3128

Please sign in to comment.