* Toggle selection of a single row.
(currentSelection: readonly string[], rowKey: string)
| 254 | * Toggle selection of a single row. |
| 255 | */ |
| 256 | function toggleSelection(currentSelection: readonly string[], rowKey: string): SelectionResult { |
| 257 | const isSelected = currentSelection.includes(rowKey); |
| 258 | |
| 259 | if (isSelected) { |
| 260 | const newSelection = currentSelection.filter((k) => k !== rowKey); |
| 261 | return Object.freeze({ |
| 262 | selection: Object.freeze(newSelection), |
| 263 | changed: true, |
| 264 | }); |
| 265 | } |
| 266 | |
| 267 | const newSelection = [...currentSelection, rowKey]; |
| 268 | return Object.freeze({ |
| 269 | selection: Object.freeze(newSelection), |
| 270 | changed: true, |
| 271 | }); |
| 272 | } |
| 273 | |
| 274 | /** |
| 275 | * Select all rows. |