Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.x] Reset chrome fields while switching an app (#73064) #75953

Merged
merged 3 commits into from
Aug 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions src/core/public/chrome/chrome_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
8 changes: 8 additions & 0 deletions src/core/public/chrome/chrome_service.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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 ({
Expand All @@ -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 }) => {
Expand Down