Skip to content

Commit

Permalink
feat: add workspace overview page
Browse files Browse the repository at this point in the history
Signed-off-by: Lin Wang <wonglam@amazon.com>
  • Loading branch information
wanglam committed Jun 16, 2023
1 parent 1132fc7 commit 74ade84
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/plugins/workspace/public/components/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
*/

import { WorkspaceCreator } from './workspace_creator';
import { WorkspaceOverview } from './workspace_overview';

export const paths = {
create: '/create',
overview: '/overview',
};

export interface RouteConfig {
Expand All @@ -22,4 +24,9 @@ export const ROUTES: RouteConfig[] = [
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);
};

export const WorkspaceOverview = () => {
const currentWorkspace = useCurrentWorkspace();
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>
</>
);
};

0 comments on commit 74ade84

Please sign in to comment.