Skip to content

Commit 42d1a51

Browse files
raintygaoruanyl
authored andcommitted
init workspace menu stage 1 (opensearch-project#12)
* feat: init workspace menu stage 1 Signed-off-by: tygao <tygao@amazon.com> * fix: remove port diff Signed-off-by: tygao <tygao@amazon.com> * feat: update menu logic Signed-off-by: tygao <tygao@amazon.com> --------- Signed-off-by: tygao <tygao@amazon.com>
1 parent cf16249 commit 42d1a51

File tree

4 files changed

+34
-4
lines changed

4 files changed

+34
-4
lines changed

src/core/public/chrome/chrome_service.tsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ import { ChromeNavLinks, NavLinksService, ChromeNavLink } from './nav_links';
4848
import { ChromeRecentlyAccessed, RecentlyAccessedService } from './recently_accessed';
4949
import { Header } from './ui';
5050
import { ChromeHelpExtensionMenuLink } from './ui/header/header_help_menu';
51-
import { Branding } from '../';
51+
import { Branding, WorkspacesStart } from '../';
5252
export { ChromeNavControls, ChromeRecentlyAccessed, ChromeDocTitle };
5353

5454
const IS_LOCKED_KEY = 'core.chrome.isLocked';
@@ -99,6 +99,7 @@ interface StartDeps {
9999
injectedMetadata: InjectedMetadataStart;
100100
notifications: NotificationsStart;
101101
uiSettings: IUiSettingsClient;
102+
workspaces: WorkspacesStart;
102103
}
103104

104105
/** @internal */
@@ -152,6 +153,7 @@ export class ChromeService {
152153
injectedMetadata,
153154
notifications,
154155
uiSettings,
156+
workspaces,
155157
}: StartDeps): Promise<InternalChromeStart> {
156158
this.initVisibility(application);
157159

@@ -262,6 +264,7 @@ export class ChromeService {
262264
isLocked$={getIsNavDrawerLocked$}
263265
branding={injectedMetadata.getBranding()}
264266
survey={injectedMetadata.getSurvey()}
267+
currentWorkspace$={workspaces.client.currentWorkspace$}
265268
/>
266269
),
267270

src/core/public/chrome/ui/header/collapsible_nav.tsx

+25-2
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import { HttpStart } from '../../../http';
5151
import { OnIsLockedUpdate } from './';
5252
import { createEuiListItem, createRecentNavLink, isModifiedOrPrevented } from './nav_link';
5353
import { ChromeBranding } from '../../chrome_service';
54+
import { WorkspaceAttribute } from '../../../workspace';
5455

5556
function getAllCategories(allCategorizedLinks: Record<string, ChromeNavLink[]>) {
5657
const allCategories = {} as Record<string, AppCategory | undefined>;
@@ -102,6 +103,7 @@ interface Props {
102103
navigateToUrl: InternalApplicationStart['navigateToUrl'];
103104
customNavLink$: Rx.Observable<ChromeNavLink | undefined>;
104105
branding: ChromeBranding;
106+
currentWorkspace$: Rx.BehaviorSubject<WorkspaceAttribute | null>;
105107
}
106108

107109
export function CollapsibleNav({
@@ -122,11 +124,14 @@ export function CollapsibleNav({
122124
const recentlyAccessed = useObservable(observables.recentlyAccessed$, []);
123125
const customNavLink = useObservable(observables.customNavLink$, undefined);
124126
const appId = useObservable(observables.appId$, '');
127+
const currentWorkspace = useObservable(observables.currentWorkspace$);
125128
const lockRef = useRef<HTMLButtonElement>(null);
126129
const groupedNavLinks = groupBy(navLinks, (link) => link?.category?.id);
127130
const { undefined: unknowns = [], ...allCategorizedLinks } = groupedNavLinks;
128-
const categoryDictionary = getAllCategories(allCategorizedLinks);
129-
const orderedCategories = getOrderedCategories(allCategorizedLinks, categoryDictionary);
131+
const filterdLinks = getFilterLinks(currentWorkspace, allCategorizedLinks);
132+
const categoryDictionary = getAllCategories(filterdLinks);
133+
const orderedCategories = getOrderedCategories(filterdLinks, categoryDictionary);
134+
130135
const readyForEUI = (link: ChromeNavLink, needsIcon: boolean = false) => {
131136
return createEuiListItem({
132137
link,
@@ -145,6 +150,24 @@ export function CollapsibleNav({
145150
const markDefault = branding.mark?.defaultUrl;
146151
const markDarkMode = branding.mark?.darkModeUrl;
147152

153+
function getFilterLinks(
154+
workspace: WorkspaceAttribute | null | undefined,
155+
categorizedLinks: Record<string, ChromeNavLink[]>
156+
) {
157+
// plugins are in this dictionary
158+
const pluginsDictionary = categorizedLinks.opensearch;
159+
if (!pluginsDictionary) return categorizedLinks;
160+
161+
const features = workspace?.features ?? [];
162+
const newPluginsDictionary = pluginsDictionary.filter((item) => features.indexOf(item.id) > -1);
163+
if (newPluginsDictionary.length === 0) {
164+
delete categorizedLinks.opensearch;
165+
} else {
166+
categorizedLinks.opensearch = newPluginsDictionary;
167+
}
168+
return categorizedLinks;
169+
}
170+
148171
/**
149172
* Use branding configurations to check which URL to use for rendering
150173
* side menu opensearch logo in default mode

src/core/public/chrome/ui/header/header.tsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ import { i18n } from '@osd/i18n';
4343
import classnames from 'classnames';
4444
import React, { createRef, useState } from 'react';
4545
import useObservable from 'react-use/lib/useObservable';
46-
import { Observable } from 'rxjs';
46+
import { Observable, BehaviorSubject } from 'rxjs';
4747
import { LoadingIndicator } from '../';
4848
import {
4949
ChromeBadge,
@@ -64,6 +64,7 @@ import { HomeLoader } from './home_loader';
6464
import { HeaderNavControls } from './header_nav_controls';
6565
import { HeaderActionMenu } from './header_action_menu';
6666
import { HeaderLogo } from './header_logo';
67+
import { WorkspaceAttribute } from '../../../workspace';
6768

6869
export interface HeaderProps {
6970
opensearchDashboardsVersion: string;
@@ -91,6 +92,7 @@ export interface HeaderProps {
9192
onIsLockedUpdate: OnIsLockedUpdate;
9293
branding: ChromeBranding;
9394
survey: string | undefined;
95+
currentWorkspace$: BehaviorSubject<WorkspaceAttribute | null>;
9496
}
9597

9698
export function Header({
@@ -260,6 +262,7 @@ export function Header({
260262
}}
261263
customNavLink$={observables.customNavLink$}
262264
branding={branding}
265+
currentWorkspace$={observables.currentWorkspace$}
263266
/>
264267
</header>
265268
</>

src/core/public/core_system.ts

+1
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ export class CoreSystem {
233233
injectedMetadata,
234234
notifications,
235235
uiSettings,
236+
workspaces,
236237
});
237238

238239
this.coreApp.start({ application, http, notifications, uiSettings });

0 commit comments

Comments
 (0)