Skip to content

Commit

Permalink
update to workspace plugin
Browse files Browse the repository at this point in the history
Signed-off-by: tygao <tygao@amazon.com>
  • Loading branch information
raintygao committed Apr 11, 2024
1 parent 6ba49b9 commit 793bbe6
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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<string>('');
const [sections, setSections] = useState<ManagementSection[]>();

Expand All @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions src/plugins/management/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@ export class ManagementPlugin implements Plugin<ManagementSetup, ManagementStart
sections: getSectionsServiceStartPrivate(),
opensearchDashboardsVersion,
setBreadcrumbs: coreStart.chrome.setBreadcrumbs,
capabilities: coreStart.application.capabilities,
workspaces: coreStart.workspaces,
});
},
});
Expand Down
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
14 changes: 13 additions & 1 deletion src/plugins/workspace/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import type { 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 { featureMatchesConfig } from './utils';
import {
AppMountParameters,
Expand Down Expand Up @@ -34,6 +35,7 @@ type WorkspaceAppType = (params: AppMountParameters, services: Services) => () =

interface WorkspacePluginSetupDeps {
savedObjectsManagement?: SavedObjectsManagementPluginSetup;
management: ManagementSetup;
}

export class WorkspacePlugin implements Plugin<{}, {}> {
Expand Down Expand Up @@ -98,7 +100,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();
/**
Expand Down Expand Up @@ -140,6 +145,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());
}
}

Expand Down

0 comments on commit 793bbe6

Please sign in to comment.