Skip to content

Commit a9ffd47

Browse files
[SR] add ability to execute snapshot retention manually (#47150) (#47619)
1 parent da61b42 commit a9ffd47

File tree

9 files changed

+338
-104
lines changed

9 files changed

+338
-104
lines changed

x-pack/legacy/plugins/snapshot_restore/public/app/components/index.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ export { RestoreSnapshotForm } from './restore_snapshot_form';
1717
export { PolicyExecuteProvider } from './policy_execute_provider';
1818
export { PolicyDeleteProvider } from './policy_delete_provider';
1919
export {
20-
UpdateRetentionModalProvider,
21-
UpdateRetentionSetting,
22-
} from './update_retention_modal_provider';
20+
RetentionSettingsUpdateModalProvider,
21+
UpdateRetentionSettings,
22+
} from './retention_update_modal_provider';
23+
export {
24+
RetentionExecuteModalProvider,
25+
ExecuteRetention,
26+
} from './retention_execute_modal_provider';
2327
export { PolicyForm } from './policy_form';
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import React, { useState } from 'react';
8+
import { EuiConfirmModal, EuiOverlayMask } from '@elastic/eui';
9+
import { useAppDependencies } from '../index';
10+
import { executeRetention as executeRetentionRequest } from '../services/http';
11+
12+
interface Props {
13+
children: (executeRetention: ExecuteRetention) => React.ReactElement;
14+
}
15+
16+
export type ExecuteRetention = () => void;
17+
18+
export const RetentionExecuteModalProvider: React.FunctionComponent<Props> = ({ children }) => {
19+
const {
20+
core: {
21+
i18n,
22+
notification: { toastNotifications },
23+
},
24+
} = useAppDependencies();
25+
const { FormattedMessage } = i18n;
26+
const [isModalOpen, setIsModalOpen] = useState<boolean>(false);
27+
28+
const executeRetentionPrompt: ExecuteRetention = () => {
29+
setIsModalOpen(true);
30+
};
31+
32+
const closeModal = () => {
33+
setIsModalOpen(false);
34+
};
35+
36+
const executeRetention = () => {
37+
executeRetentionRequest().then(({ error }) => {
38+
if (error) {
39+
const errorMessage = i18n.translate('xpack.snapshotRestore.executeRetention.errorMessage', {
40+
defaultMessage: 'Error running retention',
41+
});
42+
toastNotifications.addDanger(errorMessage);
43+
} else {
44+
const successMessage = i18n.translate(
45+
'xpack.snapshotRestore.executeRetention.successMessage',
46+
{
47+
defaultMessage: 'Retention is running',
48+
}
49+
);
50+
toastNotifications.addSuccess(successMessage);
51+
}
52+
});
53+
closeModal();
54+
};
55+
56+
const renderModal = () => {
57+
if (!isModalOpen) {
58+
return null;
59+
}
60+
61+
return (
62+
<EuiOverlayMask>
63+
<EuiConfirmModal
64+
title={
65+
<FormattedMessage
66+
id="xpack.snapshotRestore.executeRetention.confirmModal.executeRetentionTitle"
67+
defaultMessage="Run snapshot retention now?"
68+
/>
69+
}
70+
onCancel={closeModal}
71+
onConfirm={executeRetention}
72+
cancelButtonText={
73+
<FormattedMessage
74+
id="xpack.snapshotRestore.executeRetention.confirmModal.cancelButtonLabel"
75+
defaultMessage="Cancel"
76+
/>
77+
}
78+
confirmButtonText={
79+
<FormattedMessage
80+
id="xpack.snapshotRestore.executeRetention.confirmModal.confirmButtonLabel"
81+
defaultMessage="Run retention"
82+
/>
83+
}
84+
data-test-subj="executeRetentionModal"
85+
/>
86+
</EuiOverlayMask>
87+
);
88+
};
89+
90+
return (
91+
<>
92+
{children(executeRetentionPrompt)}
93+
{renderModal()}
94+
</>
95+
);
96+
};
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,19 @@ import { DEFAULT_RETENTION_SCHEDULE, DEFAULT_RETENTION_FREQUENCY } from '../cons
2828
import { updateRetentionSchedule } from '../services/http';
2929

3030
interface Props {
31-
children: (updateRetention: UpdateRetentionSetting) => React.ReactElement;
31+
children: (updateRetention: UpdateRetentionSettings) => React.ReactElement;
3232
}
3333

34-
export type UpdateRetentionSetting = (
34+
export type UpdateRetentionSettings = (
3535
retentionSchedule?: string,
3636
onSuccess?: OnSuccessCallback
3737
) => void;
3838

3939
type OnSuccessCallback = () => void;
4040

41-
export const UpdateRetentionModalProvider: React.FunctionComponent<Props> = ({ children }) => {
41+
export const RetentionSettingsUpdateModalProvider: React.FunctionComponent<Props> = ({
42+
children,
43+
}) => {
4244
const {
4345
core: {
4446
i18n,
@@ -68,7 +70,7 @@ export const UpdateRetentionModalProvider: React.FunctionComponent<Props> = ({ c
6870

6971
const [isInvalid, setIsInvalid] = useState<boolean>(false);
7072

71-
const updateRetentionPrompt: UpdateRetentionSetting = (
73+
const updateRetentionPrompt: UpdateRetentionSettings = (
7274
originalRetentionSchedule,
7375
onSuccess = () => undefined
7476
) => {

x-pack/legacy/plugins/snapshot_restore/public/app/constants/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,4 +122,5 @@ export const UIM_POLICY_DELETE = 'policy_delete';
122122
export const UIM_POLICY_DELETE_MANY = 'policy_delete_many';
123123
export const UIM_POLICY_CREATE = 'policy_create';
124124
export const UIM_POLICY_UPDATE = 'policy_update';
125-
export const UIM_POLICY_RETENTION_SETTINGS_UPDATE = 'policy_retention_settings_update';
125+
export const UIM_RETENTION_SETTINGS_UPDATE = 'retention_settings_update';
126+
export const UIM_RETENTION_EXECUTE = 'retention_execute';

0 commit comments

Comments
 (0)