From 3202ffb0c0a694ab1d003b53174963c3420e616c Mon Sep 17 00:00:00 2001 From: tygao Date: Thu, 11 Apr 2024 16:18:25 +0800 Subject: [PATCH 1/9] hide datasource and settings menu Signed-off-by: tygao --- .../management_app/management_app.tsx | 20 ++++++++++++++++--- src/plugins/management/public/plugin.ts | 2 ++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/plugins/management/public/components/management_app/management_app.tsx b/src/plugins/management/public/components/management_app/management_app.tsx index b2109ceb08ca..c78eb77c5d13 100644 --- a/src/plugins/management/public/components/management_app/management_app.tsx +++ b/src/plugins/management/public/components/management_app/management_app.tsx @@ -37,7 +37,8 @@ import { ManagementSection, MANAGEMENT_BREADCRUMB } from '../../utils'; import { ManagementRouter } from './management_router'; import { ManagementSidebarNav } from '../management_sidebar_nav'; import { reactRouterNavigate } from '../../../../opensearch_dashboards_react/public'; -import { SectionsServiceStart } from '../../types'; +import { SectionsServiceStart, ManagementSectionId } from '../../types'; +import { ApplicationStart, WorkspacesStart } from '../../../../../core/public'; import './management_app.scss'; @@ -51,10 +52,12 @@ export interface ManagementAppDependencies { sections: SectionsServiceStart; opensearchDashboardsVersion: string; setBreadcrumbs: (newBreadcrumbs: ChromeBreadcrumb[]) => void; + capabilities: ApplicationStart['capabilities']; + workspaces: WorkspacesStart; } export const ManagementApp = ({ dependencies, history }: ManagementAppProps) => { - const { setBreadcrumbs } = dependencies; + const { setBreadcrumbs, capabilities, workspaces } = dependencies; const [selectedId, setSelectedId] = useState(''); const [sections, setSections] = useState(); @@ -79,8 +82,19 @@ export const ManagementApp = ({ dependencies, history }: ManagementAppProps) => ); useEffect(() => { + // If workspace is enabled and user has entered workspace, hide advance settings and dataSource menu + if (capabilities.workspaces.enabled && workspaces.currentWorkspace$.getValue()) { + const opensearchDashboardsSection = dependencies.sections + .getSectionsEnabled() + .find((section) => section.id === ManagementSectionId.OpenSearchDashboards); + const disabledApps = opensearchDashboardsSection?.apps.filter( + (app) => app.id === 'settings' || app.id === 'dataSources' + ); + disabledApps?.forEach((app) => app.disable()); + } + setSections(dependencies.sections.getSectionsEnabled()); - }, [dependencies.sections]); + }, [dependencies.sections, capabilities, workspaces]); if (!sections) { return null; diff --git a/src/plugins/management/public/plugin.ts b/src/plugins/management/public/plugin.ts index 81a970a0fc48..2c1bca7907de 100644 --- a/src/plugins/management/public/plugin.ts +++ b/src/plugins/management/public/plugin.ts @@ -87,6 +87,8 @@ export class ManagementPlugin implements Plugin Date: Thu, 11 Apr 2024 16:32:27 +0800 Subject: [PATCH 2/9] Update src/plugins/management/public/components/management_app/management_app.tsx Co-authored-by: SuZhou-Joe --- .../public/components/management_app/management_app.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/management/public/components/management_app/management_app.tsx b/src/plugins/management/public/components/management_app/management_app.tsx index c78eb77c5d13..ecb5b5c08645 100644 --- a/src/plugins/management/public/components/management_app/management_app.tsx +++ b/src/plugins/management/public/components/management_app/management_app.tsx @@ -94,7 +94,7 @@ export const ManagementApp = ({ dependencies, history }: ManagementAppProps) => } setSections(dependencies.sections.getSectionsEnabled()); - }, [dependencies.sections, capabilities, workspaces]); + }, [dependencies.sections.getSectionsEnabled(), capabilities.workspaces.enabled, workspaces.currentWorkspace$.getValue()]); if (!sections) { return null; From 5db6063a89cae12defce4b8bf5785d9435a5ea5a Mon Sep 17 00:00:00 2001 From: tygao Date: Thu, 11 Apr 2024 17:09:17 +0800 Subject: [PATCH 3/9] update to workspace plugin Signed-off-by: tygao --- .../management_app/management_app.tsx | 20 +++---------------- src/plugins/management/public/plugin.ts | 2 -- .../workspace/opensearch_dashboards.json | 3 ++- src/plugins/workspace/public/plugin.ts | 14 ++++++++++++- 4 files changed, 18 insertions(+), 21 deletions(-) diff --git a/src/plugins/management/public/components/management_app/management_app.tsx b/src/plugins/management/public/components/management_app/management_app.tsx index ecb5b5c08645..b2109ceb08ca 100644 --- a/src/plugins/management/public/components/management_app/management_app.tsx +++ b/src/plugins/management/public/components/management_app/management_app.tsx @@ -37,8 +37,7 @@ import { ManagementSection, MANAGEMENT_BREADCRUMB } from '../../utils'; import { ManagementRouter } from './management_router'; import { ManagementSidebarNav } from '../management_sidebar_nav'; import { reactRouterNavigate } from '../../../../opensearch_dashboards_react/public'; -import { SectionsServiceStart, ManagementSectionId } from '../../types'; -import { ApplicationStart, WorkspacesStart } from '../../../../../core/public'; +import { SectionsServiceStart } from '../../types'; import './management_app.scss'; @@ -52,12 +51,10 @@ export interface ManagementAppDependencies { sections: SectionsServiceStart; opensearchDashboardsVersion: string; setBreadcrumbs: (newBreadcrumbs: ChromeBreadcrumb[]) => void; - capabilities: ApplicationStart['capabilities']; - workspaces: WorkspacesStart; } export const ManagementApp = ({ dependencies, history }: ManagementAppProps) => { - const { setBreadcrumbs, capabilities, workspaces } = dependencies; + const { setBreadcrumbs } = dependencies; const [selectedId, setSelectedId] = useState(''); const [sections, setSections] = useState(); @@ -82,19 +79,8 @@ export const ManagementApp = ({ dependencies, history }: ManagementAppProps) => ); useEffect(() => { - // If workspace is enabled and user has entered workspace, hide advance settings and dataSource menu - if (capabilities.workspaces.enabled && workspaces.currentWorkspace$.getValue()) { - const opensearchDashboardsSection = dependencies.sections - .getSectionsEnabled() - .find((section) => section.id === ManagementSectionId.OpenSearchDashboards); - const disabledApps = opensearchDashboardsSection?.apps.filter( - (app) => app.id === 'settings' || app.id === 'dataSources' - ); - disabledApps?.forEach((app) => app.disable()); - } - setSections(dependencies.sections.getSectionsEnabled()); - }, [dependencies.sections.getSectionsEnabled(), capabilities.workspaces.enabled, workspaces.currentWorkspace$.getValue()]); + }, [dependencies.sections]); if (!sections) { return null; diff --git a/src/plugins/management/public/plugin.ts b/src/plugins/management/public/plugin.ts index 2c1bca7907de..81a970a0fc48 100644 --- a/src/plugins/management/public/plugin.ts +++ b/src/plugins/management/public/plugin.ts @@ -87,8 +87,6 @@ export class ManagementPlugin implements Plugin () = interface WorkspacePluginSetupDeps { savedObjectsManagement?: SavedObjectsManagementPluginSetup; + management: ManagementSetup; } export class WorkspacePlugin implements Plugin<{}, {}> { @@ -74,7 +76,10 @@ export class WorkspacePlugin implements Plugin<{}, {}> { }); } - public async setup(core: CoreSetup, { savedObjectsManagement }: WorkspacePluginSetupDeps) { + public async setup( + core: CoreSetup, + { savedObjectsManagement, management }: WorkspacePluginSetupDeps + ) { const workspaceClient = new WorkspaceClient(core.http, core.workspaces); await workspaceClient.init(); core.application.registerAppUpdater(this.appUpdater$); @@ -118,6 +123,13 @@ export class WorkspacePlugin implements Plugin<{}, {}> { currentAppIdSubscription.unsubscribe(); }); })(); + + // 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()); } } From a12bdb4732a822bbf2a5b4d1d295ef3a3aa1f53d Mon Sep 17 00:00:00 2001 From: tygao Date: Thu, 11 Apr 2024 17:45:57 +0800 Subject: [PATCH 4/9] 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 193d16053908..4093f4c036cf 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(); } } From 32c504950e08c35a438bfe5017a79a16f81804ce Mon Sep 17 00:00:00 2001 From: tygao Date: Thu, 11 Apr 2024 17:49:42 +0800 Subject: [PATCH 5/9] update function name Signed-off-by: tygao --- src/plugins/workspace/public/plugin.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/plugins/workspace/public/plugin.ts b/src/plugins/workspace/public/plugin.ts index 4093f4c036cf..ffa0dff24461 100644 --- a/src/plugins/workspace/public/plugin.ts +++ b/src/plugins/workspace/public/plugin.ts @@ -41,7 +41,7 @@ export class WorkspacePlugin implements Plugin<{}, {}> { private coreStart?: CoreStart; private currentWorkspaceIdSubscription?: Subscription; private currentWorkspaceSubscription?: Subscription; - private managementCurrentWorkspaceSubscription?: Subscription; + private managementCurrentWorkspaceIdSubscription?: Subscription; private appUpdater$ = new BehaviorSubject(() => undefined); private _changeSavedObjectCurrentWorkspace() { if (this.coreStart) { @@ -82,9 +82,9 @@ export class WorkspacePlugin implements Plugin<{}, {}> { */ private disableManagementApps(core: CoreSetup, management: ManagementSetup) { const currentWorkspaceId$ = core.workspaces.currentWorkspaceId$; - this.managementCurrentWorkspaceSubscription?.unsubscribe(); + this.managementCurrentWorkspaceIdSubscription?.unsubscribe(); - this.managementCurrentWorkspaceSubscription = currentWorkspaceId$.subscribe( + this.managementCurrentWorkspaceIdSubscription = currentWorkspaceId$.subscribe( (currentWorkspaceId) => { if (currentWorkspaceId) { const managementSectionApps = management.sections.section.opensearchDashboards.getAppsEnabled(); @@ -252,6 +252,6 @@ export class WorkspacePlugin implements Plugin<{}, {}> { public stop() { this.currentWorkspaceIdSubscription?.unsubscribe(); this.currentWorkspaceSubscription?.unsubscribe(); - this.managementCurrentWorkspaceSubscription?.unsubscribe(); + this.managementCurrentWorkspaceIdSubscription?.unsubscribe(); } } From 9bc6fc2ce18c673eaa52e9bfa07eea75a5e93e79 Mon Sep 17 00:00:00 2001 From: tygao Date: Thu, 11 Apr 2024 17:54:20 +0800 Subject: [PATCH 6/9] update test dependency Signed-off-by: tygao --- src/plugins/workspace/public/plugin.test.ts | 5 +++++ 1 file changed, 5 insertions(+) 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); }); From b8477fc9d2e918c0497c61ed6fb254cfaaf487b1 Mon Sep 17 00:00:00 2001 From: tygao Date: Thu, 11 Apr 2024 17:56:16 +0800 Subject: [PATCH 7/9] move function order Signed-off-by: tygao --- src/plugins/workspace/public/plugin.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/plugins/workspace/public/plugin.ts b/src/plugins/workspace/public/plugin.ts index ffa0dff24461..24b72bda811f 100644 --- a/src/plugins/workspace/public/plugin.ts +++ b/src/plugins/workspace/public/plugin.ts @@ -105,6 +105,8 @@ export class WorkspacePlugin implements Plugin<{}, {}> { await workspaceClient.init(); core.application.registerAppUpdater(this.appUpdater$); + // Hide advance settings and dataSource menus and disable in setup + this.disableManagementApps(core, management); /** * Retrieve workspace id from url */ @@ -144,9 +146,6 @@ export class WorkspacePlugin implements Plugin<{}, {}> { currentAppIdSubscription.unsubscribe(); }); })(); - - // Hide advance settings and dataSource menus and disable in setup - this.disableManagementApps(core, management); } } From 94858273de40e473f32a7139e9baa1846f00d1e9 Mon Sep 17 00:00:00 2001 From: tygao Date: Fri, 12 Apr 2024 13:56:33 +0800 Subject: [PATCH 8/9] Update src/plugins/workspace/public/plugin.ts Co-authored-by: Yulong Ruan --- src/plugins/workspace/public/plugin.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/plugins/workspace/public/plugin.ts b/src/plugins/workspace/public/plugin.ts index 24b72bda811f..8f0aff8d5e74 100644 --- a/src/plugins/workspace/public/plugin.ts +++ b/src/plugins/workspace/public/plugin.ts @@ -87,11 +87,9 @@ export class WorkspacePlugin implements Plugin<{}, {}> { this.managementCurrentWorkspaceIdSubscription = currentWorkspaceId$.subscribe( (currentWorkspaceId) => { if (currentWorkspaceId) { - const managementSectionApps = management.sections.section.opensearchDashboards.getAppsEnabled(); - const disabledApps = managementSectionApps.filter( - (app) => app.id === 'settings' || app.id === 'dataSources' + ['settings', 'dataSources'].forEach((appId) => + management.sections.section.opensearchDashboards.getApp(appId)?.disable() ); - disabledApps?.forEach((app) => app.disable()); } } ); From b2aa530b02107777b5fdb0613ac36717f29b6de6 Mon Sep 17 00:00:00 2001 From: tygao Date: Fri, 12 Apr 2024 17:55:25 +0800 Subject: [PATCH 9/9] update management plugin to optional Signed-off-by: tygao --- src/plugins/workspace/opensearch_dashboards.json | 5 ++--- src/plugins/workspace/public/plugin.ts | 6 ++++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/plugins/workspace/opensearch_dashboards.json b/src/plugins/workspace/opensearch_dashboards.json index fd46111980d8..34a684995fff 100644 --- a/src/plugins/workspace/opensearch_dashboards.json +++ b/src/plugins/workspace/opensearch_dashboards.json @@ -4,9 +4,8 @@ "server": true, "ui": true, "requiredPlugins": [ - "savedObjects", - "management" + "savedObjects" ], - "optionalPlugins": ["savedObjectsManagement"], + "optionalPlugins": ["savedObjectsManagement","management"], "requiredBundles": ["opensearchDashboardsReact"] } diff --git a/src/plugins/workspace/public/plugin.ts b/src/plugins/workspace/public/plugin.ts index 24b72bda811f..d6d2b4286a6b 100644 --- a/src/plugins/workspace/public/plugin.ts +++ b/src/plugins/workspace/public/plugin.ts @@ -34,7 +34,7 @@ type WorkspaceAppType = (params: AppMountParameters, services: Services) => () = interface WorkspacePluginSetupDeps { savedObjectsManagement?: SavedObjectsManagementPluginSetup; - management: ManagementSetup; + management?: ManagementSetup; } export class WorkspacePlugin implements Plugin<{}, {}> { @@ -106,7 +106,9 @@ export class WorkspacePlugin implements Plugin<{}, {}> { core.application.registerAppUpdater(this.appUpdater$); // Hide advance settings and dataSource menus and disable in setup - this.disableManagementApps(core, management); + if (management) { + this.disableManagementApps(core, management); + } /** * Retrieve workspace id from url */