Skip to content

Commit

Permalink
Hide datasource and settings menu in dashboard management when in wor…
Browse files Browse the repository at this point in the history
…kspace (#6455)

* hide datasource and settings menu when workspace enabled and entering workspace

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

* doc: update changelog

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

* update comments

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

---------

Signed-off-by: tygao <[email protected]>
Co-authored-by: Yulong Ruan <[email protected]>
(cherry picked from commit 7a46475)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

# Conflicts:
#	CHANGELOG.md
  • Loading branch information
github-actions[bot] committed Apr 22, 2024
1 parent 78bf7cf commit 88a1116
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 5 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 @@ -7,6 +7,6 @@
"savedObjects",
"opensearchDashboardsReact"
],
"optionalPlugins": ["savedObjectsManagement"],
"optionalPlugins": ["savedObjectsManagement","management"],
"requiredBundles": ["opensearchDashboardsReact"]
}
14 changes: 11 additions & 3 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 { 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 = () => ({
Expand All @@ -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);
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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();
Expand All @@ -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);
});
});
32 changes: 31 additions & 1 deletion src/plugins/workspace/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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<AppUpdater>(() => undefined);
private _changeSavedObjectCurrentWorkspace() {
if (this.coreStart) {
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -212,5 +241,6 @@ export class WorkspacePlugin implements Plugin<{}, {}, WorkspacePluginSetupDeps>
public stop() {
this.currentWorkspaceSubscription?.unsubscribe();
this.currentWorkspaceIdSubscription?.unsubscribe();
this.managementCurrentWorkspaceIdSubscription?.unsubscribe();
}
}

0 comments on commit 88a1116

Please sign in to comment.