(state: TreeState<unknown>, selectedRoute: string)
| 746 | |
| 747 | // The set of collection keys that are ancestors of the item matching `selectedRoute`. |
| 748 | function getSelectedAncestors(state: TreeState<unknown>, selectedRoute: string): Set<Key> { |
| 749 | let {collection} = state; |
| 750 | let cached = selectedAncestorsCache.get(collection); |
| 751 | if (cached && cached.selection === selectedRoute) { |
| 752 | return cached.ancestors; |
| 753 | } |
| 754 | |
| 755 | let matchKey = findKeyForRoute(collection, selectedRoute); |
| 756 | |
| 757 | let ancestors = new Set<Key>(); |
| 758 | let node = matchKey != null ? collection.getItem(matchKey) : null; |
| 759 | while (node?.parentKey != null && !ancestors.has(node.parentKey)) { |
| 760 | ancestors.add(node.parentKey); |
| 761 | node = collection.getItem(node.parentKey); |
| 762 | } |
| 763 | |
| 764 | selectedAncestorsCache.set(collection, {selection: selectedRoute, ancestors}); |
| 765 | return ancestors; |
| 766 | } |
| 767 | |
| 768 | // Whether the row `id` is an ancestor of the item matching `selectedRoute`, i.e. it has a |
| 769 | // selected descendant. Used to keep a collapsed parent styled when its selected child is hidden. |
no test coverage detected