From 0dce61bae079f9fc4ed1568b071f161d4fd8db07 Mon Sep 17 00:00:00 2001 From: SuZhou-Joe Date: Fri, 21 Jul 2023 13:58:17 +0800 Subject: [PATCH] Feature: hide workspace from saved objects management page. (#45) * setup workspace plugin project skeleton Signed-off-by: Yulong Ruan * test: add unit tests add license header Signed-off-by: Yulong Ruan * workspace template init commit Signed-off-by: Hailong Cui * refacter workspace template into hooks Signed-off-by: Hailong Cui * refacter workspace template hooks Signed-off-by: Hailong Cui * update coverImage comments Signed-off-by: Hailong Cui * feature: add public/workspaces service Signed-off-by: SuZhoue-Joe * feat: add interfaces for workspaces client Signed-off-by: SuZhoue-Joe * feat: add interfaces for workspaces client Signed-off-by: SuZhoue-Joe * feat: add interfaces for workspaces client Signed-off-by: SuZhoue-Joe * feat: implement workspaces service Signed-off-by: SuZhoue-Joe * feat: changes to client type interface Signed-off-by: SuZhoue-Joe * feat: changes to client implement Signed-off-by: SuZhoue-Joe * feat: implement more for workspaces service Signed-off-by: SuZhoue-Joe * feat: implement more for workspaces service Signed-off-by: SuZhoue-Joe * feat: implement more for workspaces service Signed-off-by: SuZhoue-Joe * feat: add workspace creator page (#5) * feat: add workspace creator page Signed-off-by: Lin Wang * feat: integrate with application workspace template Signed-off-by: Lin Wang * feat: add max-width and remove image wrapper if not exists Signed-off-by: Lin Wang * feat: update filter condition to align with collapsible nav Signed-off-by: Lin Wang --------- Signed-off-by: Lin Wang * Add validation when load page (#8) * fix: validation & query Signed-off-by: SuZhoue-Joe * feat: modify file name to reduce confusion Signed-off-by: SuZhoue-Joe * feat: add landing logic to retrive workspace id Signed-off-by: SuZhoue-Joe * feat: add worklist observable Signed-off-by: SuZhoue-Joe * feat: add worklist observable Signed-off-by: SuZhoue-Joe * feat: add worklist observable Signed-off-by: SuZhoue-Joe * fix: type error Signed-off-by: SuZhoue-Joe * fix: type error Signed-off-by: SuZhoue-Joe * feat: make client more robust Signed-off-by: SuZhoue-Joe * feat: use Subject Signed-off-by: SuZhoue-Joe --------- Signed-off-by: SuZhoue-Joe * feat: use BehaviorObject and optimize code (#14) Signed-off-by: SuZhoue-Joe * feat: integrate with workspace create API (#13) * feat: integrate with workspace create API Signed-off-by: Lin Wang * feat: update to i18n text for toast Signed-off-by: Lin Wang --------- Signed-off-by: Lin Wang * Add currentWorkspace$ (#15) * feat: add currentWorkspace$ Signed-off-by: SuZhoue-Joe * fix: type error Signed-off-by: SuZhoue-Joe * feat: add emit on currentWorkspace$ Signed-off-by: SuZhoue-Joe --------- Signed-off-by: SuZhoue-Joe * register plugin with workspace template (#16) Signed-off-by: Hailong Cui * workspace dropdown list (#9) Add workspace dropdown list --------- Signed-off-by: zhichao-aws Signed-off-by: SuZhoue-Joe Signed-off-by: suzhou Co-authored-by: SuZhoue-Joe * init workspace menu stage 1 (#12) * feat: init workspace menu stage 1 Signed-off-by: tygao * fix: remove port diff Signed-off-by: tygao * feat: update menu logic Signed-off-by: tygao --------- Signed-off-by: tygao * Fix template registration import error (#21) * fix import error Signed-off-by: Hailong Cui * fix osd bootstrap failure Signed-off-by: Hailong Cui --------- Signed-off-by: Hailong Cui * Add workspace overview page (#19) * feat: add workspace overview page Signed-off-by: Lin Wang * refactor: move paths to common constants Signed-off-by: Lin Wang * feat: add workspace overview item by custom nav in start phase Signed-off-by: Lin Wang * refactor: change to currentWorkspace$ in workspace client Signed-off-by: Lin Wang --------- Signed-off-by: Lin Wang * feat: navigate to workspace create page after button clicked (#23) Signed-off-by: Lin Wang * fix failed test snapshots (#22) fix failed test snapshots temporary fix: fetch functional test from main branch fixed git error which cannot find ref due to feature branch `workspace` not exists on repo opensearch-dashboards-functional-test Signed-off-by: Yulong Ruan --------- Signed-off-by: Yulong Ruan * change to currentWorkspace, wrap title using i18n (#20) * change to currentWorkspace, wrap title using i18n Signed-off-by: zhichao-aws * change import Signed-off-by: zhichao-aws * directly return [] if currentWorkspace is null Signed-off-by: zhichao-aws --------- Signed-off-by: zhichao-aws * add workspace switch (#17) * feat: update workspace switch Signed-off-by: tygao * fix: fix switch error Signed-off-by: tygao * fix: fix prettier after merge Signed-off-by: tygao * chore: remove extra code after merge Signed-off-by: tygao --------- Signed-off-by: tygao * Add update workspace page (#25) Signed-off-by: gaobinlong * Delete Workspace (#24) * add delete workspace modal Signed-off-by: yuye-aws * implement delete on workspace overview page Signed-off-by: yuye-aws * fix export on delete workspace modal Signed-off-by: yuye-aws * add try catch to handle errors for workspace delete Signed-off-by: yuye-aws * move visibility control to workspace overview page exlusively Signed-off-by: yuye-aws * remove unused import Signed-off-by: yuye-aws --------- Signed-off-by: yuye-aws * feat: redirect to overview page after workspace switch (#26) Signed-off-by: Lin Wang * update menu filter logic (#28) * feat: update menu logic Signed-off-by: tygao * fix: use navLinks to filter Signed-off-by: tygao --------- Signed-off-by: tygao * feat: redirect to workspace overview page after created success (#29) Signed-off-by: Lin Wang * [Feature] Complied saved_objects create/find (#18) * temp: save Signed-off-by: SuZhoue-Joe * feat: make create/find support workspaces Signed-off-by: SuZhoue-Joe * feat: extract management code Signed-off-by: SuZhoue-Joe * fix: type check Signed-off-by: SuZhoue-Joe * fix: build error Signed-off-by: SuZhoue-Joe * feat: enable workspaces on saved client server side Signed-off-by: SuZhoue-Joe * feat: some optimization Signed-off-by: SuZhoue-Joe * feat: extract management code Signed-off-by: SuZhoue-Joe * feat: merge fix Signed-off-by: SuZhoue-Joe * feat: optimize code Signed-off-by: SuZhoue-Joe * feat: reuse common function Signed-off-by: SuZhoue-Joe * feat: optimize code when create Signed-off-by: SuZhoue-Joe * feat: remove useless test code Signed-off-by: SuZhoue-Joe --------- Signed-off-by: SuZhoue-Joe * feat: redirect to workspace update page after workspace switch (#30) * Move delete button to update page (#27) * add delete workspace modal Signed-off-by: yuye-aws * implement delete on workspace overview page Signed-off-by: yuye-aws * fix export on delete workspace modal Signed-off-by: yuye-aws * add try catch to handle errors for workspace delete Signed-off-by: yuye-aws * move visibility control to workspace overview page exlusively Signed-off-by: yuye-aws * remove unused import Signed-off-by: yuye-aws * change workspace overview route to workspace update Signed-off-by: yuye-aws * move delete button from workspace overview page to update page Signed-off-by: yuye-aws * remove update button from workspace overview page Signed-off-by: yuye-aws * recover router to workspace overview page Signed-off-by: yuye-aws * change navigation url for workspace overview button on left side panel Signed-off-by: yuye-aws --------- Signed-off-by: yuye-aws * fix: linting error Signed-off-by: Yulong Ruan * remove duplicate EuiPage (#34) * remove duplicate EuiPage Signed-off-by: Hailong Cui * fix: remove duplicate workspace template Signed-off-by: Hailong Cui --------- Signed-off-by: Hailong Cui * remove clear button, add the width of create button (#33) Signed-off-by: zhichao-aws * rename OpenSearch Plugins to OpenSearch Features this is a temporary fix just for demo, should be reverted later Signed-off-by: Yulong Ruan * Add some logic check when overwrite a saved object (#32) * feat: add some logic check when overwrite a saved object Signed-off-by: SuZhoue-Joe * fix: type check Signed-off-by: SuZhoue-Joe * feat: update Signed-off-by: SuZhoue-Joe --------- Signed-off-by: SuZhoue-Joe * Add color, icon and defaultVISTheme for workspace (#36) * feat: add color, icon and defaultVISTheme field for workspace saved object Signed-off-by: Lin Wang * add new fields to workspace form Signed-off-by: Lin Wang * feat: remove feature or group name hack Signed-off-by: Lin Wang --------- Signed-off-by: Lin Wang * feat: add workspace list (#39) Signed-off-by: tygao * Feature/menu change (#37) * feat: register library menus Signed-off-by: SuZhoue-Joe * feat: some update Signed-off-by: SuZhoue-Joe * feat: optimize code Signed-off-by: SuZhou-Joe * feat: optimize code Signed-off-by: SuZhou-Joe --------- Signed-off-by: SuZhoue-Joe Signed-off-by: SuZhou-Joe * feat: different left menu and exit workspace (#38) * Exit workspace from left menu Signed-off-by: yuye-aws * Show exit workspace button with small window size Signed-off-by: yuye-aws * Remove recently viewed and workspace overview on left menu Signed-off-by: yuye-aws * Add buttons for outside, inside workspace case Signed-off-by: yuye-aws * Implement home button and workspace over view button on left menu Signed-off-by: yuye-aws * Implement workspace dropdown list in left menu Signed-off-by: yuye-aws * Add props on recently accessed and custom nav link Signed-off-by: yuye-aws * Add three props to mock props for collapsible nav: exitWorkspace, getWorkspaceUrl, workspaceList$ Signed-off-by: yuye-aws * Add three props to mock props for header: exitWorkspace, getWorkspaceUrl, workspaceList$ Signed-off-by: yuye-aws * Fix bugs for function createWorkspaceNavLink Signed-off-by: yuye-aws * Remove unused constants Signed-off-by: yuye-aws * Reuse method getWorkspaceUrl Signed-off-by: yuye-aws * Remove recently accessed and custom nav props in test Signed-off-by: yuye-aws * Revert "Remove recently accessed and custom nav props in test" This reverts commit 7895e5c5dcde9e134f26b2d6a3df54a2d62e9274. * Wrap title with i18n Signed-off-by: yuye-aws * Add redirect for workspace app Signed-off-by: yuye-aws * Enable users to go to workspace lists page via see more under workspaces in left menu Signed-off-by: yuye-aws --------- Signed-off-by: yuye-aws * feat: make url stateful (#35) * feat: make url stateful Signed-off-by: SuZhoue-Joe * feat: optimize code Signed-off-by: SuZhoue-Joe * feat: remove useless change Signed-off-by: SuZhoue-Joe * feat: optimize url listener Signed-off-by: SuZhoue-Joe * feat: make formatUrlWithWorkspaceId extensible Signed-off-by: SuZhoue-Joe * feat: modify to related components Signed-off-by: SuZhoue-Joe * feat: modify the async format to be sync function Signed-off-by: SuZhoue-Joe * feat: modify the async format to be sync function Signed-off-by: SuZhoue-Joe * fix: type check Signed-off-by: SuZhoue-Joe * feat: use path to maintain workspace info Signed-off-by: SuZhou-Joe * feat: optimize code Signed-off-by: SuZhou-Joe * feat: optimize code Signed-off-by: SuZhou-Joe * feat: optimize code Signed-off-by: SuZhou-Joe * feat: optimize code Signed-off-by: SuZhou-Joe * feat: optimize code Signed-off-by: SuZhou-Joe * feat: optimize code Signed-off-by: SuZhou-Joe --------- Signed-off-by: SuZhoue-Joe Signed-off-by: SuZhou-Joe * Fix build error and part of test error (#42) * fix: fix build error and some ut Signed-off-by: tygao * chore: remove saved object client test diff Signed-off-by: tygao --------- Signed-off-by: tygao * feat: optimize code (#40) Signed-off-by: SuZhou-Joe * fix: bootstrap error (#43) Signed-off-by: SuZhou-Joe * feat: add workspace permission control interface (#41) * feat: add workspace permission control interface Signed-off-by: Lin Wang * feat: add request parameter for workspace permission control Signed-off-by: Lin Wang --------- Signed-off-by: Lin Wang * allow user to turn on/off workspace from advance settings (#46) return 404 if accessing a workspace path when workspace is disabled --------- Signed-off-by: Yulong Ruan * fix: unit test failure (#50) Signed-off-by: SuZhou-Joe * Add workspace column into saved objects table (#44) * Add workspace column into saved management page Signed-off-by: Hailong Cui * savedObjectsManagement as optional dependency Signed-off-by: Hailong Cui * i18n for column title Signed-off-by: Hailong Cui --------- Signed-off-by: Hailong Cui * feat: make edit url clickable Signed-off-by: SuZhou-Joe * feat: add ui capability path Signed-off-by: SuZhou-Joe * feat: add ui capability path Signed-off-by: SuZhou-Joe * fet: remove useless jump code Signed-off-by: SuZhou-Joe * feat: hide workspace from saved objects management page Signed-off-by: SuZhou-Joe * feat: hide workspace from saved objects management page Signed-off-by: SuZhou-Joe --------- Signed-off-by: Yulong Ruan Signed-off-by: Hailong Cui Signed-off-by: SuZhoue-Joe Signed-off-by: Lin Wang Signed-off-by: zhichao-aws Signed-off-by: suzhou Signed-off-by: tygao Signed-off-by: gaobinlong Signed-off-by: yuye-aws Signed-off-by: SuZhou-Joe Co-authored-by: Yulong Ruan Co-authored-by: Hailong Cui Co-authored-by: Lin Wang Co-authored-by: zhichao-aws Co-authored-by: raintygao Co-authored-by: gaobinlong Co-authored-by: Yuye Zhu --- src/core/public/http/base_path.ts | 16 ++++++++----- src/core/public/http/http_service.ts | 3 ++- src/core/public/http/types.ts | 14 +++++++++-- src/core/public/index.ts | 2 ++ src/core/public/utils/index.ts | 3 ++- src/core/public/utils/workspace.ts | 2 ++ src/core/server/index.ts | 2 +- src/core/server/workspaces/constants.ts | 6 +++++ src/core/server/workspaces/index.ts | 1 + .../workspaces/saved_objects/workspace.ts | 23 ++++--------------- .../server/workspaces/workspaces_client.ts | 16 +++++-------- src/core/utils/constants.ts | 6 +++++ src/core/utils/index.ts | 1 + .../management_section/mount_section.tsx | 8 ++++++- .../components/utils/workspace_column.tsx | 4 ---- src/plugins/workspace/public/plugin.ts | 13 +++++++---- 16 files changed, 71 insertions(+), 49 deletions(-) create mode 100644 src/core/server/workspaces/constants.ts create mode 100644 src/core/utils/constants.ts diff --git a/src/core/public/http/base_path.ts b/src/core/public/http/base_path.ts index 44d2560bb4c..254e4e2e6ad 100644 --- a/src/core/public/http/base_path.ts +++ b/src/core/public/http/base_path.ts @@ -29,6 +29,7 @@ */ import { modifyUrl } from '@osd/std'; +import type { PrependOptions } from './types'; export class BasePath { constructor( @@ -45,7 +46,8 @@ export class BasePath { return this.basePath; }; - public prepend = (path: string, withoutWorkspace: boolean = false): string => { + public prepend = (path: string, prependOptions?: PrependOptions): string => { + const { withoutWorkspace } = prependOptions || {}; const basePath = withoutWorkspace ? this.basePath : this.get(); if (!basePath) return path; return modifyUrl(path, (parts) => { @@ -55,17 +57,19 @@ export class BasePath { }); }; - public remove = (path: string): string => { - if (!this.get()) { + public remove = (path: string, prependOptions?: PrependOptions): string => { + const { withoutWorkspace } = prependOptions || {}; + const basePath = withoutWorkspace ? this.basePath : this.get(); + if (!basePath) { return path; } - if (path === this.get()) { + if (path === basePath) { return '/'; } - if (path.startsWith(`${this.get()}/`)) { - return path.slice(this.get().length); + if (path.startsWith(`${basePath}/`)) { + return path.slice(basePath.length); } return path; diff --git a/src/core/public/http/http_service.ts b/src/core/public/http/http_service.ts index 45f69f1a692..c2caf18be88 100644 --- a/src/core/public/http/http_service.ts +++ b/src/core/public/http/http_service.ts @@ -37,6 +37,7 @@ import { LoadingCountService } from './loading_count_service'; import { Fetch } from './fetch'; import { CoreService } from '../../types'; import { getWorkspaceIdFromUrl } from '../utils'; +import { WORKSPACE_PATH_PREFIX } from '../../utils/constants'; interface HttpDeps { injectedMetadata: InjectedMetadataSetup; @@ -54,7 +55,7 @@ export class HttpService implements CoreService { let workspaceBasePath = ''; const workspaceId = getWorkspaceIdFromUrl(window.location.href); if (workspaceId) { - workspaceBasePath = `/w/${workspaceId}`; + workspaceBasePath = `${WORKSPACE_PATH_PREFIX}/${workspaceId}`; } const basePath = new BasePath( injectedMetadata.getBasePath(), diff --git a/src/core/public/http/types.ts b/src/core/public/http/types.ts index 4c81dbdd7a5..a50b9cb0c95 100644 --- a/src/core/public/http/types.ts +++ b/src/core/public/http/types.ts @@ -87,6 +87,16 @@ export interface HttpSetup { */ export type HttpStart = HttpSetup; +/** + * prepend options + * + * withoutWorkspace option will prepend a relative url with only basePath + * workspaceId will rewrite the /w/{workspaceId} part, if workspace id is an empty string, prepend will remove the workspaceId part + */ +export interface PrependOptions { + withoutWorkspace?: boolean; +} + /** * APIs for manipulating the basePath on URL segments. * @public @@ -105,12 +115,12 @@ export interface IBasePath { /** * Prepends `path` with the basePath + workspace. */ - prepend: (url: string) => string; + prepend: (url: string, prependOptions?: PrependOptions) => string; /** * Removes the prepended basePath + workspace from the `path`. */ - remove: (url: string) => string; + remove: (url: string, prependOptions?: PrependOptions) => string; /** * Returns the server's root basePath as configured, without any namespace prefix. diff --git a/src/core/public/index.ts b/src/core/public/index.ts index ae35430d580..c1a8d34aa67 100644 --- a/src/core/public/index.ts +++ b/src/core/public/index.ts @@ -357,3 +357,5 @@ export { WorkspaceAttribute, WorkspaceFindOptions, } from './workspace'; + +export { getWorkspaceIdFromUrl, WORKSPACE_TYPE } from './utils'; diff --git a/src/core/public/utils/index.ts b/src/core/public/utils/index.ts index 0719f5e83c5..ad363c53bd4 100644 --- a/src/core/public/utils/index.ts +++ b/src/core/public/utils/index.ts @@ -31,4 +31,5 @@ export { shareWeakReplay } from './share_weak_replay'; export { Sha256 } from './crypto'; export { MountWrapper, mountReactNode } from './mount'; -export { getWorkspaceIdFromUrl } from './workspace'; +export { getWorkspaceIdFromUrl, WORKSPACE_TYPE } from './workspace'; +export { WORKSPACE_PATH_PREFIX } from '../../utils'; diff --git a/src/core/public/utils/workspace.ts b/src/core/public/utils/workspace.ts index e93355aa00e..9a0f55b3fa8 100644 --- a/src/core/public/utils/workspace.ts +++ b/src/core/public/utils/workspace.ts @@ -13,3 +13,5 @@ export const getWorkspaceIdFromUrl = (url: string): string => { return ''; }; + +export const WORKSPACE_TYPE = 'workspace'; diff --git a/src/core/server/index.ts b/src/core/server/index.ts index 6a234a405e5..e369b98d810 100644 --- a/src/core/server/index.ts +++ b/src/core/server/index.ts @@ -509,4 +509,4 @@ export const config = { }, }; -export { formatWorkspaces, workspacesValidator } from './workspaces'; +export { formatWorkspaces, workspacesValidator, WORKSPACE_TYPE } from './workspaces'; diff --git a/src/core/server/workspaces/constants.ts b/src/core/server/workspaces/constants.ts new file mode 100644 index 00000000000..73c2d601084 --- /dev/null +++ b/src/core/server/workspaces/constants.ts @@ -0,0 +1,6 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +export const WORKSPACE_TYPE = 'workspace'; diff --git a/src/core/server/workspaces/index.ts b/src/core/server/workspaces/index.ts index 28079e7a36b..c1f88784aa0 100644 --- a/src/core/server/workspaces/index.ts +++ b/src/core/server/workspaces/index.ts @@ -14,3 +14,4 @@ export { WorkspaceAttribute, WorkspaceFindOptions } from './types'; export { WorkspacePermissionControl } from './workspace_permission_control'; export { workspacesValidator, formatWorkspaces } from './utils'; +export { WORKSPACE_TYPE } from './constants'; diff --git a/src/core/server/workspaces/saved_objects/workspace.ts b/src/core/server/workspaces/saved_objects/workspace.ts index d73a9e3b760..284ed013b7e 100644 --- a/src/core/server/workspaces/saved_objects/workspace.ts +++ b/src/core/server/workspaces/saved_objects/workspace.ts @@ -4,28 +4,15 @@ */ import { SavedObjectsType } from 'opensearch-dashboards/server'; +import { WORKSPACE_TYPE } from '../constants'; export const workspace: SavedObjectsType = { - name: 'workspace', + name: WORKSPACE_TYPE, namespaceType: 'agnostic', hidden: false, - management: { - icon: 'apps', // todo: pending ux #2034 - defaultSearchField: 'title', - importableAndExportable: true, - getTitle(obj) { - return obj.attributes.title; - }, - getEditUrl(obj) { - return `/management/opensearch-dashboards/dataSources/${encodeURIComponent(obj.id)}`; - }, - getInAppUrl(obj) { - return { - path: `/app/management/opensearch-dashboards/dataSources/${encodeURIComponent(obj.id)}`, - uiCapabilitiesPath: 'management.opensearchDashboards.dataSources', - }; - }, - }, + /** + * workspace won't appear in management page. + */ mappings: { dynamic: false, properties: { diff --git a/src/core/server/workspaces/workspaces_client.ts b/src/core/server/workspaces/workspaces_client.ts index 058d7477efd..7d4fdc85814 100644 --- a/src/core/server/workspaces/workspaces_client.ts +++ b/src/core/server/workspaces/workspaces_client.ts @@ -12,8 +12,7 @@ import { } from './types'; import { WorkspacesSetupDeps } from './workspaces_service'; import { workspace } from './saved_objects'; - -export const WORKSPACES_TYPE_FOR_SAVED_OBJECT = 'workspace'; +import { WORKSPACE_TYPE } from './constants'; export class WorkspacesClientWithSavedObject implements IWorkspaceDBImpl { private setupDep: WorkspacesSetupDeps; @@ -50,7 +49,7 @@ export class WorkspacesClientWithSavedObject implements IWorkspaceDBImpl { try { const result = await this.getSavedObjectClientsFromRequestDetail(requestDetail).create< Omit - >(WORKSPACES_TYPE_FOR_SAVED_OBJECT, payload); + >(WORKSPACE_TYPE, payload); return { success: true, result: { @@ -75,7 +74,7 @@ export class WorkspacesClientWithSavedObject implements IWorkspaceDBImpl { } = await this.getSavedObjectClientsFromRequestDetail(requestDetail).find( { ...options, - type: WORKSPACES_TYPE_FOR_SAVED_OBJECT, + type: WORKSPACE_TYPE, } ); return { @@ -99,7 +98,7 @@ export class WorkspacesClientWithSavedObject implements IWorkspaceDBImpl { try { const result = await this.getSavedObjectClientsFromRequestDetail(requestDetail).get< WorkspaceAttribute - >(WORKSPACES_TYPE_FOR_SAVED_OBJECT, id); + >(WORKSPACE_TYPE, id); return { success: true, result: this.getFlatternedResultWithSavedObject(result), @@ -119,7 +118,7 @@ export class WorkspacesClientWithSavedObject implements IWorkspaceDBImpl { try { await this.getSavedObjectClientsFromRequestDetail(requestDetail).update< Omit - >(WORKSPACES_TYPE_FOR_SAVED_OBJECT, id, payload); + >(WORKSPACE_TYPE, id, payload); return { success: true, result: true, @@ -133,10 +132,7 @@ export class WorkspacesClientWithSavedObject implements IWorkspaceDBImpl { } public async delete(requestDetail: IRequestDetail, id: string): Promise> { try { - await this.getSavedObjectClientsFromRequestDetail(requestDetail).delete( - WORKSPACES_TYPE_FOR_SAVED_OBJECT, - id - ); + await this.getSavedObjectClientsFromRequestDetail(requestDetail).delete(WORKSPACE_TYPE, id); return { success: true, result: true, diff --git a/src/core/utils/constants.ts b/src/core/utils/constants.ts new file mode 100644 index 00000000000..e35ff014b38 --- /dev/null +++ b/src/core/utils/constants.ts @@ -0,0 +1,6 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +export const WORKSPACE_PATH_PREFIX = '/w'; diff --git a/src/core/utils/index.ts b/src/core/utils/index.ts index 797d90c1813..5c3130c500d 100644 --- a/src/core/utils/index.ts +++ b/src/core/utils/index.ts @@ -38,3 +38,4 @@ export { } from './context'; export { DEFAULT_APP_CATEGORIES } from './default_app_categories'; export { DEFAULT_WORKSPACE_TEMPLATES } from './default_workspace_templates'; +export { WORKSPACE_PATH_PREFIX } from './constants'; diff --git a/src/plugins/saved_objects_management/public/management_section/mount_section.tsx b/src/plugins/saved_objects_management/public/management_section/mount_section.tsx index acc2c5bc8af..bb741e89087 100644 --- a/src/plugins/saved_objects_management/public/management_section/mount_section.tsx +++ b/src/plugins/saved_objects_management/public/management_section/mount_section.tsx @@ -38,6 +38,7 @@ import { ManagementAppMountParams } from 'src/plugins/management/public'; import { StartDependencies, SavedObjectsManagementPluginStart } from '../plugin'; import { ISavedObjectsManagementServiceRegistry } from '../services'; import { getAllowedTypes } from './../lib'; +import { WORKSPACE_TYPE } from '../../../../core/public'; interface MountParams { core: CoreSetup; @@ -67,7 +68,12 @@ export const mountManagementSection = async ({ const setBreadcrumbs = mountParams?.setBreadcrumbs || chrome.setBreadcrumbs; let finalAllowedObjectTypes = allowedObjectTypes; if (finalAllowedObjectTypes === undefined) { - finalAllowedObjectTypes = await getAllowedTypes(coreStart.http); + /** + * Workspace needs to be filtered out since it is a concept with higher level than normal saved objects. + */ + finalAllowedObjectTypes = (await getAllowedTypes(coreStart.http)).filter( + (item) => item !== WORKSPACE_TYPE + ); } coreStart.chrome.docTitle.change(title); diff --git a/src/plugins/workspace/public/components/utils/workspace_column.tsx b/src/plugins/workspace/public/components/utils/workspace_column.tsx index b51a4d3178f..77ada67c7cd 100644 --- a/src/plugins/workspace/public/components/utils/workspace_column.tsx +++ b/src/plugins/workspace/public/components/utils/workspace_column.tsx @@ -31,10 +31,6 @@ function WorkspaceColumn({ coreSetup, workspaces, record }: WorkspaceColumnProps }); wsLookUp?.set('public', publicWsName); - if (record.type === 'workspace') { - return null; - } - if (!workspaces) { return {publicWsName}; } diff --git a/src/plugins/workspace/public/plugin.ts b/src/plugins/workspace/public/plugin.ts index 45e8d6deb03..f79eb6d9bf5 100644 --- a/src/plugins/workspace/public/plugin.ts +++ b/src/plugins/workspace/public/plugin.ts @@ -14,9 +14,9 @@ import { } from '../../../core/public'; import { WORKSPACE_APP_ID } from '../common/constants'; import { mountDropdownList } from './mount'; -import { getWorkspaceIdFromUrl } from '../../../core/public/utils'; import { SavedObjectsManagementPluginSetup } from '../../saved_objects_management/public'; import { getWorkspaceColumn } from './components/utils/workspace_column'; +import { getWorkspaceIdFromUrl, WORKSPACE_PATH_PREFIX } from '../../../core/public/utils'; interface WorkspacesPluginSetupDeps { savedObjectsManagement?: SavedObjectsManagementPluginSetup; @@ -36,13 +36,16 @@ export class WorkspacesPlugin implements Plugin<{}, {}, WorkspacesPluginSetupDep */ newUrl.pathname = this.coreSetup?.http.basePath.remove(newUrl.pathname) || ''; if (workspaceId) { - newUrl.pathname = `${this.coreSetup?.http.basePath.serverBasePath || ''}/w/${workspaceId}${ - newUrl.pathname - }`; + newUrl.pathname = `${WORKSPACE_PATH_PREFIX}/${workspaceId}${newUrl.pathname}`; } else { - newUrl.pathname = `${this.coreSetup?.http.basePath.serverBasePath || ''}${newUrl.pathname}`; + newUrl.pathname = newUrl.pathname.replace(/^\/w\/([^\/]*)/, ''); } + newUrl.pathname = + this.coreSetup?.http.basePath.prepend(newUrl.pathname, { + withoutWorkspace: true, + }) || ''; + return newUrl.toString(); }; public async setup(core: CoreSetup, { savedObjectsManagement }: WorkspacesPluginSetupDeps) {