From be7391bef2c452d895852a8a88fe19bcf536ff91 Mon Sep 17 00:00:00 2001 From: Yulong Ruan Date: Thu, 7 Mar 2024 10:36:39 +0800 Subject: [PATCH] add back cleanWorkspaceId and address PR comments Signed-off-by: Yulong Ruan --- src/core/public/index.ts | 2 +- src/core/public/utils/index.ts | 1 + .../workspace_menu/workspace_menu.tsx | 30 ++++++++++--------- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/core/public/index.ts b/src/core/public/index.ts index 1c0658a27b85..50e3621b0ab8 100644 --- a/src/core/public/index.ts +++ b/src/core/public/index.ts @@ -354,4 +354,4 @@ export { __osdBootstrap__ } from './osd_bootstrap'; export { WorkspacesStart, WorkspacesSetup, WorkspacesService } from './workspace'; -export { WORKSPACE_TYPE } from '../utils'; +export { WORKSPACE_TYPE, cleanWorkspaceId } from '../utils'; diff --git a/src/core/public/utils/index.ts b/src/core/public/utils/index.ts index c0c6f2582e9c..30055b0ff81c 100644 --- a/src/core/public/utils/index.ts +++ b/src/core/public/utils/index.ts @@ -36,4 +36,5 @@ export { WORKSPACE_TYPE, formatUrlWithWorkspaceId, getWorkspaceIdFromUrl, + cleanWorkspaceId, } from '../../utils'; diff --git a/src/plugins/workspace/public/components/workspace_menu/workspace_menu.tsx b/src/plugins/workspace/public/components/workspace_menu/workspace_menu.tsx index 726689a8e953..94882a41442a 100644 --- a/src/plugins/workspace/public/components/workspace_menu/workspace_menu.tsx +++ b/src/plugins/workspace/public/components/workspace_menu/workspace_menu.tsx @@ -19,14 +19,13 @@ import { } from '@elastic/eui'; import type { EuiContextMenuPanelItemDescriptor } from '@elastic/eui'; -import { WorkspaceAttribute } from '../../../../../core/public'; import { WORKSPACE_CREATE_APP_ID, WORKSPACE_LIST_APP_ID, WORKSPACE_OVERVIEW_APP_ID, } from '../../../common/constants'; -import { formatUrlWithWorkspaceId } from '../../../../../core/public/utils'; -import { CoreStart } from '../../../../../core/public'; +import { cleanWorkspaceId, formatUrlWithWorkspaceId } from '../../../../../core/public/utils'; +import { CoreStart, WorkspaceAttribute } from '../../../../../core/public'; interface Props { coreStart: CoreStart; @@ -36,7 +35,7 @@ function getFilteredWorkspaceList( workspaceList: WorkspaceAttribute[], currentWorkspace: WorkspaceAttribute | null ): WorkspaceAttribute[] { - // list top5 workspaces except management workspace, place current workspace at the top + // list top5 workspaces and place the current workspace at the top return [ ...(currentWorkspace ? [currentWorkspace] : []), ...workspaceList.filter((workspace) => workspace.id !== currentWorkspace?.id), @@ -83,7 +82,7 @@ export const WorkspaceMenu = ({ coreStart }: Props) => { ); return { name, - key: index.toString(), + key: workspace.id, icon: , onClick: () => { window.location.assign(workspaceURL); @@ -95,18 +94,19 @@ export const WorkspaceMenu = ({ coreStart }: Props) => { const workspaceListItems: EuiContextMenuPanelItemDescriptor[] = filteredWorkspaceList.map( (workspace, index) => workspaceToItem(workspace, index) ); - const length = workspaceListItems.length; workspaceListItems.push({ icon: , name: i18n.translate('core.ui.primaryNav.workspaceContextMenu.createWorkspace', { defaultMessage: 'Create workspace', }), - key: length.toString(), + key: WORKSPACE_CREATE_APP_ID, onClick: () => { window.location.assign( - coreStart.application.getUrlForApp(WORKSPACE_CREATE_APP_ID, { - absolute: false, - }) + cleanWorkspaceId( + coreStart.application.getUrlForApp(WORKSPACE_CREATE_APP_ID, { + absolute: false, + }) + ) ); }, }); @@ -115,12 +115,14 @@ export const WorkspaceMenu = ({ coreStart }: Props) => { name: i18n.translate('core.ui.primaryNav.workspaceContextMenu.allWorkspace', { defaultMessage: 'All workspaces', }), - key: (length + 1).toString(), + key: WORKSPACE_LIST_APP_ID, onClick: () => { window.location.assign( - coreStart.application.getUrlForApp(WORKSPACE_LIST_APP_ID, { - absolute: false, - }) + cleanWorkspaceId( + coreStart.application.getUrlForApp(WORKSPACE_LIST_APP_ID, { + absolute: false, + }) + ) ); }, });