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

[Workspace]Fix breadcrumbs not set properly when out a workspace #7432

Merged
merged 1 commit into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
Loading