Skip to content

Commit

Permalink
All use case can accessible any app and add comment
Browse files Browse the repository at this point in the history
Signed-off-by: Lin Wang <[email protected]>
  • Loading branch information
wanglam committed Jul 19, 2024
1 parent d60341d commit 8edcc99
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 22 deletions.
10 changes: 10 additions & 0 deletions src/plugins/workspace/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down
27 changes: 9 additions & 18 deletions src/plugins/workspace/public/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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', () => {
Expand Down
12 changes: 8 additions & 4 deletions src/plugins/workspace/public/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@ export const isFeatureIdInsideUseCase = (
useCaseId: string,
useCases: WorkspaceUseCase[]
) => {
const availableFeatures =
useCaseId === ALL_USE_CASE_ID
? useCases.reduce<string[]>((previous, { features }) => previous.concat(features ?? []), [])
: useCases.find(({ id }) => id === useCaseId)?.features ?? [];
const availableFeatures = useCases.find(({ id }) => id === useCaseId)?.features ?? [];
return availableFeatures.includes(featureId);
};

Expand Down Expand Up @@ -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
*/
Expand Down

0 comments on commit 8edcc99

Please sign in to comment.