mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 07:07:19 +00:00
fix the flatten
This commit is contained in:
@ -407,21 +407,31 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
||||
|
||||
List<SpaceModel> flattenSpaces(List<SpaceModel> spaces) {
|
||||
List<SpaceModel> result = [];
|
||||
Map<String, SpaceModel> idToSpace = {};
|
||||
|
||||
void flatten(SpaceModel space) {
|
||||
if (space.status == SpaceStatus.deleted || space.status == SpaceStatus.parentDeleted) {
|
||||
return;
|
||||
}
|
||||
result.add(space);
|
||||
idToSpace[space.internalId] = space;
|
||||
|
||||
for (var child in space.children) {
|
||||
flatten(child);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (var space in spaces) {
|
||||
flatten(space);
|
||||
}
|
||||
|
||||
for (var space in result) {
|
||||
if (space.parent != null) {
|
||||
space.parent = idToSpace[space.parent!.internalId];
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user