Skip to content

Commit

Permalink
refactor: move workspace uiSettings registration to workspace service
Browse files Browse the repository at this point in the history
Signed-off-by: Yulong Ruan <ruanyl@amazon.com>
  • Loading branch information
ruanyl committed Aug 8, 2023
1 parent 8bacb1b commit 27d727b
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 29 deletions.
1 change: 1 addition & 0 deletions src/core/server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ export class Server {
await this.workspaces.setup({
http: httpSetup,
savedObject: savedObjectsSetup,
uiSettings: uiSettingsSetup,
});

const statusSetup = await this.status.setup({
Expand Down
2 changes: 0 additions & 2 deletions src/core/server/ui_settings/settings/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import { getNotificationsSettings } from './notifications';
import { getThemeSettings } from './theme';
import { getCoreSettings } from './index';
import { getStateSettings } from './state';
import { getWorkspaceSettings } from './workspace';

describe('getCoreSettings', () => {
it('should not have setting overlaps', () => {
Expand All @@ -49,7 +48,6 @@ describe('getCoreSettings', () => {
getNotificationsSettings(),
getThemeSettings(),
getStateSettings(),
getWorkspaceSettings(),
].reduce((sum, settings) => sum + Object.keys(settings).length, 0);

expect(coreSettingsLength).toBe(summedLength);
Expand Down
2 changes: 0 additions & 2 deletions src/core/server/ui_settings/settings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import { getNavigationSettings } from './navigation';
import { getNotificationsSettings } from './notifications';
import { getThemeSettings } from './theme';
import { getStateSettings } from './state';
import { getWorkspaceSettings } from './workspace';

export const getCoreSettings = (): Record<string, UiSettingsParams> => {
return {
Expand All @@ -47,6 +46,5 @@ export const getCoreSettings = (): Record<string, UiSettingsParams> => {
...getNotificationsSettings(),
...getThemeSettings(),
...getStateSettings(),
...getWorkspaceSettings(),
};
};
25 changes: 0 additions & 25 deletions src/core/server/ui_settings/settings/workspace.ts

This file was deleted.

24 changes: 24 additions & 0 deletions src/core/server/workspaces/ui_settings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { i18n } from '@osd/i18n';
import { schema } from '@osd/config-schema';

import { UiSettingsParams } from 'opensearch-dashboards/server';

export const uiSettings: Record<string, UiSettingsParams> = {
'workspace:enabled': {
name: i18n.translate('core.ui_settings.params.workspace.enableWorkspaceTitle', {
defaultMessage: 'Enable Workspace',
}),
value: false,
requiresPageReload: true,
description: i18n.translate('core.ui_settings.params.workspace.enableWorkspaceTitle', {
defaultMessage: 'Enable or disable OpenSearch Dashboards Workspace',
}),
category: ['workspace'],
schema: schema.boolean(),
},
};
5 changes: 5 additions & 0 deletions src/core/server/workspaces/workspaces_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { InternalSavedObjectsServiceSetup } from '../saved_objects';
import { IWorkspaceDBImpl } from './types';
import { WorkspacesClientWithSavedObject } from './workspaces_client';
import { WorkspaceSavedObjectsClientWrapper } from './saved_objects';
import { InternalUiSettingsServiceSetup } from '../ui_settings';
import { uiSettings } from './ui_settings';

export interface WorkspacesServiceSetup {
client: IWorkspaceDBImpl;
Expand All @@ -24,6 +26,7 @@ export interface WorkspacesServiceStart {
export interface WorkspacesSetupDeps {
http: InternalHttpServiceSetup;
savedObject: InternalSavedObjectsServiceSetup;
uiSettings: InternalUiSettingsServiceSetup;
}

export type InternalWorkspacesServiceSetup = WorkspacesServiceSetup;
Expand Down Expand Up @@ -58,6 +61,8 @@ export class WorkspacesService
public async setup(setupDeps: WorkspacesSetupDeps): Promise<InternalWorkspacesServiceSetup> {
this.logger.debug('Setting up Workspaces service');

setupDeps.uiSettings.register(uiSettings);

this.client = new WorkspacesClientWithSavedObject(setupDeps);

await this.client.setup(setupDeps);
Expand Down

0 comments on commit 27d727b

Please sign in to comment.