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

[Dashboard First] Lens Originating App Breadcrumb #75470

Merged
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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: This type cast doesn't seem necessary:

            {
              onClick: () => {
                core.application.navigateToApp(originatingApp);
              },
              text: getAppNameFromId(originatingApp),
            }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will fix this in the lens by value PR

]
: []),
{
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