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

Add workspace overview page #19

Merged
merged 4 commits into from
Jun 19, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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: 5 additions & 0 deletions src/plugins/workspace/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,8 @@
export const WORKSPACE_APP_ID = 'workspace';
export const WORKSPACE_APP_NAME = 'Workspace';
export const WORKSPACE_ID_IN_SESSION_STORAGE = '_workspace_id_';

export const PATHS = {
create: '/create',
overview: '/overview',
};
14 changes: 9 additions & 5 deletions src/plugins/workspace/public/components/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { WorkspaceCreator } from './workspace_creator';
import { PATHS } from '../../common/constants';

export const paths = {
create: '/create',
};
import { WorkspaceCreator } from './workspace_creator';
import { WorkspaceOverview } from './workspace_overview';

export interface RouteConfig {
path: string;
Expand All @@ -18,8 +17,13 @@ export interface RouteConfig {

export const ROUTES: RouteConfig[] = [
{
path: paths.create,
path: PATHS.create,
Component: WorkspaceCreator,
label: 'Create',
},
{
path: PATHS.overview,
Component: WorkspaceOverview,
label: 'Overview',
},
];
51 changes: 51 additions & 0 deletions src/plugins/workspace/public/components/workspace_overview.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import React, { useMemo } from 'react';
import { EuiPageHeader, EuiButton, EuiPanel, EuiSpacer, EuiTitle } from '@elastic/eui';
import { useObservable } from 'react-use';
import { switchMap } from 'rxjs/operators';
import { of } from 'rxjs';

import { useOpenSearchDashboards } from '../../../../../src/plugins/opensearch_dashboards_react/public';

export const useCurrentWorkspace = () => {
const {
services: { workspaces },
} = useOpenSearchDashboards();
const workspaceObservable = useMemo(
() =>
workspaces
? workspaces.client.currentWorkspaceId$
.pipe(switchMap((id) => workspaces.client.get(id)))
.pipe(switchMap((response) => (response.success ? of(response.result) : of(null))))
: of(null),
[workspaces]
);

return useObservable(workspaceObservable);
};
Hailong-am marked this conversation as resolved.
Show resolved Hide resolved

export const WorkspaceOverview = () => {
const currentWorkspace = useCurrentWorkspace();
Copy link
Collaborator

Choose a reason for hiding this comment

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

There is a currentWorkspace$ in workspaces, not sure if that can be a substitution of useCurrentWorkspace.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated.

return (
<>
<EuiPageHeader
pageTitle="Overview"
rightSideItems={[
<EuiButton color="danger">Delete</EuiButton>,
<EuiButton>Update</EuiButton>,
]}
/>
<EuiPanel>
<EuiTitle size="m">
<h3>Workspace</h3>
</EuiTitle>
<EuiSpacer />
{JSON.stringify(currentWorkspace)}
</EuiPanel>
</>
);
};
8 changes: 7 additions & 1 deletion src/plugins/workspace/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
AppMountParameters,
AppNavLinkStatus,
} from '../../../core/public';
import { WORKSPACE_APP_ID, WORKSPACE_ID_IN_SESSION_STORAGE } from '../common/constants';
import { WORKSPACE_APP_ID, WORKSPACE_ID_IN_SESSION_STORAGE, PATHS } from '../common/constants';
import { WORKSPACE_ID_QUERYSTRING_NAME } from '../../../core/public';
import { mountDropdownList } from './mount';

Expand Down Expand Up @@ -102,6 +102,12 @@ export class WorkspacesPlugin implements Plugin<{}, {}> {

public start(core: CoreStart) {
mountDropdownList(core);

core.chrome.setCustomNavLink({
title: i18n.translate('workspace.nav.title', { defaultMessage: 'Workspace Overview' }),
baseUrl: core.http.basePath.get(),
href: core.application.getUrlForApp(WORKSPACE_APP_ID, { path: PATHS.overview }),
});
return {};
}
}