From 56939e857d23bed9cad55837278ced926d86a5a9 Mon Sep 17 00:00:00 2001 From: Hailong Cui Date: Wed, 24 Jul 2024 10:57:04 +0800 Subject: [PATCH] fix breadcrumbs not set properly when out a workspace Signed-off-by: Hailong Cui --- .../workspace/public/components/workspace_detail_app.tsx | 4 ++++ src/plugins/workspace/public/utils.test.ts | 2 +- src/plugins/workspace/public/utils.ts | 7 +++++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/plugins/workspace/public/components/workspace_detail_app.tsx b/src/plugins/workspace/public/components/workspace_detail_app.tsx index 2236cd67c139..294851502567 100644 --- a/src/plugins/workspace/public/components/workspace_detail_app.tsx +++ b/src/plugins/workspace/public/components/workspace_detail_app.tsx @@ -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'; @@ -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]); diff --git a/src/plugins/workspace/public/utils.test.ts b/src/plugins/workspace/public/utils.test.ts index 5c91effc4146..0f31a70722a1 100644 --- a/src/plugins/workspace/public/utils.test.ts +++ b/src/plugins/workspace/public/utils.test.ts @@ -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 () => { diff --git a/src/plugins/workspace/public/utils.ts b/src/plugins/workspace/public/utils.ts index e1093495c049..bed2cf257df6 100644 --- a/src/plugins/workspace/public/utils.ts +++ b/src/plugins/workspace/public/utils.ts @@ -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 @@ -336,7 +341,5 @@ export function prependWorkspaceToBreadcrumbs( return [homeBreadcrumb, navGroupBreadcrumb, ...breadcrumbs]; } }); - } else { - core.chrome.setBreadcrumbsEnricher(undefined); } }