Skip to content

Commit

Permalink
[ML] Change to using docTitle.change
Browse files Browse the repository at this point in the history
  • Loading branch information
qn895 committed Sep 8, 2020
1 parent 5d0c800 commit c62a924
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import React, { FC, useState, useEffect } from 'react';
import { EuiTabs, EuiTab, EuiLink } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { TabId } from './navigation_menu';
import { useMlUrlGenerator, useNavigateToPath } from '../../contexts/kibana';
import { useMlKibana, useMlUrlGenerator, useNavigateToPath } from '../../contexts/kibana';
import { MlUrlGeneratorState } from '../../../../common/types/ml_url_generator';
import { useUrlState } from '../../util/url_state';

Expand Down Expand Up @@ -111,6 +111,12 @@ const TAB_DATA: Record<TabId, TabData> = {
};

export const MainTabs: FC<Props> = ({ tabId, disableLinks }) => {
const {
services: {
appName,
chrome: { docTitle },
},
} = useMlKibana();
const [globalState] = useUrlState('_g');
const [selectedTabId, setSelectedTabId] = useState(tabId);
function onSelectedTabChanged(id: TabId) {
Expand All @@ -126,14 +132,16 @@ export const MainTabs: FC<Props> = ({ tabId, disableLinks }) => {
// @ts-ignore
const path = await mlUrlGenerator.createUrl({
page: defaultPathId,
// globalState (e.g. selected jobs and time range) should be retained when changing pages.
// appState will not be considered.
pageState: { globalState },
});

await navigateToPath(path, false);
};

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

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

return disabled ? (
<EuiTab key={`${id}-key`} className={'mlNavigationMenu__mainTab'} disabled={true}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ interface StartPlugins {
share: SharePluginStart;
}
export type StartServices = CoreStart &
StartPlugins & { kibanaVersion: string } & MlServicesContext;
StartPlugins & { appName: string; kibanaVersion: string } & MlServicesContext;
export const useMlKibana = () => useKibana<StartServices>();
export type MlKibanaReactContextValue = KibanaReactContextValue<StartServices>;

0 comments on commit c62a924

Please sign in to comment.