@bento-core/table 1.0.0-c3dc.8 → 1.0.0-c3dc.9
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/util/downloadTable.js +24 -16
- package/package.json +1 -1
- package/src/util/downloadTable.js +15 -9
|
@@ -8,7 +8,7 @@ exports.createFileName = createFileName;
|
|
|
8
8
|
exports.downloadData = downloadData;
|
|
9
9
|
var _Dataformat = require("./Dataformat");
|
|
10
10
|
var _Types = require("./Types");
|
|
11
|
-
function createFileName(fileName
|
|
11
|
+
function createFileName(fileName) {
|
|
12
12
|
const date = new Date();
|
|
13
13
|
const yyyy = date.getFullYear();
|
|
14
14
|
let dd = date.getDate();
|
|
@@ -32,7 +32,7 @@ function createFileName(fileName, type) {
|
|
|
32
32
|
if (seconds < 10) {
|
|
33
33
|
seconds = "0".concat(seconds);
|
|
34
34
|
}
|
|
35
|
-
return "".concat(fileName, " ").concat(todaysDate, " ").concat(hours, "-").concat(minutes, "-").concat(seconds)
|
|
35
|
+
return "".concat(fileName, " ").concat(todaysDate, " ").concat(hours, "-").concat(minutes, "-").concat(seconds);
|
|
36
36
|
}
|
|
37
37
|
function convertToCSV(jsonse, keysToInclude, header) {
|
|
38
38
|
const objArray = jsonse;
|
|
@@ -73,49 +73,57 @@ function downloadData(tableData, table, downloadFileName) {
|
|
|
73
73
|
} = table;
|
|
74
74
|
const filterColumns = columns.filter(_ref => {
|
|
75
75
|
let {
|
|
76
|
-
cellType
|
|
76
|
+
cellType,
|
|
77
|
+
doNotDownload
|
|
77
78
|
} = _ref;
|
|
78
|
-
return !_Types.actionCellTypes.includes(cellType);
|
|
79
|
+
return !_Types.actionCellTypes.includes(cellType) && !doNotDownload;
|
|
79
80
|
});
|
|
80
81
|
let formatDataVal = (0, _Dataformat.formatColumnValues)(filterColumns, tableData);
|
|
82
|
+
formatDataVal = formatDataVal.map(item => {
|
|
83
|
+
const updatedItem = {};
|
|
84
|
+
filterColumns.forEach(_ref2 => {
|
|
85
|
+
let {
|
|
86
|
+
dataField
|
|
87
|
+
} = _ref2;
|
|
88
|
+
updatedItem[dataField] = item[dataField];
|
|
89
|
+
});
|
|
90
|
+
return updatedItem;
|
|
91
|
+
});
|
|
81
92
|
let fileContent;
|
|
82
93
|
let fileType;
|
|
83
|
-
let fileExtension;
|
|
84
94
|
if (format === 'json') {
|
|
85
95
|
filterColumns.forEach(column => {
|
|
86
96
|
formatDataVal = JSON.parse(JSON.stringify(formatDataVal).split("\"".concat(column.dataField, "\":")).join("\"".concat(column.header, "\":")));
|
|
87
97
|
});
|
|
88
98
|
fileContent = JSON.stringify(formatDataVal);
|
|
89
99
|
fileType = 'application/json';
|
|
90
|
-
fileExtension = 'json';
|
|
91
100
|
} else {
|
|
92
101
|
const jsonse = JSON.stringify(formatDataVal);
|
|
93
|
-
const keysToInclude =
|
|
102
|
+
const keysToInclude = filterColumns.filter(_ref3 => {
|
|
94
103
|
let {
|
|
95
104
|
dataField
|
|
96
|
-
} =
|
|
105
|
+
} = _ref3;
|
|
97
106
|
return dataField;
|
|
98
|
-
}).map(
|
|
107
|
+
}).map(_ref4 => {
|
|
99
108
|
let {
|
|
100
109
|
dataField
|
|
101
|
-
} =
|
|
110
|
+
} = _ref4;
|
|
102
111
|
return dataField;
|
|
103
112
|
});
|
|
104
|
-
const headers =
|
|
113
|
+
const headers = filterColumns.filter(_ref5 => {
|
|
105
114
|
let {
|
|
106
115
|
dataField
|
|
107
|
-
} =
|
|
116
|
+
} = _ref5;
|
|
108
117
|
return dataField;
|
|
109
|
-
}).map(
|
|
118
|
+
}).map(_ref6 => {
|
|
110
119
|
let {
|
|
111
120
|
header,
|
|
112
121
|
downloadHeader
|
|
113
|
-
} =
|
|
122
|
+
} = _ref6;
|
|
114
123
|
return downloadHeader || header;
|
|
115
124
|
});
|
|
116
125
|
fileContent = convertToCSV(jsonse, keysToInclude, headers);
|
|
117
126
|
fileType = 'text/csv';
|
|
118
|
-
fileExtension = 'csv';
|
|
119
127
|
}
|
|
120
128
|
const exportData = new Blob([fileContent], {
|
|
121
129
|
type: fileType
|
|
@@ -123,7 +131,7 @@ function downloadData(tableData, table, downloadFileName) {
|
|
|
123
131
|
const fileURL = window.URL.createObjectURL(exportData);
|
|
124
132
|
const tempLink = document.createElement('a');
|
|
125
133
|
tempLink.setAttribute('href', fileURL);
|
|
126
|
-
tempLink.setAttribute('download', createFileName(downloadFileName || ''
|
|
134
|
+
tempLink.setAttribute('download', createFileName(downloadFileName || ''));
|
|
127
135
|
document.body.appendChild(tempLink);
|
|
128
136
|
tempLink.click();
|
|
129
137
|
document.body.removeChild(tempLink);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { formatBytes, formatColumnValues } from './Dataformat';
|
|
2
2
|
import { actionCellTypes } from './Types';
|
|
3
3
|
|
|
4
|
-
export function createFileName(fileName
|
|
4
|
+
export function createFileName(fileName) {
|
|
5
5
|
const date = new Date();
|
|
6
6
|
const yyyy = date.getFullYear();
|
|
7
7
|
let dd = date.getDate();
|
|
@@ -22,7 +22,7 @@ export function createFileName(fileName, type) {
|
|
|
22
22
|
if (minutes < 10) { minutes = `0${minutes}`; }
|
|
23
23
|
|
|
24
24
|
if (seconds < 10) { seconds = `0${seconds}`; }
|
|
25
|
-
return `${fileName} ${todaysDate} ${hours}-${minutes}-${seconds}
|
|
25
|
+
return `${fileName} ${todaysDate} ${hours}-${minutes}-${seconds}`;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
export function convertToCSV(jsonse, keysToInclude, header) {
|
|
@@ -60,12 +60,20 @@ export function convertToCSV(jsonse, keysToInclude, header) {
|
|
|
60
60
|
|
|
61
61
|
export function downloadData(tableData, table, downloadFileName, format = 'csv') {
|
|
62
62
|
const { columns = [] } = table;
|
|
63
|
-
const filterColumns = columns.filter(({ cellType }) =>
|
|
63
|
+
const filterColumns = columns.filter(({ cellType, doNotDownload }) => (
|
|
64
|
+
!actionCellTypes.includes(cellType) && !doNotDownload));
|
|
64
65
|
let formatDataVal = formatColumnValues(filterColumns, tableData);
|
|
65
66
|
|
|
67
|
+
formatDataVal = formatDataVal.map((item) => {
|
|
68
|
+
const updatedItem = {};
|
|
69
|
+
filterColumns.forEach(({ dataField }) => {
|
|
70
|
+
updatedItem[dataField] = item[dataField];
|
|
71
|
+
});
|
|
72
|
+
return updatedItem;
|
|
73
|
+
});
|
|
74
|
+
|
|
66
75
|
let fileContent;
|
|
67
76
|
let fileType;
|
|
68
|
-
let fileExtension;
|
|
69
77
|
|
|
70
78
|
if (format === 'json') {
|
|
71
79
|
filterColumns.forEach((column) => {
|
|
@@ -75,23 +83,21 @@ export function downloadData(tableData, table, downloadFileName, format = 'csv')
|
|
|
75
83
|
});
|
|
76
84
|
fileContent = JSON.stringify(formatDataVal);
|
|
77
85
|
fileType = 'application/json';
|
|
78
|
-
fileExtension = 'json';
|
|
79
86
|
} else {
|
|
80
87
|
const jsonse = JSON.stringify(formatDataVal);
|
|
81
|
-
const keysToInclude =
|
|
88
|
+
const keysToInclude = filterColumns.filter(({ dataField }) => dataField)
|
|
82
89
|
.map(({ dataField }) => dataField);
|
|
83
|
-
const headers =
|
|
90
|
+
const headers = filterColumns.filter(({ dataField }) => dataField)
|
|
84
91
|
.map(({ header, downloadHeader }) => (downloadHeader || header));
|
|
85
92
|
fileContent = convertToCSV(jsonse, keysToInclude, headers);
|
|
86
93
|
fileType = 'text/csv';
|
|
87
|
-
fileExtension = 'csv';
|
|
88
94
|
}
|
|
89
95
|
|
|
90
96
|
const exportData = new Blob([fileContent], { type: fileType });
|
|
91
97
|
const fileURL = window.URL.createObjectURL(exportData);
|
|
92
98
|
const tempLink = document.createElement('a');
|
|
93
99
|
tempLink.setAttribute('href', fileURL);
|
|
94
|
-
tempLink.setAttribute('download', createFileName(downloadFileName || ''
|
|
100
|
+
tempLink.setAttribute('download', createFileName(downloadFileName || ''));
|
|
95
101
|
document.body.appendChild(tempLink);
|
|
96
102
|
tempLink.click();
|
|
97
103
|
document.body.removeChild(tempLink);
|