Skip to content

Commit

Permalink
Add more comments
Browse files Browse the repository at this point in the history
Signed-off-by: Lin Wang <[email protected]>
  • Loading branch information
wanglam committed Mar 12, 2024
1 parent 1f173f2 commit 2a12e43
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ export const WorkspaceCreator = () => {
paddingSize="none"
color="subdued"
hasShadow={false}
/**
* Since above EuiPageHeader has a maxWidth: 1000 style,
* add maxWidth: 100 below to align with the above page header
**/
style={{ width: '100%', maxWidth: 1000 }}
>
{application && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,41 +186,43 @@ export const useWorkspaceForm = ({ application, defaultValues, onSubmit }: Works

const handleFeatureGroupChange = useCallback<EuiCheckboxProps['onChange']>(
(e) => {
for (const featureOrGroup of featureOrGroups) {
if (isWorkspaceFeatureGroup(featureOrGroup) && featureOrGroup.name === e.target.id) {
const groupFeatureIds = featureOrGroup.features.map((feature) => feature.id);
setSelectedFeatureIds((previousData) => {
const notExistsIds = groupFeatureIds.filter((id) => !previousData.includes(id));
if (notExistsIds.length > 0) {
return getFinalFeatureIdsByDependency(
notExistsIds,
featureDependencies,
previousData
);
}
let groupRemainFeatureIds = groupFeatureIds;
const outGroupFeatureIds = previousData.filter(
(featureId) => !groupFeatureIds.includes(featureId)
);

while (true) {
const lastRemainFeatures = groupRemainFeatureIds.length;
groupRemainFeatureIds = groupRemainFeatureIds.filter((featureId) =>
isFeatureDependBySelectedFeatures(
featureId,
[...outGroupFeatureIds, ...groupRemainFeatureIds],
featureDependencies
)
);
if (lastRemainFeatures === groupRemainFeatureIds.length) {
break;
}
}

return [...outGroupFeatureIds, ...groupRemainFeatureIds];
});
}
const featureOrGroup = featureOrGroups.find(
(item) => isWorkspaceFeatureGroup(item) && item.name === e.target.id
);
if (!featureOrGroup || !isWorkspaceFeatureGroup(featureOrGroup)) {
return;
}
const groupFeatureIds = featureOrGroup.features.map((feature) => feature.id);
setSelectedFeatureIds((previousData) => {
const notExistsIds = groupFeatureIds.filter((id) => !previousData.includes(id));
// Check all not selected features if not been selected in current group.
if (notExistsIds.length > 0) {
return getFinalFeatureIdsByDependency(notExistsIds, featureDependencies, previousData);
}
// Need to un-check all features, if all features in group has been selected
let groupRemainFeatureIds = groupFeatureIds;
const outGroupFeatureIds = previousData.filter(
(featureId) => !groupFeatureIds.includes(featureId)
);

while (true) {
const lastRemainFeatures = groupRemainFeatureIds.length;
// Remove not depend by others feature in changed feature group.
groupRemainFeatureIds = groupRemainFeatureIds.filter((featureId) =>
isFeatureDependBySelectedFeatures(
featureId,
[...outGroupFeatureIds, ...groupRemainFeatureIds],
featureDependencies
)
);
// If no more features can be removed, the loop can be break.
if (lastRemainFeatures === groupRemainFeatureIds.length) {
break;
}
}

return [...outGroupFeatureIds, ...groupRemainFeatureIds];
});
},
[featureOrGroups, featureDependencies]
);
Expand Down

0 comments on commit 2a12e43

Please sign in to comment.