diff --git a/src/core/public/http/base_path.ts b/src/core/public/http/base_path.ts index 8c45d707cf26..44d2560bb4c8 100644 --- a/src/core/public/http/base_path.ts +++ b/src/core/public/http/base_path.ts @@ -45,20 +45,12 @@ export class BasePath { return this.basePath; }; - public prepend = (path: string): string => { - if (!this.get()) return path; + public prepend = (path: string, withoutWorkspace: boolean = false): string => { + const basePath = withoutWorkspace ? this.basePath : this.get(); + if (!basePath) return path; return modifyUrl(path, (parts) => { if (!parts.hostname && parts.pathname && parts.pathname.startsWith('/')) { - parts.pathname = `${this.get()}${parts.pathname}`; - } - }); - }; - - public prependWithoutWorkspacePath = (path: string): string => { - if (!this.basePath) return path; - return modifyUrl(path, (parts) => { - if (!parts.hostname && parts.pathname && parts.pathname.startsWith('/')) { - parts.pathname = `${this.basePath}${parts.pathname}`; + parts.pathname = `${basePath}${parts.pathname}`; } }); }; diff --git a/src/core/public/http/http_service.ts b/src/core/public/http/http_service.ts index 10d51bb2de7d..45f69f1a6926 100644 --- a/src/core/public/http/http_service.ts +++ b/src/core/public/http/http_service.ts @@ -36,6 +36,7 @@ import { AnonymousPathsService } from './anonymous_paths_service'; import { LoadingCountService } from './loading_count_service'; import { Fetch } from './fetch'; import { CoreService } from '../../types'; +import { getWorkspaceIdFromUrl } from '../utils'; interface HttpDeps { injectedMetadata: InjectedMetadataSetup; @@ -50,10 +51,15 @@ export class HttpService implements CoreService { public setup({ injectedMetadata, fatalErrors }: HttpDeps): HttpSetup { const opensearchDashboardsVersion = injectedMetadata.getOpenSearchDashboardsVersion(); + let workspaceBasePath = ''; + const workspaceId = getWorkspaceIdFromUrl(window.location.href); + if (workspaceId) { + workspaceBasePath = `/w/${workspaceId}`; + } const basePath = new BasePath( injectedMetadata.getBasePath(), injectedMetadata.getServerBasePath(), - injectedMetadata.getWorkspaceBasePath() + workspaceBasePath ); const fetchService = new Fetch({ basePath, opensearchDashboardsVersion }); const loadingCount = this.loadingCount.setup({ fatalErrors }); diff --git a/src/core/public/http/types.ts b/src/core/public/http/types.ts index e5fb68b464e9..9a466a1519c7 100644 --- a/src/core/public/http/types.ts +++ b/src/core/public/http/types.ts @@ -113,11 +113,6 @@ export interface IBasePath { * See {@link BasePath.get} for getting the basePath value for a specific request */ readonly serverBasePath: string; - - /** - * Prepends `path` with the basePath. - */ - prependWithoutWorkspacePath: (url: string) => string; } /** diff --git a/src/core/public/injected_metadata/injected_metadata_service.ts b/src/core/public/injected_metadata/injected_metadata_service.ts index ccda2fbc925a..88ea56cfa62e 100644 --- a/src/core/public/injected_metadata/injected_metadata_service.ts +++ b/src/core/public/injected_metadata/injected_metadata_service.ts @@ -152,15 +152,6 @@ export class InjectedMetadataService { getSurvey: () => { return this.state.survey; }, - - getWorkspaceBasePath: () => { - const workspaceId = getWorkspaceIdFromUrl(window.location.href); - if (workspaceId) { - return `/w/${workspaceId}`; - } - - return ''; - }, }; } } diff --git a/src/plugins/workspace/public/plugin.ts b/src/plugins/workspace/public/plugin.ts index 07f1b84f32fe..31d996f3b341 100644 --- a/src/plugins/workspace/public/plugin.ts +++ b/src/plugins/workspace/public/plugin.ts @@ -11,13 +11,13 @@ import { AppMountParameters, AppNavLinkStatus, } from '../../../core/public'; -import { WORKSPACE_APP_ID, PATHS } from '../common/constants'; +import { WORKSPACE_APP_ID } from '../common/constants'; import { mountDropdownList } from './mount'; import { getWorkspaceIdFromUrl } from '../../../core/public/utils'; export class WorkspacesPlugin implements Plugin<{}, {}> { private core?: CoreSetup; - private getWorkpsaceIdFromURL(): string | null { + private getWorkspaceIdFromURL(): string | null { return getWorkspaceIdFromUrl(window.location.href); } private getPatchedUrl = (url: string, workspaceId: string) => { @@ -40,9 +40,9 @@ export class WorkspacesPlugin implements Plugin<{}, {}> { this.core = core; this.core?.workspaces.setFormatUrlWithWorkspaceId((url, id) => this.getPatchedUrl(url, id)); /** - * Retrive workspace id from url + * Retrieve workspace id from url */ - const workspaceId = this.getWorkpsaceIdFromURL(); + const workspaceId = this.getWorkspaceIdFromURL(); if (workspaceId) { const result = await core.workspaces.client.enterWorkspace(workspaceId);