Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hide datasource and settings menu when workspace enabled and entering workspace #325

Merged
merged 11 commits into from
Apr 15, 2024
3 changes: 2 additions & 1 deletion src/plugins/workspace/opensearch_dashboards.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"server": true,
"ui": true,
"requiredPlugins": [
"savedObjects"
"savedObjects",
"management"
],
"optionalPlugins": ["savedObjectsManagement"],
"requiredBundles": ["opensearchDashboardsReact"]
Expand Down
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 @@ -33,12 +34,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 @@ -74,11 +77,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();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we move this to stop method?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stop method will also call this.


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'
SuZhou-Joe marked this conversation as resolved.
Show resolved Hide resolved
);
disabledApps?.forEach((app) => app.disable());
}
}
);
}
raintygao marked this conversation as resolved.
Show resolved Hide resolved

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
this.disableManagementApps(core, management);
Hailong-am marked this conversation as resolved.
Show resolved Hide resolved
/**
* Retrieve workspace id from url
*/
Expand Down Expand Up @@ -223,6 +251,6 @@ export class WorkspacePlugin implements Plugin<{}, {}> {
public stop() {
this.currentWorkspaceIdSubscription?.unsubscribe();
this.currentWorkspaceSubscription?.unsubscribe();
this.currentWorkspaceIdSubscription?.unsubscribe();
this.managementCurrentWorkspaceIdSubscription?.unsubscribe();
}
}
Loading