Skip to content

Commit b73abcd

Browse files
Add ILM url generator and use it in Index Management (#82165) (#82837)
* Add ILM url generator and use in IM for cross linking to policy edit page * Fix policy name in the link * Add review suggestions * Fix import * Fix eslint error Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
1 parent d51e117 commit b73abcd

27 files changed

Lines changed: 362 additions & 84 deletions

File tree

x-pack/plugins/index_lifecycle_management/kibana.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"requiredPlugins": [
77
"licensing",
88
"management",
9-
"features"
9+
"features",
10+
"share"
1011
],
1112
"optionalPlugins": [
1213
"cloud",

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { UIM_APP_LOAD } from './constants/ui_metric';
1313
import { EditPolicy } from './sections/edit_policy';
1414
import { PolicyTable } from './sections/policy_table';
1515
import { trackUiMetric } from './services/ui_metric';
16+
import { ROUTES } from './services/navigation';
1617

1718
export const App = ({
1819
history,
@@ -28,14 +29,14 @@ export const App = ({
2829
return (
2930
<Router history={history}>
3031
<Switch>
31-
<Redirect exact from="/" to="/policies" />
32+
<Redirect exact from="/" to={ROUTES.list} />
3233
<Route
3334
exact
34-
path={`/policies`}
35+
path={ROUTES.list}
3536
render={(props) => <PolicyTable {...props} navigateToApp={navigateToApp} />}
3637
/>
3738
<Route
38-
path={`/policies/edit/:policyName?`}
39+
path={ROUTES.edit}
3940
render={(props) => <EditPolicy {...props} getUrlForApp={getUrlForApp} />}
4041
/>
4142
</Switch>

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import { RouteComponentProps } from 'react-router-dom';
3535
import { reactRouterNavigate } from '../../../../../../../../src/plugins/kibana_react/public';
3636
import { getIndexListUri } from '../../../../../../index_management/public';
3737
import { PolicyFromES } from '../../../../../common/types';
38-
import { getPolicyPath } from '../../../services/navigation';
38+
import { getPolicyEditPath } from '../../../services/navigation';
3939
import { sortTable } from '../../../services';
4040
import { trackUiMetric } from '../../../services/ui_metric';
4141

@@ -229,7 +229,7 @@ export const TableContent: React.FunctionComponent<Props> = ({
229229
return (
230230
<EuiLink
231231
data-test-subj="policyTablePolicyNameLink"
232-
{...reactRouterNavigate(history, getPolicyPath(value as string), () =>
232+
{...reactRouterNavigate(history, getPolicyEditPath(value as string), () =>
233233
trackUiMetric(METRIC_TYPE.CLICK, UIM_EDIT_CLICK)
234234
)}
235235
>

x-pack/plugins/index_lifecycle_management/public/application/sections/policy_table/policy_table.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import { reactRouterNavigate } from '../../../../../../../src/plugins/kibana_rea
2626
import { PolicyFromES } from '../../../../common/types';
2727
import { filterItems } from '../../services';
2828
import { TableContent } from './components/table_content';
29+
import { getPolicyCreatePath } from '../../services/navigation';
2930

3031
interface Props {
3132
policies: PolicyFromES[];
@@ -45,7 +46,7 @@ export const PolicyTable: React.FunctionComponent<Props> = ({
4546

4647
const createPolicyButton = (
4748
<EuiButton
48-
{...reactRouterNavigate(history, '/policies/edit')}
49+
{...reactRouterNavigate(history, getPolicyCreatePath())}
4950
fill
5051
iconType="plusInCircle"
5152
data-test-subj="createPolicyButton"

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

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

7-
export const getPolicyPath = (policyName: string): string => {
7+
export const ROUTES = {
8+
list: '/policies',
9+
edit: '/policies/edit/:policyName?',
10+
create: '/policies/edit',
11+
};
12+
13+
export const getPolicyEditPath = (policyName: string): string => {
814
return encodeURI(`/policies/edit/${encodeURIComponent(policyName)}`);
915
};
16+
17+
export const getPolicyCreatePath = () => {
18+
return ROUTES.create;
19+
};
20+
21+
export const getPoliciesListPath = () => {
22+
return ROUTES.list;
23+
};

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import {
2525
} from '@elastic/eui';
2626

2727
import { ApplicationStart } from 'kibana/public';
28-
import { getPolicyPath } from '../../application/services/navigation';
28+
import { getPolicyEditPath } from '../../application/services/navigation';
2929
import { Index, IndexLifecyclePolicy } from '../../../common/types';
3030

3131
const getHeaders = (): Array<[keyof IndexLifecyclePolicy, string]> => {
@@ -192,7 +192,7 @@ export class IndexLifecycleSummary extends Component<Props, State> {
192192
content = (
193193
<EuiLink
194194
href={this.props.getUrlForApp('management', {
195-
path: `data/index_lifecycle_management/${getPolicyPath(value)}`,
195+
path: `data/index_lifecycle_management/${getPolicyEditPath(value)}`,
196196
})}
197197
>
198198
{value}

x-pack/plugins/index_lifecycle_management/public/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@ import { IndexLifecycleManagementPlugin } from './plugin';
1212
export const plugin = (initializerContext: PluginInitializerContext) => {
1313
return new IndexLifecycleManagementPlugin(initializerContext);
1414
};
15+
16+
export { ILM_URL_GENERATOR_ID, IlmUrlGeneratorState } from './url_generator';

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@ import { init as initUiMetric } from './application/services/ui_metric';
1414
import { init as initNotification } from './application/services/notification';
1515
import { BreadcrumbService } from './application/services/breadcrumbs';
1616
import { addAllExtensions } from './extend_index_management';
17-
import { PluginsDependencies, ClientConfigType } from './types';
17+
import { ClientConfigType, SetupDependencies } from './types';
18+
import { registerUrlGenerator } from './url_generator';
1819

1920
export class IndexLifecycleManagementPlugin {
2021
constructor(private readonly initializerContext: PluginInitializerContext) {}
2122

2223
private breadcrumbService = new BreadcrumbService();
2324

24-
public setup(coreSetup: CoreSetup, plugins: PluginsDependencies) {
25+
public setup(coreSetup: CoreSetup, plugins: SetupDependencies) {
2526
const {
2627
ui: { enabled: isIndexLifecycleManagementUiEnabled },
2728
} = this.initializerContext.config.get<ClientConfigType>();
@@ -34,7 +35,7 @@ export class IndexLifecycleManagementPlugin {
3435
getStartServices,
3536
} = coreSetup;
3637

37-
const { usageCollection, management, indexManagement, home, cloud } = plugins;
38+
const { usageCollection, management, indexManagement, home, cloud, share } = plugins;
3839

3940
// Initialize services even if the app isn't mounted, because they're used by index management extensions.
4041
initHttp(http);
@@ -102,6 +103,8 @@ export class IndexLifecycleManagementPlugin {
102103
if (indexManagement) {
103104
addAllExtensions(indexManagement.extensionsService);
104105
}
106+
107+
registerUrlGenerator(coreSetup, management, share);
105108
}
106109
}
107110

x-pack/plugins/index_lifecycle_management/public/types.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,17 @@ import { UsageCollectionSetup } from '../../../../src/plugins/usage_collection/p
99
import { ManagementSetup } from '../../../../src/plugins/management/public';
1010
import { IndexManagementPluginSetup } from '../../index_management/public';
1111
import { CloudSetup } from '../../cloud/public';
12+
import { SharePluginSetup } from '../../../../src/plugins/share/public';
1213

1314
import { BreadcrumbService } from './application/services/breadcrumbs';
1415

15-
export interface PluginsDependencies {
16+
export interface SetupDependencies {
1617
usageCollection?: UsageCollectionSetup;
1718
management: ManagementSetup;
1819
cloud?: CloudSetup;
1920
indexManagement?: IndexManagementPluginSetup;
2021
home?: HomePublicPluginSetup;
22+
share: SharePluginSetup;
2123
}
2224

2325
export interface ClientConfigType {
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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 { CoreSetup } from 'kibana/public';
8+
import { UrlGeneratorsDefinition } from '../../../../src/plugins/share/public/';
9+
import {
10+
getPoliciesListPath,
11+
getPolicyCreatePath,
12+
getPolicyEditPath,
13+
} from './application/services/navigation';
14+
import { MANAGEMENT_APP_ID } from '../../../../src/plugins/management/public';
15+
import { SetupDependencies } from './types';
16+
import { PLUGIN } from '../common/constants';
17+
18+
export const ILM_URL_GENERATOR_ID = 'ILM_URL_GENERATOR_ID';
19+
20+
export interface IlmUrlGeneratorState {
21+
page: 'policies_list' | 'policy_edit' | 'policy_create';
22+
policyName?: string;
23+
absolute?: boolean;
24+
}
25+
export const createIlmUrlGenerator = (
26+
getAppBasePath: (absolute?: boolean) => Promise<string>
27+
): UrlGeneratorsDefinition<typeof ILM_URL_GENERATOR_ID> => {
28+
return {
29+
id: ILM_URL_GENERATOR_ID,
30+
createUrl: async (state: IlmUrlGeneratorState): Promise<string> => {
31+
switch (state.page) {
32+
case 'policy_create': {
33+
return `${await getAppBasePath(!!state.absolute)}${getPolicyCreatePath()}`;
34+
}
35+
case 'policy_edit': {
36+
return `${await getAppBasePath(!!state.absolute)}${getPolicyEditPath(state.policyName!)}`;
37+
}
38+
case 'policies_list': {
39+
return `${await getAppBasePath(!!state.absolute)}${getPoliciesListPath()}`;
40+
}
41+
}
42+
},
43+
};
44+
};
45+
46+
export const registerUrlGenerator = (
47+
coreSetup: CoreSetup,
48+
management: SetupDependencies['management'],
49+
share: SetupDependencies['share']
50+
) => {
51+
const getAppBasePath = async (absolute = false) => {
52+
const [coreStart] = await coreSetup.getStartServices();
53+
return coreStart.application.getUrlForApp(MANAGEMENT_APP_ID, {
54+
path: management.sections.section.data.getApp(PLUGIN.ID)!.basePath,
55+
absolute,
56+
});
57+
};
58+
59+
share.urlGenerators.registerUrlGenerator(createIlmUrlGenerator(getAppBasePath));
60+
};

0 commit comments

Comments
 (0)