Reset chrome fields while switching an app (#73064)
* Reset chrome help extension while switching an app * Reset other chrome fields * Set docTitle in saved objects app * Add unit tests Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
This commit is contained in:
parent
686cde88af
commit
4efaba3298
3 changed files with 68 additions and 0 deletions
|
@ -405,6 +405,59 @@ describe('start', () => {
|
|||
`);
|
||||
});
|
||||
});
|
||||
|
||||
describe('erase chrome fields', () => {
|
||||
it('while switching an app', async () => {
|
||||
const startDeps = defaultStartDeps([new FakeApp('alpha')]);
|
||||
const { navigateToApp } = startDeps.application;
|
||||
const { chrome, service } = await start({ startDeps });
|
||||
|
||||
const helpExtensionPromise = chrome.getHelpExtension$().pipe(toArray()).toPromise();
|
||||
const breadcrumbsPromise = chrome.getBreadcrumbs$().pipe(toArray()).toPromise();
|
||||
const badgePromise = chrome.getBadge$().pipe(toArray()).toPromise();
|
||||
const docTitleResetSpy = jest.spyOn(chrome.docTitle, 'reset');
|
||||
|
||||
const promises = Promise.all([helpExtensionPromise, breadcrumbsPromise, badgePromise]);
|
||||
|
||||
chrome.setHelpExtension({ appName: 'App name' });
|
||||
chrome.setBreadcrumbs([{ text: 'App breadcrumb' }]);
|
||||
chrome.setBadge({ text: 'App badge', tooltip: 'App tooltip' });
|
||||
|
||||
navigateToApp('alpha');
|
||||
|
||||
service.stop();
|
||||
|
||||
expect(docTitleResetSpy).toBeCalledTimes(1);
|
||||
await expect(promises).resolves.toMatchInlineSnapshot(`
|
||||
Array [
|
||||
Array [
|
||||
undefined,
|
||||
Object {
|
||||
"appName": "App name",
|
||||
},
|
||||
undefined,
|
||||
],
|
||||
Array [
|
||||
Array [],
|
||||
Array [
|
||||
Object {
|
||||
"text": "App breadcrumb",
|
||||
},
|
||||
],
|
||||
Array [],
|
||||
],
|
||||
Array [
|
||||
undefined,
|
||||
Object {
|
||||
"text": "App badge",
|
||||
"tooltip": "App tooltip",
|
||||
},
|
||||
undefined,
|
||||
],
|
||||
]
|
||||
`);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('stop', () => {
|
||||
|
|
|
@ -157,6 +157,14 @@ export class ChromeService {
|
|||
const recentlyAccessed = await this.recentlyAccessed.start({ http });
|
||||
const docTitle = this.docTitle.start({ document: window.document });
|
||||
|
||||
// erase chrome fields from a previous app while switching to a next app
|
||||
application.currentAppId$.subscribe(() => {
|
||||
helpExtension$.next(undefined);
|
||||
breadcrumbs$.next([]);
|
||||
badge$.next(undefined);
|
||||
docTitle.reset();
|
||||
});
|
||||
|
||||
const setIsNavDrawerLocked = (isLocked: boolean) => {
|
||||
isNavDrawerLocked$.next(isLocked);
|
||||
localStorage.setItem(IS_LOCKED_KEY, `${isLocked}`);
|
||||
|
|
|
@ -21,6 +21,7 @@ import React, { lazy, Suspense } from 'react';
|
|||
import ReactDOM from 'react-dom';
|
||||
import { Router, Switch, Route } from 'react-router-dom';
|
||||
import { I18nProvider } from '@kbn/i18n/react';
|
||||
import { i18n } from '@kbn/i18n';
|
||||
import { EuiLoadingSpinner } from '@elastic/eui';
|
||||
import { CoreSetup } from 'src/core/public';
|
||||
import { ManagementAppMountParams } from '../../../management/public';
|
||||
|
@ -36,6 +37,10 @@ interface MountParams {
|
|||
|
||||
let allowedObjectTypes: string[] | undefined;
|
||||
|
||||
const title = i18n.translate('savedObjectsManagement.objects.savedObjectsTitle', {
|
||||
defaultMessage: 'Saved Objects',
|
||||
});
|
||||
|
||||
const SavedObjectsEditionPage = lazy(() => import('./saved_objects_edition_page'));
|
||||
const SavedObjectsTablePage = lazy(() => import('./saved_objects_table_page'));
|
||||
export const mountManagementSection = async ({
|
||||
|
@ -49,6 +54,8 @@ export const mountManagementSection = async ({
|
|||
allowedObjectTypes = await getAllowedTypes(coreStart.http);
|
||||
}
|
||||
|
||||
coreStart.chrome.docTitle.change(title);
|
||||
|
||||
const capabilities = coreStart.application.capabilities;
|
||||
|
||||
const RedirectToHomeIfUnauthorized: React.FunctionComponent = ({ children }) => {
|
||||
|
|
Loading…
Reference in a new issue