Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3525997
D8105.id27697.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
D8105.id27697.diff
View Options
diff --git a/native/utils/drawer-utils.react.js b/native/utils/drawer-utils.react.js
--- a/native/utils/drawer-utils.react.js
+++ b/native/utils/drawer-utils.react.js
@@ -72,4 +72,47 @@
return results;
}
-export { flattenDrawerItemsData };
+function findAllDescendantIDs<T>(
+ data: $ReadOnlyArray<CommunityDrawerItemData<T>>,
+): $ReadOnlyArray<string> {
+ const results = [];
+ for (const item of data) {
+ results.push(item.threadInfo.id);
+ results.concat(findAllDescendantIDs(item.itemChildren));
+ }
+ return results;
+}
+
+function findThreadChildrenItems<T>(
+ data: $ReadOnlyArray<CommunityDrawerItemData<T>>,
+ id: string,
+): ?$ReadOnlyArray<CommunityDrawerItemData<T>> {
+ for (const item of data) {
+ if (item.threadInfo.id === id) {
+ return item.itemChildren;
+ }
+ const result = findThreadChildrenItems(item.itemChildren, id);
+ if (result) {
+ return result;
+ }
+ }
+ return undefined;
+}
+
+function filterOutThreadAndDescendantIDs<T>(
+ idsToFilter: $ReadOnlyArray<string>,
+ allItems: $ReadOnlyArray<CommunityDrawerItemData<T>>,
+ threadID: string,
+): $ReadOnlyArray<string> {
+ const childItems = findThreadChildrenItems(allItems, threadID);
+ if (!childItems) {
+ return [];
+ }
+ const descendants = findAllDescendantIDs(childItems);
+ const descendantsSet = new Set(descendants);
+ return idsToFilter.filter(
+ item => !descendantsSet.has(item) && item !== threadID,
+ );
+}
+
+export { flattenDrawerItemsData, filterOutThreadAndDescendantIDs };
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Dec 24, 7:07 PM (8 h, 26 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2699898
Default Alt Text
D8105.id27697.diff (1 KB)
Attached To
Mode
D8105: [native] Add functions to filter thread descendants in community drawer
Attached
Detach File
Event Timeline
Log In to Comment