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
31 changes: 24 additions & 7 deletions src/plugins/workspace/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<AppUpdater>(() => undefined);
private _changeSavedObjectCurrentWorkspace() {
if (this.coreStart) {
Expand Down Expand Up @@ -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'
SuZhou-Joe marked this conversation as resolved.
Show resolved Hide resolved
);
disabledApps?.forEach((app) => app.disable());
}
}
);
}

public async setup(
core: CoreSetup,
{ savedObjectsManagement, management }: WorkspacePluginSetupDeps
Expand Down Expand Up @@ -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);
SuZhou-Joe marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down Expand Up @@ -235,6 +252,6 @@ export class WorkspacePlugin implements Plugin<{}, {}> {
public stop() {
this.currentWorkspaceIdSubscription?.unsubscribe();
this.currentWorkspaceSubscription?.unsubscribe();
this.currentWorkspaceIdSubscription?.unsubscribe();
this.managementCurrentWorkspaceSubscription?.unsubscribe();
}
}
Loading