Skip to content

Commit 7ade6a9

Browse files
committed
Fixed routing for index lifecycle management
1 parent 02bd880 commit 7ade6a9

File tree

13 files changed

+60
-36
lines changed

13 files changed

+60
-36
lines changed

x-pack/plugins/index_lifecycle_management/public/application/app.tsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,32 @@
66

77
import React, { useEffect } from 'react';
88
import { Router, Switch, Route, Redirect } from 'react-router-dom';
9-
import { ScopedHistory } from 'kibana/public';
9+
import { ScopedHistory, ApplicationStart } from 'kibana/public';
1010
import { METRIC_TYPE } from '@kbn/analytics';
1111

1212
import { UIM_APP_LOAD } from './constants';
1313
import { EditPolicy } from './sections/edit_policy';
1414
import { PolicyTable } from './sections/policy_table';
1515
import { trackUiMetric } from './services/ui_metric';
1616

17-
export const App = ({ history }: { history: ScopedHistory }) => {
17+
export const App = ({
18+
history,
19+
navigateToApp,
20+
}: {
21+
history: ScopedHistory;
22+
navigateToApp: ApplicationStart['navigateToApp'];
23+
}) => {
1824
useEffect(() => trackUiMetric(METRIC_TYPE.LOADED, UIM_APP_LOAD), []);
1925

2026
return (
2127
<Router history={history}>
2228
<Switch>
23-
<Redirect exact from="" to="/policies" />
2429
<Redirect exact from="/" to="/policies" />
25-
<Route exact path={`/policies`} component={PolicyTable} />
30+
<Route
31+
exact
32+
path={`/policies`}
33+
render={(props) => <PolicyTable {...props} navigateToApp={navigateToApp} />}
34+
/>
2635
<Route path={`/policies/edit/:policyName?`} component={EditPolicy} />
2736
</Switch>
2837
</Router>

x-pack/plugins/index_lifecycle_management/public/application/index.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import React from 'react';
88
import { render, unmountComponentAtNode } from 'react-dom';
99
import { Provider } from 'react-redux';
10-
import { I18nStart, ScopedHistory } from 'kibana/public';
10+
import { I18nStart, ScopedHistory, ApplicationStart } from 'kibana/public';
1111
import { UnmountCallback } from 'src/core/public';
1212

1313
import { App } from './app';
@@ -16,12 +16,13 @@ import { indexLifecycleManagementStore } from './store';
1616
export const renderApp = (
1717
element: Element,
1818
I18nContext: I18nStart['Context'],
19-
history: ScopedHistory
19+
history: ScopedHistory,
20+
navigateToApp: ApplicationStart['navigateToApp']
2021
): UnmountCallback => {
2122
render(
2223
<I18nContext>
2324
<Provider store={indexLifecycleManagementStore()}>
24-
<App history={history} />
25+
<App history={history} navigateToApp={navigateToApp} />
2526
</Provider>
2627
</I18nContext>,
2728
element

x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/edit_policy.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ import {
3636
} from '../../constants';
3737

3838
import { toasts } from '../../services/notification';
39-
import { goToPolicyList } from '../../services/navigation';
4039
import { findFirstError } from '../../services/find_errors';
4140
import { LearnMoreLink } from '../components';
4241
import { NodeAttrsDetails } from './components/node_attrs_details';
@@ -100,7 +99,7 @@ export class EditPolicy extends Component {
10099

101100
backToPolicyList = () => {
102101
this.props.setSelectedPolicy(null);
103-
goToPolicyList();
102+
this.props.history.push('/policies');
104103
};
105104

106105
submit = async () => {

x-pack/plugins/index_lifecycle_management/public/application/sections/policy_table/components/policy_table/policy_table.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,8 @@ import {
3636
} from '@elastic/eui';
3737

3838
import { RIGHT_ALIGNMENT } from '@elastic/eui/lib/services';
39-
39+
import { reactRouterNavigate } from '../../../../../../../../../src/plugins/kibana_react/public';
4040
import { getIndexListUri } from '../../../../../../../index_management/public';
41-
import { BASE_PATH } from '../../../../../../common/constants';
4241
import { UIM_EDIT_CLICK } from '../../../../constants';
4342
import { getPolicyPath } from '../../../../services/navigation';
4443
import { flattenPanelTree } from '../../../../services/flatten_panel_tree';
@@ -181,8 +180,9 @@ export class PolicyTable extends Component {
181180
/* eslint-disable-next-line @elastic/eui/href-or-on-click */
182181
<EuiLink
183182
data-test-subj="policyTablePolicyNameLink"
184-
href={getPolicyPath(value)}
185-
onClick={() => trackUiMetric('click', UIM_EDIT_CLICK)}
183+
{...reactRouterNavigate(this.props.history, getPolicyPath(value), () =>
184+
trackUiMetric('click', UIM_EDIT_CLICK)
185+
)}
186186
>
187187
{value}
188188
</EuiLink>
@@ -201,7 +201,7 @@ export class PolicyTable extends Component {
201201
renderCreatePolicyButton() {
202202
return (
203203
<EuiButton
204-
href={`#${BASE_PATH}policies/edit`}
204+
{...reactRouterNavigate(this.props.history, '/policies/edit')}
205205
fill
206206
iconType="plusInCircle"
207207
data-test-subj="createPolicyButton"
@@ -253,7 +253,9 @@ export class PolicyTable extends Component {
253253
name: viewIndicesLabel,
254254
icon: 'list',
255255
onClick: () => {
256-
window.location.hash = getIndexListUri(`ilm.policy:${policy.name}`);
256+
this.props.navigateToApp('management', {
257+
path: `/data/index_management${getIndexListUri(`ilm.policy:${policy.name}`)}`,
258+
});
257259
},
258260
});
259261
}

x-pack/plugins/index_lifecycle_management/public/application/services/navigation.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,6 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
import { BASE_PATH } from '../../../common/constants';
8-
9-
export const goToPolicyList = () => {
10-
window.location.hash = `${BASE_PATH}policies`;
11-
};
12-
137
export const getPolicyPath = (policyName: string): string => {
14-
return encodeURI(`#${BASE_PATH}policies/edit/${encodeURIComponent(policyName)}`);
8+
return encodeURI(`/policies/edit/${encodeURIComponent(policyName)}`);
159
};

x-pack/plugins/index_lifecycle_management/public/extend_index_management/components/add_lifecycle_confirm_modal.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import {
2323
EuiModalHeaderTitle,
2424
} from '@elastic/eui';
2525

26-
import { BASE_PATH } from '../../../common/constants';
2726
import { loadPolicies, addLifecyclePolicyToIndex } from '../../application/services/api';
2827
import { showApiError } from '../../application/services/api_errors';
2928
import { toasts } from '../../application/services/notification';
@@ -216,7 +215,7 @@ export class AddLifecyclePolicyConfirmModal extends Component {
216215
}
217216
render() {
218217
const { policies } = this.state;
219-
const { indexName, closeModal } = this.props;
218+
const { indexName, closeModal, getUrlForApp } = this.props;
220219
const title = (
221220
<FormattedMessage
222221
id="xpack.indexLifecycleMgmt.indexManagementTable.addLifecyclePolicyConfirmModal.modalTitle"
@@ -246,7 +245,11 @@ export class AddLifecyclePolicyConfirmModal extends Component {
246245
color="warning"
247246
>
248247
<p>
249-
<EuiLink href={`#${BASE_PATH}policies/edit`}>
248+
<EuiLink
249+
href={getUrlForApp('management', {
250+
path: `data/index_lifecycle_management/policies/edit`,
251+
})}
252+
>
250253
<FormattedMessage
251254
id="xpack.indexLifecycleMgmt.indexManagementTable.addLifecyclePolicyConfirmModal.defineLifecyclePolicyLinkText"
252255
defaultMessage="Define lifecycle policy"

x-pack/plugins/index_lifecycle_management/public/extend_index_management/components/index_lifecycle_summary.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,15 @@ export class IndexLifecycleSummary extends Component {
163163
if (fieldName === 'action_time_millis') {
164164
content = moment(value).format('YYYY-MM-DD HH:mm:ss');
165165
} else if (fieldName === 'policy') {
166-
content = <EuiLink href={getPolicyPath(value)}>{value}</EuiLink>;
166+
content = (
167+
<EuiLink
168+
href={this.props.getUrlForApp('management', {
169+
path: `data/index_lifecycle_management/${getPolicyPath(value)}`,
170+
})}
171+
>
172+
{value}
173+
</EuiLink>
174+
);
167175
} else {
168176
content = value;
169177
}

x-pack/plugins/index_lifecycle_management/public/extend_index_management/index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export const removeLifecyclePolicyActionExtension = ({ indices, reloadIndices })
6767
};
6868
};
6969

70-
export const addLifecyclePolicyActionExtension = ({ indices, reloadIndices }) => {
70+
export const addLifecyclePolicyActionExtension = ({ indices, reloadIndices, getUrlForApp }) => {
7171
if (indices.length !== 1) {
7272
return null;
7373
}
@@ -86,6 +86,7 @@ export const addLifecyclePolicyActionExtension = ({ indices, reloadIndices }) =>
8686
closeModal={closeModal}
8787
index={index}
8888
reloadIndices={reloadIndices}
89+
getUrlForApp={getUrlForApp}
8990
/>
9091
);
9192
},
@@ -123,8 +124,8 @@ export const ilmBannerExtension = (indices) => {
123124
};
124125
};
125126

126-
export const ilmSummaryExtension = (index) => {
127-
return <IndexLifecycleSummary index={index} />;
127+
export const ilmSummaryExtension = (index, getUrlForApp) => {
128+
return <IndexLifecycleSummary index={index} getUrlForApp={getUrlForApp} />;
128129
};
129130

130131
export const ilmFilterExtension = (indices) => {

x-pack/plugins/index_lifecycle_management/public/plugin.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export class IndexLifecycleManagementPlugin {
4747
const {
4848
i18n: { Context: I18nContext },
4949
docLinks: { ELASTIC_WEBSITE_URL, DOC_LINK_VERSION },
50+
application: { navigateToApp },
5051
} = coreStart;
5152

5253
// Initialize additional services.
@@ -55,7 +56,7 @@ export class IndexLifecycleManagementPlugin {
5556
);
5657

5758
const { renderApp } = await import('./application');
58-
return renderApp(element, I18nContext, history);
59+
return renderApp(element, I18nContext, history, navigateToApp);
5960
},
6061
});
6162

x-pack/plugins/index_management/public/application/app_context.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const AppContext = createContext<AppDependencies | undefined>(undefined);
1818
export interface AppDependencies {
1919
core: {
2020
fatalErrors: CoreStart['fatalErrors'];
21+
getUrlForApp: CoreStart['application']['getUrlForApp'];
2122
};
2223
plugins: {
2324
usageCollection: UsageCollectionSetup;

0 commit comments

Comments
 (0)