Skip to content

Commit

Permalink
[navigation] display workspace picker content when outside workspace …
Browse files Browse the repository at this point in the history
…and nav group (#7716) (#7880)

* feat: show workspace picker content in left nav

Signed-off-by: SuZhou-Joe <[email protected]>

* fix: bootstrap error

Signed-off-by: SuZhou-Joe <[email protected]>

* fix: unit test error

Signed-off-by: SuZhou-Joe <[email protected]>

* feat: finish picker content

Signed-off-by: SuZhou-Joe <[email protected]>

* feat: finish picker content

Signed-off-by: SuZhou-Joe <[email protected]>

* feat: only register index patterns to settings and setup when workspace is disabled

Signed-off-by: SuZhou-Joe <[email protected]>

* fix: unit test

Signed-off-by: SuZhou-Joe <[email protected]>

* feat: put discover 2.0 behind discover

Signed-off-by: SuZhou-Joe <[email protected]>

* feat: add coverage

Signed-off-by: SuZhou-Joe <[email protected]>

* feat: improve test coverage

Signed-off-by: SuZhou-Joe <[email protected]>

* feat: merge conflict

Signed-off-by: SuZhou-Joe <[email protected]>

* feat: optimize code based on comment

Signed-off-by: SuZhou-Joe <[email protected]>

* feat: optimize code based on comment

Signed-off-by: SuZhou-Joe <[email protected]>

* feat: optimize filter code

Signed-off-by: SuZhou-Joe <[email protected]>

* feat: update

Signed-off-by: SuZhou-Joe <[email protected]>

---------

Signed-off-by: SuZhou-Joe <[email protected]>
(cherry picked from commit 56fc8f4)
  • Loading branch information
SuZhou-Joe authored Aug 28, 2024
1 parent f64a270 commit b02dd2b
Show file tree
Hide file tree
Showing 23 changed files with 907 additions and 1,002 deletions.
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

0 comments on commit b02dd2b

Please sign in to comment.