Skip to content

Commit b22e47b

Browse files
BirjuVachhaniSaadArdati
authored andcommitted
Add Resolved Component parentID.
1 parent 1cdd3cb commit b22e47b

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

lib/src/api/extensions.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,13 @@ extension TextInputFormatterModelIterableExt<T extends TextInputFormatterModel>
116116
return model;
117117
}
118118
}
119+
120+
/// A helper extension that adds additional functionality to [List].
121+
extension ListExt<T> on List<T> {
122+
/// Removes all the items in the [items] list from this list.
123+
void removeAll(Iterable<T> items) {
124+
for (final item in items) {
125+
remove(item);
126+
}
127+
}
128+
}

lib/src/api/utils.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,15 @@ String resolveParentNodeIDs({
9595
)?.id ??
9696
kRootNode;
9797
}
98+
99+
/// Returns the top-most parent ID of the given [nodes] map.
100+
/// Where [nodes] map is a map of node IDs to their respective node JSON.
101+
List<String> getTopMostParentIDs(Map<String, dynamic> nodes) {
102+
List<String> parentIds = nodes.keys.toList();
103+
for (final Map<String, dynamic> node in nodes.values) {
104+
if (node.containsKey('children')) {
105+
parentIds.removeAll(List<String>.from(node['children']));
106+
}
107+
}
108+
return parentIds;
109+
}

0 commit comments

Comments
 (0)