Skip to content

Commit

Permalink
init workspace menu stage 1 (opensearch-project#12)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
raintygao authored and ruanyl committed Sep 15, 2023
1 parent 0ed84c1 commit 2b143cd
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 4 deletions.
5 changes: 4 additions & 1 deletion src/core/public/chrome/chrome_service.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import { ChromeNavLinks, NavLinksService, ChromeNavLink } from './nav_links';
import { ChromeRecentlyAccessed, RecentlyAccessedService } from './recently_accessed';
import { Header } from './ui';
import { ChromeHelpExtensionMenuLink } from './ui/header/header_help_menu';
import { Branding } from '../';
import { Branding, WorkspacesStart } from '../';
import { getLogos } from '../../common';
import type { Logos } from '../../common/types';

Expand Down Expand Up @@ -96,6 +96,7 @@ interface StartDeps {
injectedMetadata: InjectedMetadataStart;
notifications: NotificationsStart;
uiSettings: IUiSettingsClient;
workspaces: WorkspacesStart;
}

/** @internal */
Expand Down Expand Up @@ -149,6 +150,7 @@ export class ChromeService {
injectedMetadata,
notifications,
uiSettings,
workspaces,
}: StartDeps): Promise<InternalChromeStart> {
this.initVisibility(application);

Expand Down Expand Up @@ -262,6 +264,7 @@ export class ChromeService {
branding={injectedMetadata.getBranding()}
logos={logos}
survey={injectedMetadata.getSurvey()}
currentWorkspace$={workspaces.client.currentWorkspace$}
/>
),

Expand Down
27 changes: 25 additions & 2 deletions src/core/public/chrome/ui/header/collapsible_nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import { HttpStart } from '../../../http';
import { OnIsLockedUpdate } from './';
import { createEuiListItem, createRecentNavLink, isModifiedOrPrevented } from './nav_link';
import type { Logos } from '../../../../common/types';
import { WorkspaceAttribute } from '../../../workspace';

function getAllCategories(allCategorizedLinks: Record<string, ChromeNavLink[]>) {
const allCategories = {} as Record<string, AppCategory | undefined>;
Expand Down Expand Up @@ -102,6 +103,7 @@ interface Props {
navigateToUrl: InternalApplicationStart['navigateToUrl'];
customNavLink$: Rx.Observable<ChromeNavLink | undefined>;
logos: Logos;
currentWorkspace$: Rx.BehaviorSubject<WorkspaceAttribute | null>;
}

export function CollapsibleNav({
Expand All @@ -122,11 +124,14 @@ export function CollapsibleNav({
const recentlyAccessed = useObservable(observables.recentlyAccessed$, []);
const customNavLink = useObservable(observables.customNavLink$, undefined);
const appId = useObservable(observables.appId$, '');
const currentWorkspace = useObservable(observables.currentWorkspace$);
const lockRef = useRef<HTMLButtonElement>(null);
const groupedNavLinks = groupBy(navLinks, (link) => link?.category?.id);
const { undefined: unknowns = [], ...allCategorizedLinks } = groupedNavLinks;
const categoryDictionary = getAllCategories(allCategorizedLinks);
const orderedCategories = getOrderedCategories(allCategorizedLinks, categoryDictionary);
const filterdLinks = getFilterLinks(currentWorkspace, allCategorizedLinks);
const categoryDictionary = getAllCategories(filterdLinks);
const orderedCategories = getOrderedCategories(filterdLinks, categoryDictionary);

const readyForEUI = (link: ChromeNavLink, needsIcon: boolean = false) => {
return createEuiListItem({
link,
Expand All @@ -138,6 +143,24 @@ export function CollapsibleNav({
});
};

function getFilterLinks(
workspace: WorkspaceAttribute | null | undefined,
categorizedLinks: Record<string, ChromeNavLink[]>
) {
// plugins are in this dictionary
const pluginsDictionary = categorizedLinks.opensearch;
if (!pluginsDictionary) return categorizedLinks;

const features = workspace?.features ?? [];
const newPluginsDictionary = pluginsDictionary.filter((item) => features.indexOf(item.id) > -1);
if (newPluginsDictionary.length === 0) {
delete categorizedLinks.opensearch;
} else {
categorizedLinks.opensearch = newPluginsDictionary;
}
return categorizedLinks;
}

return (
<EuiCollapsibleNav
data-test-subj="collapsibleNav"
Expand Down
5 changes: 4 additions & 1 deletion src/core/public/chrome/ui/header/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import { i18n } from '@osd/i18n';
import classnames from 'classnames';
import React, { createRef, useState } from 'react';
import useObservable from 'react-use/lib/useObservable';
import { Observable } from 'rxjs';
import { Observable, BehaviorSubject } from 'rxjs';
import { LoadingIndicator } from '../';
import {
ChromeBadge,
Expand All @@ -65,6 +65,7 @@ import { HeaderNavControls } from './header_nav_controls';
import { HeaderActionMenu } from './header_action_menu';
import { HeaderLogo } from './header_logo';
import type { Logos } from '../../../../common/types';
import { WorkspaceAttribute } from '../../../workspace';

export interface HeaderProps {
opensearchDashboardsVersion: string;
Expand Down Expand Up @@ -93,6 +94,7 @@ export interface HeaderProps {
branding: ChromeBranding;
logos: Logos;
survey: string | undefined;
currentWorkspace$: BehaviorSubject<WorkspaceAttribute | null>;
}

export function Header({
Expand Down Expand Up @@ -264,6 +266,7 @@ export function Header({
}}
customNavLink$={observables.customNavLink$}
logos={logos}
currentWorkspace$={observables.currentWorkspace$}
/>
</header>
</>
Expand Down
1 change: 1 addition & 0 deletions src/core/public/core_system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ export class CoreSystem {
injectedMetadata,
notifications,
uiSettings,
workspaces,
});

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

0 comments on commit 2b143cd

Please sign in to comment.