Skip to content

Commit

Permalink
fix breadcrumbs not set properly when out a workspace
Browse files Browse the repository at this point in the history
Signed-off-by: Hailong Cui <ihailong@amazon.com>
  • Loading branch information
Hailong-am committed Jul 24, 2024
1 parent 67670fd commit 56939e8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import React, { useEffect } from 'react';
import { I18nProvider } from '@osd/i18n/react';
import { i18n } from '@osd/i18n';
import { CoreStart } from 'opensearch-dashboards/public';
import { useObservable } from 'react-use';
import { EuiBreadcrumb } from '@elastic/eui';
Expand Down Expand Up @@ -34,6 +35,9 @@ export const WorkspaceDetailApp = (props: WorkspaceDetailProps) => {
breadcrumbs.push({
text: currentWorkspace.name,
});
breadcrumbs.push({
text: i18n.translate('workspace.detail.breadcrumb', { defaultMessage: 'Workspace Detail' }),
});
}
chrome?.setBreadcrumbs(breadcrumbs);
}, [chrome, currentWorkspace, application]);
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/workspace/public/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ describe('workspace utils: prependWorkspaceToBreadcrumbs', () => {
it('should not enrich breadcrumbs when out a workspace', async () => {
const coreStart = coreMock.createStart();
prependWorkspaceToBreadcrumbs(coreStart, null, 'app1', undefined, {});
expect(coreStart.chrome.setBreadcrumbsEnricher).toHaveBeenCalledWith(undefined);
expect(coreStart.chrome.setBreadcrumbsEnricher).not.toHaveBeenCalled();
});

it('should enrich breadcrumbs when in a workspace and use workspace use case as current nav group', async () => {
Expand Down
7 changes: 5 additions & 2 deletions src/plugins/workspace/public/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,11 @@ export function prependWorkspaceToBreadcrumbs(
core.chrome.setBreadcrumbsEnricher(undefined);
return;
}

/**
* when navigates in/out a workspace, page refreshes and breadcrumbs enricher will reset automatically
* so we don't need to reset the enricher if currentWorkspace is undefined/null
*/
if (currentWorkspace) {
const useCase = getFirstUseCaseOfFeatureConfigs(currentWorkspace?.features || []);
// get workspace the only use case
Expand Down Expand Up @@ -336,7 +341,5 @@ export function prependWorkspaceToBreadcrumbs(
return [homeBreadcrumb, navGroupBreadcrumb, ...breadcrumbs];
}
});
} else {
core.chrome.setBreadcrumbsEnricher(undefined);
}
}

0 comments on commit 56939e8

Please sign in to comment.