Skip to content

Commit

Permalink
Refactor navigation links from left menu hard code to workspace plugi…
Browse files Browse the repository at this point in the history
…n register (opensearch-project#55)

* feature: add public/workspaces service

Signed-off-by: SuZhoue-Joe <suzhou@amazon.com>

* Exit workspace from left menu

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* Show exit workspace button with small window size

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* Remove recently viewed and workspace overview on left menu

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* Add buttons for outside, inside workspace case

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* Implement home button and workspace over view button on left menu

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* Implement workspace dropdown list in left menu

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* Add props on recently accessed and custom nav link

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* Reuse method getWorkspaceUrl

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* Remove recently accessed and custom nav props in test

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* Revert "Remove recently accessed and custom nav props in test"

This reverts commit 7895e5c.

* Wrap title with i18n

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* Add redirect for workspace app

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* Enable users to go to workspace lists page via see more under workspaces in left menu

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* Fix build error and part of test error (opensearch-project#42)

* fix: fix build error and some ut

Signed-off-by: tygao <tygao@amazon.com>

* chore: remove saved object client test diff

Signed-off-by: tygao <tygao@amazon.com>

---------

Signed-off-by: tygao <tygao@amazon.com>

* Comment Alerts and Favorites in left menu

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* Recover recently viewed items in left menu

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* Move exit workspace from left menu to update page

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* Remove unused import

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* Add workspace category info

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* Remove workspace nav link

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* Remove unused import

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* Add FilteredNavLinks props to chrome service mock

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* Remove workspace related constans from chrome

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* Remove workspace related props from chrome and core

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* Remove workspace related props from header

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* Shorten import path for workspace updater

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* Add euiIconType for workspace left menu category

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* Remove workspace related props for collapsible nav

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* Remove workspace related props for collapsible nav

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* Implement navigation for delete and exit workspace

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* Navigate external links through url change

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* Implement filteredNavLinks and sort ChromeNavLinks in nav link service

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* Add workspace list, see more, admin and overview into chromenavlinks

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* fix: unit test failure (opensearch-project#50)

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

* Fix osd bootstrap error

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* Check workspace enabled for left menu

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* Add home nav link to left menu when outside workspace

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* Fix unit test for collapsible nav

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* Fix unit test for header

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* Fix unit test for collapsible nav

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* Fix unit test for collapsible nav

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* Update snapshot for unit tests

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* fix osd bootstrap error

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* fix combinelatest import error

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* update snapshot for unit tests

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* variable rename

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* move custom nav link to mock props

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* move default filtered nav link to core

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* change navigation method in workspace updater

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* Update src/plugins/workspace/public/components/workspace_updater/workspace_updater.tsx

Co-authored-by: SuZhou-Joe <suzhou@amazon.com>

* revert some unncessary changes

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* fix navigation url bug

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* move default filtered nav link value setting from core to workspace plugin

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* move filter nav link to a new function

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* process filter nav links when workspace is disabled

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* change navigation method

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

---------

Signed-off-by: SuZhoue-Joe <suzhou@amazon.com>
Signed-off-by: yuye-aws <yuyezhu@amazon.com>
Signed-off-by: tygao <tygao@amazon.com>
Signed-off-by: SuZhou-Joe <suzhou@amazon.com>
Co-authored-by: SuZhoue-Joe <suzhou@amazon.com>
Co-authored-by: raintygao <tygao@amazon.com>
  • Loading branch information
3 people authored and ruanyl committed Aug 3, 2023
1 parent 444d7f6 commit ed560b9
Show file tree
Hide file tree
Showing 16 changed files with 4,078 additions and 5,900 deletions.
2 changes: 2 additions & 0 deletions src/core/public/chrome/chrome_service.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ const createStartContractMock = () => {
getHeaderComponent: jest.fn(),
navLinks: {
getNavLinks$: jest.fn(),
getFilteredNavLinks$: jest.fn(),
setFilteredNavLinks: jest.fn(),
has: jest.fn(),
get: jest.fn(),
getAll: jest.fn(),
Expand Down
48 changes: 3 additions & 45 deletions src/core/public/chrome/chrome_service.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,21 @@ import { FormattedMessage } from '@osd/i18n/react';
import { BehaviorSubject, combineLatest, merge, Observable, of, ReplaySubject } from 'rxjs';
import { flatMap, map, takeUntil } from 'rxjs/operators';
import { EuiLink } from '@elastic/eui';
import { i18n } from '@osd/i18n';
import { mountReactNode } from '../utils/mount';
import { InternalApplicationStart } from '../application';
import { DocLinksStart } from '../doc_links';
import { HttpStart } from '../http';
import { InjectedMetadataStart } from '../injected_metadata';
import { NotificationsStart } from '../notifications';
import { IUiSettingsClient } from '../ui_settings';
import { OPENSEARCH_DASHBOARDS_ASK_OPENSEARCH_LINK, WORKSPACE_APP_ID } from './constants';
import { OPENSEARCH_DASHBOARDS_ASK_OPENSEARCH_LINK } from './constants';
import { ChromeDocTitle, DocTitleService } from './doc_title';
import { ChromeNavControls, NavControlsService } from './nav_controls';
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, WorkspacesStart } from '../';
import { Branding } from '../';
export { ChromeNavControls, ChromeRecentlyAccessed, ChromeDocTitle };

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

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

Expand All @@ -181,41 +178,6 @@ export class ChromeService {
docTitle.reset();
});

const getWorkspaceUrl = (id: string) => {
return workspaces.formatUrlWithWorkspaceId(
application.getUrlForApp(WORKSPACE_APP_ID, {
path: '/',
absolute: true,
}),
id
);
};

const exitWorkspace = async () => {
let result;
try {
result = await workspaces.client.exitWorkspace();
} catch (error) {
notifications?.toasts.addDanger({
title: i18n.translate('workspace.exit.failed', {
defaultMessage: 'Failed to exit workspace',
}),
text: error instanceof Error ? error.message : JSON.stringify(error),
});
return;
}
if (!result?.success) {
notifications?.toasts.addDanger({
title: i18n.translate('workspace.exit.failed', {
defaultMessage: 'Failed to exit workspace',
}),
text: result?.error,
});
return;
}
await application.navigateToApp('home');
};

const setIsNavDrawerLocked = (isLocked: boolean) => {
isNavDrawerLocked$.next(isLocked);
localStorage.setItem(IS_LOCKED_KEY, `${isLocked}`);
Expand Down Expand Up @@ -288,7 +250,7 @@ export class ChromeService {
homeHref={http.basePath.prepend('/app/home')}
isVisible$={this.isVisible$}
opensearchDashboardsVersion={injectedMetadata.getOpenSearchDashboardsVersion()}
navLinks$={navLinks.getNavLinks$()}
navLinks$={navLinks.getFilteredNavLinks$()}
customNavLink$={customNavLink$.pipe(takeUntil(this.stop$))}
recentlyAccessed$={recentlyAccessed.get$()}
navControlsLeft$={navControls.getLeft$()}
Expand All @@ -297,13 +259,9 @@ export class ChromeService {
navControlsExpandedCenter$={navControls.getExpandedCenter$()}
navControlsExpandedRight$={navControls.getExpandedRight$()}
onIsLockedUpdate={setIsNavDrawerLocked}
exitWorkspace={exitWorkspace}
getWorkspaceUrl={getWorkspaceUrl}
isLocked$={getIsNavDrawerLocked$}
branding={injectedMetadata.getBranding()}
survey={injectedMetadata.getSurvey()}
currentWorkspace$={workspaces.client.currentWorkspace$}
workspaceList$={workspaces.client.workspaceList$}
/>
),

Expand Down
6 changes: 0 additions & 6 deletions src/core/public/chrome/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,3 @@
export const OPENSEARCH_DASHBOARDS_ASK_OPENSEARCH_LINK = 'https://forum.opensearch.org/';
export const GITHUB_CREATE_ISSUE_LINK =
'https://github.com/opensearch-project/OpenSearch-Dashboards/issues/new/choose';

export const WORKSPACE_APP_ID = 'workspace';

export const PATHS = {
list: '/list',
};
5 changes: 5 additions & 0 deletions src/core/public/chrome/nav_links/nav_link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ export interface ChromeNavLink {
* Hides a link from the navigation.
*/
readonly hidden?: boolean;

/**
* Links can be navigated through url.
*/
readonly externalLink?: boolean;
}

/** @public */
Expand Down
26 changes: 26 additions & 0 deletions src/core/public/chrome/nav_links/nav_links_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ export interface ChromeNavLinks {
*/
getNavLinks$(): Observable<Array<Readonly<ChromeNavLink>>>;

/**
* Set an observable for a sorted list of filtered navlinks.
*/
getFilteredNavLinks$(): Observable<Array<Readonly<ChromeNavLink>>>;

/**
* Set filtered navlinks.
*/
setFilteredNavLinks(filteredNavLinks: ReadonlyMap<string, ChromeNavLink>): void;

/**
* Get the state of a navlink at this point in time.
* @param id
Expand Down Expand Up @@ -116,6 +126,7 @@ type LinksUpdater = (navLinks: Map<string, NavLinkWrapper>) => Map<string, NavLi

export class NavLinksService {
private readonly stop$ = new ReplaySubject(1);
private filteredNavLinks$ = new BehaviorSubject<ReadonlyMap<string, ChromeNavLink>>(new Map());

public start({ application, http }: StartDeps): ChromeNavLinks {
const appLinks$ = application.applications$.pipe(
Expand Down Expand Up @@ -151,6 +162,14 @@ export class NavLinksService {
return navLinks$.pipe(map(sortNavLinks), takeUntil(this.stop$));
},

setFilteredNavLinks: (filteredNavLinks: ReadonlyMap<string, ChromeNavLink>) => {
this.filteredNavLinks$.next(filteredNavLinks);
},

getFilteredNavLinks$: () => {
return this.filteredNavLinks$.pipe(map(sortChromeNavLinks), takeUntil(this.stop$));
},

get(id: string) {
const link = navLinks$.value.get(id);
return link && link.properties;
Expand Down Expand Up @@ -215,3 +234,10 @@ function sortNavLinks(navLinks: ReadonlyMap<string, NavLinkWrapper>) {
'order'
);
}

function sortChromeNavLinks(chromeNavLinks: ReadonlyMap<string, ChromeNavLink>) {
return sortBy(
[...chromeNavLinks.values()].map((link) => link as Readonly<ChromeNavLink>),
'order'
);
}
Loading

0 comments on commit ed560b9

Please sign in to comment.