Skip to content

Commit

Permalink
[8.x] [Upgrade Assistant] Add confirmation modal before migrating sys…
Browse files Browse the repository at this point in the history
…tem indices (#200117) (#203085)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[Upgrade Assistant] Add confirmation modal before migrating system
indices (#200117)](#200117)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT
[{"author":{"name":"youhonglian","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-12-05T11:54:34Z","message":"[Upgrade
Assistant] Add confirmation modal before migrating system indices
(#200117)","sha":"bd576e6cef57001692eb79c2befab09ac076714d","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Team:Kibana
Management","release_note:skip","Feature:Upgrade
Assistant","💝community","v9.0.0","backport:prev-minor"],"title":"[Upgrade
Assistant] Add confirmation modal before migrating system
indices","number":200117,"url":"https://github.com/elastic/kibana/pull/200117","mergeCommit":{"message":"[Upgrade
Assistant] Add confirmation modal before migrating system indices
(#200117)","sha":"bd576e6cef57001692eb79c2befab09ac076714d"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/200117","number":200117,"mergeCommit":{"message":"[Upgrade
Assistant] Add confirmation modal before migrating system indices
(#200117)","sha":"bd576e6cef57001692eb79c2befab09ac076714d"}}]}]
BACKPORT-->

Co-authored-by: youhonglian <[email protected]>
  • Loading branch information
kibanamachine and youhonglian authored Dec 5, 2024
1 parent a21b744 commit e48a7e8
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,38 @@ describe('Overview - Migrate system indices', () => {
expect(exists('viewSystemIndicesStateButton')).toBe(true);
});

test('handles confirmModal submission', async () => {
httpRequestsMockHelpers.setLoadSystemIndicesMigrationStatus({
migration_status: 'MIGRATION_NEEDED',
});

testBed = await setupOverviewPage(httpSetup);

const { exists, component, find } = testBed;

component.update();

expect(exists('startSystemIndicesMigrationButton')).toBe(true);
await act(async () => {
find('startSystemIndicesMigrationButton').simulate('click');
});
component.update();

expect(exists('migrationConfirmModal')).toBe(true);

const modal = document.body.querySelector('[data-test-subj="migrationConfirmModal"]');
const confirmButton: HTMLButtonElement | null = modal!.querySelector(
'[data-test-subj="confirmModalConfirmButton"]'
);

await act(async () => {
confirmButton!.click();
});
component.update();

expect(exists('migrationConfirmModal')).toBe(false);
});

test('Handles errors when migrating', async () => {
httpRequestsMockHelpers.setLoadSystemIndicesMigrationStatus({
migration_status: 'MIGRATION_NEEDED',
Expand All @@ -126,6 +158,16 @@ describe('Overview - Migrate system indices', () => {

component.update();

const modal = document.body.querySelector('[data-test-subj="migrationConfirmModal"]');
const confirmButton: HTMLButtonElement | null = modal!.querySelector(
'[data-test-subj="confirmModalConfirmButton"]'
);

await act(async () => {
confirmButton!.click();
});
component.update();

// Error is displayed
expect(exists('startSystemIndicesMigrationCalloutError')).toBe(true);
// CTA is enabled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import React, { FunctionComponent, useEffect } from 'react';
import React, { FunctionComponent, useEffect, useState } from 'react';

import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n-react';
Expand All @@ -20,6 +20,7 @@ import {
EuiFlexItem,
EuiCode,
EuiLink,
EuiConfirmModal,
} from '@elastic/eui';
import type { EuiStepProps } from '@elastic/eui/src/components/steps/step';

Expand Down Expand Up @@ -123,10 +124,55 @@ const i18nTexts = {
},
};

const ConfirmModal: React.FC<{
onCancel: () => void;
onConfirm: () => void;
}> = ({ onCancel, onConfirm }) => (
<EuiConfirmModal
title={i18n.translate('xpack.upgradeAssistant.overview.systemIndices.confirmModal.title', {
defaultMessage: 'Migrate Indices',
})}
onCancel={onCancel}
onConfirm={onConfirm}
cancelButtonText={i18n.translate(
'xpack.upgradeAssistant.overview.systemIndices.confirmModal.cancelButton.label',
{
defaultMessage: 'Cancel',
}
)}
confirmButtonText={i18n.translate(
'xpack.upgradeAssistant.overview.systemIndices.confirmModal.confirmButton.label',
{
defaultMessage: 'Confirm',
}
)}
defaultFocusedButton="confirm"
data-test-subj="migrationConfirmModal"
>
{i18n.translate('xpack.upgradeAssistant.overview.systemIndices.confirmModal.description', {
defaultMessage: 'Migrating system indices may lead to downtime while they are reindexed.',
})}
</EuiConfirmModal>
);

const MigrateSystemIndicesStep: FunctionComponent<Props> = ({ setIsComplete }) => {
const { beginSystemIndicesMigration, startMigrationStatus, migrationStatus, setShowFlyout } =
useMigrateSystemIndices();

const [isModalVisible, setIsModalVisible] = useState(false);

const openMigrationModal = () => {
setIsModalVisible(true);
};
const onCancel = () => {
setIsModalVisible(false);
};

const confirmMigrationAction = () => {
beginSystemIndicesMigration();
setIsModalVisible(false);
};

useEffect(() => {
setIsComplete(migrationStatus.data?.migration_status === 'NO_MIGRATION_NEEDED');
// Depending upon setIsComplete would create an infinite loop.
Expand Down Expand Up @@ -206,12 +252,14 @@ const MigrateSystemIndicesStep: FunctionComponent<Props> = ({ setIsComplete }) =
</>
)}

{isModalVisible && <ConfirmModal onCancel={onCancel} onConfirm={confirmMigrationAction} />}

<EuiFlexGroup alignItems="center" gutterSize="s">
<EuiFlexItem grow={false}>
<EuiButton
isLoading={isMigrating}
isDisabled={isButtonDisabled}
onClick={beginSystemIndicesMigration}
onClick={openMigrationModal}
data-test-subj="startSystemIndicesMigrationButton"
>
{isMigrating ? i18nTexts.inProgressButtonLabel : i18nTexts.startButtonLabel}
Expand Down

0 comments on commit e48a7e8

Please sign in to comment.