Skip to content

Commit

Permalink
Removed delete confirmation timeout to avoid flaky failing because de…
Browse files Browse the repository at this point in the history
…letion to be a little slower on CI (elastic#77963)

* Removed delete confirmation timeout to avoid flaky failing because deletion to be a little slower on CI

* Changed delete flow to close confim dialog immediately and set data to the loading state
  • Loading branch information
YulNaumenko committed Sep 23, 2020
1 parent cd56663 commit 6e44149
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/
import { EuiConfirmModal, EuiOverlayMask } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import React from 'react';
import React, { useEffect, useState } from 'react';
import { HttpSetup } from 'kibana/public';
import { useAppDependencies } from '../app_context';

Expand All @@ -17,6 +17,7 @@ export const DeleteModalConfirmation = ({
onErrors,
singleTitle,
multipleTitle,
setIsLoadingState,
}: {
idsToDelete: string[];
apiDeleteCall: ({
Expand All @@ -31,10 +32,17 @@ export const DeleteModalConfirmation = ({
onErrors: () => void;
singleTitle: string;
multipleTitle: string;
setIsLoadingState: (isLoading: boolean) => void;
}) => {
const [deleteModalFlyoutVisible, setDeleteModalVisibility] = useState<boolean>(false);

useEffect(() => {
setDeleteModalVisibility(idsToDelete.length > 0);
}, [idsToDelete]);

const { http, toastNotifications } = useAppDependencies();
const numIdsToDelete = idsToDelete.length;
if (!numIdsToDelete) {
if (!deleteModalFlyoutVisible) {
return null;
}
const confirmModalText = i18n.translate(
Expand Down Expand Up @@ -65,12 +73,18 @@ export const DeleteModalConfirmation = ({
buttonColor="danger"
data-test-subj="deleteIdsConfirmation"
title={confirmButtonText}
onCancel={() => onCancel()}
onCancel={() => {
setDeleteModalVisibility(false);
onCancel();
}}
onConfirm={async () => {
setDeleteModalVisibility(false);
setIsLoadingState(true);
const { successes, errors } = await apiDeleteCall({ ids: idsToDelete, http });
setIsLoadingState(false);

const numSuccesses = successes.length;
const numErrors = errors.length;
onDeleted(successes);
if (numSuccesses > 0) {
toastNotifications.addSuccess(
i18n.translate(
Expand All @@ -95,8 +109,9 @@ export const DeleteModalConfirmation = ({
}
)
);
onErrors();
await onErrors();
}
await onDeleted(successes);
}}
cancelButtonText={cancelButtonText}
confirmButtonText={confirmButtonText}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ export const ActionsConnectorsList: React.FunctionComponent = () => {
'xpack.triggersActionsUI.sections.actionsConnectorsList.multipleTitle',
{ defaultMessage: 'connectors' }
)}
setIsLoadingState={(isLoading: boolean) => setIsLoadingActionTypes(isLoading)}
/>
<EuiSpacer size="m" />
{/* Render the view based on if there's data or if they can save */}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,16 +404,16 @@ export const AlertsList: React.FunctionComponent = () => {
<section data-test-subj="alertsList">
<DeleteModalConfirmation
onDeleted={async (deleted: string[]) => {
loadAlertsData();
setSelectedIds([]);
setAlertsToDelete([]);
setSelectedIds([]);
await loadAlertsData();
}}
onErrors={async () => {
// Refresh the alerts from the server, some alerts may have beend deleted
await loadAlertsData();
setAlertsToDelete([]);
}}
onCancel={async () => {
onCancel={() => {
setAlertsToDelete([]);
}}
apiDeleteCall={deleteAlerts}
Expand All @@ -424,6 +424,9 @@ export const AlertsList: React.FunctionComponent = () => {
multipleTitle={i18n.translate('xpack.triggersActionsUI.sections.alertsList.multipleTitle', {
defaultMessage: 'alerts',
})}
setIsLoadingState={(isLoading: boolean) => {
setAlertsState({ ...alertsState, isLoading });
}}
/>
<EuiSpacer size="m" />
{loadedItems.length || isFilterApplied ? (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
return createdAlert;
}

// FLAKY: https://github.com/elastic/kibana/issues/77401
describe.skip('alerts', function () {
describe('alerts', function () {
before(async () => {
await pageObjects.common.navigateToApp('triggersActions');
await testSubjects.click('alertsTab');
Expand Down Expand Up @@ -382,9 +381,12 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
await testSubjects.click('deleteAll');
await testSubjects.existOrFail('deleteIdsConfirmation');
await testSubjects.click('deleteIdsConfirmation > confirmModalConfirmButton');
await testSubjects.missingOrFail('deleteIdsConfirmation', { timeout: 5000 });
await testSubjects.missingOrFail('deleteIdsConfirmation');

await pageObjects.common.closeToast();
await retry.try(async () => {
const toastTitle = await pageObjects.common.closeToast();
expect(toastTitle).to.eql('Deleted 10 alerts');
});

await pageObjects.common.navigateToApp('triggersActions');
await pageObjects.triggersActionsUI.searchAlerts(namePrefix);
Expand Down

0 comments on commit 6e44149

Please sign in to comment.