Skip to content

Commit

Permalink
[Workspace] Refactor workspace detail page (#7598) (#7729)
Browse files Browse the repository at this point in the history
* refactor workspace detail page



* Changeset file for PR #7598 created/updated

* add datasource list page



* add workspace detail hash router



* reset useless update



* optimize the code



* add unit tests



* add unit tests



* Fix left navigation overlapped with bottom bar



* update workspace detail use case



* It should only support change to the “ALL” use case



* fix error



* fix errors



* optimize the code



* optimize the code



* fix test error



---------



(cherry picked from commit 2165e03)

Signed-off-by: yubonluo <[email protected]>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
  • Loading branch information
3 people committed Aug 19, 2024
1 parent f6d8e1c commit 034a2c2
Show file tree
Hide file tree
Showing 35 changed files with 2,748 additions and 931 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/7598.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
feat:
- [Workspace] Refactor workspace detail page ([#7598](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/7598))
5 changes: 4 additions & 1 deletion src/plugins/workspace/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@

import { DataSourceAttributes } from 'src/plugins/data_source/common/data_sources';

export type DataSource = Pick<DataSourceAttributes, 'title'> & {
export type DataSource = Pick<
DataSourceAttributes,
'title' | 'description' | 'dataSourceEngineType'
> & {
// Id defined in SavedObjectAttribute could be single or array, here only should be single string.
id: string;
};
10 changes: 9 additions & 1 deletion src/plugins/workspace/public/application.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import React from 'react';
import ReactDOM from 'react-dom';
import { HashRouter as Router, Route, Switch, Redirect } from 'react-router-dom';
import { AppMountParameters, ScopedHistory } from '../../../core/public';
import { OpenSearchDashboardsContextProvider } from '../../opensearch_dashboards_react/public';
import { WorkspaceFatalError } from './components/workspace_fatal_error';
Expand All @@ -14,6 +15,7 @@ import { Services } from './types';
import { WorkspaceCreatorProps } from './components/workspace_creator/workspace_creator';
import { WorkspaceDetailApp } from './components/workspace_detail_app';
import { WorkspaceDetailProps } from './components/workspace_detail/workspace_detail';
import { DetailTab } from './components/workspace_form/constants';

export const renderCreatorApp = (
{ element }: AppMountParameters,
Expand Down Expand Up @@ -70,7 +72,13 @@ export const renderDetailApp = (
) => {
ReactDOM.render(
<OpenSearchDashboardsContextProvider services={services}>
<WorkspaceDetailApp {...props} />
<Router>
<Switch>
<Route>
<WorkspaceDetailApp {...props} />
</Route>
</Switch>
</Router>
</OpenSearchDashboardsContextProvider>,
element
);
Expand Down
27 changes: 18 additions & 9 deletions src/plugins/workspace/public/components/utils/workspace.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,28 @@ describe('workspace utils', () => {

describe('navigateToWorkspaceDetail', () => {
it('should redirect if newUrl is returned', () => {
Object.defineProperty(window, 'location', {
value: {
href: defaultUrl,
},
writable: true,
});
// @ts-ignore
formatUrlWithWorkspaceId.mockImplementation(() => 'new_url');
formatUrlWithWorkspaceId.mockImplementation(() => 'localhost:5601/w/id/app/workspace_detail');
navigateToWorkspaceDetail(
{ application: coreStartMock.application, http: coreStartMock.http },
''
'id'
);
expect(mockNavigateToUrl).toHaveBeenCalledWith(
'localhost:5601/w/id/app/workspace_detail#/?tab=details'
);
});

it('should redirect to collaborators if newUrl is returned and tab id is collaborators', () => {
// @ts-ignore
formatUrlWithWorkspaceId.mockImplementation(() => 'localhost:5601/w/id/app/workspace_detail');
navigateToWorkspaceDetail(
{ application: coreStartMock.application, http: coreStartMock.http },
'id',
'collaborators'
);
expect(mockNavigateToUrl).toHaveBeenCalledWith(
'localhost:5601/w/id/app/workspace_detail#/?tab=collaborators'
);
expect(mockNavigateToUrl).toHaveBeenCalledWith('new_url');
});

it('should not redirect if newUrl is not returned', () => {
Expand Down
11 changes: 9 additions & 2 deletions src/plugins/workspace/public/components/utils/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@
import { WORKSPACE_DETAIL_APP_ID } from '../../../common/constants';
import { CoreStart } from '../../../../../core/public';
import { formatUrlWithWorkspaceId } from '../../../../../core/public/utils';
import { DetailTab } from '../workspace_form/constants';

type Core = Pick<CoreStart, 'application' | 'http'>;

export const navigateToWorkspaceDetail = ({ application, http }: Core, id: string) => {
export const navigateToWorkspaceDetail = (
{ application, http }: Core,
id: string,
tabId: string = DetailTab.Details
) => {
const newUrl = formatUrlWithWorkspaceId(
application.getUrlForApp(WORKSPACE_DETAIL_APP_ID, {
absolute: true,
Expand All @@ -18,6 +23,8 @@ export const navigateToWorkspaceDetail = ({ application, http }: Core, id: strin
http.basePath
);
if (newUrl) {
application.navigateToUrl(newUrl);
const url = new URL(newUrl);
url.hash = `/?tab=${tabId}`;
application.navigateToUrl(url.toString());
}
};
Loading

0 comments on commit 034a2c2

Please sign in to comment.