Skip to content

Commit

Permalink
optimize code
Browse files Browse the repository at this point in the history
Signed-off-by: yubonluo <yubonluo@amazon.com>
  • Loading branch information
yubonluo committed Apr 15, 2024
1 parent 991971e commit 62e19b4
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 { getAllIncludingDashboardsManagementApps } from '../../utils';

const libraryCategoryLabel = i18n.translate('core.ui.libraryNavList.label', {
defaultMessage: 'Library',
Expand Down Expand Up @@ -55,7 +55,7 @@ export const WorkspaceFeatureSelector = ({
Array<WorkspaceFeature | WorkspaceFeatureGroup>
>((previousValue, currentKey) => {
const apps = category2Applications[currentKey];
const features = getAllExcludingManagementApps(apps).map(({ id, title }) => ({
const features = getAllIncludingDashboardsManagementApps(apps).map(({ id, title }) => ({
id,
name: title,
}));
Expand Down
23 changes: 18 additions & 5 deletions src/plugins/workspace/public/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,19 +141,32 @@ describe('workspace utils: getSelectedFeatureQuantities', () => {
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 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);
});
});
Expand Down
6 changes: 4 additions & 2 deletions src/plugins/workspace/public/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ export const featureMatchesConfig = (featureConfigs: string[]) => ({
};

// Get all apps excluding management category
export const getAllExcludingManagementApps = (applications: PublicAppInfo[]): PublicAppInfo[] => {
export const getAllIncludingDashboardsManagementApps = (
applications: PublicAppInfo[]
): PublicAppInfo[] => {
return applications.filter(
({ navLinkStatus, chromeless, category, workspaceAccessibility, id }) => {
const filterCondition =
Expand All @@ -90,7 +92,7 @@ export const getSelectedFeatureQuantities = (
featuresConfig: string[],
applications: PublicAppInfo[]
) => {
const visibleApplications = getAllExcludingManagementApps(applications);
const visibleApplications = getAllIncludingDashboardsManagementApps(applications);
const featureFilter = featureMatchesConfig(featuresConfig);
const selectedApplications = visibleApplications.filter((app) => featureFilter(app));
return {
Expand Down

0 comments on commit 62e19b4

Please sign in to comment.