Skip to content

Commit

Permalink
add callout when restoring snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
alisonelizabeth committed Mar 22, 2021
1 parent ea8efd5 commit c616133
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 12 deletions.
1 change: 1 addition & 0 deletions src/core/public/doc_links/doc_links_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -23,11 +24,19 @@ const initTestBed = registerTestBed<RestoreSnapshotFormTestSubject>(
);

const setupActions = (testBed: TestBed<RestoreSnapshotFormTestSubject>) => {
const { find } = testBed;
const { find, component, form } = testBed;
return {
findDataStreamCallout() {
return find('dataStreamWarningCallOut');
},

toggleGlobalState() {
act(() => {
form.toggleEuiSwitch('includeGlobalStateSwitch');
});

component.update();
},
};
};

Expand All @@ -48,4 +57,6 @@ export const setup = async (): Promise<RestoreSnapshotTestBed> => {

export type RestoreSnapshotFormTestSubject =
| 'snapshotRestoreStepLogistics'
| 'includeGlobalStateSwitch'
| 'systemIndicesInfoCallOut'
| 'dataStreamWarningCallOut';
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -20,11 +21,15 @@ describe('<RestoreSnapshot />', () => {
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();
});

Expand All @@ -37,8 +42,10 @@ describe('<RestoreSnapshot />', () => {
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();
});

Expand All @@ -47,4 +54,25 @@ describe('<RestoreSnapshot />', () => {
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);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export const PolicyStepSettings: React.FunctionComponent<StepProps> = ({
description={
<FormattedMessage
id="xpack.snapshotRestore.policyForm.stepSettings.includeGlobalStateDescription"
defaultMessage="Stores the global cluster state as part of the snapshot."
defaultMessage="Stores the global cluster state and system indices as part of the snapshot."
/>
}
fullWidth
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<StepProps> = ({
snapshotDetails,
restoreSettings,
Expand All @@ -50,6 +53,7 @@ export const RestoreSnapshotStepLogistics: React.FunctionComponent<StepProps> =
indices: unfilteredSnapshotIndices,
dataStreams: snapshotDataStreams = [],
includeGlobalState: snapshotIncludeGlobalState,
version,
} = snapshotDetails;

const snapshotIndices = unfilteredSnapshotIndices.filter(
Expand Down Expand Up @@ -564,11 +568,23 @@ export const RestoreSnapshotStepLogistics: React.FunctionComponent<StepProps> =
</EuiTitle>
}
description={
<FormattedMessage
id="xpack.snapshotRestore.restoreForm.stepLogistics.includeGlobalStateDescription"
defaultMessage="Restores templates that don’t currently exist in the cluster and overrides
templates with the same name. Also restores persistent settings."
/>
<>
<FormattedMessage
id="xpack.snapshotRestore.restoreForm.stepLogistics.includeGlobalStateDescription"
defaultMessage="Restores templates that don’t currently exist in the cluster and overrides
templates with the same name. Also restores persistent settings and all system indices."
/>

{/* 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') && (
<>
<EuiSpacer size="xs" />
<SystemIndicesOverwrittenCallOut />
</>
)}
</>
}
fullWidth
>
Expand All @@ -594,6 +610,7 @@ export const RestoreSnapshotStepLogistics: React.FunctionComponent<StepProps> =
checked={includeGlobalState === undefined ? false : includeGlobalState}
onChange={(e) => updateRestoreSettings({ includeGlobalState: e.target.checked })}
disabled={!snapshotIncludeGlobalState}
data-test-subj="includeGlobalStateSwitch"
/>
</EuiFormRow>
</EuiDescribedFormGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -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 (
<EuiCallOut
data-test-subj="systemIndicesInfoCallOut"
title={i18n.translate(
'xpack.snapshotRestore.restoreForm.stepLogistics.systemIndicesCallOut.title',
{
defaultMessage: 'System indices will be overwritten',
}
)}
iconType="pin"
size="s"
>
<FormattedMessage
id="xpack.snapshotRestore.restoreForm.stepLogistics.systemIndicesDescription"
defaultMessage={`When this snapshot is restored, system indices will be overwritten with data from the snapshot. {learnMoreLink}`}
values={{
includeGlobalStateField: <EuiCode>include_global_state</EuiCode>,
booleanValue: <EuiCode>false</EuiCode>,
learnMoreLink: (
<EuiLink target="_blank" href={docLinks.links.snapshotRestore.restoreSnapshotApi}>
{i18n.translate(
'xpack.snapshotRestore.restoreForm.dataStreamsWarningCallOut.body.learnMoreLink',
{ defaultMessage: 'Learn more' }
)}
</EuiLink>
),
}}
/>
</EuiCallOut>
);
};

0 comments on commit c616133

Please sign in to comment.