@bento-core/table 1.0.1-ccdihub.8 → 1.0.1-ccdihub.80

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 (37) hide show
  1. package/dist/ExtendedView.js +23 -14
  2. package/dist/TableView.js +73 -6
  3. package/dist/body/CustomTblBody.js +2 -1
  4. package/dist/body/DisplayBodyCell.js +13 -3
  5. package/dist/body/components/CPIModal.js +187 -0
  6. package/dist/body/components/CPIView.js +115 -0
  7. package/dist/body/components/ModalStyle.js +107 -0
  8. package/dist/body/components/assets/CPI_icon.svg +22 -0
  9. package/dist/header/ActionHeaderCell.js +2 -1
  10. package/dist/header/CustomCell.js +8 -6
  11. package/dist/header/components/CheckBoxView.js +8 -3
  12. package/dist/index.js +6 -0
  13. package/dist/pagination/CustomPagination.js +11 -2
  14. package/dist/toolbar/DownloadButtonView.js +169 -7
  15. package/dist/toolbar/ManageColumnView.js +11 -3
  16. package/dist/util/Dataformat.js +41 -1
  17. package/dist/util/Types.js +22 -2
  18. package/dist/util/downloadTable.js +196 -0
  19. package/package.json +4 -1
  20. package/src/ExtendedView.js +34 -21
  21. package/src/TableView.js +119 -52
  22. package/src/body/CustomTblBody.js +1 -0
  23. package/src/body/DisplayBodyCell.js +12 -0
  24. package/src/body/components/CPIModal.js +227 -0
  25. package/src/body/components/CPIView.js +133 -0
  26. package/src/body/components/ModalStyle.js +101 -0
  27. package/src/body/components/assets/CPI_icon.svg +22 -0
  28. package/src/header/ActionHeaderCell.js +1 -1
  29. package/src/header/CustomCell.js +11 -1
  30. package/src/header/components/CheckBoxView.js +3 -1
  31. package/src/index.js +1 -0
  32. package/src/pagination/CustomPagination.js +4 -1
  33. package/src/toolbar/DownloadButtonView.js +178 -10
  34. package/src/toolbar/ManageColumnView.js +3 -3
  35. package/src/util/Dataformat.js +25 -0
  36. package/src/util/Types.js +15 -0
  37. package/src/util/downloadTable.js +138 -0
@@ -0,0 +1,138 @@
1
+ import { formatBytes, formatColumnValues } from './Dataformat';
2
+ import { actionCellTypes, notIncludedCellStyle } from './Types';
3
+
4
+ export function createFileName(fileName, type) {
5
+ const date = new Date();
6
+ const yyyy = date.getFullYear();
7
+ let dd = date.getDate();
8
+ let mm = (date.getMonth() + 1);
9
+
10
+ if (dd < 10) { dd = `0${dd}`; }
11
+
12
+ if (mm < 10) { mm = `0${mm}`; }
13
+
14
+ const todaysDate = `${yyyy}-${mm}-${dd}`;
15
+
16
+ let hours = date.getHours();
17
+ let minutes = date.getMinutes();
18
+ let seconds = date.getSeconds();
19
+
20
+ if (hours < 10) { hours = `0${hours}`; }
21
+
22
+ if (minutes < 10) { minutes = `0${minutes}`; }
23
+
24
+ if (seconds < 10) { seconds = `0${seconds}`; }
25
+
26
+ if (type === 'csv') {
27
+ return `${fileName} ${todaysDate} ${hours}-${minutes}-${seconds}${'.csv'}`;
28
+ }
29
+ return `${fileName} ${todaysDate} ${hours}-${minutes}-${seconds}${'.json'}`;
30
+ }
31
+
32
+ export function convertToCSV(jsonse, keysToInclude, header) {
33
+ const objArray = jsonse;
34
+ // To Do empty object just print headers
35
+ const array = typeof objArray !== 'object' ? JSON.parse(objArray) : objArray;
36
+ let str = header.join(',');
37
+ array.map((entry, index) => {
38
+ let line = '';
39
+ keysToInclude.map((keyName) => {
40
+ if (line !== '') line += ',';
41
+ if (keyName === 'file_size') {
42
+ line += entry[keyName] !== null ? `"${formatBytes(entry[keyName])}"` : ' ';
43
+ } else if (keyName === 'age_at_diagnosis' || keyName === 'participant_age_at_collection') {
44
+ if (entry[keyName] === -999) {
45
+ line += 'Not Reported';
46
+ } else {
47
+ line += entry[keyName] !== null ? `"${entry[keyName]}"` : ' ';
48
+ }
49
+ } else if (keyName === 'last_known_survival_status' || keyName === 'sample_id' || keyName === 'data_category') {
50
+ if (!entry[keyName] || entry[keyName] === '[]') {
51
+ line += '';
52
+ } else if (entry[keyName].toString().charAt(0) === '[' && entry[keyName].toString().charAt(entry[keyName].toString().length - 1) === ']') {
53
+ line += `"${entry[keyName].toString().substring(1, entry[keyName].length - 1)}"`;
54
+ } else {
55
+ line += `"${entry[keyName]}"`;
56
+ }
57
+ } else {
58
+ line += entry[keyName] !== null ? `"${entry[keyName]}"` : ' ';
59
+ }
60
+ return line;
61
+ });
62
+ if (index === 0) {
63
+ // str = header.join(',');
64
+ str += `\r\n${line}\r\n`;
65
+ } else {
66
+ str += `${line}\r\n`;
67
+ }
68
+ return str;
69
+ });
70
+ return str;
71
+ }
72
+
73
+ export function downloadCSV(tableData, table, downloadFileName) {
74
+ const { columns = [] } = table;
75
+ const filterColumns = columns.filter(({ cellType }) => !actionCellTypes.includes(cellType))
76
+ .filter(({ cellStyle }) => !notIncludedCellStyle.includes(cellStyle))
77
+ .filter(({ display }) => display);
78
+ const formatDataVal = formatColumnValues(filterColumns, tableData);
79
+ const jsonse = JSON.stringify(formatDataVal);
80
+ const keysToInclude = filterColumns.filter(({ dataField }) => dataField)
81
+ .map(({ dataField }) => dataField);
82
+ const headers = filterColumns.filter(({ dataField }) => dataField)
83
+ .map(({ header, downloadHeader }) => (downloadHeader || header));
84
+ const csv = convertToCSV(jsonse, keysToInclude, headers);
85
+ const exportData = new Blob([csv], { type: 'text/csv' });
86
+ const JsonURL = window.URL.createObjectURL(exportData);
87
+ let tempLink = '';
88
+ tempLink = document.createElement('a');
89
+ tempLink.setAttribute('href', JsonURL);
90
+ tempLink.setAttribute('download', createFileName(downloadFileName || '', 'csv'));
91
+ document.body.appendChild(tempLink);
92
+ tempLink.click();
93
+ document.body.removeChild(tempLink);
94
+ }
95
+
96
+ export function downloadJson(tableData, table, downloadFileName) {
97
+ const { columns = [] } = table;
98
+ const toDelete = columns.filter((e) => !e.display);
99
+ const filterColumns = columns.filter(({ cellType }) => !actionCellTypes.includes(cellType))
100
+ .filter(({ display }) => display);
101
+ let formatDataVal = formatColumnValues(filterColumns, tableData);
102
+ formatDataVal = formatDataVal.map((entry) => {
103
+ let survivalStatus = entry.last_known_survival_status;
104
+ let sampleId = entry.sample_id;
105
+ let dataCategory = entry.data_category;
106
+ const toReturn = { ...entry };
107
+
108
+ if (survivalStatus && survivalStatus.toString().charAt(0) === '[' && survivalStatus.toString().charAt(survivalStatus.toString().length - 1) === ']') {
109
+ survivalStatus = survivalStatus.toString().substring(1, survivalStatus.length - 1);
110
+ toReturn['Last Known Survival Status'] = survivalStatus;
111
+ }
112
+ if (sampleId && sampleId.toString().charAt(0) === '[' && sampleId.toString().charAt(sampleId.toString().length - 1) === ']') {
113
+ sampleId = sampleId.toString().substring(1, sampleId.length - 1);
114
+ toReturn['Sample Id'] = sampleId;
115
+ }
116
+ if (dataCategory && dataCategory.toString().charAt(0) === '[' && dataCategory.toString().charAt(dataCategory.toString().length - 1) === ']') {
117
+ dataCategory = dataCategory.toString().substring(1, dataCategory.length - 1);
118
+ toReturn['Data Category'] = dataCategory;
119
+ }
120
+ toDelete.forEach((column) => delete toReturn[column.dataField]);
121
+ return toReturn;
122
+ });
123
+ filterColumns.forEach((column) => {
124
+ formatDataVal = JSON.parse(
125
+ JSON.stringify(formatDataVal).split(`"${column.dataField}":`).join(`"${column.header}":`),
126
+ );
127
+ });
128
+ const jsonse = JSON.stringify(formatDataVal);
129
+ const exportData = new Blob([jsonse], { type: 'application/json' });
130
+ const JsonURL = window.URL.createObjectURL(exportData);
131
+ let tempLink = '';
132
+ tempLink = document.createElement('a');
133
+ tempLink.setAttribute('href', JsonURL);
134
+ tempLink.setAttribute('download', createFileName(downloadFileName || '', 'json'));
135
+ document.body.appendChild(tempLink);
136
+ tempLink.click();
137
+ document.body.removeChild(tempLink);
138
+ }