@homebound/beam 2.321.1 → 2.322.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.
- package/dist/utils/rtl.d.ts +1 -1
- package/dist/utils/rtl.js +17 -4
- package/package.json +1 -1
package/dist/utils/rtl.d.ts
CHANGED
|
@@ -29,7 +29,7 @@ export declare function rowAnd(r: RenderResult, rowNum: number, testId: string):
|
|
|
29
29
|
"
|
|
30
30
|
`);
|
|
31
31
|
* */
|
|
32
|
-
export declare function tableSnapshot(r: RenderResult): string;
|
|
32
|
+
export declare function tableSnapshot(r: RenderResult, columnNames?: string[]): string;
|
|
33
33
|
/** RTL wrapper for Beam's SuperDrawer/Modal context. */
|
|
34
34
|
export declare const withBeamRTL: Wrapper;
|
|
35
35
|
/**
|
package/dist/utils/rtl.js
CHANGED
|
@@ -76,17 +76,30 @@ exports.rowAnd = rowAnd;
|
|
|
76
76
|
"
|
|
77
77
|
`);
|
|
78
78
|
* */
|
|
79
|
-
function tableSnapshot(r) {
|
|
79
|
+
function tableSnapshot(r, columnNames = []) {
|
|
80
80
|
const tableEl = r.getByTestId("gridTable");
|
|
81
81
|
const dataRows = Array.from(tableEl.querySelectorAll("[data-gridrow]"));
|
|
82
82
|
const hasExpandableHeader = !!tableEl.querySelector(`[data-testid="expandableColumn"]`);
|
|
83
|
-
|
|
83
|
+
let tableDataAsStrings = dataRows.map((row) => {
|
|
84
84
|
return Array.from(row.childNodes).map(getTextFromTableCellNode);
|
|
85
85
|
});
|
|
86
|
-
|
|
86
|
+
// If the user wants a subset of columns, look for column names
|
|
87
|
+
if (columnNames.length > 0) {
|
|
88
|
+
const headerCells = tableDataAsStrings[0];
|
|
89
|
+
if (headerCells) {
|
|
90
|
+
const columnIndices = columnNames.map((name) => {
|
|
91
|
+
const i = headerCells.indexOf(name);
|
|
92
|
+
if (i === -1)
|
|
93
|
+
throw new Error(`Could not find header '${name}' in ${headerCells.join(", ")}`);
|
|
94
|
+
return i;
|
|
95
|
+
});
|
|
96
|
+
tableDataAsStrings = tableDataAsStrings.map((row) => columnIndices.map((index) => row[index]));
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return toMarkupTableString(tableDataAsStrings, hasExpandableHeader);
|
|
87
100
|
}
|
|
88
101
|
exports.tableSnapshot = tableSnapshot;
|
|
89
|
-
function toMarkupTableString(
|
|
102
|
+
function toMarkupTableString(tableRows, hasExpandableHeader) {
|
|
90
103
|
// Find the largest width of each column to set a consistent width for each row
|
|
91
104
|
const columnWidths = tableRows.reduce((acc, row) => {
|
|
92
105
|
row.forEach((cell, columnIndex) => {
|