From c3517516138219552d15ce43d9f95a95007c7549 Mon Sep 17 00:00:00 2001 From: Hailong Cui Date: Wed, 10 Apr 2024 16:16:47 +0800 Subject: [PATCH] replace default workspace with public workspace Signed-off-by: Hailong Cui --- src/core/public/index.ts | 7 +++- src/core/server/index.ts | 2 +- src/core/utils/constants.ts | 14 +++++--- src/core/utils/index.ts | 2 +- .../saved_objects_table.test.tsx | 6 ++-- .../objects_table/saved_objects_table.tsx | 33 ++++++++++--------- .../server/routes/scroll_count.ts | 6 ++-- .../workspace/server/workspace_client.ts | 5 ++- 8 files changed, 43 insertions(+), 32 deletions(-) diff --git a/src/core/public/index.ts b/src/core/public/index.ts index a5c06f3c96ed..0dc37587032e 100644 --- a/src/core/public/index.ts +++ b/src/core/public/index.ts @@ -356,6 +356,11 @@ export { __osdBootstrap__ } from './osd_bootstrap'; export { WorkspacesStart, WorkspacesSetup, WorkspacesService } from './workspace'; -export { WORKSPACE_TYPE, cleanWorkspaceId, DEFAULT_WORKSPACE_ID } from '../utils'; +export { + WORKSPACE_TYPE, + cleanWorkspaceId, + PUBLIC_WORKSPACE_ID, + PUBLIC_WORKSPACE_NAME, +} from '../utils'; export { debounce } from './utils'; diff --git a/src/core/server/index.ts b/src/core/server/index.ts index f497bed22755..9ec85aff0376 100644 --- a/src/core/server/index.ts +++ b/src/core/server/index.ts @@ -356,8 +356,8 @@ export { AppCategory, WorkspaceAttribute } from '../types'; export { DEFAULT_APP_CATEGORIES, PUBLIC_WORKSPACE_ID, + PUBLIC_WORKSPACE_NAME, WORKSPACE_TYPE, - DEFAULT_WORKSPACE_ID, } from '../utils'; export { diff --git a/src/core/utils/constants.ts b/src/core/utils/constants.ts index 5c2a24f59b0d..c05d2b06e041 100644 --- a/src/core/utils/constants.ts +++ b/src/core/utils/constants.ts @@ -3,14 +3,18 @@ * SPDX-License-Identifier: Apache-2.0 */ +import { i18n } from '@osd/i18n'; + export const WORKSPACE_TYPE = 'workspace'; export const WORKSPACE_PATH_PREFIX = '/w'; -export const PUBLIC_WORKSPACE_ID = 'public'; - /** - * deafult workspace is a virtual workspace, - * saved objects without any workspaces are consider belongs to default workspace + * public workspace has parity with global tenant, + * it includes saved objects with `public` as its workspace or without any workspce info */ -export const DEFAULT_WORKSPACE_ID = 'default'; +export const PUBLIC_WORKSPACE_ID = 'public'; + +export const PUBLIC_WORKSPACE_NAME = i18n.translate('workspaces.public.workspace.default.name', { + defaultMessage: 'Global workspace', +}); diff --git a/src/core/utils/index.ts b/src/core/utils/index.ts index e2f5fd90460a..d15ee2d538aa 100644 --- a/src/core/utils/index.ts +++ b/src/core/utils/index.ts @@ -41,6 +41,6 @@ export { getWorkspaceIdFromUrl, formatUrlWithWorkspaceId, cleanWorkspaceId } fro export { WORKSPACE_PATH_PREFIX, PUBLIC_WORKSPACE_ID, + PUBLIC_WORKSPACE_NAME, WORKSPACE_TYPE, - DEFAULT_WORKSPACE_ID, } from './constants'; diff --git a/src/plugins/saved_objects_management/public/management_section/objects_table/saved_objects_table.test.tsx b/src/plugins/saved_objects_management/public/management_section/objects_table/saved_objects_table.test.tsx index 8f895419400d..fdcd16f1a068 100644 --- a/src/plugins/saved_objects_management/public/management_section/objects_table/saved_objects_table.test.tsx +++ b/src/plugins/saved_objects_management/public/management_section/objects_table/saved_objects_table.test.tsx @@ -64,7 +64,7 @@ import { import { Flyout, Relationships } from './components'; import { SavedObjectWithMetadata } from '../../types'; import { WorkspaceObject } from 'opensearch-dashboards/public'; -import { DEFAULT_WORKSPACE_ID } from '../../../../../core/public'; +import { PUBLIC_WORKSPACE_ID } from '../../../../../core/public'; import { TableProps } from './components/table'; const allowedTypes = ['index-pattern', 'visualization', 'dashboard', 'search']; @@ -696,7 +696,7 @@ describe('SavedObjectsTable', () => { expect(filters[1].options.length).toBe(3); expect(filters[1].options[0].value).toBe('foo'); expect(filters[1].options[1].value).toBe('bar'); - expect(filters[1].options[2].value).toBe(DEFAULT_WORKSPACE_ID); + expect(filters[1].options[2].value).toBe(PUBLIC_WORKSPACE_ID); }); it('show workspace filter when workspace turn on and enter a workspace', async () => { @@ -832,7 +832,7 @@ describe('SavedObjectsTable', () => { expect(findObjectsMock).toBeCalledWith( http, expect.objectContaining({ - workspaces: expect.arrayContaining(['workspace1', 'default']), + workspaces: expect.arrayContaining(['workspace1', PUBLIC_WORKSPACE_ID]), workspacesSearchOperator: expect.stringMatching('OR'), }) ); diff --git a/src/plugins/saved_objects_management/public/management_section/objects_table/saved_objects_table.tsx b/src/plugins/saved_objects_management/public/management_section/objects_table/saved_objects_table.tsx index 1b1de928be03..0a078d5ee044 100644 --- a/src/plugins/saved_objects_management/public/management_section/objects_table/saved_objects_table.tsx +++ b/src/plugins/saved_objects_management/public/management_section/objects_table/saved_objects_table.tsx @@ -69,7 +69,7 @@ import { WorkspaceAttribute, } from 'src/core/public'; import { Subscription } from 'rxjs'; -import { DEFAULT_WORKSPACE_ID } from '../../../../../core/public'; +import { PUBLIC_WORKSPACE_ID, PUBLIC_WORKSPACE_NAME } from '../../../../../core/public'; import { RedirectAppLinks } from '../../../../opensearch_dashboards_react/public'; import { IndexPatternsContract } from '../../../../data/public'; import { @@ -193,21 +193,21 @@ export class SavedObjectsTable extends Component ws.id).concat(DEFAULT_WORKSPACE_ID); + return availableWorkspaces?.map((ws) => ws.id).concat(PUBLIC_WORKSPACE_ID); } else { return [currentWorkspaceId]; } } } - private get wsNameIdLookup() { + private get workspaceNameIdLookup() { const { availableWorkspaces } = this.state; const workspaceNameIdMap = new Map(); - workspaceNameIdMap.set(DEFAULT_WORKSPACE_ID, DEFAULT_WORKSPACE_ID); - // Assumption: workspace name is unique across the system - availableWorkspaces?.reduce((map, ws) => { - return map.set(ws.name, ws.id); - }, workspaceNameIdMap); + workspaceNameIdMap.set(PUBLIC_WORKSPACE_NAME, PUBLIC_WORKSPACE_ID); + // workspace name is unique across the system + availableWorkspaces?.forEach((workspace) => { + workspaceNameIdMap.set(workspace.name, workspace.id); + }); return workspaceNameIdMap; } @@ -258,7 +258,7 @@ export class SavedObjectsTable extends Component this.wsNameIdLookup?.get(wsName) || '') + .map((wsName) => this.workspaceNameIdLookup?.get(wsName) || '') .filter((wsId) => !!wsId); } @@ -351,13 +351,13 @@ export class SavedObjectsTable extends Component this.wsNameIdLookup?.get(wsName) || '' + (wsName) => this.workspaceNameIdLookup?.get(wsName) || '' ); findOptions.workspaces = workspaceIds; } if (findOptions.workspaces) { - if (findOptions.workspaces.indexOf(DEFAULT_WORKSPACE_ID) !== -1) { + if (findOptions.workspaces.indexOf(PUBLIC_WORKSPACE_ID) !== -1) { // search both saved objects with workspace and without workspace findOptions.workspacesSearchOperator = 'OR'; } @@ -961,6 +961,8 @@ export class SavedObjectsTable extends Component workspace.id === PUBLIC_WORKSPACE_ID) > -1; const wsFilterOptions = availableWorkspaces .filter((ws) => { return this.workspaceIdQuery?.includes(ws.id); @@ -973,11 +975,12 @@ export class SavedObjectsTable extends Component { @@ -70,7 +70,7 @@ export const registerScrollForCountRoute = (router: IRouter) => { if (requestHasWorkspaces) { counts.workspaces = {}; findOptions.workspaces = req.body.workspaces; - if (findOptions.workspaces.indexOf(DEFAULT_WORKSPACE_ID) !== -1) { + if (findOptions.workspaces.indexOf(PUBLIC_WORKSPACE_ID) !== -1) { // search both saved objects with workspace and without workspace findOptions.workspacesSearchOperator = 'OR'; } @@ -96,7 +96,7 @@ export const registerScrollForCountRoute = (router: IRouter) => { }); } if (requestHasWorkspaces) { - const resultWorkspaces = result.workspaces || [DEFAULT_WORKSPACE_ID]; + const resultWorkspaces = result.workspaces || [PUBLIC_WORKSPACE_ID]; resultWorkspaces.forEach((ws) => { counts.workspaces[ws] = counts.workspaces[ws] || 0; counts.workspaces[ws]++; diff --git a/src/plugins/workspace/server/workspace_client.ts b/src/plugins/workspace/server/workspace_client.ts index 79df5f5d4558..9462bfdd9242 100644 --- a/src/plugins/workspace/server/workspace_client.ts +++ b/src/plugins/workspace/server/workspace_client.ts @@ -14,6 +14,7 @@ import { import { DEFAULT_APP_CATEGORIES, PUBLIC_WORKSPACE_ID, + PUBLIC_WORKSPACE_NAME, WORKSPACE_TYPE, Logger, } from '../../../core/server'; @@ -108,9 +109,7 @@ export class WorkspaceClient implements IWorkspaceClientImpl { } private async setupPublicWorkspace(savedObjectClient?: SavedObjectsClientContract) { return this.checkAndCreateWorkspace(savedObjectClient, PUBLIC_WORKSPACE_ID, { - name: i18n.translate('workspaces.public.workspace.default.name', { - defaultMessage: 'Global workspace', - }), + name: PUBLIC_WORKSPACE_NAME, features: ['*', `!@${DEFAULT_APP_CATEGORIES.management.id}`], reserved: true, });