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

init workspace menu stage 1 #12

Merged
merged 3 commits into from
Jun 16, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
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);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may use useMemo to optimize the computed / filtered.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your remind. Here I originally planned to be consistent with the original getAllCategories and getOrderedCategories function, I can add it in the next commit.

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