Skip to content

Commit 95f5416

Browse files
committed
Fix: addGroup(..) function was broken in the previous commit
1 parent 022d7ec commit 95f5416

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

src/shared/utils/tc.js

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,22 @@ export const USER_ROLES = {
2727
SUBMITTER: 'Submitter',
2828
};
2929

30+
/* This is the internal implementation of addGroup(..) function.
31+
* It does exactly what is described there, but mutates its "groups" argument.
32+
*/
33+
function addGroupPrivate(groups, srcGroup) {
34+
const group = _.clone(srcGroup);
35+
if (group.subGroups) {
36+
if (group.subGroups.length) {
37+
group.subGroupIds = group.subGroups.map(g => g.id);
38+
group.subGroups.forEach(g => addGroupPrivate(groups, g));
39+
}
40+
delete group.subGroups;
41+
}
42+
groups[group.id] = group; // eslint-disable-line no-param-reassign
43+
return groups;
44+
}
45+
3046
/**
3147
* This function merges "srcGroup" into "groups" (without mutation of original
3248
* objects) and returns the result.
@@ -45,15 +61,7 @@ export const USER_ROLES = {
4561
* overwrite corresponding data from "groups".
4662
*/
4763
export function addGroup(groups, srcGroup) {
48-
const group = _.clone(srcGroup);
49-
if (group.subGroups) {
50-
if (group.subGroups.length) {
51-
group.subGroupIds = group.subGroups.map(g => g.id);
52-
group.subGroups.forEach(g => addGroup(groups, g));
53-
}
54-
delete group.subGroups;
55-
}
56-
return { ...groups, [group.id]: group };
64+
return addGroupPrivate(_.clone(groups), srcGroup);
5765
}
5866

5967
/**

0 commit comments

Comments
 (0)