@bento-core/table 1.0.0-c3dc.3 → 1.0.0-c3dc.30
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/ExtendedView.js +9 -11
- package/dist/TableView.js +7 -4
- package/dist/assets/cpi_icon.svg +22 -0
- package/dist/assets/downArrow.svg +3 -0
- package/dist/assets/leftArrow.svg +3 -0
- package/dist/assets/rightArrow.svg +3 -0
- package/dist/body/CustomTblBody.js +9 -4
- package/dist/body/DisplayBodyCell.js +18 -3
- package/dist/body/components/CPIModal.js +210 -0
- package/dist/body/components/CPIView.js +115 -0
- package/dist/body/components/CustomLinkView.js +1 -1
- package/dist/body/components/ModalStyle.js +121 -0
- package/dist/header/ActionHeaderCell.js +2 -1
- package/dist/header/CustomCell.js +8 -5
- package/dist/header/CustomTblHeader.js +3 -1
- package/dist/header/components/CheckBoxView.js +3 -2
- package/dist/pagination/CustomPagination.js +84 -28
- package/dist/toolbar/DownloadButtonView.js +152 -45
- package/dist/util/Types.js +8 -2
- package/dist/util/downloadTable.js +72 -37
- package/package.json +2 -2
- package/src/ExtendedView.js +34 -33
- package/src/TableView.js +11 -8
- package/src/assets/cpi_icon.svg +22 -0
- package/src/assets/downArrow.svg +3 -0
- package/src/assets/leftArrow.svg +3 -0
- package/src/assets/rightArrow.svg +3 -0
- package/src/body/CustomTblBody.js +6 -1
- package/src/body/DisplayBodyCell.js +23 -0
- package/src/body/components/CPIModal.js +245 -0
- package/src/body/components/CPIView.js +133 -0
- package/src/body/components/CustomLinkView.js +1 -1
- package/src/body/components/ModalStyle.js +115 -0
- package/src/header/ActionHeaderCell.js +1 -0
- package/src/header/CustomCell.js +6 -3
- package/src/header/CustomTblHeader.js +3 -1
- package/src/header/components/CheckBoxView.js +2 -1
- package/src/pagination/CustomPagination.js +97 -40
- package/src/toolbar/DownloadButtonView.js +168 -55
- package/src/util/Types.js +4 -0
- package/src/util/downloadTable.js +51 -17
|
@@ -22,8 +22,7 @@ export function createFileName(fileName) {
|
|
|
22
22
|
if (minutes < 10) { minutes = `0${minutes}`; }
|
|
23
23
|
|
|
24
24
|
if (seconds < 10) { seconds = `0${seconds}`; }
|
|
25
|
-
|
|
26
|
-
return `${fileName} ${todaysDate} ${hours}-${minutes}-${seconds}${'.csv'}`;
|
|
25
|
+
return `${fileName} ${todaysDate} ${hours}-${minutes}-${seconds}`;
|
|
27
26
|
}
|
|
28
27
|
|
|
29
28
|
export function convertToCSV(jsonse, keysToInclude, header) {
|
|
@@ -43,8 +42,11 @@ export function convertToCSV(jsonse, keysToInclude, header) {
|
|
|
43
42
|
} else {
|
|
44
43
|
line += entry[keyName] !== null ? `"${entry[keyName]}"` : ' ';
|
|
45
44
|
}
|
|
45
|
+
} else if (keyName === 'participant') {
|
|
46
|
+
line += entry[keyName].participant_id;
|
|
46
47
|
} else {
|
|
47
|
-
|
|
48
|
+
const newLine = entry[keyName] !== null ? String(entry[keyName]).replace(/"/g, '""') : '';
|
|
49
|
+
line += `"${newLine}"`;
|
|
48
50
|
}
|
|
49
51
|
return line;
|
|
50
52
|
});
|
|
@@ -59,21 +61,53 @@ export function convertToCSV(jsonse, keysToInclude, header) {
|
|
|
59
61
|
return str;
|
|
60
62
|
}
|
|
61
63
|
|
|
62
|
-
export function
|
|
64
|
+
export function downloadData(tableData, table, downloadFileName, format = 'csv') {
|
|
63
65
|
const { columns = [] } = table;
|
|
64
|
-
const filterColumns = columns.filter(({ cellType }) =>
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
.
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
66
|
+
const filterColumns = columns.filter(({ cellType, doNotDownload }) => (
|
|
67
|
+
!actionCellTypes.includes(cellType) && !doNotDownload));
|
|
68
|
+
let formatDataVal = formatColumnValues(filterColumns, tableData);
|
|
69
|
+
|
|
70
|
+
formatDataVal = formatDataVal.map((item) => {
|
|
71
|
+
const updatedItem = {};
|
|
72
|
+
filterColumns.forEach(({ dataField }) => {
|
|
73
|
+
updatedItem[dataField] = item[dataField];
|
|
74
|
+
});
|
|
75
|
+
return updatedItem;
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
let fileContent;
|
|
79
|
+
let fileType;
|
|
80
|
+
|
|
81
|
+
if (format === 'json') {
|
|
82
|
+
filterColumns.forEach((column) => {
|
|
83
|
+
const mapData = (data) => {
|
|
84
|
+
const dataObject = data;
|
|
85
|
+
if (dataObject?.[column.dataField]?.participant_id) {
|
|
86
|
+
dataObject[column.dataField] = dataObject?.[column.dataField]?.participant_id;
|
|
87
|
+
}
|
|
88
|
+
return dataObject;
|
|
89
|
+
};
|
|
90
|
+
formatDataVal = formatDataVal.map(mapData);
|
|
91
|
+
formatDataVal = JSON.parse(
|
|
92
|
+
JSON.stringify(formatDataVal).split(`"${column.dataField}":`).join(`"${column.header}":`),
|
|
93
|
+
);
|
|
94
|
+
});
|
|
95
|
+
fileContent = JSON.stringify(formatDataVal);
|
|
96
|
+
fileType = 'application/json';
|
|
97
|
+
} else {
|
|
98
|
+
const jsonse = JSON.stringify(formatDataVal);
|
|
99
|
+
const keysToInclude = filterColumns.filter(({ dataField }) => dataField)
|
|
100
|
+
.map(({ dataField }) => dataField);
|
|
101
|
+
const headers = filterColumns.filter(({ dataField }) => dataField)
|
|
102
|
+
.map(({ header, downloadHeader }) => (downloadHeader || header));
|
|
103
|
+
fileContent = convertToCSV(jsonse, keysToInclude, headers);
|
|
104
|
+
fileType = 'text/csv';
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const exportData = new Blob([fileContent], { type: fileType });
|
|
108
|
+
const fileURL = window.URL.createObjectURL(exportData);
|
|
109
|
+
const tempLink = document.createElement('a');
|
|
110
|
+
tempLink.setAttribute('href', fileURL);
|
|
77
111
|
tempLink.setAttribute('download', createFileName(downloadFileName || ''));
|
|
78
112
|
document.body.appendChild(tempLink);
|
|
79
113
|
tempLink.click();
|