@homebound/beam 2.364.0 → 2.365.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.
|
@@ -131,6 +131,13 @@ export interface GridTableProps<R extends Kinded, X> {
|
|
|
131
131
|
infiniteScroll?: InfiniteScroll;
|
|
132
132
|
/** Callback for when a row is selected or unselected. */
|
|
133
133
|
onRowSelect?: OnRowSelect<R>;
|
|
134
|
+
/**
|
|
135
|
+
* Custom prefix rows for any CSV output, i.e. a header like "Report X as of date Y with filter Z".
|
|
136
|
+
*
|
|
137
|
+
* We except the `string[][]` to be an array of cells, and `copyToClipboard` and `downloadToCsv` will drop them into
|
|
138
|
+
* the csv output basically unchanged, albeit we will escape any special chars like double quotes and newlines.
|
|
139
|
+
*/
|
|
140
|
+
csvPrefixRows?: string[][];
|
|
134
141
|
/** Drag & drop Callback. */
|
|
135
142
|
onRowDrop?: (draggedRow: GridDataRow<R>, droppedRow: GridDataRow<R>, indexOffset: number) => void;
|
|
136
143
|
}
|
|
@@ -88,7 +88,7 @@ exports.setGridTableDefaults = setGridTableDefaults;
|
|
|
88
88
|
*/
|
|
89
89
|
function GridTable(props) {
|
|
90
90
|
var _a, _b, _c;
|
|
91
|
-
const { id = "gridTable", as = "div", columns: _columns, rows, style: maybeStyle = defaults.style, rowStyles, stickyHeader = defaults.stickyHeader, stickyOffset = 0, xss, filter, filterMaxRows, fallbackMessage = "No rows found.", infoMessage, persistCollapse, resizeTarget, activeRowId, activeCellId, visibleColumnsStorageKey, infiniteScroll, onRowSelect, onRowDrop: droppedCallback, } = props;
|
|
91
|
+
const { id = "gridTable", as = "div", columns: _columns, rows, style: maybeStyle = defaults.style, rowStyles, stickyHeader = defaults.stickyHeader, stickyOffset = 0, xss, filter, filterMaxRows, fallbackMessage = "No rows found.", infoMessage, persistCollapse, resizeTarget, activeRowId, activeCellId, visibleColumnsStorageKey, infiniteScroll, onRowSelect, onRowDrop: droppedCallback, csvPrefixRows, } = props;
|
|
92
92
|
const columnsWithIds = (0, react_1.useMemo)(() => (0, columns_1.assignDefaultColumnIds)(_columns), [_columns]);
|
|
93
93
|
// We only use this in as=virtual mode, but keep this here for rowLookup to use
|
|
94
94
|
const virtuosoRef = (0, react_1.useRef)(null);
|
|
@@ -129,10 +129,11 @@ function GridTable(props) {
|
|
|
129
129
|
tableState.setRows(rows);
|
|
130
130
|
tableState.setColumns(columnsWithIds, visibleColumnsStorageKey);
|
|
131
131
|
tableState.setSearch(filter);
|
|
132
|
+
tableState.setCsvPrefixRows(csvPrefixRows);
|
|
132
133
|
tableState.activeRowId = activeRowId;
|
|
133
134
|
tableState.activeCellId = activeCellId;
|
|
134
135
|
});
|
|
135
|
-
}, [tableState, rows, columnsWithIds, visibleColumnsStorageKey, activeRowId, activeCellId, filter]);
|
|
136
|
+
}, [tableState, rows, columnsWithIds, visibleColumnsStorageKey, activeRowId, activeCellId, filter, csvPrefixRows]);
|
|
136
137
|
const columns = (0, hooks_1.useComputed)(() => {
|
|
137
138
|
return tableState.visibleColumns;
|
|
138
139
|
}, [tableState]);
|
|
@@ -134,8 +134,10 @@ class GridTableApiImpl {
|
|
|
134
134
|
// ...although maybe it could be public someday, to allow getting the raw the CSV content
|
|
135
135
|
// and then sending it somewhere else, like directly to a gsheet.
|
|
136
136
|
generateCsvContent() {
|
|
137
|
+
var _a, _b;
|
|
138
|
+
const csvPrefixRows = (_b = (_a = this.tableState.csvPrefixRows) === null || _a === void 0 ? void 0 : _a.map((row) => row.map(escapeCsvValue).join(","))) !== null && _b !== void 0 ? _b : [];
|
|
137
139
|
// Convert the array of rows into CSV format
|
|
138
|
-
|
|
140
|
+
const dataRows = this.tableState.visibleRows.map((rs) => {
|
|
139
141
|
const values = this.tableState.visibleColumns
|
|
140
142
|
.filter((c) => !c.isAction)
|
|
141
143
|
.map((c) => {
|
|
@@ -157,6 +159,7 @@ class GridTableApiImpl {
|
|
|
157
159
|
});
|
|
158
160
|
return values.map(toCsvString).map(escapeCsvValue).join(",");
|
|
159
161
|
});
|
|
162
|
+
return [...csvPrefixRows, ...dataRows];
|
|
160
163
|
}
|
|
161
164
|
}
|
|
162
165
|
exports.GridTableApiImpl = GridTableApiImpl;
|
|
@@ -32,6 +32,8 @@ export declare class TableState<R extends Kinded> {
|
|
|
32
32
|
activeCellId: string | undefined;
|
|
33
33
|
/** Stores the current client-side type-ahead search/filter. */
|
|
34
34
|
search: string[];
|
|
35
|
+
/** Stores whether CSVs should have some prefix rows. */
|
|
36
|
+
csvPrefixRows: string[][] | undefined;
|
|
35
37
|
sortConfig: GridSortConfig | undefined;
|
|
36
38
|
sort: SortState;
|
|
37
39
|
private initialSortState;
|
|
@@ -50,6 +52,7 @@ export declare class TableState<R extends Kinded> {
|
|
|
50
52
|
setRows(rows: GridDataRow<R>[]): void;
|
|
51
53
|
setColumns(columns: GridColumnWithId<R>[], visibleColumnsStorageKey: string | undefined): void;
|
|
52
54
|
setSearch(search: string | undefined): void;
|
|
55
|
+
setCsvPrefixRows(csvPrefixRows: string[][] | undefined): void;
|
|
53
56
|
get visibleRows(): RowState<R>[];
|
|
54
57
|
/** Returns visible columns, i.e. those that are visible + any expanded children. */
|
|
55
58
|
get visibleColumns(): GridColumnWithId<R>[];
|
|
@@ -42,6 +42,8 @@ class TableState {
|
|
|
42
42
|
this.activeCellId = undefined;
|
|
43
43
|
/** Stores the current client-side type-ahead search/filter. */
|
|
44
44
|
this.search = [];
|
|
45
|
+
/** Stores whether CSVs should have some prefix rows. */
|
|
46
|
+
this.csvPrefixRows = undefined;
|
|
45
47
|
// Tracks the active sort column(s), so GridTable or SortHeaders can reactively
|
|
46
48
|
// re-render (for GridTable, only if client-side sorting)
|
|
47
49
|
this.sort = {};
|
|
@@ -143,6 +145,9 @@ class TableState {
|
|
|
143
145
|
// Break up "foo bar" into `[foo, bar]` and a row must match both `foo` and `bar`
|
|
144
146
|
this.search = (search && search.split(/ +/)) || [];
|
|
145
147
|
}
|
|
148
|
+
setCsvPrefixRows(csvPrefixRows) {
|
|
149
|
+
this.csvPrefixRows = csvPrefixRows;
|
|
150
|
+
}
|
|
146
151
|
get visibleRows() {
|
|
147
152
|
return this.rowStates.visibleRows;
|
|
148
153
|
}
|