Skip to content

Commit

Permalink
don't relay on text to drop home
Browse files Browse the repository at this point in the history
Signed-off-by: Hailong Cui <ihailong@amazon.com>
  • Loading branch information
Hailong-am authored and SuZhou-Joe committed Sep 5, 2024
1 parent cd0a375 commit b83d54f
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 13 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/core/public/chrome/ui/header/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -204,14 +204,14 @@ export function Header({
/>
);

const renderBreadcrumbs = (renderFullLength?: boolean, hideFirstHome?: boolean) => (
const renderBreadcrumbs = (renderFullLength?: boolean, dropHomeFromBreadcrumb?: boolean) => (
<HeaderBreadcrumbs
appTitle$={observables.appTitle$}
breadcrumbs$={observables.breadcrumbs$}
breadcrumbsEnricher$={observables.breadcrumbsEnricher$}
useUpdatedHeader={useUpdatedHeader}
renderFullLength={renderFullLength}
hideFirstHome={hideFirstHome}
dropHomeFromBreadcrumb={dropHomeFromBreadcrumb}
/>
);

Expand Down
18 changes: 14 additions & 4 deletions src/core/public/chrome/ui/header/header_breadcrumbs.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
import { mount } from 'enzyme';
import React from 'react';
import { act } from 'react-dom/test-utils';
import { BehaviorSubject } from 'rxjs';
import { ChromeBreadcrumb } from '../../chrome_service';
import { BehaviorSubject, Observable } from 'rxjs';
import { ChromeBreadcrumb, ChromeBreadcrumbEnricher } from '../../chrome_service';
import { HeaderBreadcrumbs } from './header_breadcrumbs';

describe('HeaderBreadcrumbs', () => {
Expand Down Expand Up @@ -111,7 +111,7 @@ describe('HeaderBreadcrumbs', () => {
it('remove heading home when workspace is enabled', () => {
const breadcrumbs$ = new BehaviorSubject([{ text: 'First' }]);
const breadcrumbsEnricher$ = new BehaviorSubject((crumbs: ChromeBreadcrumb[]) => [
{ text: 'Home' },
{ text: 'Home', home: true },
{ text: 'Analytics' },
...crumbs,
]);
Expand All @@ -120,12 +120,22 @@ describe('HeaderBreadcrumbs', () => {
appTitle$={new BehaviorSubject('')}
breadcrumbs$={breadcrumbs$}
breadcrumbsEnricher$={breadcrumbsEnricher$}
hideFirstHome={true}
dropHomeFromBreadcrumb={true}
/>
);
const breadcrumbs = wrapper.find('.euiBreadcrumbWrapper');
expect(breadcrumbs).toHaveLength(2);
expect(breadcrumbs.at(0).text()).toBe('Analytics');
expect(breadcrumbs.at(1).text()).toBe('First');

// if no home property, we don't drop by text
act(() => {
breadcrumbsEnricher$.next((items) => items);
breadcrumbs$.next([{ text: 'Home' }, { text: 'Second' }]);
});
wrapper.update();
expect(breadcrumbs).toHaveLength(2);
expect(breadcrumbs.at(0).text()).toBe('Home');
expect(breadcrumbs.at(1).text()).toBe('Second');
});
});
6 changes: 3 additions & 3 deletions src/core/public/chrome/ui/header/header_breadcrumbs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ interface Props {
breadcrumbsEnricher$: Observable<ChromeBreadcrumbEnricher | undefined>;
useUpdatedHeader?: boolean;
renderFullLength?: boolean;
hideFirstHome?: boolean;
dropHomeFromBreadcrumb?: boolean;
}

export function HeaderBreadcrumbs({
Expand All @@ -50,7 +50,7 @@ export function HeaderBreadcrumbs({
breadcrumbsEnricher$,
useUpdatedHeader,
renderFullLength,
hideFirstHome,
dropHomeFromBreadcrumb,
}: Props) {
const appTitle = useObservable(appTitle$, 'OpenSearch Dashboards');
const breadcrumbs = useObservable(breadcrumbs$, []);
Expand All @@ -75,7 +75,7 @@ export function HeaderBreadcrumbs({
crumbs = breadcrumbEnricher(crumbs);
}

if (hideFirstHome && crumbs[0].text === 'Home') {
if (dropHomeFromBreadcrumb && Object.hasOwn(crumbs[0], 'home')) {
crumbs = crumbs.slice(1);
}

Expand Down
3 changes: 2 additions & 1 deletion src/plugins/workspace/public/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,9 @@ export function prependWorkspaceToBreadcrumbs(
return;
}

const homeBreadcrumb: ChromeBreadcrumb = {
const homeBreadcrumb: ChromeBreadcrumb & { home: boolean } = {
text: 'Home',
home: true,
onClick: () => {
core.application.navigateToApp('home');
},
Expand Down

0 comments on commit b83d54f

Please sign in to comment.