@homebound/beam 2.231.1 → 2.232.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -65,5 +65,7 @@ export type GridDataRow<R extends Kinded> = {
|
|
|
65
65
|
initSelected?: boolean;
|
|
66
66
|
/** Whether row can be selected */
|
|
67
67
|
selectable?: false;
|
|
68
|
+
/** Whether this row should infer its selected state based on its children's selected state */
|
|
69
|
+
inferSelectedState?: false;
|
|
68
70
|
} & IfAny<R, {}, DiscriminateUnion<R, "kind", R["kind"]>>;
|
|
69
71
|
export {};
|
|
@@ -258,7 +258,8 @@ class TableState {
|
|
|
258
258
|
(0, visitor_1.visit)([curr.row], (row) => this.matchedRows.has(row.id) && map.set(row.id, selected ? "checked" : "unchecked"));
|
|
259
259
|
// Now walk up the parents and see if they are now-all-checked/now-all-unchecked/some-of-each
|
|
260
260
|
for (const parent of [...curr.parents].reverse()) {
|
|
261
|
-
|
|
261
|
+
// Only derive selected state of the parent row if `inferSelectedState` is not `false`
|
|
262
|
+
if (parent.children && parent.inferSelectedState !== false) {
|
|
262
263
|
map.set(parent.id, deriveParentSelected(this.getMatchedChildrenStates(parent.children, map)));
|
|
263
264
|
}
|
|
264
265
|
}
|
|
@@ -327,14 +328,16 @@ class TableState {
|
|
|
327
328
|
}
|
|
328
329
|
}
|
|
329
330
|
getMatchedChildrenStates(children, map) {
|
|
330
|
-
|
|
331
|
+
const respectedChildren = children.flatMap(getChildrenForDerivingSelectState);
|
|
332
|
+
return respectedChildren
|
|
331
333
|
.filter((row) => row.id !== "header" && this.matchedRows.has(row.id))
|
|
332
334
|
.map((row) => map.get(row.id) || this.getSelected(row.id));
|
|
333
335
|
}
|
|
334
336
|
// Recursively traverse through rows to determine selected state of parent rows based on children
|
|
335
337
|
setNestedSelectedStates(row, map) {
|
|
336
338
|
if (this.matchedRows.has(row.id)) {
|
|
337
|
-
if
|
|
339
|
+
// do not derive selected state if there are no children, or if `inferSelectedState` is set to false
|
|
340
|
+
if (!row.children || row.inferSelectedState === false) {
|
|
338
341
|
return [this.getSelected(row.id)];
|
|
339
342
|
}
|
|
340
343
|
const childrenSelectedStates = row.children.flatMap((rc) => this.setNestedSelectedStates(rc, map));
|
|
@@ -346,6 +349,13 @@ class TableState {
|
|
|
346
349
|
}
|
|
347
350
|
}
|
|
348
351
|
exports.TableState = TableState;
|
|
352
|
+
/** Returns the child rows needed for deriving the selected state of a parent/group row */
|
|
353
|
+
function getChildrenForDerivingSelectState(row) {
|
|
354
|
+
if (row.children && row.inferSelectedState === false) {
|
|
355
|
+
return [row, ...row.children.flatMap(getChildrenForDerivingSelectState)];
|
|
356
|
+
}
|
|
357
|
+
return [row];
|
|
358
|
+
}
|
|
349
359
|
/** Provides a context for rows to access their table's `TableState`. */
|
|
350
360
|
exports.TableStateContext = react_1.default.createContext({
|
|
351
361
|
get tableState() {
|