diff --git a/src/plugins/workspace/public/plugin.ts b/src/plugins/workspace/public/plugin.ts index 90517f2f0e5e..a2c84554205a 100644 --- a/src/plugins/workspace/public/plugin.ts +++ b/src/plugins/workspace/public/plugin.ts @@ -121,6 +121,16 @@ export class WorkspacePlugin implements Plugin<{}, {}, WorkspacePluginSetupDeps> this.currentWorkspaceSubscription = currentWorkspace$.subscribe((currentWorkspace) => { if (currentWorkspace) { this.navGroupUpdater$.next((navGroup) => { + /** + * The following logic determines whether a navigation group should be hidden or not based on the workspace's feature configurations. + * It checks the following conditions: + * 1. The navigation group is not a system-level group (system groups are always visible). + * 2. The current workspace has feature configurations set up. + * 3. The current workspace's use case it not "All use case". + * 4. The current navigation group is not included in the feature configurations of the workspace. + * + * If all these conditions are true, it means that the navigation group should be hidden. + */ if ( navGroup.type !== NavGroupType.SYSTEM && currentWorkspace.features && diff --git a/src/plugins/workspace/public/utils.test.ts b/src/plugins/workspace/public/utils.test.ts index b110772616ff..4763a4455746 100644 --- a/src/plugins/workspace/public/utils.test.ts +++ b/src/plugins/workspace/public/utils.test.ts @@ -246,6 +246,15 @@ describe('workspace utils: isAppAccessibleInWorkspace', () => { ) ).toBe(true); }); + it('any app is accessible when workspace is all use case', () => { + expect( + isAppAccessibleInWorkspace( + { id: 'any_app', title: 'Any app', mount: jest.fn() }, + { id: 'workspace_id', name: 'workspace name', features: ['use-case-all'] }, + STATIC_USE_CASES + ) + ).toBe(true); + }); }); describe('workspace utils: filterWorkspaceConfigurableApps', () => { @@ -341,24 +350,6 @@ describe('workspace utils: isFeatureIdInsideUseCase', () => { ]) ).toBe(true); }); - it('should return true if feature id exists inside any use case', () => { - expect( - isFeatureIdInsideUseCase('searchRelevance', 'all', [ - { - id: 'foo', - title: 'Foo', - description: 'Foo description', - features: ['discover'], - }, - { - id: 'bar', - title: 'Bar', - description: 'Bar description', - features: ['searchRelevance'], - }, - ]) - ).toBe(true); - }); }); describe('workspace utils: isNavGroupInFeatureConfigs', () => { diff --git a/src/plugins/workspace/public/utils.ts b/src/plugins/workspace/public/utils.ts index 6f51b97574ef..589f1d8159d2 100644 --- a/src/plugins/workspace/public/utils.ts +++ b/src/plugins/workspace/public/utils.ts @@ -40,10 +40,7 @@ export const isFeatureIdInsideUseCase = ( useCaseId: string, useCases: WorkspaceUseCase[] ) => { - const availableFeatures = - useCaseId === ALL_USE_CASE_ID - ? useCases.reduce((previous, { features }) => previous.concat(features ?? []), []) - : useCases.find(({ id }) => id === useCaseId)?.features ?? []; + const availableFeatures = useCases.find(({ id }) => id === useCaseId)?.features ?? []; return availableFeatures.includes(featureId); }; @@ -142,6 +139,13 @@ export function isAppAccessibleInWorkspace( return true; } + /** + * When workspace is all use case, all apps are accessible + */ + if (getFirstUseCaseOfFeatureConfigs(workspace.features) === ALL_USE_CASE_ID) { + return true; + } + /** * The app is configured into a workspace, it is accessible after entering the workspace */