From 3400f81b6c6163df125461500c72efa0b1a6a3f2 Mon Sep 17 00:00:00 2001 From: Yulong Ruan Date: Thu, 28 Sep 2023 18:42:30 +0800 Subject: [PATCH] fix tests and add comments Signed-off-by: Yulong Ruan --- .../capabilities/capabilities_service.mock.ts | 1 + src/core/public/index.ts | 7 +----- src/core/public/workspace/index.ts | 8 ++----- .../public/workspace/workspaces_service.ts | 23 ++++++++++++++++++- .../capabilities/capabilities_service.mock.ts | 1 + .../capabilities/capabilities_service.ts | 1 + .../capabilities/resolve_capabilities.test.ts | 1 + 7 files changed, 29 insertions(+), 13 deletions(-) diff --git a/src/core/public/application/capabilities/capabilities_service.mock.ts b/src/core/public/application/capabilities/capabilities_service.mock.ts index 971a43d06d05..d4490b60901b 100644 --- a/src/core/public/application/capabilities/capabilities_service.mock.ts +++ b/src/core/public/application/capabilities/capabilities_service.mock.ts @@ -37,6 +37,7 @@ const createStartContractMock = (): jest.Mocked => ({ catalogue: {}, management: {}, navLinks: {}, + workspaces: {}, }), }); diff --git a/src/core/public/index.ts b/src/core/public/index.ts index 14ab91e1cb13..2967b45f1d75 100644 --- a/src/core/public/index.ts +++ b/src/core/public/index.ts @@ -348,9 +348,4 @@ export { export { __osdBootstrap__ } from './osd_bootstrap'; -export { - WorkspacesStart, - WorkspacesSetup, - WorkspacesService, - WorkspaceObservables, -} from './workspace'; +export { WorkspacesStart, WorkspacesSetup, WorkspacesService } from './workspace'; diff --git a/src/core/public/workspace/index.ts b/src/core/public/workspace/index.ts index 4ef6aaae7fd4..4b9b2c86f649 100644 --- a/src/core/public/workspace/index.ts +++ b/src/core/public/workspace/index.ts @@ -2,9 +2,5 @@ * Copyright OpenSearch Contributors * SPDX-License-Identifier: Apache-2.0 */ -export { - WorkspacesStart, - WorkspacesService, - WorkspacesSetup, - WorkspaceObservables, -} from './workspaces_service'; + +export { WorkspacesStart, WorkspacesService, WorkspacesSetup } from './workspaces_service'; diff --git a/src/core/public/workspace/workspaces_service.ts b/src/core/public/workspace/workspaces_service.ts index f4cad977deef..a7c62a76bec2 100644 --- a/src/core/public/workspace/workspaces_service.ts +++ b/src/core/public/workspace/workspaces_service.ts @@ -10,10 +10,31 @@ import { CoreService, WorkspaceAttribute } from '../../types'; type WorkspaceObject = WorkspaceAttribute & { readonly?: boolean }; -export interface WorkspaceObservables { +interface WorkspaceObservables { + /** + * Indicates the current activated workspace id, the value should be changed every time + * when switching to a different workspace + */ currentWorkspaceId$: BehaviorSubject; + + /** + * The workspace that is derived from `currentWorkspaceId` and `workspaceList`, if + * `currentWorkspaceId` cannot be found from `workspaceList`, it will return an error + * + * This value MUST NOT set manually from outside of WorkspacesService + */ currentWorkspace$: BehaviorSubject; + + /** + * The list of available workspaces. This workspace list should be set by whoever + * the workspace functionalities + */ workspaceList$: BehaviorSubject; + + /** + * This is a flag which indicates the WorkspacesService module is initialized and ready + * for consuming by others. For example, the `workspaceList` has been set, etc + */ initialized$: BehaviorSubject; } diff --git a/src/core/server/capabilities/capabilities_service.mock.ts b/src/core/server/capabilities/capabilities_service.mock.ts index fb0785aac947..f8be8f22b70c 100644 --- a/src/core/server/capabilities/capabilities_service.mock.ts +++ b/src/core/server/capabilities/capabilities_service.mock.ts @@ -52,6 +52,7 @@ const createCapabilitiesMock = (): Capabilities => { navLinks: {}, management: {}, catalogue: {}, + workspaces: {}, }; }; diff --git a/src/core/server/capabilities/capabilities_service.ts b/src/core/server/capabilities/capabilities_service.ts index b92166427271..5153cd5ded1d 100644 --- a/src/core/server/capabilities/capabilities_service.ts +++ b/src/core/server/capabilities/capabilities_service.ts @@ -123,6 +123,7 @@ const defaultCapabilities: Capabilities = { navLinks: {}, management: {}, catalogue: {}, + workspaces: {}, }; /** @internal */ diff --git a/src/core/server/capabilities/resolve_capabilities.test.ts b/src/core/server/capabilities/resolve_capabilities.test.ts index 25968d858e7a..b307929d2671 100644 --- a/src/core/server/capabilities/resolve_capabilities.test.ts +++ b/src/core/server/capabilities/resolve_capabilities.test.ts @@ -42,6 +42,7 @@ describe('resolveCapabilities', () => { navLinks: {}, catalogue: {}, management: {}, + workspaces: {}, }; request = httpServerMock.createOpenSearchDashboardsRequest(); });