Skip to content

Commit

Permalink
hide datasource and settings menu when workspace enabled and entering…
Browse files Browse the repository at this point in the history
… workspace (opensearch-project#325)

* hide datasource and settings menu

Signed-off-by: tygao <[email protected]>

* Update src/plugins/management/public/components/management_app/management_app.tsx

Co-authored-by: SuZhou-Joe <[email protected]>

* update to workspace plugin

Signed-off-by: tygao <[email protected]>

* update

Signed-off-by: tygao <[email protected]>

* update function name

Signed-off-by: tygao <[email protected]>

* update test dependency

Signed-off-by: tygao <[email protected]>

* move function order

Signed-off-by: tygao <[email protected]>

* Update src/plugins/workspace/public/plugin.ts

Co-authored-by: Yulong Ruan <[email protected]>

* update management plugin to optional

Signed-off-by: tygao <[email protected]>

---------

Signed-off-by: tygao <[email protected]>
Co-authored-by: SuZhou-Joe <[email protected]>
Co-authored-by: Yulong Ruan <[email protected]>
  • Loading branch information
3 people authored Apr 15, 2024
1 parent 2c0827c commit 2058998
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/plugins/workspace/opensearch_dashboards.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
"requiredPlugins": [
"savedObjects"
],
"optionalPlugins": ["savedObjectsManagement", "applicationConfig"],
"optionalPlugins": ["savedObjectsManagement", "applicationConfig", "management"],
"requiredBundles": ["opensearchDashboardsReact"]
}
5 changes: 5 additions & 0 deletions src/plugins/workspace/public/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
});
Expand Down
32 changes: 30 additions & 2 deletions src/plugins/workspace/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<AppUpdater>(() => undefined);
private _changeSavedObjectCurrentWorkspace() {
if (this.coreStart) {
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -226,6 +254,6 @@ export class WorkspacePlugin implements Plugin<{}, {}> {
public stop() {
this.currentWorkspaceIdSubscription?.unsubscribe();
this.currentWorkspaceSubscription?.unsubscribe();
this.currentWorkspaceIdSubscription?.unsubscribe();
this.managementCurrentWorkspaceIdSubscription?.unsubscribe();
}
}

0 comments on commit 2058998

Please sign in to comment.