diff --git a/src/plugins/workspace/opensearch_dashboards.json b/src/plugins/workspace/opensearch_dashboards.json index e6ff1e2d0173..cf67547f788c 100644 --- a/src/plugins/workspace/opensearch_dashboards.json +++ b/src/plugins/workspace/opensearch_dashboards.json @@ -7,6 +7,6 @@ "savedObjects", "opensearchDashboardsReact" ], - "optionalPlugins": ["savedObjectsManagement"], + "optionalPlugins": ["savedObjectsManagement","management"], "requiredBundles": ["opensearchDashboardsReact"] } diff --git a/src/plugins/workspace/public/plugin.test.ts b/src/plugins/workspace/public/plugin.test.ts index 50a6b5e70a5b..894795e6c50e 100644 --- a/src/plugins/workspace/public/plugin.test.ts +++ b/src/plugins/workspace/public/plugin.test.ts @@ -10,6 +10,7 @@ import { applicationServiceMock, chromeServiceMock, coreMock } from '../../../co import { WorkspacePlugin } from './plugin'; import { WORKSPACE_FATAL_ERROR_APP_ID, WORKSPACE_OVERVIEW_APP_ID } from '../common/constants'; import { savedObjectsManagementPluginMock } from '../../saved_objects_management/public/mocks'; +import { managementPluginMock } from '../../management/public/mocks'; describe('Workspace plugin', () => { const getSetupMock = () => ({ @@ -25,6 +26,7 @@ describe('Workspace plugin', () => { const workspacePlugin = new WorkspacePlugin(); await workspacePlugin.setup(setupMock, { savedObjectsManagement: savedObjectManagementSetupMock, + management: managementPluginMock.createSetupContract(), }); expect(setupMock.application.register).toBeCalledTimes(4); expect(WorkspaceClientMock).toBeCalledTimes(1); @@ -73,7 +75,9 @@ describe('Workspace plugin', () => { }); const workspacePlugin = new WorkspacePlugin(); - await workspacePlugin.setup(setupMock, {}); + await workspacePlugin.setup(setupMock, { + management: managementPluginMock.createSetupContract(), + }); expect(setupMock.application.register).toBeCalledTimes(4); expect(WorkspaceClientMock).toBeCalledTimes(1); expect(workspaceClientMock.enterWorkspace).toBeCalledWith('workspaceId'); @@ -127,7 +131,9 @@ describe('Workspace plugin', () => { }); const workspacePlugin = new WorkspacePlugin(); - await workspacePlugin.setup(setupMock, {}); + await workspacePlugin.setup(setupMock, { + management: managementPluginMock.createSetupContract(), + }); currentAppIdSubscriber?.next(WORKSPACE_FATAL_ERROR_APP_ID); expect(applicationStartMock.navigateToApp).toBeCalledWith(WORKSPACE_OVERVIEW_APP_ID); windowSpy.mockRestore(); @@ -136,7 +142,9 @@ describe('Workspace plugin', () => { it('#setup register workspace dropdown menu when setup', async () => { const setupMock = coreMock.createSetup(); const workspacePlugin = new WorkspacePlugin(); - await workspacePlugin.setup(setupMock, {}); + await workspacePlugin.setup(setupMock, { + 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 b27c4b3bdd4a..2155eabea84b 100644 --- a/src/plugins/workspace/public/plugin.ts +++ b/src/plugins/workspace/public/plugin.ts @@ -26,6 +26,7 @@ import { getWorkspaceIdFromUrl } from '../../../core/public/utils'; import { Services } from './types'; import { WorkspaceClient } from './workspace_client'; import { SavedObjectsManagementPluginSetup } from '../../../plugins/saved_objects_management/public'; +import { ManagementSetup } from '../../../plugins/management/public'; import { WorkspaceMenu } from './components/workspace_menu/workspace_menu'; import { getWorkspaceColumn } from './components/workspace_column'; import { isAppAccessibleInWorkspace } from './utils'; @@ -34,12 +35,14 @@ type WorkspaceAppType = (params: AppMountParameters, services: Services) => () = interface WorkspacePluginSetupDeps { savedObjectsManagement?: SavedObjectsManagementPluginSetup; + management?: ManagementSetup; } export class WorkspacePlugin implements Plugin<{}, {}, WorkspacePluginSetupDeps> { private coreStart?: CoreStart; private currentWorkspaceSubscription?: Subscription; private currentWorkspaceIdSubscription?: Subscription; + private managementCurrentWorkspaceIdSubscription?: Subscription; private appUpdater$ = new BehaviorSubject(() => undefined); private _changeSavedObjectCurrentWorkspace() { if (this.coreStart) { @@ -75,11 +78,37 @@ export class WorkspacePlugin implements Plugin<{}, {}, WorkspacePluginSetupDeps> }); } - public async setup(core: CoreSetup, { savedObjectsManagement }: WorkspacePluginSetupDeps) { + /** + * If workspace is enabled and user has entered workspace, hide advance settings and dataSource menu by disabling the corresponding apps. + */ + 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 */ @@ -212,5 +241,6 @@ export class WorkspacePlugin implements Plugin<{}, {}, WorkspacePluginSetupDeps> public stop() { this.currentWorkspaceSubscription?.unsubscribe(); this.currentWorkspaceIdSubscription?.unsubscribe(); + this.managementCurrentWorkspaceIdSubscription?.unsubscribe(); } }