fixed flatten function (#38530)

fixes: #37744

Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
This commit is contained in:
Erik Jan de Wit 2025-04-08 15:13:42 +02:00 committed by GitHub
parent 25feda7801
commit c33cc5c51e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -242,7 +242,8 @@ export const GroupPickerDialog = ({
/>
))
: groups
?.map((g) => deepGroup(g))
?.map((g) => deepGroup([g]))
.flat()
.map((g) => (
<GroupRow
key={g.id}
@ -274,14 +275,16 @@ export const GroupPickerDialog = ({
);
};
const deepGroup = (group: GroupRepresentation): GroupRepresentation => {
let result = group;
if (group.subGroups?.length === 1) {
result = deepGroup(group.subGroups[0]);
function deepGroup(groups: GroupRepresentation[]) {
const flattened: GroupRepresentation[] = [];
for (const group of groups) {
flattened.push(group);
if (group.subGroups && group.subGroups.length > 0) {
flattened.push(...deepGroup(group.subGroups));
}
}
return result;
};
return flattened;
}
type GroupRowProps = {
group: SelectableGroup;