From a12bdb4732a822bbf2a5b4d1d295ef3a3aa1f53d Mon Sep 17 00:00:00 2001 From: tygao Date: Thu, 11 Apr 2024 17:45:57 +0800 Subject: [PATCH] update Signed-off-by: tygao --- src/plugins/workspace/public/plugin.ts | 31 ++++++++++++++++++++------ 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/src/plugins/workspace/public/plugin.ts b/src/plugins/workspace/public/plugin.ts index 193d1605390..4093f4c036c 100644 --- a/src/plugins/workspace/public/plugin.ts +++ b/src/plugins/workspace/public/plugin.ts @@ -41,6 +41,7 @@ export class WorkspacePlugin implements Plugin<{}, {}> { private coreStart?: CoreStart; private currentWorkspaceIdSubscription?: Subscription; private currentWorkspaceSubscription?: Subscription; + private managementCurrentWorkspaceSubscription?: Subscription; private appUpdater$ = new BehaviorSubject(() => undefined); private _changeSavedObjectCurrentWorkspace() { if (this.coreStart) { @@ -76,6 +77,26 @@ export class WorkspacePlugin implements Plugin<{}, {}> { }); } + /** + * 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.managementCurrentWorkspaceSubscription?.unsubscribe(); + + this.managementCurrentWorkspaceSubscription = currentWorkspaceId$.subscribe( + (currentWorkspaceId) => { + if (currentWorkspaceId) { + const managementSectionApps = management.sections.section.opensearchDashboards.getAppsEnabled(); + const disabledApps = managementSectionApps.filter( + (app) => app.id === 'settings' || app.id === 'dataSources' + ); + disabledApps?.forEach((app) => app.disable()); + } + } + ); + } + public async setup( core: CoreSetup, { savedObjectsManagement, management }: WorkspacePluginSetupDeps @@ -124,12 +145,8 @@ export class WorkspacePlugin implements Plugin<{}, {}> { }); })(); - // If workspace is enabled and user has entered workspace, hide advance settings and dataSource menu and disable - const managementSectionApps = management.sections.section.opensearchDashboards.getAppsEnabled(); - const disabledApps = managementSectionApps.filter( - (app) => app.id === 'settings' || app.id === 'dataSources' - ); - disabledApps?.forEach((app) => app.disable()); + // Hide advance settings and dataSource menus and disable in setup + this.disableManagementApps(core, management); } } @@ -235,6 +252,6 @@ export class WorkspacePlugin implements Plugin<{}, {}> { public stop() { this.currentWorkspaceIdSubscription?.unsubscribe(); this.currentWorkspaceSubscription?.unsubscribe(); - this.currentWorkspaceIdSubscription?.unsubscribe(); + this.managementCurrentWorkspaceSubscription?.unsubscribe(); } }