diff --git a/src/plugins/workspace/public/components/workspace_form/workspace_feature_selector.tsx b/src/plugins/workspace/public/components/workspace_form/workspace_feature_selector.tsx index e172b851f1f3..51badcba5360 100644 --- a/src/plugins/workspace/public/components/workspace_form/workspace_feature_selector.tsx +++ b/src/plugins/workspace/public/components/workspace_form/workspace_feature_selector.tsx @@ -20,7 +20,7 @@ import { DEFAULT_APP_CATEGORIES, PublicAppInfo } from '../../../../../core/publi import { WorkspaceFeature, WorkspaceFeatureGroup } from './types'; import { isDefaultCheckedFeatureId, isWorkspaceFeatureGroup } from './utils'; -import { getAllExcludingManagementApps } from '../../utils'; +import { getAllFilterApps } from '../../utils'; const libraryCategoryLabel = i18n.translate('core.ui.libraryNavList.label', { defaultMessage: 'Library', @@ -55,7 +55,7 @@ export const WorkspaceFeatureSelector = ({ Array >((previousValue, currentKey) => { const apps = category2Applications[currentKey]; - const features = getAllExcludingManagementApps(apps).map(({ id, title }) => ({ + const features = getAllFilterApps(apps).map(({ id, title }) => ({ id, name: title, })); diff --git a/src/plugins/workspace/public/utils.test.ts b/src/plugins/workspace/public/utils.test.ts index d2b9909eb682..ad30ccf6c2c0 100644 --- a/src/plugins/workspace/public/utils.test.ts +++ b/src/plugins/workspace/public/utils.test.ts @@ -5,6 +5,7 @@ import { featureMatchesConfig, + getAllFilterApps, getSelectedFeatureQuantities, isAppAccessibleInWorkspace, } from './utils'; @@ -126,19 +127,55 @@ describe('workspace utils: getSelectedFeatureQuantities', () => { status: 0, navLinkStatus: 1, }, + { + appRoute: '/app/opensearch_dashboards_overview', + id: 'opensearchDashboardsOverview', + title: 'Overview', + category: { + id: 'opensearchDashboards', + label: 'Library', + euiIconType: 'inputOutput', + order: 1000, + }, + navLinkStatus: 1, + order: -2000, + status: 0, + workspaceAccessibility: WorkspaceAccessibility.NO, + }, + { + appRoute: '/app/management', + id: 'management', + title: 'Dashboards Management', + category: { + id: 'management', + label: 'Management', + order: 5000, + euiIconType: 'managementApp', + }, + status: 0, + navLinkStatus: 1, + }, ] as PublicAppInfo[]; - it('should support * rules and exclude management category', () => { + + it('should filter out apps correctly', () => { + const filterApps = getAllFilterApps(defaultApplications); + expect(filterApps.length).toBe(2); + expect(filterApps[0].id).toBe('dashboards'); + expect(filterApps[1].id).toBe('management'); + }); + + it('should support * rules and include dashboards management', () => { const { total, selected } = getSelectedFeatureQuantities(['*'], defaultApplications); - expect(total).toBe(1); - expect(selected).toBe(1); + expect(total).toBe(2); + expect(selected).toBe(2); }); - it('should get quantity normally and exclude management category', () => { + it('should get quantity normally and include dashboards management', () => { const { total, selected } = getSelectedFeatureQuantities( ['dev_tools', '!@management'], defaultApplications ); - expect(total).toBe(1); + expect(total).toBe(2); expect(selected).toBe(0); }); }); diff --git a/src/plugins/workspace/public/utils.ts b/src/plugins/workspace/public/utils.ts index e65d62a58396..48b85db1fbc2 100644 --- a/src/plugins/workspace/public/utils.ts +++ b/src/plugins/workspace/public/utils.ts @@ -69,13 +69,20 @@ export const featureMatchesConfig = (featureConfigs: string[]) => ({ return matched; }; -// Get all apps excluding management category -export const getAllExcludingManagementApps = (applications: PublicAppInfo[]): PublicAppInfo[] => { +// Get all apps that should be displayed in workspace. +export const getAllFilterApps = (applications: PublicAppInfo[]): PublicAppInfo[] => { return applications.filter( - ({ navLinkStatus, chromeless, category }) => - navLinkStatus !== AppNavLinkStatus.hidden && - !chromeless && - category?.id !== DEFAULT_APP_CATEGORIES.management.id + ({ navLinkStatus, chromeless, category, workspaceAccessibility, id }) => { + const filterCondition = + navLinkStatus !== AppNavLinkStatus.hidden && + !chromeless && + workspaceAccessibility !== WorkspaceAccessibility.NO; + // If the category is management, only retain dashboards management. + if (category?.id === DEFAULT_APP_CATEGORIES.management.id) { + return filterCondition && id === 'management'; + } + return filterCondition; + } ); }; @@ -83,7 +90,7 @@ export const getSelectedFeatureQuantities = ( featuresConfig: string[], applications: PublicAppInfo[] ) => { - const visibleApplications = getAllExcludingManagementApps(applications); + const visibleApplications = getAllFilterApps(applications); const featureFilter = featureMatchesConfig(featuresConfig); const selectedApplications = visibleApplications.filter((app) => featureFilter(app)); return {