Skip to content

Commit

Permalink
fix breadcrumbs not set properly when out a workspace (opensearch-pro…
Browse files Browse the repository at this point in the history
…ject#7432) (opensearch-project#7433)

(cherry picked from commit f872b02)

Signed-off-by: Hailong Cui <[email protected]>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
1 parent a7d8733 commit 5e9e300
Show file tree
Hide file tree
Showing 3 changed files with 15 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
12 changes: 10 additions & 2 deletions src/plugins/workspace/public/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,16 @@ export function prependWorkspaceToBreadcrumbs(
core.chrome.setBreadcrumbsEnricher(undefined);
return;
}

/**
* There has 3 cases
* nav group is enable + workspace enable + in a workspace -> workspace enricher
* nav group is enable + workspace enable + out a workspace -> nav group enricher
* nav group is enable + workspace disabled -> nav group enricher
*
* switch workspace will cause page refresh, breadcrumbs enricher will reset automatically
* so we don't need to have reset logic for workspace
*/
if (currentWorkspace) {
const useCase = getFirstUseCaseOfFeatureConfigs(currentWorkspace?.features || []);
// get workspace the only use case
Expand Down Expand Up @@ -336,7 +346,5 @@ export function prependWorkspaceToBreadcrumbs(
return [homeBreadcrumb, navGroupBreadcrumb, ...breadcrumbs];
}
});
} else {
core.chrome.setBreadcrumbsEnricher(undefined);
}
}

0 comments on commit 5e9e300

Please sign in to comment.