Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
Signed-off-by: tygao <tygao@amazon.com>
  • Loading branch information
raintygao committed Mar 27, 2024
1 parent 6ee592c commit 3a5648d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 67 deletions.
2 changes: 1 addition & 1 deletion src/plugins/workspace/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const WORKSPACE_LIST_APP_ID = 'workspace_list';
export const WORKSPACE_UPDATE_APP_ID = 'workspace_update';
export const WORKSPACE_OVERVIEW_APP_ID = 'workspace_overview';
// These features will be checked and disabled in checkbox on default.
export const DEFAULT_SELECTED_FEATURES_IDS = [WORKSPACE_UPDATE_APP_ID, WORKSPACE_OVERVIEW_APP_ID];
export const DEFAULT_CHECKED_FEATURES_IDS = [WORKSPACE_UPDATE_APP_ID, WORKSPACE_OVERVIEW_APP_ID];
export const WORKSPACE_FATAL_ERROR_APP_ID = 'workspace_fatal_error';
export const WORKSPACE_SAVED_OBJECTS_CLIENT_WRAPPER_ID = 'workspace';
export const WORKSPACE_CONFLICT_CONTROL_SAVED_OBJECTS_CLIENT_WRAPPER_ID =
Expand Down
69 changes: 3 additions & 66 deletions src/plugins/workspace/public/components/workspace_form/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { WorkspacePermissionMode, DEFAULT_SELECTED_FEATURES_IDS } from '../../../common/constants';
import { WorkspacePermissionMode, DEFAULT_CHECKED_FEATURES_IDS } from '../../../common/constants';

import {
WorkspaceFeature,
Expand All @@ -16,11 +16,6 @@ import {
optionIdToWorkspacePermissionModesMap,
PermissionModeId,
} from './constants';
import {
AppNavLinkStatus,
DEFAULT_APP_CATEGORIES,
PublicAppInfo,
} from '../../../../../core/public';

export const isWorkspaceFeatureGroup = (
featureOrGroup: WorkspaceFeature | WorkspaceFeatureGroup
Expand All @@ -35,12 +30,12 @@ export const isValidWorkspacePermissionSetting = (
(setting.type === WorkspacePermissionItemType.Group && !!setting.group));

export const isDefaultCheckedFeatureId = (id: string) => {
return DEFAULT_SELECTED_FEATURES_IDS.indexOf(id) > -1;
return DEFAULT_CHECKED_FEATURES_IDS.indexOf(id) > -1;
};

export const appendDefaultFeatureIds = (ids: string[]) => {
// concat default checked ids and unique the result
return Array.from(new Set(ids.concat(DEFAULT_SELECTED_FEATURES_IDS)));
return Array.from(new Set(ids.concat(DEFAULT_CHECKED_FEATURES_IDS)));
};

export const isValidNameOrDescription = (input?: string) => {
Expand Down Expand Up @@ -100,61 +95,3 @@ export const getPermissionModeId = (modes: WorkspacePermissionMode[]) => {
}
return PermissionModeId.Read;
};

export const convertApplicationsToFeaturesOrGroups = (
applications: Array<
Pick<PublicAppInfo, 'id' | 'title' | 'category' | 'navLinkStatus' | 'chromeless'>
>
) => {
const UNDEFINED = 'undefined';

// Filter out all hidden applications and management applications and default selected features
const visibleApplications = applications.filter(
({ navLinkStatus, chromeless, category, id }) =>
navLinkStatus !== AppNavLinkStatus.hidden &&
!chromeless &&
!DEFAULT_SELECTED_FEATURES_IDS.includes(id) &&
category?.id !== DEFAULT_APP_CATEGORIES.management.id
);

/**
*
* Convert applications to features map, the map use category label as
* map key and group all same category applications in one array after
* transfer application to feature.
*
**/
const categoryLabel2Features = visibleApplications.reduce<{
[key: string]: WorkspaceFeature[];
}>((previousValue, application) => {
const label = application.category?.label || UNDEFINED;

return {
...previousValue,
[label]: [...(previousValue[label] || []), { id: application.id, name: application.title }],
};
}, {});

/**
*
* Iterate all keys of categoryLabel2Features map, convert map to features or groups array.
* Features with category label will be converted to feature groups. Features without "undefined"
* category label will be converted to single features. Then append them to the result array.
*
**/
return Object.keys(categoryLabel2Features).reduce<
Array<WorkspaceFeature | WorkspaceFeatureGroup>
>((previousValue, categoryLabel) => {
const features = categoryLabel2Features[categoryLabel];
if (categoryLabel === UNDEFINED) {
return [...previousValue, ...features];
}
return [
...previousValue,
{
name: categoryLabel,
features,
},
];
}, []);
};

0 comments on commit 3a5648d

Please sign in to comment.