@bento-core/table 1.0.0-c3dc.1 → 1.0.0-c3dc.10
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 +8 -10
- package/dist/TableView.js +1 -6
- package/dist/body/DisplayBodyCell.js +5 -0
- package/dist/body/components/CustomLinkView.js +1 -1
- package/dist/toolbar/DownloadButtonView.js +129 -46
- package/dist/util/Types.js +5 -2
- package/dist/util/downloadTable.js +58 -36
- package/package.json +1 -1
- package/src/ExtendedView.js +29 -33
- package/src/TableView.js +1 -7
- package/src/body/DisplayBodyCell.js +11 -0
- package/src/body/components/CustomLinkView.js +1 -1
- package/src/toolbar/DownloadButtonView.js +145 -55
- package/src/util/Types.js +2 -0
- package/src/util/downloadTable.js +39 -16
package/dist/ExtendedView.js
CHANGED
|
@@ -48,20 +48,13 @@ const ExtendedView = _ref => {
|
|
|
48
48
|
});
|
|
49
49
|
return /*#__PURE__*/_react.default.createElement(_core.ThemeProvider, {
|
|
50
50
|
theme: themeConfig
|
|
51
|
-
}, numSelected === 0 && (download || manageViewColumns) && /*#__PURE__*/_react.default.createElement(
|
|
52
|
-
className: "downloadColumnView"
|
|
53
|
-
}, /*#__PURE__*/_react.default.createElement(_DownloadButtonView.default, {
|
|
54
|
-
count: table.totalRowCount || 0,
|
|
55
|
-
queryVariables: queryVariables,
|
|
56
|
-
table: table,
|
|
57
|
-
buttonConfig: downloadButtonConfig
|
|
58
|
-
}), /*#__PURE__*/_react.default.createElement(_ManageColumnView.default, {
|
|
51
|
+
}, numSelected === 0 && (download || manageViewColumns) && /*#__PURE__*/_react.default.createElement(_ManageColumnView.default, {
|
|
59
52
|
table: table,
|
|
60
53
|
manageViewColumns: manageViewColumns,
|
|
61
54
|
onColumnViewChange: onColumnViewChange
|
|
62
|
-
})
|
|
55
|
+
}), pagination && /*#__PURE__*/_react.default.createElement("div", {
|
|
63
56
|
className: "downloadArea",
|
|
64
|
-
style: downloadAreaStyle
|
|
57
|
+
style: table.paginationCustomStyle && table.paginationCustomStyle.topPagination ? table.paginationCustomStyle.topPagination : downloadAreaStyle
|
|
65
58
|
}, /*#__PURE__*/_react.default.createElement(_CustomPagination.default, {
|
|
66
59
|
customTheme: customTheme.tblTopPgn,
|
|
67
60
|
rowsPerPageOptions: [10, 25, 50, 100],
|
|
@@ -73,6 +66,11 @@ const ExtendedView = _ref => {
|
|
|
73
66
|
onRowsPerPageChange: onRowsPerPageChange,
|
|
74
67
|
queryVariables: queryVariables,
|
|
75
68
|
table: table
|
|
69
|
+
}), table.showDownloadIcon !== false && /*#__PURE__*/_react.default.createElement(_DownloadButtonView.default, {
|
|
70
|
+
count: table.totalRowCount || 0,
|
|
71
|
+
queryVariables: queryVariables,
|
|
72
|
+
table: table,
|
|
73
|
+
buttonConfig: downloadButtonConfig
|
|
76
74
|
})));
|
|
77
75
|
};
|
|
78
76
|
var _default = ExtendedView;
|
package/dist/TableView.js
CHANGED
|
@@ -12,7 +12,6 @@ var _CustomTblBody = _interopRequireDefault(require("./body/CustomTblBody"));
|
|
|
12
12
|
var _CustomToolbar = _interopRequireDefault(require("./toolbar/CustomToolbar"));
|
|
13
13
|
var _DisplayErrMsg = _interopRequireDefault(require("./errMsg/DisplayErrMsg"));
|
|
14
14
|
var _ExtendedView = _interopRequireDefault(require("./ExtendedView"));
|
|
15
|
-
var _DownloadButtonView = _interopRequireDefault(require("./toolbar/DownloadButtonView"));
|
|
16
15
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
16
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
18
17
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
@@ -92,7 +91,7 @@ const TableView = _ref => {
|
|
|
92
91
|
table: table
|
|
93
92
|
}), /*#__PURE__*/_react.default.createElement("div", {
|
|
94
93
|
className: "downloadArea",
|
|
95
|
-
style: table.paginationAPIField === 'filesInList' ? cartDownloadAreaStyle : downloadAreaStyle
|
|
94
|
+
style: table.paginationAPIField === 'filesInList' ? cartDownloadAreaStyle : table.paginationCustomStyle && table.paginationCustomStyle.bottomPagination ? table.paginationCustomStyle.bottomPagination : downloadAreaStyle
|
|
96
95
|
}, /*#__PURE__*/_react.default.createElement(_CustomPagination.default, {
|
|
97
96
|
customTheme: themeConfig.tblPgn,
|
|
98
97
|
rowsPerPageOptions: [10, 25, 50, 100],
|
|
@@ -102,10 +101,6 @@ const TableView = _ref => {
|
|
|
102
101
|
page: table.page || 0,
|
|
103
102
|
onPageChange: onPageChange,
|
|
104
103
|
onRowsPerPageChange: onRowsPerPageChange
|
|
105
|
-
}), /*#__PURE__*/_react.default.createElement(_DownloadButtonView.default, {
|
|
106
|
-
count: table.totalRowCount || 0,
|
|
107
|
-
queryVariables: queryVariables,
|
|
108
|
-
table: table
|
|
109
104
|
})));
|
|
110
105
|
};
|
|
111
106
|
var _default = TableView;
|
|
@@ -44,6 +44,9 @@ const ViewCell = _ref2 => {
|
|
|
44
44
|
const {
|
|
45
45
|
cellType
|
|
46
46
|
} = column;
|
|
47
|
+
function isNumeric(value) {
|
|
48
|
+
return /^-?\d+\.?\d*$/.test(value);
|
|
49
|
+
}
|
|
47
50
|
switch (cellType) {
|
|
48
51
|
case _Types.cellTypes.FORMAT_DATA:
|
|
49
52
|
return /*#__PURE__*/_react.default.createElement(_DataFormatView.default, {
|
|
@@ -60,6 +63,8 @@ const ViewCell = _ref2 => {
|
|
|
60
63
|
row: row,
|
|
61
64
|
column: column
|
|
62
65
|
});
|
|
66
|
+
case _Types.cellTypes.COMMA:
|
|
67
|
+
return /*#__PURE__*/_react.default.createElement(_core.Typography, null, isNumeric(row[column.dataField]) ? Number(row[column.dataField]).toLocaleString() : row[column.dataField]);
|
|
63
68
|
default:
|
|
64
69
|
return /*#__PURE__*/_react.default.createElement(_core.Typography, null, row[column.dataField]);
|
|
65
70
|
}
|
|
@@ -20,7 +20,7 @@ const CustomLinkView = _ref => {
|
|
|
20
20
|
rootPath,
|
|
21
21
|
pathParams
|
|
22
22
|
} = column === null || column === void 0 ? void 0 : column.linkAttr;
|
|
23
|
-
const url = pathParams.map(attr => "
|
|
23
|
+
const url = pathParams.map(attr => "".concat(rootPath, "/").concat(row[attr]));
|
|
24
24
|
return /*#__PURE__*/_react.default.createElement(_core.Link, {
|
|
25
25
|
href: url,
|
|
26
26
|
className: _Types.cellTypes.LINK
|
|
@@ -7,8 +7,10 @@ exports.default = void 0;
|
|
|
7
7
|
var _react = _interopRequireWildcard(require("react"));
|
|
8
8
|
var _client = require("@apollo/client");
|
|
9
9
|
var _core = require("@material-ui/core");
|
|
10
|
+
var _KeyboardArrowDownOutlined = _interopRequireDefault(require("@material-ui/icons/KeyboardArrowDownOutlined"));
|
|
10
11
|
var _icons = require("@material-ui/icons");
|
|
11
12
|
var _downloadTable = require("../util/downloadTable");
|
|
13
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
14
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
13
15
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
14
16
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
@@ -16,42 +18,36 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
16
18
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
17
19
|
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
18
20
|
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
19
|
-
const downloadButtonStyle = {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
};
|
|
21
|
+
// const downloadButtonStyle = {
|
|
22
|
+
// color: '#d1d2d3',
|
|
23
|
+
// marginTop: '7px',
|
|
24
|
+
// };
|
|
23
25
|
|
|
24
|
-
// Default style for Download Button with Text.
|
|
25
|
-
const DEFAULT_BUTTON_STYLE = {
|
|
26
|
-
width: '223px',
|
|
27
|
-
height: '41px',
|
|
28
|
-
borderRadius: '5px',
|
|
29
|
-
backgroundColor: '#2A6E93',
|
|
30
|
-
color: '#fff',
|
|
31
|
-
marginTop: '10px',
|
|
32
|
-
fontFamily: 'poppins',
|
|
33
|
-
'& #cloudIcon': {
|
|
34
|
-
margin: '10px',
|
|
35
|
-
marginTop: '6px'
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
26
|
const DownloadButton = _ref => {
|
|
39
27
|
let {
|
|
40
28
|
count,
|
|
41
29
|
queryVariables,
|
|
42
|
-
table
|
|
43
|
-
buttonConfig = {},
|
|
44
|
-
isIcon = false
|
|
30
|
+
table
|
|
45
31
|
} = _ref;
|
|
32
|
+
const [listDisplay, setListDisplay] = (0, _react.useState)('none');
|
|
33
|
+
const dropdownSelection = (0, _react.useRef)(null);
|
|
34
|
+
const useOutsideAlerter = ref => {
|
|
35
|
+
(0, _react.useEffect)(() => {
|
|
36
|
+
function handleClickOutside(event) {
|
|
37
|
+
if (!(event.target.getAttribute('id') && event.target.getAttribute('id').includes('dropdownListItem'))) {
|
|
38
|
+
setListDisplay('none');
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
document.addEventListener('mousedown', handleClickOutside);
|
|
42
|
+
return () => {
|
|
43
|
+
document.removeEventListener('mousedown', handleClickOutside);
|
|
44
|
+
};
|
|
45
|
+
}, [ref]);
|
|
46
|
+
};
|
|
47
|
+
useOutsideAlerter(dropdownSelection);
|
|
46
48
|
if (table.paginationAPIField === 'filesInList') {
|
|
47
49
|
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null);
|
|
48
50
|
}
|
|
49
|
-
if (count === 0) {
|
|
50
|
-
return /*#__PURE__*/_react.default.createElement(_icons.CloudDownload, {
|
|
51
|
-
className: "disableButton",
|
|
52
|
-
style: downloadButtonStyle
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
51
|
const client = (0, _client.useApolloClient)();
|
|
56
52
|
async function downloadSCSVFile() {
|
|
57
53
|
const {
|
|
@@ -62,7 +58,9 @@ const DownloadButton = _ref => {
|
|
|
62
58
|
query,
|
|
63
59
|
variables: _objectSpread(_objectSpread({}, queryVariables), {}, {
|
|
64
60
|
page: 0,
|
|
65
|
-
first: 10000
|
|
61
|
+
first: 10000,
|
|
62
|
+
order_by: table.sortBy,
|
|
63
|
+
sort_direction: table.sortOrder
|
|
66
64
|
})
|
|
67
65
|
}).then(response => {
|
|
68
66
|
if (paginationAPIField && response && response.data) {
|
|
@@ -70,29 +68,114 @@ const DownloadButton = _ref => {
|
|
|
70
68
|
}
|
|
71
69
|
return response.data;
|
|
72
70
|
});
|
|
73
|
-
(0, _downloadTable.
|
|
71
|
+
(0, _downloadTable.downloadData)(result, table, table.downloadFileName, 'csv');
|
|
72
|
+
}
|
|
73
|
+
async function downloadJsonFile() {
|
|
74
|
+
const {
|
|
75
|
+
query,
|
|
76
|
+
paginationAPIField
|
|
77
|
+
} = table;
|
|
78
|
+
const result = await client.query({
|
|
79
|
+
query,
|
|
80
|
+
variables: _objectSpread(_objectSpread({}, queryVariables), {}, {
|
|
81
|
+
page: 0,
|
|
82
|
+
first: 10000,
|
|
83
|
+
order_by: table.sortBy,
|
|
84
|
+
sort_direction: table.sortOrder
|
|
85
|
+
})
|
|
86
|
+
}).then(response => {
|
|
87
|
+
if (paginationAPIField && response && response.data) {
|
|
88
|
+
return response.data[paginationAPIField];
|
|
89
|
+
}
|
|
90
|
+
return response.data;
|
|
91
|
+
});
|
|
92
|
+
(0, _downloadTable.downloadData)(result, table, table.downloadFileName, 'json');
|
|
74
93
|
}
|
|
75
94
|
const downloadTableCSV = (0, _react.useCallback)(() => {
|
|
76
95
|
downloadSCSVFile();
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
96
|
+
setListDisplay('none');
|
|
97
|
+
}, [queryVariables, table]);
|
|
98
|
+
const downloadTableJson = (0, _react.useCallback)(() => {
|
|
99
|
+
downloadJsonFile();
|
|
100
|
+
setListDisplay('none');
|
|
101
|
+
}, [queryVariables, table]);
|
|
102
|
+
const handleClickButton = () => {
|
|
103
|
+
if (listDisplay === 'none') {
|
|
104
|
+
setListDisplay('block');
|
|
105
|
+
} else {
|
|
106
|
+
setListDisplay('none');
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
const useStyles = (0, _core.makeStyles)({
|
|
110
|
+
dropdown: {
|
|
111
|
+
width: '60px',
|
|
112
|
+
height: '25px',
|
|
113
|
+
marginTop: '8px',
|
|
114
|
+
paddingLeft: '5px',
|
|
115
|
+
border: '0.75px solid #606060',
|
|
116
|
+
borderRadius: '5px',
|
|
117
|
+
display: 'inline-block',
|
|
118
|
+
position: 'relative'
|
|
119
|
+
},
|
|
120
|
+
dropdownList: {
|
|
121
|
+
display: 'block',
|
|
122
|
+
position: 'absolute',
|
|
123
|
+
width: '60px',
|
|
124
|
+
marginTop: '3px',
|
|
125
|
+
marginLeft: '-5px',
|
|
126
|
+
overflow: 'auto',
|
|
127
|
+
zIndex: '5',
|
|
128
|
+
border: '1.5px solid #41545E',
|
|
129
|
+
borderRadius: '5px',
|
|
130
|
+
background: '#ffffff'
|
|
131
|
+
},
|
|
132
|
+
dropdownListItem: {
|
|
133
|
+
padding: '2px 4px',
|
|
134
|
+
font: 'Poppins',
|
|
135
|
+
fontSize: '14px',
|
|
136
|
+
fontWeight: 400,
|
|
137
|
+
lineHeight: '21px',
|
|
138
|
+
'&:hover': {
|
|
139
|
+
background: '#D7D7D7',
|
|
140
|
+
cursor: 'pointer'
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
arrowdownIcon: {
|
|
144
|
+
marginLeft: '5px',
|
|
145
|
+
fill: '#606060'
|
|
146
|
+
},
|
|
147
|
+
arrowdownIconDisabled: {
|
|
148
|
+
marginLeft: '5px',
|
|
149
|
+
fill: '#00000042'
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
const classes = useStyles();
|
|
153
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
154
|
+
className: classes.dropdown
|
|
155
|
+
}, /*#__PURE__*/_react.default.createElement(_core.Tooltip, {
|
|
156
|
+
title: table.downloadButtonTooltipText || 'Download filtered results'
|
|
157
|
+
}, count !== 0 ? /*#__PURE__*/_react.default.createElement(_core.IconButton, {
|
|
158
|
+
onClick: handleClickButton
|
|
159
|
+
}, /*#__PURE__*/_react.default.createElement(_icons.CloudDownload, null), /*#__PURE__*/_react.default.createElement(_KeyboardArrowDownOutlined.default, {
|
|
160
|
+
className: classes.arrowdownIcon
|
|
161
|
+
})) : /*#__PURE__*/_react.default.createElement(_core.IconButton, {
|
|
162
|
+
disabled: true
|
|
163
|
+
}, /*#__PURE__*/_react.default.createElement(_icons.CloudDownload, null), /*#__PURE__*/_react.default.createElement(_KeyboardArrowDownOutlined.default, {
|
|
164
|
+
className: classes.arrowdownIconDisabled
|
|
165
|
+
}))), /*#__PURE__*/_react.default.createElement("div", {
|
|
166
|
+
className: classes.dropdownList,
|
|
92
167
|
style: {
|
|
93
|
-
|
|
168
|
+
display: listDisplay
|
|
94
169
|
}
|
|
95
|
-
}
|
|
170
|
+
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
171
|
+
id: "dropdownListItemCSV",
|
|
172
|
+
className: classes.dropdownListItem,
|
|
173
|
+
onClick: downloadTableCSV
|
|
174
|
+
}, "CSV"), /*#__PURE__*/_react.default.createElement("div", {
|
|
175
|
+
id: "dropdownListItemJSON",
|
|
176
|
+
className: classes.dropdownListItem,
|
|
177
|
+
onClick: downloadTableJson
|
|
178
|
+
}, "JSON")));
|
|
96
179
|
};
|
|
97
180
|
var _default = DownloadButton;
|
|
98
181
|
exports.default = _default;
|
package/dist/util/Types.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.headerTypes = exports.dataFormatTypes = exports.cellTypes = exports.cellStyles = exports.actionCellTypes = exports.TRANSFORM = exports.LINK = exports.FORMAT_DATA_CELLS = exports.FORMAT_DATA = exports.FORMAT_BYTES = exports.EXPAND = exports.DISPLAY = exports.DELETE = exports.DEFAULT = exports.ComponentTypes = exports.CUSTOM_ELEM = exports.CHECKBOX = void 0;
|
|
6
|
+
exports.headerTypes = exports.dataFormatTypes = exports.cellTypes = exports.cellStyles = exports.actionCellTypes = exports.TRANSFORM = exports.LINK = exports.FORMAT_DATA_CELLS = exports.FORMAT_DATA = exports.FORMAT_BYTES = exports.EXPAND = exports.DISPLAY = exports.DELETE = exports.DEFAULT = exports.ComponentTypes = exports.CUSTOM_ELEM = exports.COMMA = exports.CHECKBOX = void 0;
|
|
7
7
|
const CHECKBOX = 'CHECKBOX';
|
|
8
8
|
exports.CHECKBOX = CHECKBOX;
|
|
9
9
|
const DELETE = 'DELETE';
|
|
@@ -24,6 +24,8 @@ const TRANSFORM = 'TRANSFORM';
|
|
|
24
24
|
exports.TRANSFORM = TRANSFORM;
|
|
25
25
|
const EXPAND = 'EXPAND';
|
|
26
26
|
exports.EXPAND = EXPAND;
|
|
27
|
+
const COMMA = 'COMMA';
|
|
28
|
+
exports.COMMA = COMMA;
|
|
27
29
|
const cellTypes = {
|
|
28
30
|
CUSTOM_ELEM,
|
|
29
31
|
LINK,
|
|
@@ -31,7 +33,8 @@ const cellTypes = {
|
|
|
31
33
|
CHECKBOX,
|
|
32
34
|
DELETE,
|
|
33
35
|
DEFAULT,
|
|
34
|
-
FORMAT_DATA
|
|
36
|
+
FORMAT_DATA,
|
|
37
|
+
COMMA
|
|
35
38
|
};
|
|
36
39
|
exports.cellTypes = cellTypes;
|
|
37
40
|
const cellStyles = {
|
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.convertToCSV = convertToCSV;
|
|
7
7
|
exports.createFileName = createFileName;
|
|
8
|
-
exports.
|
|
8
|
+
exports.downloadData = downloadData;
|
|
9
9
|
var _Dataformat = require("./Dataformat");
|
|
10
10
|
var _Types = require("./Types");
|
|
11
11
|
function createFileName(fileName) {
|
|
@@ -32,7 +32,7 @@ function createFileName(fileName) {
|
|
|
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;
|
|
@@ -66,49 +66,71 @@ function convertToCSV(jsonse, keysToInclude, header) {
|
|
|
66
66
|
});
|
|
67
67
|
return str;
|
|
68
68
|
}
|
|
69
|
-
function
|
|
69
|
+
function downloadData(tableData, table, downloadFileName) {
|
|
70
|
+
let format = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'csv';
|
|
70
71
|
const {
|
|
71
72
|
columns = []
|
|
72
73
|
} = table;
|
|
73
74
|
const filterColumns = columns.filter(_ref => {
|
|
74
75
|
let {
|
|
75
|
-
cellType
|
|
76
|
+
cellType,
|
|
77
|
+
doNotDownload
|
|
76
78
|
} = _ref;
|
|
77
|
-
return !_Types.actionCellTypes.includes(cellType);
|
|
79
|
+
return !_Types.actionCellTypes.includes(cellType) && !doNotDownload;
|
|
78
80
|
});
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
} = _ref3;
|
|
90
|
-
return dataField;
|
|
91
|
-
});
|
|
92
|
-
const headers = columns.filter(_ref4 => {
|
|
93
|
-
let {
|
|
94
|
-
dataField
|
|
95
|
-
} = _ref4;
|
|
96
|
-
return dataField;
|
|
97
|
-
}).map(_ref5 => {
|
|
98
|
-
let {
|
|
99
|
-
header,
|
|
100
|
-
downloadHeader
|
|
101
|
-
} = _ref5;
|
|
102
|
-
return downloadHeader || header;
|
|
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;
|
|
103
91
|
});
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
92
|
+
let fileContent;
|
|
93
|
+
let fileType;
|
|
94
|
+
if (format === 'json') {
|
|
95
|
+
filterColumns.forEach(column => {
|
|
96
|
+
formatDataVal = JSON.parse(JSON.stringify(formatDataVal).split("\"".concat(column.dataField, "\":")).join("\"".concat(column.header, "\":")));
|
|
97
|
+
});
|
|
98
|
+
fileContent = JSON.stringify(formatDataVal);
|
|
99
|
+
fileType = 'application/json';
|
|
100
|
+
} else {
|
|
101
|
+
const jsonse = JSON.stringify(formatDataVal);
|
|
102
|
+
const keysToInclude = filterColumns.filter(_ref3 => {
|
|
103
|
+
let {
|
|
104
|
+
dataField
|
|
105
|
+
} = _ref3;
|
|
106
|
+
return dataField;
|
|
107
|
+
}).map(_ref4 => {
|
|
108
|
+
let {
|
|
109
|
+
dataField
|
|
110
|
+
} = _ref4;
|
|
111
|
+
return dataField;
|
|
112
|
+
});
|
|
113
|
+
const headers = filterColumns.filter(_ref5 => {
|
|
114
|
+
let {
|
|
115
|
+
dataField
|
|
116
|
+
} = _ref5;
|
|
117
|
+
return dataField;
|
|
118
|
+
}).map(_ref6 => {
|
|
119
|
+
let {
|
|
120
|
+
header,
|
|
121
|
+
downloadHeader
|
|
122
|
+
} = _ref6;
|
|
123
|
+
return downloadHeader || header;
|
|
124
|
+
});
|
|
125
|
+
fileContent = convertToCSV(jsonse, keysToInclude, headers);
|
|
126
|
+
fileType = 'text/csv';
|
|
127
|
+
}
|
|
128
|
+
const exportData = new Blob([fileContent], {
|
|
129
|
+
type: fileType
|
|
107
130
|
});
|
|
108
|
-
const
|
|
109
|
-
|
|
110
|
-
tempLink
|
|
111
|
-
tempLink.setAttribute('href', JsonURL);
|
|
131
|
+
const fileURL = window.URL.createObjectURL(exportData);
|
|
132
|
+
const tempLink = document.createElement('a');
|
|
133
|
+
tempLink.setAttribute('href', fileURL);
|
|
112
134
|
tempLink.setAttribute('download', createFileName(downloadFileName || ''));
|
|
113
135
|
document.body.appendChild(tempLink);
|
|
114
136
|
tempLink.click();
|
package/package.json
CHANGED
package/src/ExtendedView.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import {
|
|
3
3
|
ThemeProvider,
|
|
4
|
-
Toolbar,
|
|
5
4
|
createTheme,
|
|
6
5
|
} from '@material-ui/core';
|
|
7
6
|
import CustomPagination from './pagination/CustomPagination';
|
|
@@ -39,45 +38,42 @@ const ExtendedView = ({
|
|
|
39
38
|
return (
|
|
40
39
|
<ThemeProvider theme={themeConfig}>
|
|
41
40
|
{(numSelected === 0 && (download || manageViewColumns)) && (
|
|
42
|
-
|
|
43
|
-
<DownloadButton
|
|
44
|
-
count={table.totalRowCount || 0}
|
|
45
|
-
queryVariables={queryVariables}
|
|
46
|
-
table={table}
|
|
47
|
-
buttonConfig={downloadButtonConfig}
|
|
48
|
-
/>
|
|
41
|
+
|
|
49
42
|
<ManageColumnView
|
|
50
43
|
table={table}
|
|
51
44
|
manageViewColumns={manageViewColumns}
|
|
52
45
|
onColumnViewChange={onColumnViewChange}
|
|
53
46
|
/>
|
|
54
|
-
|
|
47
|
+
|
|
55
48
|
)}
|
|
56
49
|
{
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
50
|
+
(pagination) && (
|
|
51
|
+
<div className="downloadArea" style={(table.paginationCustomStyle && table.paginationCustomStyle.topPagination) ? table.paginationCustomStyle.topPagination : downloadAreaStyle}>
|
|
52
|
+
<CustomPagination
|
|
53
|
+
customTheme={customTheme.tblTopPgn}
|
|
54
|
+
rowsPerPageOptions={[10, 25, 50, 100]}
|
|
55
|
+
component="div"
|
|
56
|
+
count={table.totalRowCount || 0}
|
|
57
|
+
rowsPerPage={table.rowsPerPage || 10}
|
|
58
|
+
page={table.page || 0}
|
|
59
|
+
onPageChange={onPageChange}
|
|
60
|
+
onRowsPerPageChange={onRowsPerPageChange}
|
|
61
|
+
queryVariables={queryVariables}
|
|
62
|
+
table={table}
|
|
63
|
+
/>
|
|
64
|
+
{table.showDownloadIcon !== false
|
|
65
|
+
&& (
|
|
66
|
+
<DownloadButton
|
|
67
|
+
count={table.totalRowCount || 0}
|
|
68
|
+
queryVariables={queryVariables}
|
|
69
|
+
table={table}
|
|
70
|
+
buttonConfig={downloadButtonConfig}
|
|
71
|
+
/>
|
|
72
|
+
)}
|
|
73
|
+
|
|
74
|
+
</div>
|
|
75
|
+
)
|
|
76
|
+
}
|
|
81
77
|
</ThemeProvider>
|
|
82
78
|
);
|
|
83
79
|
};
|
package/src/TableView.js
CHANGED
|
@@ -12,7 +12,6 @@ import CustomTableBody from './body/CustomTblBody';
|
|
|
12
12
|
import CustomToolbar from './toolbar/CustomToolbar';
|
|
13
13
|
import DisplayErrMsg from './errMsg/DisplayErrMsg';
|
|
14
14
|
import ExtendedView from './ExtendedView';
|
|
15
|
-
import DownloadButton from './toolbar/DownloadButtonView';
|
|
16
15
|
|
|
17
16
|
const CustomTableContainer = (props) => {
|
|
18
17
|
const { children, customTheme } = props;
|
|
@@ -95,7 +94,7 @@ const TableView = ({
|
|
|
95
94
|
table={table}
|
|
96
95
|
/>
|
|
97
96
|
)}
|
|
98
|
-
<div className="downloadArea" style={table.paginationAPIField === 'filesInList' ? cartDownloadAreaStyle : downloadAreaStyle}>
|
|
97
|
+
<div className="downloadArea" style={table.paginationAPIField === 'filesInList' ? cartDownloadAreaStyle : (table.paginationCustomStyle && table.paginationCustomStyle.bottomPagination) ? table.paginationCustomStyle.bottomPagination : downloadAreaStyle}>
|
|
99
98
|
<CustomPagination
|
|
100
99
|
customTheme={themeConfig.tblPgn}
|
|
101
100
|
rowsPerPageOptions={[10, 25, 50, 100]}
|
|
@@ -106,11 +105,6 @@ const TableView = ({
|
|
|
106
105
|
onPageChange={onPageChange}
|
|
107
106
|
onRowsPerPageChange={onRowsPerPageChange}
|
|
108
107
|
/>
|
|
109
|
-
<DownloadButton
|
|
110
|
-
count={table.totalRowCount || 0}
|
|
111
|
-
queryVariables={queryVariables}
|
|
112
|
-
table={table}
|
|
113
|
-
/>
|
|
114
108
|
</div>
|
|
115
109
|
</>
|
|
116
110
|
);
|
|
@@ -31,6 +31,9 @@ const ViewCell = ({
|
|
|
31
31
|
row,
|
|
32
32
|
}) => {
|
|
33
33
|
const { cellType } = column;
|
|
34
|
+
function isNumeric(value) {
|
|
35
|
+
return /^-?\d+\.?\d*$/.test(value);
|
|
36
|
+
}
|
|
34
37
|
switch (cellType) {
|
|
35
38
|
case cellTypes.FORMAT_DATA:
|
|
36
39
|
return (
|
|
@@ -53,6 +56,14 @@ const ViewCell = ({
|
|
|
53
56
|
column={column}
|
|
54
57
|
/>
|
|
55
58
|
);
|
|
59
|
+
case cellTypes.COMMA:
|
|
60
|
+
return (
|
|
61
|
+
<Typography>
|
|
62
|
+
{isNumeric(row[column.dataField])
|
|
63
|
+
? Number(row[column.dataField]).toLocaleString()
|
|
64
|
+
: row[column.dataField]}
|
|
65
|
+
</Typography>
|
|
66
|
+
);
|
|
56
67
|
default:
|
|
57
68
|
return (
|
|
58
69
|
<Typography>
|
|
@@ -12,7 +12,7 @@ const CustomLinkView = ({
|
|
|
12
12
|
row,
|
|
13
13
|
}) => {
|
|
14
14
|
const { rootPath, pathParams } = column?.linkAttr;
|
|
15
|
-
const url = pathParams.map((attr) =>
|
|
15
|
+
const url = pathParams.map((attr) => `${rootPath}/`.concat(row[attr]));
|
|
16
16
|
return (
|
|
17
17
|
<Link href={url} className={cellTypes.LINK}>
|
|
18
18
|
<Typography>
|
|
@@ -1,47 +1,49 @@
|
|
|
1
|
-
import React, {
|
|
1
|
+
import React, {
|
|
2
|
+
useState,
|
|
3
|
+
useEffect,
|
|
4
|
+
useRef,
|
|
5
|
+
useCallback,
|
|
6
|
+
} from 'react';
|
|
2
7
|
import { useApolloClient } from '@apollo/client';
|
|
3
8
|
import {
|
|
4
9
|
IconButton,
|
|
5
10
|
Tooltip,
|
|
6
|
-
|
|
11
|
+
makeStyles,
|
|
7
12
|
} from '@material-ui/core';
|
|
8
|
-
|
|
13
|
+
import KeyboardArrowDownOutlinedIcon from '@material-ui/icons/KeyboardArrowDownOutlined';
|
|
9
14
|
import { CloudDownload } from '@material-ui/icons';
|
|
10
|
-
import {
|
|
15
|
+
import { downloadData } from '../util/downloadTable';
|
|
11
16
|
|
|
12
|
-
const downloadButtonStyle = {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
// Default style for Download Button with Text.
|
|
18
|
-
const DEFAULT_BUTTON_STYLE = {
|
|
19
|
-
width: '223px',
|
|
20
|
-
height: '41px',
|
|
21
|
-
borderRadius: '5px',
|
|
22
|
-
backgroundColor: '#2A6E93',
|
|
23
|
-
color: '#fff',
|
|
24
|
-
marginTop: '10px',
|
|
25
|
-
fontFamily: 'poppins',
|
|
26
|
-
'& #cloudIcon': {
|
|
27
|
-
margin: '10px',
|
|
28
|
-
marginTop: '6px',
|
|
29
|
-
},
|
|
30
|
-
};
|
|
17
|
+
// const downloadButtonStyle = {
|
|
18
|
+
// color: '#d1d2d3',
|
|
19
|
+
// marginTop: '7px',
|
|
20
|
+
// };
|
|
31
21
|
|
|
32
22
|
const DownloadButton = ({
|
|
33
23
|
count,
|
|
34
24
|
queryVariables,
|
|
35
25
|
table,
|
|
36
|
-
buttonConfig = {},
|
|
37
|
-
isIcon = false,
|
|
38
26
|
}) => {
|
|
27
|
+
const [listDisplay, setListDisplay] = useState('none');
|
|
28
|
+
const dropdownSelection = useRef(null);
|
|
29
|
+
const useOutsideAlerter = (ref) => {
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
function handleClickOutside(event) {
|
|
32
|
+
if (!(event.target.getAttribute('id') && event.target.getAttribute('id').includes('dropdownListItem'))) {
|
|
33
|
+
setListDisplay('none');
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
document.addEventListener('mousedown', handleClickOutside);
|
|
37
|
+
return () => {
|
|
38
|
+
document.removeEventListener('mousedown', handleClickOutside);
|
|
39
|
+
};
|
|
40
|
+
}, [ref]);
|
|
41
|
+
};
|
|
42
|
+
useOutsideAlerter(dropdownSelection);
|
|
43
|
+
|
|
39
44
|
if (table.paginationAPIField === 'filesInList') {
|
|
40
45
|
return <></>;
|
|
41
46
|
}
|
|
42
|
-
if (count === 0) {
|
|
43
|
-
return <CloudDownload className="disableButton" style={downloadButtonStyle} />;
|
|
44
|
-
}
|
|
45
47
|
|
|
46
48
|
const client = useApolloClient();
|
|
47
49
|
|
|
@@ -57,6 +59,8 @@ const DownloadButton = ({
|
|
|
57
59
|
...queryVariables,
|
|
58
60
|
page: 0,
|
|
59
61
|
first: 10000,
|
|
62
|
+
order_by: table.sortBy,
|
|
63
|
+
sort_direction: table.sortOrder,
|
|
60
64
|
},
|
|
61
65
|
})
|
|
62
66
|
.then((response) => {
|
|
@@ -65,37 +69,123 @@ const DownloadButton = ({
|
|
|
65
69
|
}
|
|
66
70
|
return response.data;
|
|
67
71
|
});
|
|
68
|
-
|
|
72
|
+
downloadData(result, table, table.downloadFileName, 'csv');
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
async function downloadJsonFile() {
|
|
76
|
+
const {
|
|
77
|
+
query,
|
|
78
|
+
paginationAPIField,
|
|
79
|
+
} = table;
|
|
80
|
+
|
|
81
|
+
const result = await client.query({
|
|
82
|
+
query,
|
|
83
|
+
variables: {
|
|
84
|
+
...queryVariables,
|
|
85
|
+
page: 0,
|
|
86
|
+
first: 10000,
|
|
87
|
+
order_by: table.sortBy,
|
|
88
|
+
sort_direction: table.sortOrder,
|
|
89
|
+
},
|
|
90
|
+
})
|
|
91
|
+
.then((response) => {
|
|
92
|
+
if (paginationAPIField && response && response.data) {
|
|
93
|
+
return response.data[paginationAPIField];
|
|
94
|
+
}
|
|
95
|
+
return response.data;
|
|
96
|
+
});
|
|
97
|
+
downloadData(result, table, table.downloadFileName, 'json');
|
|
69
98
|
}
|
|
70
99
|
|
|
71
100
|
const downloadTableCSV = useCallback(() => {
|
|
72
101
|
downloadSCSVFile();
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
102
|
+
setListDisplay('none');
|
|
103
|
+
}, [queryVariables, table]);
|
|
104
|
+
|
|
105
|
+
const downloadTableJson = useCallback(() => {
|
|
106
|
+
downloadJsonFile();
|
|
107
|
+
setListDisplay('none');
|
|
108
|
+
}, [queryVariables, table]);
|
|
109
|
+
|
|
110
|
+
const handleClickButton = () => {
|
|
111
|
+
if (listDisplay === 'none') {
|
|
112
|
+
setListDisplay('block');
|
|
113
|
+
} else {
|
|
114
|
+
setListDisplay('none');
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
const useStyles = makeStyles({
|
|
119
|
+
dropdown: {
|
|
120
|
+
width: '60px',
|
|
121
|
+
height: '25px',
|
|
122
|
+
marginTop: '8px',
|
|
123
|
+
paddingLeft: '5px',
|
|
124
|
+
border: '0.75px solid #606060',
|
|
125
|
+
borderRadius: '5px',
|
|
126
|
+
display: 'inline-block',
|
|
127
|
+
position: 'relative',
|
|
128
|
+
},
|
|
129
|
+
dropdownList: {
|
|
130
|
+
display: 'block',
|
|
131
|
+
position: 'absolute',
|
|
132
|
+
width: '60px',
|
|
133
|
+
marginTop: '3px',
|
|
134
|
+
marginLeft: '-5px',
|
|
135
|
+
overflow: 'auto',
|
|
136
|
+
zIndex: '5',
|
|
137
|
+
border: '1.5px solid #41545E',
|
|
138
|
+
borderRadius: '5px',
|
|
139
|
+
background: '#ffffff',
|
|
140
|
+
},
|
|
141
|
+
dropdownListItem: {
|
|
142
|
+
padding: '2px 4px',
|
|
143
|
+
font: 'Poppins',
|
|
144
|
+
fontSize: '14px',
|
|
145
|
+
fontWeight: 400,
|
|
146
|
+
lineHeight: '21px',
|
|
147
|
+
'&:hover': {
|
|
148
|
+
background: '#D7D7D7',
|
|
149
|
+
cursor: 'pointer',
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
arrowdownIcon: {
|
|
153
|
+
marginLeft: '5px',
|
|
154
|
+
fill: '#606060',
|
|
155
|
+
},
|
|
156
|
+
arrowdownIconDisabled: {
|
|
157
|
+
marginLeft: '5px',
|
|
158
|
+
fill: '#00000042',
|
|
159
|
+
},
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
const classes = useStyles();
|
|
163
|
+
|
|
164
|
+
return (
|
|
165
|
+
<div className={classes.dropdown}>
|
|
166
|
+
|
|
167
|
+
<Tooltip title={table.downloadButtonTooltipText || 'Download filtered results'}>
|
|
168
|
+
{
|
|
169
|
+
count !== 0
|
|
170
|
+
? (
|
|
171
|
+
<IconButton onClick={handleClickButton}>
|
|
172
|
+
<CloudDownload />
|
|
173
|
+
<KeyboardArrowDownOutlinedIcon className={classes.arrowdownIcon} />
|
|
174
|
+
</IconButton>
|
|
175
|
+
)
|
|
176
|
+
: (
|
|
177
|
+
<IconButton disabled>
|
|
178
|
+
<CloudDownload />
|
|
179
|
+
<KeyboardArrowDownOutlinedIcon className={classes.arrowdownIconDisabled} />
|
|
180
|
+
</IconButton>
|
|
181
|
+
)
|
|
182
|
+
}
|
|
183
|
+
</Tooltip>
|
|
184
|
+
<div className={classes.dropdownList} style={{ display: listDisplay }}>
|
|
185
|
+
<div id="dropdownListItemCSV" className={classes.dropdownListItem} onClick={downloadTableCSV}>CSV</div>
|
|
186
|
+
<div id="dropdownListItemJSON" className={classes.dropdownListItem} onClick={downloadTableJson}>JSON</div>
|
|
187
|
+
</div>
|
|
188
|
+
</div>
|
|
99
189
|
);
|
|
100
190
|
};
|
|
101
191
|
|
package/src/util/Types.js
CHANGED
|
@@ -8,6 +8,7 @@ export const FORMAT_DATA = 'FORMAT_DATA';
|
|
|
8
8
|
export const FORMAT_BYTES = 'FORMAT_BYTES';
|
|
9
9
|
export const TRANSFORM = 'TRANSFORM';
|
|
10
10
|
export const EXPAND = 'EXPAND';
|
|
11
|
+
export const COMMA = 'COMMA';
|
|
11
12
|
|
|
12
13
|
export const cellTypes = {
|
|
13
14
|
CUSTOM_ELEM,
|
|
@@ -17,6 +18,7 @@ export const cellTypes = {
|
|
|
17
18
|
DELETE,
|
|
18
19
|
DEFAULT,
|
|
19
20
|
FORMAT_DATA,
|
|
21
|
+
COMMA,
|
|
20
22
|
};
|
|
21
23
|
|
|
22
24
|
export const cellStyles = {
|
|
@@ -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) {
|
|
@@ -59,21 +58,45 @@ export function convertToCSV(jsonse, keysToInclude, header) {
|
|
|
59
58
|
return str;
|
|
60
59
|
}
|
|
61
60
|
|
|
62
|
-
export function
|
|
61
|
+
export function downloadData(tableData, table, downloadFileName, format = 'csv') {
|
|
63
62
|
const { columns = [] } = table;
|
|
64
|
-
const filterColumns = columns.filter(({ cellType }) =>
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
.
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
63
|
+
const filterColumns = columns.filter(({ cellType, doNotDownload }) => (
|
|
64
|
+
!actionCellTypes.includes(cellType) && !doNotDownload));
|
|
65
|
+
let formatDataVal = formatColumnValues(filterColumns, tableData);
|
|
66
|
+
|
|
67
|
+
formatDataVal = formatDataVal.map((item) => {
|
|
68
|
+
const updatedItem = {};
|
|
69
|
+
filterColumns.forEach(({ dataField }) => {
|
|
70
|
+
updatedItem[dataField] = item[dataField];
|
|
71
|
+
});
|
|
72
|
+
return updatedItem;
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
let fileContent;
|
|
76
|
+
let fileType;
|
|
77
|
+
|
|
78
|
+
if (format === 'json') {
|
|
79
|
+
filterColumns.forEach((column) => {
|
|
80
|
+
formatDataVal = JSON.parse(
|
|
81
|
+
JSON.stringify(formatDataVal).split(`"${column.dataField}":`).join(`"${column.header}":`),
|
|
82
|
+
);
|
|
83
|
+
});
|
|
84
|
+
fileContent = JSON.stringify(formatDataVal);
|
|
85
|
+
fileType = 'application/json';
|
|
86
|
+
} else {
|
|
87
|
+
const jsonse = JSON.stringify(formatDataVal);
|
|
88
|
+
const keysToInclude = filterColumns.filter(({ dataField }) => dataField)
|
|
89
|
+
.map(({ dataField }) => dataField);
|
|
90
|
+
const headers = filterColumns.filter(({ dataField }) => dataField)
|
|
91
|
+
.map(({ header, downloadHeader }) => (downloadHeader || header));
|
|
92
|
+
fileContent = convertToCSV(jsonse, keysToInclude, headers);
|
|
93
|
+
fileType = 'text/csv';
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const exportData = new Blob([fileContent], { type: fileType });
|
|
97
|
+
const fileURL = window.URL.createObjectURL(exportData);
|
|
98
|
+
const tempLink = document.createElement('a');
|
|
99
|
+
tempLink.setAttribute('href', fileURL);
|
|
77
100
|
tempLink.setAttribute('download', createFileName(downloadFileName || ''));
|
|
78
101
|
document.body.appendChild(tempLink);
|
|
79
102
|
tempLink.click();
|