Skip to content

Commit

Permalink
feat: different left menu and exit workspace (opensearch-project#38)
Browse files Browse the repository at this point in the history
* Exit workspace from left menu

Signed-off-by: yuye-aws <[email protected]>

* Show exit workspace button with small window size

Signed-off-by: yuye-aws <[email protected]>

* Remove recently viewed and workspace overview on left menu

Signed-off-by: yuye-aws <[email protected]>

* Add buttons for outside, inside workspace case

Signed-off-by: yuye-aws <[email protected]>

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

Signed-off-by: yuye-aws <[email protected]>

* Implement workspace dropdown list in left menu

Signed-off-by: yuye-aws <[email protected]>

* Add props on recently accessed and custom nav link

Signed-off-by: yuye-aws <[email protected]>

* Add three props to mock props for collapsible nav: exitWorkspace, getWorkspaceUrl, workspaceList$

Signed-off-by: yuye-aws <[email protected]>

* Add three props to mock props for header: exitWorkspace, getWorkspaceUrl, workspaceList$

Signed-off-by: yuye-aws <[email protected]>

* Fix bugs for function createWorkspaceNavLink

Signed-off-by: yuye-aws <[email protected]>

* Remove unused constants

Signed-off-by: yuye-aws <[email protected]>

* Reuse method getWorkspaceUrl

Signed-off-by: yuye-aws <[email protected]>

* Remove recently accessed and custom nav props in test

Signed-off-by: yuye-aws <[email protected]>

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

This reverts commit 7895e5c.

* Wrap title with i18n

Signed-off-by: yuye-aws <[email protected]>

* Add redirect for workspace app

Signed-off-by: yuye-aws <[email protected]>

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

Signed-off-by: yuye-aws <[email protected]>

---------

Signed-off-by: yuye-aws <[email protected]>
  • Loading branch information
yuye-aws authored and Hailong-am committed Jul 18, 2023
1 parent e01963c commit 2a4261a
Show file tree
Hide file tree
Showing 9 changed files with 326 additions and 169 deletions.
43 changes: 41 additions & 2 deletions src/core/public/chrome/chrome_service.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,15 @@ 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 } from './constants';
import { OPENSEARCH_DASHBOARDS_ASK_OPENSEARCH_LINK, WORKSPACE_APP_ID } from './constants';
import { ChromeDocTitle, DocTitleService } from './doc_title';
import { ChromeNavControls, NavControlsService } from './nav_controls';
import { ChromeNavLinks, NavLinksService, ChromeNavLink } from './nav_links';
Expand Down Expand Up @@ -180,6 +181,41 @@ 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 @@ -245,7 +281,6 @@ export class ChromeService {
badge$={badge$.pipe(takeUntil(this.stop$))}
basePath={http.basePath}
breadcrumbs$={breadcrumbs$.pipe(takeUntil(this.stop$))}
customNavLink$={customNavLink$.pipe(takeUntil(this.stop$))}
opensearchDashboardsDocLink={docLinks.links.opensearchDashboards.introduction}
forceAppSwitcherNavigation$={navLinks.getForceAppSwitcherNavigation$()}
helpExtension$={helpExtension$.pipe(takeUntil(this.stop$))}
Expand All @@ -254,17 +289,21 @@ export class ChromeService {
isVisible$={this.isVisible$}
opensearchDashboardsVersion={injectedMetadata.getOpenSearchDashboardsVersion()}
navLinks$={navLinks.getNavLinks$()}
customNavLink$={customNavLink$.pipe(takeUntil(this.stop$))}
recentlyAccessed$={recentlyAccessed.get$()}
navControlsLeft$={navControls.getLeft$()}
navControlsCenter$={navControls.getCenter$()}
navControlsRight$={navControls.getRight$()}
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: 6 additions & 0 deletions src/core/public/chrome/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,9 @@
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',
};
3 changes: 3 additions & 0 deletions src/core/public/chrome/ui/header/collapsible_nav.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,11 @@ function mockProps() {
closeNav: () => {},
navigateToApp: () => Promise.resolve(),
navigateToUrl: () => Promise.resolve(),
exitWorkspace: () => {},
getWorkspaceUrl: (id: string) => '',
customNavLink$: new BehaviorSubject(undefined),
currentWorkspace$: workspacesServiceMock.createStartContract().client.currentWorkspace$,
workspaceList$: workspacesServiceMock.createStartContract().client.workspaceList$,
branding: {
darkMode: false,
mark: {
Expand Down
Loading

0 comments on commit 2a4261a

Please sign in to comment.