Skip to content

Commit c62a924

Browse files
committed
[ML] Change to using docTitle.change
1 parent 5d0c800 commit c62a924

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

x-pack/plugins/ml/public/application/components/navigation_menu/main_tabs.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import React, { FC, useState, useEffect } from 'react';
99
import { EuiTabs, EuiTab, EuiLink } from '@elastic/eui';
1010
import { i18n } from '@kbn/i18n';
1111
import { TabId } from './navigation_menu';
12-
import { useMlUrlGenerator, useNavigateToPath } from '../../contexts/kibana';
12+
import { useMlKibana, useMlUrlGenerator, useNavigateToPath } from '../../contexts/kibana';
1313
import { MlUrlGeneratorState } from '../../../../common/types/ml_url_generator';
1414
import { useUrlState } from '../../util/url_state';
1515

@@ -111,6 +111,12 @@ const TAB_DATA: Record<TabId, TabData> = {
111111
};
112112

113113
export const MainTabs: FC<Props> = ({ tabId, disableLinks }) => {
114+
const {
115+
services: {
116+
appName,
117+
chrome: { docTitle },
118+
},
119+
} = useMlKibana();
114120
const [globalState] = useUrlState('_g');
115121
const [selectedTabId, setSelectedTabId] = useState(tabId);
116122
function onSelectedTabChanged(id: TabId) {
@@ -126,14 +132,16 @@ export const MainTabs: FC<Props> = ({ tabId, disableLinks }) => {
126132
// @ts-ignore
127133
const path = await mlUrlGenerator.createUrl({
128134
page: defaultPathId,
135+
// globalState (e.g. selected jobs and time range) should be retained when changing pages.
136+
// appState will not be considered.
129137
pageState: { globalState },
130138
});
131139

132140
await navigateToPath(path, false);
133141
};
134142

135143
useEffect(() => {
136-
document.title = `ML - ${TAB_DATA[selectedTabId].name} - Kibana`;
144+
docTitle.change([appName, TAB_DATA[selectedTabId].name, 'Kibana']);
137145
}, [selectedTabId]);
138146

139147
return (
@@ -142,8 +150,6 @@ export const MainTabs: FC<Props> = ({ tabId, disableLinks }) => {
142150
const { id, disabled } = tab;
143151
const testSubject = TAB_DATA[id].testSubject;
144152
const defaultPathId = (TAB_DATA[id].pathId || id) as MlUrlGeneratorState['page'];
145-
// globalState (e.g. selected jobs and time range) should be retained when changing pages.
146-
// appState will not be considered.
147153

148154
return disabled ? (
149155
<EuiTab key={`${id}-key`} className={'mlNavigationMenu__mainTab'} disabled={true}>

x-pack/plugins/ml/public/application/contexts/kibana/kibana_context.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ interface StartPlugins {
2222
share: SharePluginStart;
2323
}
2424
export type StartServices = CoreStart &
25-
StartPlugins & { kibanaVersion: string } & MlServicesContext;
25+
StartPlugins & { appName: string; kibanaVersion: string } & MlServicesContext;
2626
export const useMlKibana = () => useKibana<StartServices>();
2727
export type MlKibanaReactContextValue = KibanaReactContextValue<StartServices>;

0 commit comments

Comments
 (0)