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

[navigation] display workspace picker content when outside workspace and nav group #7716

Merged
Show file tree
Hide file tree
Changes from 15 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
2 changes: 2 additions & 0 deletions changelogs/fragments/7716.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
feat:
- Display workspace picker content when outside workspace ([#7716](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/7716))
50 changes: 47 additions & 3 deletions src/core/public/chrome/nav_group/nav_group_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { uiSettingsServiceMock } from '../../ui_settings/ui_settings_service.moc
import { NavLinksService } from '../nav_links';
import { applicationServiceMock, httpServiceMock, workspacesServiceMock } from '../../mocks';
import { AppCategory } from 'opensearch-dashboards/public';
import { DEFAULT_NAV_GROUPS } from '../../';
import { DEFAULT_NAV_GROUPS, NavGroupStatus, ALL_USE_CASE_ID } from '../../';
import { ChromeBreadcrumbEnricher } from '../chrome_service';

const mockedGroupFoo = {
Expand Down Expand Up @@ -381,7 +381,50 @@ describe('ChromeNavGroupService#start()', () => {
expect(currentNavGroup?.title).toEqual('barGroupTitle');
});

it('should erase current nav group if application is home', async () => {
it('should be able to find the right nav group when visible nav group is all', async () => {
const uiSettings = uiSettingsServiceMock.createSetupContract();
const navGroupEnabled$ = new Rx.BehaviorSubject(true);
uiSettings.get$.mockImplementation(() => navGroupEnabled$);

const chromeNavGroupService = new ChromeNavGroupService();
const chromeNavGroupServiceSetup = chromeNavGroupService.setup({ uiSettings });

chromeNavGroupServiceSetup.addNavLinksToGroup(
{
id: ALL_USE_CASE_ID,
title: 'fooGroupTitle',
description: 'foo description',
},
[mockedNavLinkFoo]
);

chromeNavGroupServiceSetup.addNavLinksToGroup(
{
id: 'bar-group',
title: 'barGroupTitle',
description: 'bar description',
status: NavGroupStatus.Hidden,
},
[mockedNavLinkFoo, mockedNavLinkBar]
);

const chromeNavGroupServiceStart = await chromeNavGroupService.start({
navLinks: mockedNavLinkService,
application: mockedApplicationService,
breadcrumbsEnricher$: new Rx.BehaviorSubject<ChromeBreadcrumbEnricher | undefined>(undefined),
workspaces: workspacesServiceMock.createStartContract(),
});
mockedApplicationService.navigateToApp(mockedNavLinkBar.id);

const currentNavGroup = await chromeNavGroupServiceStart
.getCurrentNavGroup$()
.pipe(first())
.toPromise();

expect(currentNavGroup?.id).toEqual('bar-group');
});

it('should erase current nav group if application can not be found in any of the visible nav groups', async () => {
const uiSettings = uiSettingsServiceMock.createSetupContract();
const navGroupEnabled$ = new Rx.BehaviorSubject(true);
uiSettings.get$.mockImplementation(() => navGroupEnabled$);
Expand All @@ -403,6 +446,7 @@ describe('ChromeNavGroupService#start()', () => {
id: 'bar-group',
title: 'barGroupTitle',
description: 'bar description',
status: NavGroupStatus.Hidden,
},
[mockedNavLinkFoo, mockedNavLinkBar]
);
Expand All @@ -416,7 +460,7 @@ describe('ChromeNavGroupService#start()', () => {

chromeNavGroupServiceStart.setCurrentNavGroup('foo-group');

mockedApplicationService.navigateToApp('home');
mockedApplicationService.navigateToApp(mockedNavLinkBar.id);
const currentNavGroup = await chromeNavGroupServiceStart
.getCurrentNavGroup$()
.pipe(first())
Expand Down
46 changes: 30 additions & 16 deletions src/core/public/chrome/nav_group/nav_group_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,16 @@ import {
import { map, switchMap, takeUntil } from 'rxjs/operators';
import { i18n } from '@osd/i18n';
import { IUiSettingsClient } from '../../ui_settings';
import { fulfillRegistrationLinksToChromeNavLinks, getSortedNavLinks } from '../utils';
import {
fulfillRegistrationLinksToChromeNavLinks,
getSortedNavLinks,
getVisibleUseCases,
} from '../utils';
import { ChromeNavLinks } from '../nav_links';
import { InternalApplicationStart } from '../../application';
import { NavGroupStatus } from '../../../../core/types';
import { ChromeBreadcrumb, ChromeBreadcrumbEnricher } from '../chrome_service';
import { ALL_USE_CASE_ID } from '../../../utils';

export const CURRENT_NAV_GROUP_ID = 'core.chrome.currentNavGroupId';

Expand Down Expand Up @@ -211,7 +216,7 @@ export class ChromeNavGroupService {

const setCurrentNavGroup = (navGroupId: string | undefined) => {
const navGroup = navGroupId ? this.navGroupsMap$.getValue()[navGroupId] : undefined;
if (navGroup && navGroup.status !== NavGroupStatus.Hidden) {
if (navGroup) {
this.currentNavGroup$.next(navGroup);
sessionStorage.setItem(CURRENT_NAV_GROUP_ID, navGroup.id);
} else {
Expand Down Expand Up @@ -254,28 +259,37 @@ export class ChromeNavGroupService {
application.currentAppId$,
this.getSortedNavGroupsMap$(),
]).subscribe(([appId, navGroupMap]) => {
if (appId === 'home') {
setCurrentNavGroup(undefined);
return;
}
if (appId && navGroupMap) {
const appIdNavGroupMap = new Map<string, Set<string>>();
// iterate navGroupMap
Object.keys(navGroupMap)
const visibleUseCases = getVisibleUseCases(navGroupMap);
const mapAppIdToNavGroup = (navGroup: NavGroupItemInMap) => {
navGroup.navLinks.forEach((navLink) => {
const navLinkId = navLink.id;
const navGroupSet = appIdNavGroupMap.get(navLinkId) || new Set();
navGroupSet.add(navGroup.id);
appIdNavGroupMap.set(navLinkId, navGroupSet);
});
};
if (visibleUseCases.length === 1 && visibleUseCases[0].id === ALL_USE_CASE_ID) {
// If the only visible use case is all use case
// All the other nav groups will be visible because all use case can visit all of the nav groups.
Object.values(navGroupMap).forEach((navGroup) => mapAppIdToNavGroup(navGroup));
} else {
// Nav group of Hidden status should be filtered out when counting navGroups the currentApp belongs to
.filter((navGroupId) => navGroupMap[navGroupId].status !== NavGroupStatus.Hidden)
.forEach((navGroupId) => {
navGroupMap[navGroupId].navLinks.forEach((navLink) => {
const navLinkId = navLink.id;
const navGroupSet = appIdNavGroupMap.get(navLinkId) || new Set();
navGroupSet.add(navGroupId);
appIdNavGroupMap.set(navLinkId, navGroupSet);
});
Object.values(navGroupMap).forEach((navGroup) => {
if (navGroup.status === NavGroupStatus.Hidden) {
return;
}

mapAppIdToNavGroup(navGroup);
});
}

const navGroups = appIdNavGroupMap.get(appId);
if (navGroups && navGroups.size === 1) {
setCurrentNavGroup(navGroups.values().next().value);
} else if (!navGroups) {
setCurrentNavGroup(undefined);
}
}
});
Expand Down

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

Loading
Loading