From c616133ae2ecb86017e36fec3c597f702143bb1b Mon Sep 17 00:00:00 2001 From: Alison Goryachev Date: Mon, 22 Mar 2021 15:54:11 -0400 Subject: [PATCH] add callout when restoring snapshot --- .../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 +- .../steps/step_logistics/step_logistics.tsx | 27 +++++++++-- .../system_indices_overwritten_callout.tsx | 48 +++++++++++++++++++ 6 files changed, 117 insertions(+), 12 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 e187b7ea581bf..6ecf9c67875f3 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 644ad6ea3089b..c0ffae81a4258 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 36cd178060f83..2fecce36f09df 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 dcaad024eb0f7..fc230affc980b 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/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 bb66585579d7d..99e4150579397 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,23 @@ export const RestoreSnapshotStepLogistics: React.FunctionComponent = } description={ - + <> + + + {/* Only display callout if include global state is enabled and the snapshot was created by ES 7.12.0+ + * Note: Once we support features states in the UI, we will also need to add a check here for that + */} + {includeGlobalState && semverGt(version, '7.12.0') && ( + <> + + + + )} + } fullWidth > @@ -594,6 +610,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 0000000000000..237d5fe42f85d --- /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,48 @@ +/* + * 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 { FormattedMessage } from '@kbn/i18n/react'; +import React, { FunctionComponent } from 'react'; +import { EuiCallOut, EuiCode, EuiLink } from '@elastic/eui'; + +import { useCore } from '../../../../app_context'; + +export const SystemIndicesOverwrittenCallOut: FunctionComponent = () => { + const { docLinks } = useCore(); + + return ( + + include_global_state, + booleanValue: false, + learnMoreLink: ( + + {i18n.translate( + 'xpack.snapshotRestore.restoreForm.dataStreamsWarningCallOut.body.learnMoreLink', + { defaultMessage: 'Learn more' } + )} + + ), + }} + /> + + ); +};