Skip to content

Commit

Permalink
Refactor UI setting register (opensearch-project#77)
Browse files Browse the repository at this point in the history
refactor: move workspace uiSettings registration to workspace service

---------

Signed-off-by: Yulong Ruan <ruanyl@amazon.com>
  • Loading branch information
ruanyl committed Sep 15, 2023
1 parent 6910346 commit e8dcf49
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 35 deletions.
7 changes: 1 addition & 6 deletions src/core/public/workspace/workspaces_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,9 @@ export class WorkspacesService implements CoreService<WorkspacesSetup, Workspace
private setFormatUrlWithWorkspaceId(formatFn: WorkspacesStart['formatUrlWithWorkspaceId']) {
this.formatUrlWithWorkspaceId = formatFn;
}
public async setup({ http, uiSettings }: { http: HttpSetup; uiSettings: IUiSettingsClient }) {
public async setup({ http }: { http: HttpSetup; uiSettings: IUiSettingsClient }) {
this.client = new WorkspacesClient(http);

// If workspace was disabled while opening a workspace url, navigate to basePath
if (uiSettings.get('workspace:enabled') === true) {
this.client.init();
}

return {
client: this.client,
formatUrlWithWorkspaceId: (url: string, id: string) => this.formatUrlWithWorkspaceId(url, id),
Expand Down
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
1 change: 1 addition & 0 deletions src/plugins/workspace/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export class WorkspacesPlugin implements Plugin<{}, {}, WorkspacesPluginSetupDep
}

this.coreSetup = core;
core.workspaces.client.init();
core.workspaces.setFormatUrlWithWorkspaceId((url, id) => this.getPatchedUrl(url, id));
/**
* Retrieve workspace id from url
Expand Down

0 comments on commit e8dcf49

Please sign in to comment.