diff --git a/src/core/server/utils/workspace.test.ts b/src/core/server/utils/workspace.test.ts index 49382cfac38f..7dfcff9e5d18 100644 --- a/src/core/server/utils/workspace.test.ts +++ b/src/core/server/utils/workspace.test.ts @@ -10,10 +10,10 @@ describe('updateWorkspaceState', () => { it('update with payload', () => { const requestMock = httpServerMock.createOpenSearchDashboardsRequest(); updateWorkspaceState(requestMock, { - id: 'foo', + requestWorkspaceId: 'foo', }); expect(getWorkspaceState(requestMock)).toEqual({ - id: 'foo', + requestWorkspaceId: 'foo', }); }); }); diff --git a/src/core/server/utils/workspace.ts b/src/core/server/utils/workspace.ts index c5dcf84b92d9..2003e615d501 100644 --- a/src/core/server/utils/workspace.ts +++ b/src/core/server/utils/workspace.ts @@ -3,14 +3,12 @@ * SPDX-License-Identifier: Apache-2.0 */ -/** - * This file is using {@link PluginsStates} to store workspace info into request. - * The best practice would be using {@link Server.register} to register plugins into the hapi server - * but OSD is wrappering the hapi server and the hapi server instance is hidden as internal implementation. - */ -import { PluginsStates } from '@hapi/hapi'; import { OpenSearchDashboardsRequest, ensureRawRequest } from '../http/router'; +export interface WorkspaceState { + requestWorkspaceId?: string; +} + /** * This function will be used as a proxy * because `ensureRequest` is only importable from core module. @@ -20,24 +18,19 @@ import { OpenSearchDashboardsRequest, ensureRawRequest } from '../http/router'; */ export const updateWorkspaceState = ( request: OpenSearchDashboardsRequest, - payload: Partial + payload: Partial ) => { const rawRequest = ensureRawRequest(request); - if (!rawRequest.plugins) { - rawRequest.plugins = {}; - } - - if (!rawRequest.plugins.workspace) { - rawRequest.plugins.workspace = {}; - } - - rawRequest.plugins.workspace = { - ...rawRequest.plugins.workspace, + rawRequest.app = { + ...rawRequest.app, ...payload, }; }; -export const getWorkspaceState = (request: OpenSearchDashboardsRequest) => { - return ensureRawRequest(request).plugins?.workspace; +export const getWorkspaceState = (request: OpenSearchDashboardsRequest): WorkspaceState => { + const { requestWorkspaceId } = ensureRawRequest(request).app as WorkspaceState; + return { + requestWorkspaceId, + }; };