Skip to content

Commit f9baaa2

Browse files
Observability landing page title (#72088)
* updating window title based on breadcrumbs * updating window title based on breadcrumbs * updating window title based on breadcrumbs
1 parent 5160c7e commit f9baaa2

2 files changed

Lines changed: 24 additions & 13 deletions

File tree

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

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,31 @@
33
* or more contributor license agreements. Licensed under the Elastic License;
44
* you may not use this file except in compliance with the Elastic License.
55
*/
6+
import { i18n } from '@kbn/i18n';
67
import { createHashHistory } from 'history';
78
import React, { useEffect } from 'react';
89
import ReactDOM from 'react-dom';
910
import { Route, Router, Switch } from 'react-router-dom';
10-
import { i18n } from '@kbn/i18n';
11-
import { RedirectAppLinks } from '../../../../../src/plugins/kibana_react/public';
1211
import { AppMountParameters, CoreStart } from '../../../../../src/core/public';
12+
import { RedirectAppLinks } from '../../../../../src/plugins/kibana_react/public';
1313
import { EuiThemeProvider } from '../../../../legacy/common/eui_styled_components';
1414
import { PluginContext } from '../context/plugin_context';
15-
import { useRouteParams } from '../hooks/use_route_params';
16-
import { routes } from '../routes';
1715
import { usePluginContext } from '../hooks/use_plugin_context';
16+
import { useRouteParams } from '../hooks/use_route_params';
17+
import { Breadcrumbs, routes } from '../routes';
18+
19+
const observabilityLabelBreadcrumb = {
20+
text: i18n.translate('xpack.observability.observability.breadcrumb.', {
21+
defaultMessage: 'Observability',
22+
}),
23+
};
24+
25+
function getTitleFromBreadCrumbs(breadcrumbs: Breadcrumbs) {
26+
return breadcrumbs
27+
.map(({ text }) => text)
28+
.reverse()
29+
.join(' | ');
30+
}
1831

1932
const App = () => {
2033
return (
@@ -25,16 +38,12 @@ const App = () => {
2538
const route = routes[path];
2639
const Wrapper = () => {
2740
const { core } = usePluginContext();
41+
42+
const breadcrumb = [observabilityLabelBreadcrumb, ...route.breadcrumb];
2843
useEffect(() => {
29-
core.chrome.setBreadcrumbs([
30-
{
31-
text: i18n.translate('xpack.observability.observability.breadcrumb.', {
32-
defaultMessage: 'Observability',
33-
}),
34-
},
35-
...route.breadcrumb,
36-
]);
37-
}, [core]);
44+
core.chrome.setBreadcrumbs(breadcrumb);
45+
document.title = getTitleFromBreadCrumbs(breadcrumb);
46+
}, [core, breadcrumb]);
3847

3948
const { query, path: pathParams } = useRouteParams(route.params);
4049
return route.handler({ query, path: pathParams });

x-pack/plugins/observability/public/routes/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ type DecodeParams<TParams extends Params | undefined> = {
1717
[key in keyof TParams]: TParams[key] extends t.Any ? t.TypeOf<TParams[key]> : never;
1818
};
1919

20+
export type Breadcrumbs = Array<{ text: string }>;
21+
2022
export interface Params {
2123
query?: t.HasProps;
2224
path?: t.HasProps;

0 commit comments

Comments
 (0)