Skip to content

Commit 12bb59a

Browse files
authored
Adds doc titles to security management sections (#91013)
1 parent db2a385 commit 12bb59a

File tree

15 files changed

+133
-51
lines changed

15 files changed

+133
-51
lines changed

src/plugins/advanced_settings/public/management_app/mount_management_section.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ export async function mountManagementSection(
6767
chrome.setBadge(readOnlyBadge);
6868
}
6969

70+
chrome.docTitle.change(title);
71+
7072
ReactDOM.render(
7173
<I18nProvider>
7274
<Router history={params.history}>
@@ -90,6 +92,7 @@ export async function mountManagementSection(
9092
params.element
9193
);
9294
return () => {
95+
chrome.docTitle.reset();
9396
ReactDOM.unmountComponentAtNode(params.element);
9497
};
9598
}

src/plugins/saved_objects_management/public/management_section/mount_section.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ export const mountManagementSection = async ({
103103
);
104104

105105
return () => {
106+
coreStart.chrome.docTitle.reset();
106107
ReactDOM.unmountComponentAtNode(element);
107108
};
108109
};

x-pack/plugins/saved_objects_tagging/public/management/mount_section.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ interface MountSectionParams {
2121
assignmentService: ITagAssignmentService;
2222
core: CoreSetup<{}, SavedObjectTaggingPluginStart>;
2323
mountParams: ManagementAppMountParams;
24+
title: string;
2425
}
2526

2627
const RedirectToHomeIfUnauthorized: FC<{
@@ -40,11 +41,13 @@ export const mountSection = async ({
4041
assignmentService,
4142
core,
4243
mountParams,
44+
title,
4345
}: MountSectionParams) => {
4446
const [coreStart] = await core.getStartServices();
4547
const { element, setBreadcrumbs } = mountParams;
4648
const capabilities = getTagsCapabilities(coreStart.application.capabilities);
4749
const assignableTypes = await assignmentService.getAssignableTypes();
50+
coreStart.chrome.docTitle.change(title);
4851

4952
ReactDOM.render(
5053
<I18nProvider>
@@ -64,6 +67,7 @@ export const mountSection = async ({
6467
);
6568

6669
return () => {
70+
coreStart.chrome.docTitle.reset();
6771
ReactDOM.unmountComponentAtNode(element);
6872
};
6973
};

x-pack/plugins/saved_objects_tagging/public/plugin.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,12 @@ export class SavedObjectTaggingPlugin
3939
{ management, savedObjectsTaggingOss }: SetupDeps
4040
) {
4141
const kibanaSection = management.sections.section.kibana;
42+
const title = i18n.translate('xpack.savedObjectsTagging.management.sectionLabel', {
43+
defaultMessage: 'Tags',
44+
});
4245
kibanaSection.registerApp({
4346
id: tagManagementSectionId,
44-
title: i18n.translate('xpack.savedObjectsTagging.management.sectionLabel', {
45-
defaultMessage: 'Tags',
46-
}),
47+
title,
4748
order: 1.5,
4849
mount: async (mountParams) => {
4950
const { mountSection } = await import('./management');
@@ -53,6 +54,7 @@ export class SavedObjectTaggingPlugin
5354
assignmentService: this.assignmentService!,
5455
core,
5556
mountParams,
57+
title,
5658
});
5759
},
5860
});

x-pack/plugins/security/public/management/api_keys/api_keys_management_app.test.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,15 @@ describe('apiKeysManagementApp', () => {
2828

2929
it('mount() works for the `grid` page', async () => {
3030
const { getStartServices } = coreMock.createSetup();
31+
32+
const startServices = await getStartServices();
33+
const docTitle = startServices[0].chrome.docTitle;
34+
3135
const container = document.createElement('div');
3236

3337
const setBreadcrumbs = jest.fn();
3438
const unmount = await apiKeysManagementApp
35-
.create({ getStartServices: getStartServices as any })
39+
.create({ getStartServices: () => Promise.resolve(startServices) as any })
3640
.mount({
3741
basePath: '/some-base-path',
3842
element: container,
@@ -42,13 +46,16 @@ describe('apiKeysManagementApp', () => {
4246

4347
expect(setBreadcrumbs).toHaveBeenCalledTimes(1);
4448
expect(setBreadcrumbs).toHaveBeenCalledWith([{ href: '/', text: 'API Keys' }]);
49+
expect(docTitle.change).toHaveBeenCalledWith('API Keys');
50+
expect(docTitle.reset).not.toHaveBeenCalled();
4551
expect(container).toMatchInlineSnapshot(`
4652
<div>
4753
Page: {"notifications":{"toasts":{}},"apiKeysAPIClient":{"http":{"basePath":{"basePath":"","serverBasePath":""},"anonymousPaths":{},"externalUrl":{}}}}
4854
</div>
4955
`);
5056

5157
unmount();
58+
expect(docTitle.reset).toHaveBeenCalledTimes(1);
5259

5360
expect(container).toMatchInlineSnapshot(`<div />`);
5461
});

x-pack/plugins/security/public/management/api_keys/api_keys_management_app.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,17 @@ interface CreateParams {
2020
export const apiKeysManagementApp = Object.freeze({
2121
id: 'api_keys',
2222
create({ getStartServices }: CreateParams) {
23+
const title = i18n.translate('xpack.security.management.apiKeysTitle', {
24+
defaultMessage: 'API Keys',
25+
});
2326
return {
2427
id: this.id,
2528
order: 30,
26-
title: i18n.translate('xpack.security.management.apiKeysTitle', {
27-
defaultMessage: 'API Keys',
28-
}),
29+
title,
2930
async mount({ element, setBreadcrumbs }) {
3031
setBreadcrumbs([
3132
{
32-
text: i18n.translate('xpack.security.apiKeys.breadcrumb', {
33-
defaultMessage: 'API Keys',
34-
}),
33+
text: title,
3534
href: `/`,
3635
},
3736
]);
@@ -42,6 +41,8 @@ export const apiKeysManagementApp = Object.freeze({
4241
import('./api_keys_api_client'),
4342
]);
4443

44+
core.chrome.docTitle.change(title);
45+
4546
render(
4647
<KibanaContextProvider services={core}>
4748
<core.i18n.Context>
@@ -55,6 +56,7 @@ export const apiKeysManagementApp = Object.freeze({
5556
);
5657

5758
return () => {
59+
core.chrome.docTitle.reset();
5860
unmountComponentAtNode(element);
5961
};
6062
},

x-pack/plugins/security/public/management/role_mappings/role_mappings_management_app.test.tsx

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,18 @@ async function mountApp(basePath: string, pathname: string) {
3030
const container = document.createElement('div');
3131
const setBreadcrumbs = jest.fn();
3232

33+
const startServices = await coreMock.createSetup().getStartServices();
34+
3335
const unmount = await roleMappingsManagementApp
34-
.create({ getStartServices: coreMock.createSetup().getStartServices as any })
36+
.create({ getStartServices: () => Promise.resolve(startServices) as any })
3537
.mount({
3638
basePath,
3739
element: container,
3840
setBreadcrumbs,
3941
history: scopedHistoryMock.create({ pathname }),
4042
});
4143

42-
return { unmount, container, setBreadcrumbs };
44+
return { unmount, container, setBreadcrumbs, docTitle: startServices[0].chrome.docTitle };
4345
}
4446

4547
describe('roleMappingsManagementApp', () => {
@@ -59,10 +61,12 @@ describe('roleMappingsManagementApp', () => {
5961
});
6062

6163
it('mount() works for the `grid` page', async () => {
62-
const { setBreadcrumbs, container, unmount } = await mountApp('/', '/');
64+
const { setBreadcrumbs, container, unmount, docTitle } = await mountApp('/', '/');
6365

6466
expect(setBreadcrumbs).toHaveBeenCalledTimes(1);
6567
expect(setBreadcrumbs).toHaveBeenCalledWith([{ href: `/`, text: 'Role Mappings' }]);
68+
expect(docTitle.change).toHaveBeenCalledWith('Role Mappings');
69+
expect(docTitle.reset).not.toHaveBeenCalled();
6670
expect(container).toMatchInlineSnapshot(`
6771
<div>
6872
Role Mappings Page: {"notifications":{"toasts":{}},"rolesAPIClient":{"http":{"basePath":{"basePath":"","serverBasePath":""},"anonymousPaths":{},"externalUrl":{}}},"roleMappingsAPI":{"http":{"basePath":{"basePath":"","serverBasePath":""},"anonymousPaths":{},"externalUrl":{}}},"docLinks":{},"history":{"action":"PUSH","length":1,"location":{"pathname":"/","search":"","hash":""}}}
@@ -71,17 +75,21 @@ describe('roleMappingsManagementApp', () => {
7175

7276
unmount();
7377

78+
expect(docTitle.reset).toHaveBeenCalledTimes(1);
79+
7480
expect(container).toMatchInlineSnapshot(`<div />`);
7581
});
7682

7783
it('mount() works for the `create role mapping` page', async () => {
78-
const { setBreadcrumbs, container, unmount } = await mountApp('/', '/edit');
84+
const { setBreadcrumbs, container, unmount, docTitle } = await mountApp('/', '/edit');
7985

8086
expect(setBreadcrumbs).toHaveBeenCalledTimes(1);
8187
expect(setBreadcrumbs).toHaveBeenCalledWith([
8288
{ href: `/`, text: 'Role Mappings' },
8389
{ text: 'Create' },
8490
]);
91+
expect(docTitle.change).toHaveBeenCalledWith('Role Mappings');
92+
expect(docTitle.reset).not.toHaveBeenCalled();
8593
expect(container).toMatchInlineSnapshot(`
8694
<div>
8795
Role Mapping Edit Page: {"roleMappingsAPI":{"http":{"basePath":{"basePath":"","serverBasePath":""},"anonymousPaths":{},"externalUrl":{}}},"rolesAPIClient":{"http":{"basePath":{"basePath":"","serverBasePath":""},"anonymousPaths":{},"externalUrl":{}}},"notifications":{"toasts":{}},"docLinks":{},"history":{"action":"PUSH","length":1,"location":{"pathname":"/edit","search":"","hash":""}}}
@@ -90,19 +98,26 @@ describe('roleMappingsManagementApp', () => {
9098

9199
unmount();
92100

101+
expect(docTitle.reset).toHaveBeenCalledTimes(1);
102+
93103
expect(container).toMatchInlineSnapshot(`<div />`);
94104
});
95105

96106
it('mount() works for the `edit role mapping` page', async () => {
97107
const roleMappingName = 'role@mapping';
98108

99-
const { setBreadcrumbs, container, unmount } = await mountApp('/', `/edit/${roleMappingName}`);
109+
const { setBreadcrumbs, container, unmount, docTitle } = await mountApp(
110+
'/',
111+
`/edit/${roleMappingName}`
112+
);
100113

101114
expect(setBreadcrumbs).toHaveBeenCalledTimes(1);
102115
expect(setBreadcrumbs).toHaveBeenCalledWith([
103116
{ href: `/`, text: 'Role Mappings' },
104117
{ href: `/edit/${encodeURIComponent(roleMappingName)}`, text: roleMappingName },
105118
]);
119+
expect(docTitle.change).toHaveBeenCalledWith('Role Mappings');
120+
expect(docTitle.reset).not.toHaveBeenCalled();
106121
expect(container).toMatchInlineSnapshot(`
107122
<div>
108123
Role Mapping Edit Page: {"name":"role@mapping","roleMappingsAPI":{"http":{"basePath":{"basePath":"","serverBasePath":""},"anonymousPaths":{},"externalUrl":{}}},"rolesAPIClient":{"http":{"basePath":{"basePath":"","serverBasePath":""},"anonymousPaths":{},"externalUrl":{}}},"notifications":{"toasts":{}},"docLinks":{},"history":{"action":"PUSH","length":1,"location":{"pathname":"/edit/role@mapping","search":"","hash":""}}}
@@ -111,6 +126,8 @@ describe('roleMappingsManagementApp', () => {
111126

112127
unmount();
113128

129+
expect(docTitle.reset).toHaveBeenCalledTimes(1);
130+
114131
expect(container).toMatchInlineSnapshot(`<div />`);
115132
});
116133

x-pack/plugins/security/public/management/role_mappings/role_mappings_management_app.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,24 @@ interface CreateParams {
2222
export const roleMappingsManagementApp = Object.freeze({
2323
id: 'role_mappings',
2424
create({ getStartServices }: CreateParams) {
25+
const title = i18n.translate('xpack.security.management.roleMappingsTitle', {
26+
defaultMessage: 'Role Mappings',
27+
});
2528
return {
2629
id: this.id,
2730
order: 40,
28-
title: i18n.translate('xpack.security.management.roleMappingsTitle', {
29-
defaultMessage: 'Role Mappings',
30-
}),
31+
title,
3132
async mount({ element, setBreadcrumbs, history }) {
3233
const [coreStart] = await getStartServices();
3334
const roleMappingsBreadcrumbs = [
3435
{
35-
text: i18n.translate('xpack.security.roleMapping.breadcrumb', {
36-
defaultMessage: 'Role Mappings',
37-
}),
36+
text: title,
3837
href: `/`,
3938
},
4039
];
4140

41+
coreStart.chrome.docTitle.change(title);
42+
4243
const [
4344
[core],
4445
{ RoleMappingsGridPage },
@@ -117,6 +118,7 @@ export const roleMappingsManagementApp = Object.freeze({
117118
);
118119

119120
return () => {
121+
coreStart.chrome.docTitle.reset();
120122
unmountComponentAtNode(element);
121123
};
122124
},

0 commit comments

Comments
 (0)