From 43e3d558fd6d7e50949f6bde95591114d1d182db Mon Sep 17 00:00:00 2001 From: Alison Goryachev Date: Thu, 25 Mar 2021 14:41:58 -0400 Subject: [PATCH] [Snapshot + Restore] Add callout when restoring snapshot (#95104) --- .../public/doc_links/doc_links_service.ts | 1 + .../helpers/restore_snapshot.helpers.ts | 13 ++++++- .../restore_snapshot.test.ts | 38 ++++++++++++++++--- .../steps/step_settings/step_settings.tsx | 2 +- .../restore_snapshot_form.tsx | 3 +- .../steps/step_logistics/step_logistics.tsx | 38 ++++++++++++++++--- .../system_indices_overwritten_callout.tsx | 29 ++++++++++++++ .../translations/translations/ja-JP.json | 1 - .../translations/translations/zh-CN.json | 1 - 9 files changed, 111 insertions(+), 15 deletions(-) create mode 100644 x-pack/plugins/snapshot_restore/public/application/components/restore_snapshot_form/steps/step_logistics/system_indices_overwritten_callout.tsx diff --git a/src/core/public/doc_links/doc_links_service.ts b/src/core/public/doc_links/doc_links_service.ts index 6279d62d2c40..9711d546fc94 100644 --- a/src/core/public/doc_links/doc_links_service.ts +++ b/src/core/public/doc_links/doc_links_service.ts @@ -284,6 +284,7 @@ export class DocLinksService { registerSourceOnly: `${ELASTICSEARCH_DOCS}snapshots-register-repository.html#snapshots-source-only-repository`, registerUrl: `${ELASTICSEARCH_DOCS}snapshots-register-repository.html#snapshots-read-only-repository`, restoreSnapshot: `${ELASTICSEARCH_DOCS}snapshots-restore-snapshot.html`, + restoreSnapshotApi: `${ELASTICSEARCH_DOCS}restore-snapshot-api.html#restore-snapshot-api-request-body`, }, ingest: { pipelines: `${ELASTICSEARCH_DOCS}ingest.html`, diff --git a/x-pack/plugins/snapshot_restore/__jest__/client_integration/helpers/restore_snapshot.helpers.ts b/x-pack/plugins/snapshot_restore/__jest__/client_integration/helpers/restore_snapshot.helpers.ts index 644ad6ea3089..c0ffae81a425 100644 --- a/x-pack/plugins/snapshot_restore/__jest__/client_integration/helpers/restore_snapshot.helpers.ts +++ b/x-pack/plugins/snapshot_restore/__jest__/client_integration/helpers/restore_snapshot.helpers.ts @@ -4,6 +4,7 @@ * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ +import { act } from 'react-dom/test-utils'; import { registerTestBed, TestBed, TestBedConfig } from '@kbn/test/jest'; import { RestoreSnapshot } from '../../../public/application/sections/restore_snapshot'; @@ -23,11 +24,19 @@ const initTestBed = registerTestBed( ); const setupActions = (testBed: TestBed) => { - const { find } = testBed; + const { find, component, form } = testBed; return { findDataStreamCallout() { return find('dataStreamWarningCallOut'); }, + + toggleGlobalState() { + act(() => { + form.toggleEuiSwitch('includeGlobalStateSwitch'); + }); + + component.update(); + }, }; }; @@ -48,4 +57,6 @@ export const setup = async (): Promise => { export type RestoreSnapshotFormTestSubject = | 'snapshotRestoreStepLogistics' + | 'includeGlobalStateSwitch' + | 'systemIndicesInfoCallOut' | 'dataStreamWarningCallOut'; diff --git a/x-pack/plugins/snapshot_restore/__jest__/client_integration/restore_snapshot.test.ts b/x-pack/plugins/snapshot_restore/__jest__/client_integration/restore_snapshot.test.ts index 36cd178060f8..2fecce36f09d 100644 --- a/x-pack/plugins/snapshot_restore/__jest__/client_integration/restore_snapshot.test.ts +++ b/x-pack/plugins/snapshot_restore/__jest__/client_integration/restore_snapshot.test.ts @@ -4,8 +4,9 @@ * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ +import { act } from 'react-dom/test-utils'; -import { nextTick, pageHelpers, setupEnvironment } from './helpers'; +import { pageHelpers, setupEnvironment } from './helpers'; import { RestoreSnapshotTestBed } from './helpers/restore_snapshot.helpers'; import * as fixtures from '../../test/fixtures'; @@ -20,11 +21,15 @@ describe('', () => { afterAll(() => { server.restore(); }); + describe('with data streams', () => { beforeEach(async () => { httpRequestsMockHelpers.setGetSnapshotResponse(fixtures.getSnapshot()); - testBed = await setup(); - await nextTick(); + + await act(async () => { + testBed = await setup(); + }); + testBed.component.update(); }); @@ -37,8 +42,10 @@ describe('', () => { describe('without data streams', () => { beforeEach(async () => { httpRequestsMockHelpers.setGetSnapshotResponse(fixtures.getSnapshot({ totalDataStreams: 0 })); - testBed = await setup(); - await nextTick(); + await act(async () => { + testBed = await setup(); + }); + testBed.component.update(); }); @@ -47,4 +54,25 @@ describe('', () => { expect(exists('dataStreamWarningCallOut')).toBe(false); }); }); + + describe('global state', () => { + beforeEach(async () => { + httpRequestsMockHelpers.setGetSnapshotResponse(fixtures.getSnapshot()); + await act(async () => { + testBed = await setup(); + }); + + testBed.component.update(); + }); + + it('shows an info callout when include_global_state is enabled', () => { + const { exists, actions } = testBed; + + expect(exists('systemIndicesInfoCallOut')).toBe(false); + + actions.toggleGlobalState(); + + expect(exists('systemIndicesInfoCallOut')).toBe(true); + }); + }); }); diff --git a/x-pack/plugins/snapshot_restore/public/application/components/policy_form/steps/step_settings/step_settings.tsx b/x-pack/plugins/snapshot_restore/public/application/components/policy_form/steps/step_settings/step_settings.tsx index dcaad024eb0f..fc230affc980 100644 --- a/x-pack/plugins/snapshot_restore/public/application/components/policy_form/steps/step_settings/step_settings.tsx +++ b/x-pack/plugins/snapshot_restore/public/application/components/policy_form/steps/step_settings/step_settings.tsx @@ -142,7 +142,7 @@ export const PolicyStepSettings: React.FunctionComponent = ({ description={ } fullWidth diff --git a/x-pack/plugins/snapshot_restore/public/application/components/restore_snapshot_form/restore_snapshot_form.tsx b/x-pack/plugins/snapshot_restore/public/application/components/restore_snapshot_form/restore_snapshot_form.tsx index 4a281b270210..f672300db882 100644 --- a/x-pack/plugins/snapshot_restore/public/application/components/restore_snapshot_form/restore_snapshot_form.tsx +++ b/x-pack/plugins/snapshot_restore/public/application/components/restore_snapshot_form/restore_snapshot_form.tsx @@ -112,7 +112,8 @@ export const RestoreSnapshotForm: React.FunctionComponent = ({ errors={validation.errors} updateCurrentStep={updateCurrentStep} /> - + + {saveError ? ( diff --git a/x-pack/plugins/snapshot_restore/public/application/components/restore_snapshot_form/steps/step_logistics/step_logistics.tsx b/x-pack/plugins/snapshot_restore/public/application/components/restore_snapshot_form/steps/step_logistics/step_logistics.tsx index bb66585579d7..de30eadad454 100644 --- a/x-pack/plugins/snapshot_restore/public/application/components/restore_snapshot_form/steps/step_logistics/step_logistics.tsx +++ b/x-pack/plugins/snapshot_restore/public/application/components/restore_snapshot_form/steps/step_logistics/step_logistics.tsx @@ -7,6 +7,7 @@ import React, { Fragment, useState } from 'react'; import { FormattedMessage } from '@kbn/i18n/react'; +import semverGt from 'semver/functions/gt'; import { EuiButtonEmpty, EuiDescribedFormGroup, @@ -38,6 +39,8 @@ import { DataStreamsGlobalStateCallOut } from './data_streams_global_state_call_ import { DataStreamsAndIndicesListHelpText } from './data_streams_and_indices_list_help_text'; +import { SystemIndicesOverwrittenCallOut } from './system_indices_overwritten_callout'; + export const RestoreSnapshotStepLogistics: React.FunctionComponent = ({ snapshotDetails, restoreSettings, @@ -50,6 +53,7 @@ export const RestoreSnapshotStepLogistics: React.FunctionComponent = indices: unfilteredSnapshotIndices, dataStreams: snapshotDataStreams = [], includeGlobalState: snapshotIncludeGlobalState, + version, } = snapshotDetails; const snapshotIndices = unfilteredSnapshotIndices.filter( @@ -564,11 +568,34 @@ export const RestoreSnapshotStepLogistics: React.FunctionComponent = } description={ - + <> + + {i18n.translate( + 'xpack.snapshotRestore.restoreForm.stepLogistics.includeGlobalStateDocLink', + { defaultMessage: 'Learn more.' } + )} + + ), + }} + /> + + {/* Only display callout if include_global_state is enabled and the snapshot was created by ES 7.12+ + * Note: Once we support features states in the UI, we will also need to add a check here for that + * See https://github.com/elastic/kibana/issues/95128 more details + */} + {includeGlobalState && semverGt(version, '7.12.0') && ( + <> + + + + )} + } fullWidth > @@ -594,6 +621,7 @@ export const RestoreSnapshotStepLogistics: React.FunctionComponent = checked={includeGlobalState === undefined ? false : includeGlobalState} onChange={(e) => updateRestoreSettings({ includeGlobalState: e.target.checked })} disabled={!snapshotIncludeGlobalState} + data-test-subj="includeGlobalStateSwitch" /> diff --git a/x-pack/plugins/snapshot_restore/public/application/components/restore_snapshot_form/steps/step_logistics/system_indices_overwritten_callout.tsx b/x-pack/plugins/snapshot_restore/public/application/components/restore_snapshot_form/steps/step_logistics/system_indices_overwritten_callout.tsx new file mode 100644 index 000000000000..fac21de0bce2 --- /dev/null +++ b/x-pack/plugins/snapshot_restore/public/application/components/restore_snapshot_form/steps/step_logistics/system_indices_overwritten_callout.tsx @@ -0,0 +1,29 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { i18n } from '@kbn/i18n'; +import React, { FunctionComponent } from 'react'; +import { EuiCallOut } from '@elastic/eui'; + +export const SystemIndicesOverwrittenCallOut: FunctionComponent = () => { + return ( + + ); +}; diff --git a/x-pack/plugins/translations/translations/ja-JP.json b/x-pack/plugins/translations/translations/ja-JP.json index 290ad19718ef..5a6e9a6164cd 100644 --- a/x-pack/plugins/translations/translations/ja-JP.json +++ b/x-pack/plugins/translations/translations/ja-JP.json @@ -21323,7 +21323,6 @@ "xpack.snapshotRestore.restoreForm.stepLogistics.dataStreamsAndIndicesToggleListLink": "データストリームとインデックスを選択", "xpack.snapshotRestore.restoreForm.stepLogistics.deselectAllIndicesLink": "すべて選択解除", "xpack.snapshotRestore.restoreForm.stepLogistics.docsButtonLabel": "スナップショットと復元ドキュメント", - "xpack.snapshotRestore.restoreForm.stepLogistics.includeGlobalStateDescription": "現在クラスターに存在しないテンプレートを復元し、テンプレートを同じ名前で上書きします。永続的な設定も復元します。", "xpack.snapshotRestore.restoreForm.stepLogistics.includeGlobalStateDisabledDescription": "このスナップショットでは使用できません。", "xpack.snapshotRestore.restoreForm.stepLogistics.includeGlobalStateLabel": "グローバル状態の復元", "xpack.snapshotRestore.restoreForm.stepLogistics.includeGlobalStateTitle": "グローバル状態の復元", diff --git a/x-pack/plugins/translations/translations/zh-CN.json b/x-pack/plugins/translations/translations/zh-CN.json index c982931f91e1..dce5c3ad85d5 100644 --- a/x-pack/plugins/translations/translations/zh-CN.json +++ b/x-pack/plugins/translations/translations/zh-CN.json @@ -21661,7 +21661,6 @@ "xpack.snapshotRestore.restoreForm.stepLogistics.dataStreamsAndIndicesToggleListLink": "选择数据流和索引", "xpack.snapshotRestore.restoreForm.stepLogistics.deselectAllIndicesLink": "取消全选", "xpack.snapshotRestore.restoreForm.stepLogistics.docsButtonLabel": "快照和还原文档", - "xpack.snapshotRestore.restoreForm.stepLogistics.includeGlobalStateDescription": "还原当前在集群中不存在的模板并覆盖同名模板。同时还原永久性设置。", "xpack.snapshotRestore.restoreForm.stepLogistics.includeGlobalStateDisabledDescription": "不适用于此快照。", "xpack.snapshotRestore.restoreForm.stepLogistics.includeGlobalStateLabel": "还原全局状态", "xpack.snapshotRestore.restoreForm.stepLogistics.includeGlobalStateTitle": "还原全局状态",