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

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

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

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

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

* Fix bugs for function createWorkspaceNavLink

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

* Remove unused constants

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>

---------

Signed-off-by: yuye-aws <yuyezhu@amazon.com>
  • Loading branch information
yuye-aws authored and SuZhou-Joe committed Aug 31, 2023
1 parent f0d770e commit 147b3e0
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 @@ -35,14 +35,15 @@ import { BehaviorSubject, combineLatest, merge, Observable, of, ReplaySubject }
import { flatMap, map, takeUntil } from 'rxjs/operators';
import { parse } from 'url';
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 @@ -181,6 +182,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 @@ -246,7 +282,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 @@ -255,17 +290,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 147b3e0

Please sign in to comment.