@bento-core/table 1.0.0-c3dc.7 → 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.
@@ -153,7 +153,7 @@ const DownloadButton = _ref => {
153
153
  return /*#__PURE__*/_react.default.createElement("div", {
154
154
  className: classes.dropdown
155
155
  }, /*#__PURE__*/_react.default.createElement(_core.Tooltip, {
156
- title: "Download filtered results"
156
+ title: table.downloadButtonTooltipText || 'Download filtered results'
157
157
  }, count !== 0 ? /*#__PURE__*/_react.default.createElement(_core.IconButton, {
158
158
  onClick: handleClickButton
159
159
  }, /*#__PURE__*/_react.default.createElement(_icons.CloudDownload, null), /*#__PURE__*/_react.default.createElement(_KeyboardArrowDownOutlined.default, {
@@ -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, type) {
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).concat(type);
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 = columns.filter(_ref2 => {
102
+ const keysToInclude = filterColumns.filter(_ref3 => {
94
103
  let {
95
104
  dataField
96
- } = _ref2;
105
+ } = _ref3;
97
106
  return dataField;
98
- }).map(_ref3 => {
107
+ }).map(_ref4 => {
99
108
  let {
100
109
  dataField
101
- } = _ref3;
110
+ } = _ref4;
102
111
  return dataField;
103
112
  });
104
- const headers = columns.filter(_ref4 => {
113
+ const headers = filterColumns.filter(_ref5 => {
105
114
  let {
106
115
  dataField
107
- } = _ref4;
116
+ } = _ref5;
108
117
  return dataField;
109
- }).map(_ref5 => {
118
+ }).map(_ref6 => {
110
119
  let {
111
120
  header,
112
121
  downloadHeader
113
- } = _ref5;
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 || '', fileExtension));
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,6 +1,6 @@
1
1
  {
2
2
  "name": "@bento-core/table",
3
- "version": "1.0.0-c3dc.7",
3
+ "version": "1.0.0-c3dc.9",
4
4
  "main": "dist/index.js",
5
5
  "scripts": {
6
6
  "build": "npm run lint && cross-env-shell rm -rf dist && NODE_ENV=production BABEL_ENV=es babel src --out-dir dist --copy-files",
@@ -163,7 +163,8 @@ const DownloadButton = ({
163
163
 
164
164
  return (
165
165
  <div className={classes.dropdown}>
166
- <Tooltip title="Download filtered results">
166
+
167
+ <Tooltip title={table.downloadButtonTooltipText || 'Download filtered results'}>
167
168
  {
168
169
  count !== 0
169
170
  ? (
@@ -1,7 +1,7 @@
1
1
  import { formatBytes, formatColumnValues } from './Dataformat';
2
2
  import { actionCellTypes } from './Types';
3
3
 
4
- export function createFileName(fileName, type) {
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}${type}`;
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 }) => !actionCellTypes.includes(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 = columns.filter(({ dataField }) => dataField)
88
+ const keysToInclude = filterColumns.filter(({ dataField }) => dataField)
82
89
  .map(({ dataField }) => dataField);
83
- const headers = columns.filter(({ dataField }) => dataField)
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 || '', fileExtension));
100
+ tempLink.setAttribute('download', createFileName(downloadFileName || ''));
95
101
  document.body.appendChild(tempLink);
96
102
  tempLink.click();
97
103
  document.body.removeChild(tempLink);