Skip to content

Commit

Permalink
[Dashboard First] Lens Originating App Breadcrumb (#75470) (#75657)
Browse files Browse the repository at this point in the history
Changed lens breadcrumbs to reflect the Originating App
  • Loading branch information
ThomThomson authored Aug 21, 2020
1 parent c581671 commit 9ba8942
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
34 changes: 34 additions & 0 deletions x-pack/plugins/lens/public/app_plugin/app.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ describe('Lens App', () => {
originatingApp: string | undefined;
onAppLeave: AppMountParameters['onAppLeave'];
history: History;
getAppNameFromId?: (appId: string) => string | undefined;
}> {
return ({
navigation: navigationStartMock,
Expand Down Expand Up @@ -187,6 +188,7 @@ describe('Lens App', () => {
originatingApp: string | undefined;
onAppLeave: AppMountParameters['onAppLeave'];
history: History;
getAppNameFromId?: (appId: string) => string | undefined;
}>;
}

Expand Down Expand Up @@ -298,6 +300,38 @@ describe('Lens App', () => {
]);
});

it('sets originatingApp breadcrumb when the document title changes', async () => {
const defaultArgs = makeDefaultArgs();
defaultArgs.originatingApp = 'ultraCoolDashboard';
defaultArgs.getAppNameFromId = () => 'The Coolest Container Ever Made';
instance = mount(<App {...defaultArgs} />);

expect(core.chrome.setBreadcrumbs).toHaveBeenCalledWith([
{ text: 'The Coolest Container Ever Made', onClick: expect.anything() },
{ text: 'Visualize', href: '/testbasepath/app/visualize#/', onClick: expect.anything() },
{ text: 'Create' },
]);

(defaultArgs.docStorage.load as jest.Mock).mockResolvedValue({
id: '1234',
title: 'Daaaaaaadaumching!',
expression: 'valid expression',
state: {
query: 'fake query',
datasourceMetaData: { filterableIndexPatterns: [{ id: '1', title: 'saved' }] },
},
});
await act(async () => {
instance.setProps({ docId: '1234' });
});

expect(defaultArgs.core.chrome.setBreadcrumbs).toHaveBeenCalledWith([
{ text: 'The Coolest Container Ever Made', onClick: expect.anything() },
{ text: 'Visualize', href: '/testbasepath/app/visualize#/', onClick: expect.anything() },
{ text: 'Daaaaaaadaumching!' },
]);
});

describe('persistence', () => {
it('does not load a document if there is no document id', () => {
const args = makeDefaultArgs();
Expand Down
21 changes: 20 additions & 1 deletion x-pack/plugins/lens/public/app_plugin/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { i18n } from '@kbn/i18n';
import { NavigationPublicPluginStart } from 'src/plugins/navigation/public';
import { AppMountContext, AppMountParameters, NotificationsStart } from 'kibana/public';
import { History } from 'history';
import { EuiBreadcrumb } from '@elastic/eui';
import {
Query,
DataPublicPluginStart,
Expand Down Expand Up @@ -203,6 +204,16 @@ export function App({
// Sync Kibana breadcrumbs any time the saved document's title changes
useEffect(() => {
core.chrome.setBreadcrumbs([
...(originatingApp && getAppNameFromId
? [
{
onClick: (e) => {
core.application.navigateToApp(originatingApp);
},
text: getAppNameFromId(originatingApp),
} as EuiBreadcrumb,
]
: []),
{
href: core.http.basePath.prepend(`/app/visualize#/`),
onClick: (e) => {
Expand All @@ -219,7 +230,15 @@ export function App({
: i18n.translate('xpack.lens.breadcrumbsCreate', { defaultMessage: 'Create' }),
},
]);
}, [core.application, core.chrome, core.http.basePath, state.persistedDoc]);
}, [
core.application,
core.chrome,
core.http.basePath,
state.persistedDoc,
originatingApp,
redirectTo,
getAppNameFromId,
]);

useEffect(
() => {
Expand Down

0 comments on commit 9ba8942

Please sign in to comment.