@homebound/beam 2.116.0 → 2.117.1
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.
|
@@ -188,8 +188,10 @@ export declare type GridTableApi<R extends Kinded> = {
|
|
|
188
188
|
scrollToIndex: (index: number) => void;
|
|
189
189
|
/** Returns the ids of currently-selected rows. */
|
|
190
190
|
getSelectedRowIds(): string[];
|
|
191
|
+
getSelectedRowIds<K extends R["kind"]>(kind: K): string[];
|
|
191
192
|
/** Returns the currently-selected rows. */
|
|
192
193
|
getSelectedRows(): GridDataRow<R>[];
|
|
194
|
+
getSelectedRows<K extends R["kind"]>(kind: K): GridDataRow<DiscriminateUnion<R, "kind", K>>[];
|
|
193
195
|
/** Sets the internal state of 'activeRowId' */
|
|
194
196
|
setActiveRowId: (id: string | undefined) => void;
|
|
195
197
|
};
|
|
@@ -95,12 +95,20 @@ function GridTable(props) {
|
|
|
95
95
|
const tableRef = (0, react_1.useRef)(null);
|
|
96
96
|
const api = (0, react_1.useRef)({
|
|
97
97
|
scrollToIndex: (index) => virtuosoRef.current && virtuosoRef.current.scrollToIndex(index),
|
|
98
|
-
getSelectedRowIds
|
|
99
|
-
|
|
98
|
+
getSelectedRowIds(kind) {
|
|
99
|
+
if (kind === undefined) {
|
|
100
|
+
return rowState.selectedIds;
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
return this.getSelectedRows(kind).map((row) => row.id);
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
// The any is not great, but getting the overload to handle the optional kind is annoying
|
|
107
|
+
getSelectedRows(kind) {
|
|
100
108
|
const ids = rowState.selectedIds;
|
|
101
109
|
const selected = [];
|
|
102
110
|
(0, visitor_1.visit)(rows, (row) => {
|
|
103
|
-
if (ids.includes(row.id)) {
|
|
111
|
+
if (ids.includes(row.id) && (!kind || row.kind === kind)) {
|
|
104
112
|
selected.push(row);
|
|
105
113
|
}
|
|
106
114
|
});
|
|
@@ -113,7 +121,7 @@ function GridTable(props) {
|
|
|
113
121
|
}
|
|
114
122
|
(0, react_1.useEffect)(() => {
|
|
115
123
|
rowState.activeRowId = activeRowId;
|
|
116
|
-
}, [activeRowId]);
|
|
124
|
+
}, [rowState, activeRowId]);
|
|
117
125
|
// We track render count at the table level, which seems odd (we should be able to track this
|
|
118
126
|
// internally within each GridRow using a useRef), but we have suspicions that react-virtuoso
|
|
119
127
|
// (or us) is resetting component state more than necessary, so we track render counts from
|
|
@@ -209,12 +217,14 @@ function GridTable(props) {
|
|
|
209
217
|
observeRows,
|
|
210
218
|
columnSizes,
|
|
211
219
|
collapsedIds,
|
|
220
|
+
getCount,
|
|
212
221
|
]);
|
|
213
222
|
let tooManyClientSideRows = false;
|
|
214
223
|
if (filterMaxRows && filteredRows.length > filterMaxRows) {
|
|
215
224
|
tooManyClientSideRows = true;
|
|
216
225
|
filteredRows = filteredRows.slice(0, filterMaxRows);
|
|
217
226
|
}
|
|
227
|
+
rowState.visibleRows.replace(filteredRows.map(([row]) => { var _a; return (_a = row === null || row === void 0 ? void 0 : row.id) !== null && _a !== void 0 ? _a : ""; }));
|
|
218
228
|
// Push back to the caller a way to ask us where a row is.
|
|
219
229
|
const { rowLookup } = props;
|
|
220
230
|
if (rowLookup) {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ObservableSet } from "mobx";
|
|
1
2
|
import React, { MutableRefObject } from "react";
|
|
2
3
|
import { GridDataRow } from "./GridTable";
|
|
3
4
|
export declare type SelectedState = "checked" | "unchecked" | "partial";
|
|
@@ -21,6 +22,7 @@ export declare class RowState {
|
|
|
21
22
|
private persistCollapse;
|
|
22
23
|
private readonly collapsedRows;
|
|
23
24
|
private readonly selectedRows;
|
|
25
|
+
visibleRows: ObservableSet<string>;
|
|
24
26
|
activeRowId: string | undefined;
|
|
25
27
|
/**
|
|
26
28
|
* Creates the `RowState` for a given `GridTable`.
|
|
@@ -30,6 +30,8 @@ class RowState {
|
|
|
30
30
|
this.rows = rows;
|
|
31
31
|
this.persistCollapse = persistCollapse;
|
|
32
32
|
this.selectedRows = new mobx_1.ObservableMap();
|
|
33
|
+
// Set of just row ids. Keeps track of which rows are visible. Used to filter out non-visible rows from `selectedIds`
|
|
34
|
+
this.visibleRows = new mobx_1.ObservableSet();
|
|
33
35
|
this.collapsedRows = new mobx_1.ObservableSet(persistCollapse ? readLocalCollapseState(persistCollapse) : []);
|
|
34
36
|
this.activeRowId = activeRowId;
|
|
35
37
|
// Make ourselves an observable so that mobx will do caching of .collapseIds so
|
|
@@ -38,7 +40,9 @@ class RowState {
|
|
|
38
40
|
}
|
|
39
41
|
get selectedIds() {
|
|
40
42
|
// Return only ids that are fully checked, i.e. not partial
|
|
41
|
-
const ids = [...this.selectedRows.entries()]
|
|
43
|
+
const ids = [...this.selectedRows.entries()]
|
|
44
|
+
.filter(([id, v]) => this.visibleRows.has(id) && v === "checked")
|
|
45
|
+
.map(([k]) => k);
|
|
42
46
|
// Hide our header marker
|
|
43
47
|
const headerIndex = ids.indexOf("header");
|
|
44
48
|
if (headerIndex > -1) {
|
|
@@ -13,7 +13,7 @@ exports.defaultStyle = {
|
|
|
13
13
|
indentOneCss: Css_1.Css.pl4.$,
|
|
14
14
|
indentTwoCss: Css_1.Css.pl7.$,
|
|
15
15
|
headerCellCss: Css_1.Css.nowrap.py1.bgGray100.aife.$,
|
|
16
|
-
firstRowMessageCss: Css_1.Css.tc.
|
|
16
|
+
firstRowMessageCss: Css_1.Css.tc.py3.$,
|
|
17
17
|
};
|
|
18
18
|
/** Tightens up the padding of rows, great for rows that have form elements in them. */
|
|
19
19
|
exports.condensedStyle = {
|
|
@@ -21,6 +21,7 @@ exports.condensedStyle = {
|
|
|
21
21
|
headerCellCss: Css_1.Css.bgGray100.tinyEm.$,
|
|
22
22
|
cellCss: Css_1.Css.aic.sm.py1.px2.$,
|
|
23
23
|
rootCss: Css_1.Css.dg.gray700.xs.$,
|
|
24
|
+
firstRowMessageCss: Css_1.Css.tc.py2.$,
|
|
24
25
|
};
|
|
25
26
|
/** Renders each row as a card. */
|
|
26
27
|
exports.cardStyle = {
|
|
@@ -44,6 +45,7 @@ exports.beamFixedStyle = {
|
|
|
44
45
|
cellCss: Css_1.Css.gray900.xs.bgWhite.aic.nowrap.pxPx(12).hPx(36).boxShadow(`inset 0 -1px 0 ${Css_1.Palette.Gray100}`).$,
|
|
45
46
|
emptyCell: "-",
|
|
46
47
|
presentationSettings: { borderless: true, typeScale: "xs", wrap: false },
|
|
48
|
+
firstRowMessageCss: Css_1.Css.tc.py3.$,
|
|
47
49
|
// Included as a hacky "treat indent as deprecated for this table" hint to GridTable
|
|
48
50
|
levels: {},
|
|
49
51
|
};
|