Skip to content

Commit

Permalink
init workspace menu stage 1 (#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 committed Jun 16, 2023
1 parent aba31ba commit 1132fc7
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 '../';
export { ChromeNavControls, ChromeRecentlyAccessed, ChromeDocTitle };

const IS_LOCKED_KEY = 'core.chrome.isLocked';
Expand Down Expand Up @@ -99,6 +99,7 @@ interface StartDeps {
injectedMetadata: InjectedMetadataStart;
notifications: NotificationsStart;
uiSettings: IUiSettingsClient;
workspaces: WorkspacesStart;
}

/** @internal */
Expand Down Expand Up @@ -152,6 +153,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 {
isLocked$={getIsNavDrawerLocked$}
branding={injectedMetadata.getBranding()}
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 { ChromeBranding } from '../../chrome_service';
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>;
branding: ChromeBranding;
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 @@ -145,6 +150,24 @@ export function CollapsibleNav({
const markDefault = branding.mark?.defaultUrl;
const markDarkMode = branding.mark?.darkModeUrl;

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;
}

/**
* Use branding configurations to check which URL to use for rendering
* side menu opensearch logo in default mode
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 @@ -42,7 +42,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 @@ -63,6 +63,7 @@ import { HomeLoader } from './home_loader';
import { HeaderNavControls } from './header_nav_controls';
import { HeaderActionMenu } from './header_action_menu';
import { HeaderLogo } from './header_logo';
import { WorkspaceAttribute } from '../../../workspace';

export interface HeaderProps {
opensearchDashboardsVersion: string;
Expand Down Expand Up @@ -90,6 +91,7 @@ export interface HeaderProps {
onIsLockedUpdate: OnIsLockedUpdate;
branding: ChromeBranding;
survey: string | undefined;
currentWorkspace$: BehaviorSubject<WorkspaceAttribute | null>;
}

export function Header({
Expand Down Expand Up @@ -255,6 +257,7 @@ export function Header({
}}
customNavLink$={observables.customNavLink$}
branding={branding}
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 1132fc7

Please sign in to comment.