diff --git a/src/plugins/workspace/opensearch_dashboards.json b/src/plugins/workspace/opensearch_dashboards.json index 039486a22cbf..2bd52d8fbdde 100644 --- a/src/plugins/workspace/opensearch_dashboards.json +++ b/src/plugins/workspace/opensearch_dashboards.json @@ -6,6 +6,6 @@ "requiredPlugins": [ "savedObjects" ], - "optionalPlugins": ["savedObjectsManagement", "applicationConfig"], + "optionalPlugins": ["savedObjectsManagement", "applicationConfig", "management"], "requiredBundles": ["opensearchDashboardsReact"] } diff --git a/src/plugins/workspace/public/plugin.test.ts b/src/plugins/workspace/public/plugin.test.ts index fc16bc207345..1ec289ddf87b 100644 --- a/src/plugins/workspace/public/plugin.test.ts +++ b/src/plugins/workspace/public/plugin.test.ts @@ -10,6 +10,7 @@ import { WorkspacePlugin } from './plugin'; import { WORKSPACE_FATAL_ERROR_APP_ID, WORKSPACE_OVERVIEW_APP_ID } from '../common/constants'; import { Observable, Subscriber } from 'rxjs'; import { savedObjectsManagementPluginMock } from '../../saved_objects_management/public/mocks'; +import { managementPluginMock } from '../../management/public/mocks'; describe('Workspace plugin', () => { beforeEach(() => { @@ -22,6 +23,7 @@ describe('Workspace plugin', () => { const workspacePlugin = new WorkspacePlugin(); await workspacePlugin.setup(setupMock, { savedObjectsManagement: savedObjectManagementSetupMock, + management: managementPluginMock.createSetupContract(), }); expect(setupMock.application.register).toBeCalledTimes(5); expect(WorkspaceClientMock).toBeCalledTimes(1); @@ -60,6 +62,7 @@ describe('Workspace plugin', () => { const workspacePlugin = new WorkspacePlugin(); await workspacePlugin.setup(setupMock, { savedObjectsManagement: savedObjectsManagementPluginMock.createSetupContract(), + management: managementPluginMock.createSetupContract(), }); expect(setupMock.application.register).toBeCalledTimes(5); expect(WorkspaceClientMock).toBeCalledTimes(1); @@ -116,6 +119,7 @@ describe('Workspace plugin', () => { const workspacePlugin = new WorkspacePlugin(); await workspacePlugin.setup(setupMock, { savedObjectsManagement: savedObjectsManagementPluginMock.createSetupContract(), + management: managementPluginMock.createSetupContract(), }); currentAppIdSubscriber?.next(WORKSPACE_FATAL_ERROR_APP_ID); expect(applicationStartMock.navigateToApp).toBeCalledWith(WORKSPACE_OVERVIEW_APP_ID); @@ -135,6 +139,7 @@ describe('Workspace plugin', () => { const workspacePlugin = new WorkspacePlugin(); await workspacePlugin.setup(setupMock, { savedObjectsManagement: savedObjectsManagementPluginMock.createSetupContract(), + management: managementPluginMock.createSetupContract(), }); expect(setupMock.chrome.registerCollapsibleNavHeader).toBeCalledTimes(1); }); diff --git a/src/plugins/workspace/public/plugin.ts b/src/plugins/workspace/public/plugin.ts index 240e10c24570..4b43c3438179 100644 --- a/src/plugins/workspace/public/plugin.ts +++ b/src/plugins/workspace/public/plugin.ts @@ -6,6 +6,7 @@ import { BehaviorSubject, Subscription } from 'rxjs'; import { i18n } from '@osd/i18n'; import { SavedObjectsManagementPluginSetup } from 'src/plugins/saved_objects_management/public'; +import { ManagementSetup } from 'src/plugins/management/public'; import { AppMountParameters, AppNavLinkStatus, @@ -34,12 +35,14 @@ type WorkspaceAppType = (params: AppMountParameters, services: Services) => () = interface WorkspacePluginSetupDeps { savedObjectsManagement?: SavedObjectsManagementPluginSetup; + management?: ManagementSetup; } export class WorkspacePlugin implements Plugin<{}, {}> { private coreStart?: CoreStart; private currentWorkspaceIdSubscription?: Subscription; private currentWorkspaceSubscription?: Subscription; + private managementCurrentWorkspaceIdSubscription?: Subscription; private appUpdater$ = new BehaviorSubject(() => undefined); private _changeSavedObjectCurrentWorkspace() { if (this.coreStart) { @@ -75,11 +78,36 @@ export class WorkspacePlugin implements Plugin<{}, {}> { }); } - public async setup(core: CoreSetup, { savedObjectsManagement }: WorkspacePluginSetupDeps) { + /** + * If workspace is enabled and user has entered workspace, hide advance settings and dataSource menu and disable + */ + private disableManagementApps(core: CoreSetup, management: ManagementSetup) { + const currentWorkspaceId$ = core.workspaces.currentWorkspaceId$; + this.managementCurrentWorkspaceIdSubscription?.unsubscribe(); + + this.managementCurrentWorkspaceIdSubscription = currentWorkspaceId$.subscribe( + (currentWorkspaceId) => { + if (currentWorkspaceId) { + ['settings', 'dataSources'].forEach((appId) => + management.sections.section.opensearchDashboards.getApp(appId)?.disable() + ); + } + } + ); + } + + public async setup( + core: CoreSetup, + { savedObjectsManagement, management }: WorkspacePluginSetupDeps + ) { const workspaceClient = new WorkspaceClient(core.http, core.workspaces); await workspaceClient.init(); core.application.registerAppUpdater(this.appUpdater$); + // Hide advance settings and dataSource menus and disable in setup + if (management) { + this.disableManagementApps(core, management); + } /** * Retrieve workspace id from url */ @@ -226,6 +254,6 @@ export class WorkspacePlugin implements Plugin<{}, {}> { public stop() { this.currentWorkspaceIdSubscription?.unsubscribe(); this.currentWorkspaceSubscription?.unsubscribe(); - this.currentWorkspaceIdSubscription?.unsubscribe(); + this.managementCurrentWorkspaceIdSubscription?.unsubscribe(); } }