Skip to content

Commit

Permalink
[7.x] [ILM] Add links to "Snapshot and Restore" from ILM "wait for sn…
Browse files Browse the repository at this point in the history
…apshot policy" (#72473) (#73788)

* [ILM] Add links to "Snapshot and Restore" from ILM "wait for snapshot policy" (#72473)

* [ILM] Add links to "Snapshot and Restore" from ILM "wait for snapshot policy"

* [ILM] Fix jest tests

* [ILM] Fix jest integration tests

* [ILM] Fix eslint error

Co-authored-by: Elastic Machine <[email protected]>

* [ILM] Fix internalization error

Co-authored-by: Elastic Machine <[email protected]>
  • Loading branch information
yuliacech and elasticmachine authored Jul 30, 2020
1 parent 86f6af7 commit 9ed500d
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ const testBedConfig: TestBedConfig = {
initialEntries: [`/policies/edit/${POLICY_NAME}`],
componentRoutePath: `/policies/edit/:policyName`,
},
defaultProps: {
getUrlForApp: () => {},
},
};

const initTestBed = registerTestBed(EditPolicy, testBedConfig);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ describe('edit policy', () => {
store = indexLifecycleManagementStore();
component = (
<Provider store={store}>
<EditPolicy />
<EditPolicy getUrlForApp={() => {}} />
</Provider>
);
store.dispatch(fetchedPolicies(policies));
Expand Down Expand Up @@ -155,7 +155,7 @@ describe('edit policy', () => {
test('should show error when trying to save as new policy but using the same name', () => {
component = (
<Provider store={store}>
<EditPolicy match={{ params: { policyName: 'testy0' } }} />
<EditPolicy match={{ params: { policyName: 'testy0' } }} getUrlForApp={() => {}} />
</Provider>
);
const rendered = mountWithIntl(component);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ import { trackUiMetric } from './services/ui_metric';
export const App = ({
history,
navigateToApp,
getUrlForApp,
}: {
history: ScopedHistory;
navigateToApp: ApplicationStart['navigateToApp'];
getUrlForApp: ApplicationStart['getUrlForApp'];
}) => {
useEffect(() => trackUiMetric(METRIC_TYPE.LOADED, UIM_APP_LOAD), []);

Expand All @@ -32,7 +34,10 @@ export const App = ({
path={`/policies`}
render={(props) => <PolicyTable {...props} navigateToApp={navigateToApp} />}
/>
<Route path={`/policies/edit/:policyName?`} component={EditPolicy} />
<Route
path={`/policies/edit/:policyName?`}
render={(props) => <EditPolicy {...props} getUrlForApp={getUrlForApp} />}
/>
</Switch>
</Router>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ export const renderApp = (
element: Element,
I18nContext: I18nStart['Context'],
history: ScopedHistory,
navigateToApp: ApplicationStart['navigateToApp']
navigateToApp: ApplicationStart['navigateToApp'],
getUrlForApp: ApplicationStart['getUrlForApp']
): UnmountCallback => {
render(
<I18nContext>
<Provider store={indexLifecycleManagementStore()}>
<App history={history} navigateToApp={navigateToApp} />
<App history={history} navigateToApp={navigateToApp} getUrlForApp={getUrlForApp} />
</Provider>
</I18nContext>,
element
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ export class DeletePhase extends PureComponent {
<SnapshotPolicies
value={phaseData[PHASE_WAIT_FOR_SNAPSHOT_POLICY]}
onChange={(value) => setPhaseData(PHASE_WAIT_FOR_SNAPSHOT_POLICY, value)}
getUrlForApp={this.props.getUrlForApp}
/>
</EuiFormRow>
</EuiDescribedFormGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ import React, { Fragment } from 'react';

import { FormattedMessage } from '@kbn/i18n/react';
import { i18n } from '@kbn/i18n';
import { ApplicationStart } from 'kibana/public';

import {
EuiButtonIcon,
EuiCallOut,
EuiComboBox,
EuiComboBoxOptionOption,
EuiLink,
EuiSpacer,
} from '@elastic/eui';

Expand All @@ -22,8 +24,13 @@ import { useLoadSnapshotPolicies } from '../../../../services/api';
interface Props {
value: string;
onChange: (value: string) => void;
getUrlForApp: ApplicationStart['getUrlForApp'];
}
export const SnapshotPolicies: React.FunctionComponent<Props> = ({ value, onChange }) => {
export const SnapshotPolicies: React.FunctionComponent<Props> = ({
value,
onChange,
getUrlForApp,
}) => {
const { error, isLoading, data, sendRequest } = useLoadSnapshotPolicies();

const policies = data.map((name: string) => ({
Expand All @@ -43,14 +50,19 @@ export const SnapshotPolicies: React.FunctionComponent<Props> = ({ value, onChan
onChange(newValue);
};

const getUrlForSnapshotPolicyWizard = () => {
return getUrlForApp('management', {
path: `data/snapshot_restore/add_policy`,
});
};

let calloutContent;
if (error) {
calloutContent = (
<Fragment>
<EuiSpacer size="m" />
<EuiCallOut
data-test-subj="policiesErrorCallout"
size="s"
iconType="help"
color="warning"
title={
Expand Down Expand Up @@ -99,7 +111,19 @@ export const SnapshotPolicies: React.FunctionComponent<Props> = ({ value, onChan
>
<FormattedMessage
id="xpack.indexLifecycleMgmt.editPolicy.deletePhase.noPoliciesCreatedMessage"
defaultMessage="Create a snapshot lifecycle policy to automate the creation and deletion of cluster snapshots."
defaultMessage="{link} to automate the creation and deletion of cluster snapshots."
values={{
link: (
<EuiLink href={getUrlForSnapshotPolicyWizard()} target="_blank">
{i18n.translate(
'xpack.indexLifecycleMgmt.editPolicy.deletePhase.noPoliciesCreatedLink',
{
defaultMessage: 'Create a snapshot lifecycle policy',
}
)}
</EuiLink>
),
}}
/>
</EuiCallOut>
</Fragment>
Expand All @@ -110,7 +134,6 @@ export const SnapshotPolicies: React.FunctionComponent<Props> = ({ value, onChan
<EuiSpacer size="m" />
<EuiCallOut
data-test-subj="customPolicyCallout"
size="s"
iconType="help"
color="warning"
title={
Expand All @@ -122,7 +145,19 @@ export const SnapshotPolicies: React.FunctionComponent<Props> = ({ value, onChan
>
<FormattedMessage
id="xpack.indexLifecycleMgmt.editPolicy.deletePhase.customPolicyMessage"
defaultMessage="Enter the name of an existing snapshot policy, or create a new policy with this name."
defaultMessage="Enter the name of an existing snapshot policy, or {link} with this name."
values={{
link: (
<EuiLink href={getUrlForSnapshotPolicyWizard()} target="_blank">
{i18n.translate(
'xpack.indexLifecycleMgmt.editPolicy.deletePhase.customPolicyLink',
{
defaultMessage: 'create a new policy',
}
)}
</EuiLink>
),
}}
/>
</EuiCallOut>
</Fragment>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ export class EditPolicy extends Component {
<DeletePhase
errors={errors[PHASE_DELETE]}
isShowingErrors={isShowingErrors && !!findFirstError(errors[PHASE_DELETE], false)}
getUrlForApp={this.props.getUrlForApp}
/>

<EuiHorizontalRule />
Expand Down
11 changes: 9 additions & 2 deletions x-pack/plugins/index_lifecycle_management/public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class IndexLifecycleManagementPlugin {
chrome: { docTitle },
i18n: { Context: I18nContext },
docLinks: { ELASTIC_WEBSITE_URL, DOC_LINK_VERSION },
application: { navigateToApp },
application: { navigateToApp, getUrlForApp },
} = coreStart;

docTitle.change(PLUGIN.TITLE);
Expand All @@ -58,7 +58,14 @@ export class IndexLifecycleManagementPlugin {
);

const { renderApp } = await import('./application');
const unmountAppCallback = renderApp(element, I18nContext, history, navigateToApp);

const unmountAppCallback = renderApp(
element,
I18nContext,
history,
navigateToApp,
getUrlForApp
);

return () => {
docTitle.reset();
Expand Down
2 changes: 0 additions & 2 deletions x-pack/plugins/translations/translations/ja-JP.json
Original file line number Diff line number Diff line change
Expand Up @@ -8181,11 +8181,9 @@
"xpack.indexLifecycleMgmt.editPolicy.creationNanoSecondsOptionLabel": "インデックスの作成からの経過時間(ナノ秒)",
"xpack.indexLifecycleMgmt.editPolicy.creationSecondsOptionLabel": "インデックスの作成からの経過時間(秒)",
"xpack.indexLifecycleMgmt.editPolicy.deletePhase.activateWarmPhaseSwitchLabel": "削除フェーズを有効にする",
"xpack.indexLifecycleMgmt.editPolicy.deletePhase.customPolicyMessage": "既存のスナップショットポリシーの名前を入力するか、この名前で新しいポリシーを作成します。",
"xpack.indexLifecycleMgmt.editPolicy.deletePhase.customPolicyTitle": "ポリシー名が見つかりません",
"xpack.indexLifecycleMgmt.editPolicy.deletePhase.deletePhaseDescriptionText": "今後インデックスは必要ありません。 いつ安全に削除できるかを定義できます。",
"xpack.indexLifecycleMgmt.editPolicy.deletePhase.deletePhaseLabel": "削除フェーズ",
"xpack.indexLifecycleMgmt.editPolicy.deletePhase.noPoliciesCreatedMessage": "スナップショットライフサイクルポリシーを作成して、クラスタースナップショットの作成と削除を自動化します。",
"xpack.indexLifecycleMgmt.editPolicy.deletePhase.noPoliciesCreatedTitle": "スナップショットポリシーが見つかりません",
"xpack.indexLifecycleMgmt.editPolicy.deletePhase.noPoliciesLoadedMessage": "このフィールドを更新し、既存のスナップショットポリシーの名前を入力します。",
"xpack.indexLifecycleMgmt.editPolicy.deletePhase.noPoliciesLoadedTitle": "既存のポリシーを読み込めません",
Expand Down
2 changes: 0 additions & 2 deletions x-pack/plugins/translations/translations/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -8183,11 +8183,9 @@
"xpack.indexLifecycleMgmt.editPolicy.creationNanoSecondsOptionLabel": "纳秒(自索引创建)",
"xpack.indexLifecycleMgmt.editPolicy.creationSecondsOptionLabel": "秒(自索引创建)",
"xpack.indexLifecycleMgmt.editPolicy.deletePhase.activateWarmPhaseSwitchLabel": "激活删除阶段",
"xpack.indexLifecycleMgmt.editPolicy.deletePhase.customPolicyMessage": "输入现有快照策略的名称或使用此名称创建新策略。",
"xpack.indexLifecycleMgmt.editPolicy.deletePhase.customPolicyTitle": "未找到策略名称",
"xpack.indexLifecycleMgmt.editPolicy.deletePhase.deletePhaseDescriptionText": "您不再需要自己的索引。 您可以定义安全删除它的时间。",
"xpack.indexLifecycleMgmt.editPolicy.deletePhase.deletePhaseLabel": "删除阶段",
"xpack.indexLifecycleMgmt.editPolicy.deletePhase.noPoliciesCreatedMessage": "创建快照生命周期策略,以自动集群快照的创建和删除。",
"xpack.indexLifecycleMgmt.editPolicy.deletePhase.noPoliciesCreatedTitle": "找不到快照策略",
"xpack.indexLifecycleMgmt.editPolicy.deletePhase.noPoliciesLoadedMessage": "刷新此字段并输入现有快照策略的名称。",
"xpack.indexLifecycleMgmt.editPolicy.deletePhase.noPoliciesLoadedTitle": "无法加载现有策略",
Expand Down

0 comments on commit 9ed500d

Please sign in to comment.