@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.
Files changed (41) hide show
  1. package/dist/ExtendedView.js +9 -11
  2. package/dist/TableView.js +7 -4
  3. package/dist/assets/cpi_icon.svg +22 -0
  4. package/dist/assets/downArrow.svg +3 -0
  5. package/dist/assets/leftArrow.svg +3 -0
  6. package/dist/assets/rightArrow.svg +3 -0
  7. package/dist/body/CustomTblBody.js +9 -4
  8. package/dist/body/DisplayBodyCell.js +18 -3
  9. package/dist/body/components/CPIModal.js +210 -0
  10. package/dist/body/components/CPIView.js +115 -0
  11. package/dist/body/components/CustomLinkView.js +1 -1
  12. package/dist/body/components/ModalStyle.js +121 -0
  13. package/dist/header/ActionHeaderCell.js +2 -1
  14. package/dist/header/CustomCell.js +8 -5
  15. package/dist/header/CustomTblHeader.js +3 -1
  16. package/dist/header/components/CheckBoxView.js +3 -2
  17. package/dist/pagination/CustomPagination.js +84 -28
  18. package/dist/toolbar/DownloadButtonView.js +152 -45
  19. package/dist/util/Types.js +8 -2
  20. package/dist/util/downloadTable.js +72 -37
  21. package/package.json +2 -2
  22. package/src/ExtendedView.js +34 -33
  23. package/src/TableView.js +11 -8
  24. package/src/assets/cpi_icon.svg +22 -0
  25. package/src/assets/downArrow.svg +3 -0
  26. package/src/assets/leftArrow.svg +3 -0
  27. package/src/assets/rightArrow.svg +3 -0
  28. package/src/body/CustomTblBody.js +6 -1
  29. package/src/body/DisplayBodyCell.js +23 -0
  30. package/src/body/components/CPIModal.js +245 -0
  31. package/src/body/components/CPIView.js +133 -0
  32. package/src/body/components/CustomLinkView.js +1 -1
  33. package/src/body/components/ModalStyle.js +115 -0
  34. package/src/header/ActionHeaderCell.js +1 -0
  35. package/src/header/CustomCell.js +6 -3
  36. package/src/header/CustomTblHeader.js +3 -1
  37. package/src/header/components/CheckBoxView.js +2 -1
  38. package/src/pagination/CustomPagination.js +97 -40
  39. package/src/toolbar/DownloadButtonView.js +168 -55
  40. package/src/util/Types.js +4 -0
  41. 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
- line += entry[keyName] !== null ? `"${entry[keyName]}"` : ' ';
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 downloadJson(tableData, table, downloadFileName) {
64
+ export function downloadData(tableData, table, downloadFileName, format = 'csv') {
63
65
  const { columns = [] } = table;
64
- const filterColumns = columns.filter(({ cellType }) => !actionCellTypes.includes(cellType));
65
- const formatDataVal = formatColumnValues(filterColumns, tableData);
66
- const jsonse = JSON.stringify(formatDataVal);
67
- const keysToInclude = columns.filter(({ dataField }) => dataField)
68
- .map(({ dataField }) => dataField);
69
- const headers = columns.filter(({ dataField }) => dataField)
70
- .map(({ header, downloadHeader }) => (downloadHeader || header));
71
- const csv = convertToCSV(jsonse, keysToInclude, headers);
72
- const exportData = new Blob([csv], { type: 'text/csv' });
73
- const JsonURL = window.URL.createObjectURL(exportData);
74
- let tempLink = '';
75
- tempLink = document.createElement('a');
76
- tempLink.setAttribute('href', JsonURL);
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();