| 111 | } |
| 112 | |
| 113 | function toggleKey<T>( |
| 114 | currentExpandedKeys: 'all' | Set<Key>, |
| 115 | key: Key, |
| 116 | collection: TreeGridCollection<T> |
| 117 | ): Set<Key> { |
| 118 | let updatedExpandedKeys: Set<Key>; |
| 119 | if (currentExpandedKeys === 'all') { |
| 120 | updatedExpandedKeys = new Set( |
| 121 | collection.flattenedRows |
| 122 | .filter( |
| 123 | row => |
| 124 | row.props.UNSTABLE_childItems || row.props.children.length > collection.userColumnCount |
| 125 | ) |
| 126 | .map(row => row.key) |
| 127 | ); |
| 128 | updatedExpandedKeys.delete(key); |
| 129 | } else { |
| 130 | updatedExpandedKeys = new Set(currentExpandedKeys); |
| 131 | if (updatedExpandedKeys.has(key)) { |
| 132 | updatedExpandedKeys.delete(key); |
| 133 | } else { |
| 134 | updatedExpandedKeys.add(key); |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | return updatedExpandedKeys; |
| 139 | } |
| 140 | |
| 141 | function convertExpanded(expanded: 'all' | Iterable<Key>): 'all' | Set<Key> { |
| 142 | if (!expanded) { |