@bento-core/table 1.0.1-ccdihub.54 → 1.0.1-ccdihub.56
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/index.js +6 -0
- package/dist/toolbar/DownloadButtonView.js +107 -3
- package/dist/util/Types.js +10 -1
- package/dist/util/downloadTable.js +32 -4
- package/package.json +1 -1
- package/src/index.js +1 -0
- package/src/toolbar/DownloadButtonView.js +119 -9
- package/src/util/Types.js +7 -0
- package/src/util/downloadTable.js +23 -4
package/dist/index.js
CHANGED
|
@@ -15,6 +15,12 @@ Object.defineProperty(exports, "TableView", {
|
|
|
15
15
|
return _TableView.default;
|
|
16
16
|
}
|
|
17
17
|
});
|
|
18
|
+
Object.defineProperty(exports, "cellStyles", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function get() {
|
|
21
|
+
return _Types.cellStyles;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
18
24
|
Object.defineProperty(exports, "cellTypes", {
|
|
19
25
|
enumerable: true,
|
|
20
26
|
get: function get() {
|
|
@@ -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; }
|
|
@@ -26,6 +28,22 @@ const DownloadButton = _ref => {
|
|
|
26
28
|
queryVariables,
|
|
27
29
|
table
|
|
28
30
|
} = _ref;
|
|
31
|
+
const [listDisplay, setListDisplay] = (0, _react.useState)('none');
|
|
32
|
+
const dropdownSelection = (0, _react.useRef)(null);
|
|
33
|
+
const useOutsideAlerter = ref => {
|
|
34
|
+
(0, _react.useEffect)(() => {
|
|
35
|
+
function handleClickOutside(event) {
|
|
36
|
+
if (!event.target.getAttribute('class').includes('dropdownListItem')) {
|
|
37
|
+
setListDisplay('none');
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
document.addEventListener('mousedown', handleClickOutside);
|
|
41
|
+
return () => {
|
|
42
|
+
document.removeEventListener('mousedown', handleClickOutside);
|
|
43
|
+
};
|
|
44
|
+
}, [ref]);
|
|
45
|
+
};
|
|
46
|
+
useOutsideAlerter(dropdownSelection);
|
|
29
47
|
if (table.paginationAPIField === 'filesInList') {
|
|
30
48
|
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null);
|
|
31
49
|
}
|
|
@@ -37,6 +55,25 @@ const DownloadButton = _ref => {
|
|
|
37
55
|
}
|
|
38
56
|
const client = (0, _client.useApolloClient)();
|
|
39
57
|
async function downloadSCSVFile() {
|
|
58
|
+
const {
|
|
59
|
+
query,
|
|
60
|
+
paginationAPIField
|
|
61
|
+
} = table;
|
|
62
|
+
const result = await client.query({
|
|
63
|
+
query,
|
|
64
|
+
variables: _objectSpread(_objectSpread({}, queryVariables), {}, {
|
|
65
|
+
page: 0,
|
|
66
|
+
first: 10000
|
|
67
|
+
})
|
|
68
|
+
}).then(response => {
|
|
69
|
+
if (paginationAPIField && response && response.data) {
|
|
70
|
+
return response.data[paginationAPIField];
|
|
71
|
+
}
|
|
72
|
+
return response.data;
|
|
73
|
+
});
|
|
74
|
+
(0, _downloadTable.downloadCSV)(result, table, table.downloadFileName);
|
|
75
|
+
}
|
|
76
|
+
async function downloadJsonFile() {
|
|
40
77
|
const {
|
|
41
78
|
query,
|
|
42
79
|
paginationAPIField
|
|
@@ -57,12 +94,79 @@ const DownloadButton = _ref => {
|
|
|
57
94
|
}
|
|
58
95
|
const downloadTableCSV = (0, _react.useCallback)(() => {
|
|
59
96
|
downloadSCSVFile();
|
|
97
|
+
setListDisplay('none');
|
|
60
98
|
}, [queryVariables]);
|
|
61
|
-
|
|
62
|
-
|
|
99
|
+
const downloadTableJson = (0, _react.useCallback)(() => {
|
|
100
|
+
downloadJsonFile();
|
|
101
|
+
setListDisplay('none');
|
|
102
|
+
}, [queryVariables]);
|
|
103
|
+
const handleClickButton = () => {
|
|
104
|
+
if (listDisplay === 'none') {
|
|
105
|
+
setListDisplay('block');
|
|
106
|
+
} else {
|
|
107
|
+
setListDisplay('none');
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
const useStyles = (0, _core.makeStyles)({
|
|
111
|
+
dropdown: {
|
|
112
|
+
width: '60px',
|
|
113
|
+
height: '25px',
|
|
114
|
+
marginTop: '8px',
|
|
115
|
+
paddingLeft: '5px',
|
|
116
|
+
border: '0.75px solid #606060',
|
|
117
|
+
borderRadius: '5px',
|
|
118
|
+
display: 'inline-block',
|
|
119
|
+
position: 'relative'
|
|
120
|
+
},
|
|
121
|
+
dropdownList: {
|
|
122
|
+
display: 'block',
|
|
123
|
+
position: 'absolute',
|
|
124
|
+
width: '60px',
|
|
125
|
+
marginTop: '3px',
|
|
126
|
+
marginLeft: '-5px',
|
|
127
|
+
overflow: 'auto',
|
|
128
|
+
zIndex: '5',
|
|
129
|
+
border: '1.5px solid #41545E',
|
|
130
|
+
borderRadius: '5px',
|
|
131
|
+
background: '#ffffff'
|
|
132
|
+
},
|
|
133
|
+
dropdownListItem: {
|
|
134
|
+
padding: '2px 4px',
|
|
135
|
+
font: 'Poppins',
|
|
136
|
+
fontSize: '14px',
|
|
137
|
+
fontWeight: 400,
|
|
138
|
+
lineHeight: '21px',
|
|
139
|
+
'&:hover': {
|
|
140
|
+
background: '#D7D7D7',
|
|
141
|
+
cursor: 'pointer'
|
|
142
|
+
}
|
|
143
|
+
},
|
|
144
|
+
arrowdownIcon: {
|
|
145
|
+
marginLeft: '5px',
|
|
146
|
+
fill: '#606060'
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
const classes = useStyles();
|
|
150
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
151
|
+
className: classes.dropdown
|
|
152
|
+
}, /*#__PURE__*/_react.default.createElement(_core.Tooltip, {
|
|
153
|
+
title: "Download filtered results"
|
|
63
154
|
}, /*#__PURE__*/_react.default.createElement(_core.IconButton, {
|
|
155
|
+
onClick: handleClickButton
|
|
156
|
+
}, /*#__PURE__*/_react.default.createElement(_icons.CloudDownload, null), /*#__PURE__*/_react.default.createElement(_KeyboardArrowDownOutlined.default, {
|
|
157
|
+
className: classes.arrowdownIcon
|
|
158
|
+
}))), /*#__PURE__*/_react.default.createElement("div", {
|
|
159
|
+
className: classes.dropdownList,
|
|
160
|
+
style: {
|
|
161
|
+
display: listDisplay
|
|
162
|
+
}
|
|
163
|
+
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
164
|
+
className: classes.dropdownListItem,
|
|
64
165
|
onClick: downloadTableCSV
|
|
65
|
-
}, /*#__PURE__*/_react.default.createElement(
|
|
166
|
+
}, "CSV"), /*#__PURE__*/_react.default.createElement("div", {
|
|
167
|
+
className: classes.dropdownListItem,
|
|
168
|
+
onClick: downloadTableJson
|
|
169
|
+
}, "JSON")));
|
|
66
170
|
};
|
|
67
171
|
var _default = DownloadButton;
|
|
68
172
|
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.actionCellTypes = exports.LINK = exports.FORMAT_DATA_CELLS = exports.FORMAT_DATA = exports.FORMAT_BYTES = 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.CHECKBOX = void 0;
|
|
7
7
|
const CHECKBOX = 'CHECKBOX';
|
|
8
8
|
exports.CHECKBOX = CHECKBOX;
|
|
9
9
|
const DELETE = 'DELETE';
|
|
@@ -20,6 +20,10 @@ const FORMAT_DATA = 'FORMAT_DATA';
|
|
|
20
20
|
exports.FORMAT_DATA = FORMAT_DATA;
|
|
21
21
|
const FORMAT_BYTES = 'FORMAT_BYTES';
|
|
22
22
|
exports.FORMAT_BYTES = FORMAT_BYTES;
|
|
23
|
+
const TRANSFORM = 'TRANSFORM';
|
|
24
|
+
exports.TRANSFORM = TRANSFORM;
|
|
25
|
+
const EXPAND = 'EXPAND';
|
|
26
|
+
exports.EXPAND = EXPAND;
|
|
23
27
|
const cellTypes = {
|
|
24
28
|
CUSTOM_ELEM,
|
|
25
29
|
LINK,
|
|
@@ -30,6 +34,11 @@ const cellTypes = {
|
|
|
30
34
|
FORMAT_DATA
|
|
31
35
|
};
|
|
32
36
|
exports.cellTypes = cellTypes;
|
|
37
|
+
const cellStyles = {
|
|
38
|
+
TRANSFORM,
|
|
39
|
+
EXPAND
|
|
40
|
+
};
|
|
41
|
+
exports.cellStyles = cellStyles;
|
|
33
42
|
const actionCellTypes = [CHECKBOX, DELETE];
|
|
34
43
|
exports.actionCellTypes = actionCellTypes;
|
|
35
44
|
const FORMAT_DATA_CELLS = [FORMAT_BYTES];
|
|
@@ -5,10 +5,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.convertToCSV = convertToCSV;
|
|
7
7
|
exports.createFileName = createFileName;
|
|
8
|
+
exports.downloadCSV = downloadCSV;
|
|
8
9
|
exports.downloadJson = downloadJson;
|
|
9
10
|
var _Dataformat = require("./Dataformat");
|
|
10
11
|
var _Types = require("./Types");
|
|
11
|
-
function createFileName(fileName) {
|
|
12
|
+
function createFileName(fileName, type) {
|
|
12
13
|
const date = new Date();
|
|
13
14
|
const yyyy = date.getFullYear();
|
|
14
15
|
let dd = date.getDate();
|
|
@@ -32,7 +33,10 @@ function createFileName(fileName) {
|
|
|
32
33
|
if (seconds < 10) {
|
|
33
34
|
seconds = "0".concat(seconds);
|
|
34
35
|
}
|
|
35
|
-
|
|
36
|
+
if (type === 'csv') {
|
|
37
|
+
return "".concat(fileName, " ").concat(todaysDate, " ").concat(hours, "-").concat(minutes, "-").concat(seconds, '.csv');
|
|
38
|
+
}
|
|
39
|
+
return "".concat(fileName, " ").concat(todaysDate, " ").concat(hours, "-").concat(minutes, "-").concat(seconds, '.json');
|
|
36
40
|
}
|
|
37
41
|
function convertToCSV(jsonse, keysToInclude, header) {
|
|
38
42
|
const objArray = jsonse;
|
|
@@ -66,7 +70,7 @@ function convertToCSV(jsonse, keysToInclude, header) {
|
|
|
66
70
|
});
|
|
67
71
|
return str;
|
|
68
72
|
}
|
|
69
|
-
function
|
|
73
|
+
function downloadCSV(tableData, table, downloadFileName) {
|
|
70
74
|
const {
|
|
71
75
|
columns = []
|
|
72
76
|
} = table;
|
|
@@ -109,7 +113,31 @@ function downloadJson(tableData, table, downloadFileName) {
|
|
|
109
113
|
let tempLink = '';
|
|
110
114
|
tempLink = document.createElement('a');
|
|
111
115
|
tempLink.setAttribute('href', JsonURL);
|
|
112
|
-
tempLink.setAttribute('download', createFileName(downloadFileName || ''));
|
|
116
|
+
tempLink.setAttribute('download', createFileName(downloadFileName || '', 'csv'));
|
|
117
|
+
document.body.appendChild(tempLink);
|
|
118
|
+
tempLink.click();
|
|
119
|
+
document.body.removeChild(tempLink);
|
|
120
|
+
}
|
|
121
|
+
function downloadJson(tableData, table, downloadFileName) {
|
|
122
|
+
const {
|
|
123
|
+
columns = []
|
|
124
|
+
} = table;
|
|
125
|
+
const filterColumns = columns.filter(_ref6 => {
|
|
126
|
+
let {
|
|
127
|
+
cellType
|
|
128
|
+
} = _ref6;
|
|
129
|
+
return !_Types.actionCellTypes.includes(cellType);
|
|
130
|
+
});
|
|
131
|
+
const formatDataVal = (0, _Dataformat.formatColumnValues)(filterColumns, tableData);
|
|
132
|
+
const jsonse = JSON.stringify(formatDataVal);
|
|
133
|
+
const exportData = new Blob([jsonse], {
|
|
134
|
+
type: 'application/json'
|
|
135
|
+
});
|
|
136
|
+
const JsonURL = window.URL.createObjectURL(exportData);
|
|
137
|
+
let tempLink = '';
|
|
138
|
+
tempLink = document.createElement('a');
|
|
139
|
+
tempLink.setAttribute('href', JsonURL);
|
|
140
|
+
tempLink.setAttribute('download', createFileName(downloadFileName || '', 'json'));
|
|
113
141
|
document.body.appendChild(tempLink);
|
|
114
142
|
tempLink.click();
|
|
115
143
|
document.body.removeChild(tempLink);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bento-core/table",
|
|
3
|
-
"version": "1.0.1-ccdihub.
|
|
3
|
+
"version": "1.0.1-ccdihub.56",
|
|
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",
|
package/src/index.js
CHANGED
|
@@ -1,11 +1,18 @@
|
|
|
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,
|
|
11
|
+
makeStyles,
|
|
6
12
|
} from '@material-ui/core';
|
|
13
|
+
import KeyboardArrowDownOutlinedIcon from '@material-ui/icons/KeyboardArrowDownOutlined';
|
|
7
14
|
import { CloudDownload } from '@material-ui/icons';
|
|
8
|
-
import { downloadJson } from '../util/downloadTable';
|
|
15
|
+
import { downloadCSV, downloadJson } from '../util/downloadTable';
|
|
9
16
|
|
|
10
17
|
const downloadButtonStyle = {
|
|
11
18
|
color: '#d1d2d3',
|
|
@@ -17,6 +24,23 @@ const DownloadButton = ({
|
|
|
17
24
|
queryVariables,
|
|
18
25
|
table,
|
|
19
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('class').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
|
+
|
|
20
44
|
if (table.paginationAPIField === 'filesInList') {
|
|
21
45
|
return <></>;
|
|
22
46
|
}
|
|
@@ -32,6 +56,29 @@ const DownloadButton = ({
|
|
|
32
56
|
paginationAPIField,
|
|
33
57
|
} = table;
|
|
34
58
|
|
|
59
|
+
const result = await client.query({
|
|
60
|
+
query,
|
|
61
|
+
variables: {
|
|
62
|
+
...queryVariables,
|
|
63
|
+
page: 0,
|
|
64
|
+
first: 10000,
|
|
65
|
+
},
|
|
66
|
+
})
|
|
67
|
+
.then((response) => {
|
|
68
|
+
if (paginationAPIField && response && response.data) {
|
|
69
|
+
return response.data[paginationAPIField];
|
|
70
|
+
}
|
|
71
|
+
return response.data;
|
|
72
|
+
});
|
|
73
|
+
downloadCSV(result, table, table.downloadFileName);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
async function downloadJsonFile() {
|
|
77
|
+
const {
|
|
78
|
+
query,
|
|
79
|
+
paginationAPIField,
|
|
80
|
+
} = table;
|
|
81
|
+
|
|
35
82
|
const result = await client.query({
|
|
36
83
|
query,
|
|
37
84
|
variables: {
|
|
@@ -51,16 +98,79 @@ const DownloadButton = ({
|
|
|
51
98
|
|
|
52
99
|
const downloadTableCSV = useCallback(() => {
|
|
53
100
|
downloadSCSVFile();
|
|
101
|
+
setListDisplay('none');
|
|
102
|
+
}, [queryVariables]);
|
|
103
|
+
|
|
104
|
+
const downloadTableJson = useCallback(() => {
|
|
105
|
+
downloadJsonFile();
|
|
106
|
+
setListDisplay('none');
|
|
54
107
|
}, [queryVariables]);
|
|
55
108
|
|
|
109
|
+
const handleClickButton = () => {
|
|
110
|
+
if (listDisplay === 'none') {
|
|
111
|
+
setListDisplay('block');
|
|
112
|
+
} else {
|
|
113
|
+
setListDisplay('none');
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
const useStyles = makeStyles({
|
|
118
|
+
dropdown: {
|
|
119
|
+
width: '60px',
|
|
120
|
+
height: '25px',
|
|
121
|
+
marginTop: '8px',
|
|
122
|
+
paddingLeft: '5px',
|
|
123
|
+
border: '0.75px solid #606060',
|
|
124
|
+
borderRadius: '5px',
|
|
125
|
+
display: 'inline-block',
|
|
126
|
+
position: 'relative',
|
|
127
|
+
},
|
|
128
|
+
dropdownList: {
|
|
129
|
+
display: 'block',
|
|
130
|
+
position: 'absolute',
|
|
131
|
+
width: '60px',
|
|
132
|
+
marginTop: '3px',
|
|
133
|
+
marginLeft: '-5px',
|
|
134
|
+
overflow: 'auto',
|
|
135
|
+
zIndex: '5',
|
|
136
|
+
border: '1.5px solid #41545E',
|
|
137
|
+
borderRadius: '5px',
|
|
138
|
+
background: '#ffffff',
|
|
139
|
+
},
|
|
140
|
+
dropdownListItem: {
|
|
141
|
+
padding: '2px 4px',
|
|
142
|
+
font: 'Poppins',
|
|
143
|
+
fontSize: '14px',
|
|
144
|
+
fontWeight: 400,
|
|
145
|
+
lineHeight: '21px',
|
|
146
|
+
'&:hover': {
|
|
147
|
+
background: '#D7D7D7',
|
|
148
|
+
cursor: 'pointer',
|
|
149
|
+
},
|
|
150
|
+
},
|
|
151
|
+
arrowdownIcon: {
|
|
152
|
+
marginLeft: '5px',
|
|
153
|
+
fill: '#606060',
|
|
154
|
+
},
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
const classes = useStyles();
|
|
158
|
+
|
|
56
159
|
return (
|
|
57
|
-
<
|
|
58
|
-
<
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
160
|
+
<div className={classes.dropdown}>
|
|
161
|
+
<Tooltip title="Download filtered results">
|
|
162
|
+
<IconButton
|
|
163
|
+
onClick={handleClickButton}
|
|
164
|
+
>
|
|
165
|
+
<CloudDownload />
|
|
166
|
+
<KeyboardArrowDownOutlinedIcon className={classes.arrowdownIcon} />
|
|
167
|
+
</IconButton>
|
|
168
|
+
</Tooltip>
|
|
169
|
+
<div className={classes.dropdownList} style={{ display: listDisplay }}>
|
|
170
|
+
<div className={classes.dropdownListItem} onClick={downloadTableCSV}>CSV</div>
|
|
171
|
+
<div className={classes.dropdownListItem} onClick={downloadTableJson}>JSON</div>
|
|
172
|
+
</div>
|
|
173
|
+
</div>
|
|
64
174
|
);
|
|
65
175
|
};
|
|
66
176
|
|
package/src/util/Types.js
CHANGED
|
@@ -6,6 +6,8 @@ export const DISPLAY = 'DISPLAY';
|
|
|
6
6
|
export const DEFAULT = 'DEFAULT';
|
|
7
7
|
export const FORMAT_DATA = 'FORMAT_DATA';
|
|
8
8
|
export const FORMAT_BYTES = 'FORMAT_BYTES';
|
|
9
|
+
export const TRANSFORM = 'TRANSFORM';
|
|
10
|
+
export const EXPAND = 'EXPAND';
|
|
9
11
|
|
|
10
12
|
export const cellTypes = {
|
|
11
13
|
CUSTOM_ELEM,
|
|
@@ -17,6 +19,11 @@ export const cellTypes = {
|
|
|
17
19
|
FORMAT_DATA,
|
|
18
20
|
};
|
|
19
21
|
|
|
22
|
+
export const cellStyles = {
|
|
23
|
+
TRANSFORM,
|
|
24
|
+
EXPAND,
|
|
25
|
+
};
|
|
26
|
+
|
|
20
27
|
export const actionCellTypes = [CHECKBOX, DELETE];
|
|
21
28
|
|
|
22
29
|
export const FORMAT_DATA_CELLS = [FORMAT_BYTES];
|
|
@@ -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, type) {
|
|
5
5
|
const date = new Date();
|
|
6
6
|
const yyyy = date.getFullYear();
|
|
7
7
|
let dd = date.getDate();
|
|
@@ -23,7 +23,10 @@ export function createFileName(fileName) {
|
|
|
23
23
|
|
|
24
24
|
if (seconds < 10) { seconds = `0${seconds}`; }
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
if (type === 'csv') {
|
|
27
|
+
return `${fileName} ${todaysDate} ${hours}-${minutes}-${seconds}${'.csv'}`;
|
|
28
|
+
}
|
|
29
|
+
return `${fileName} ${todaysDate} ${hours}-${minutes}-${seconds}${'.json'}`;
|
|
27
30
|
}
|
|
28
31
|
|
|
29
32
|
export function convertToCSV(jsonse, keysToInclude, header) {
|
|
@@ -59,7 +62,7 @@ export function convertToCSV(jsonse, keysToInclude, header) {
|
|
|
59
62
|
return str;
|
|
60
63
|
}
|
|
61
64
|
|
|
62
|
-
export function
|
|
65
|
+
export function downloadCSV(tableData, table, downloadFileName) {
|
|
63
66
|
const { columns = [] } = table;
|
|
64
67
|
const filterColumns = columns.filter(({ cellType }) => !actionCellTypes.includes(cellType));
|
|
65
68
|
const formatDataVal = formatColumnValues(filterColumns, tableData);
|
|
@@ -74,7 +77,23 @@ export function downloadJson(tableData, table, downloadFileName) {
|
|
|
74
77
|
let tempLink = '';
|
|
75
78
|
tempLink = document.createElement('a');
|
|
76
79
|
tempLink.setAttribute('href', JsonURL);
|
|
77
|
-
tempLink.setAttribute('download', createFileName(downloadFileName || ''));
|
|
80
|
+
tempLink.setAttribute('download', createFileName(downloadFileName || '', 'csv'));
|
|
81
|
+
document.body.appendChild(tempLink);
|
|
82
|
+
tempLink.click();
|
|
83
|
+
document.body.removeChild(tempLink);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export function downloadJson(tableData, table, downloadFileName) {
|
|
87
|
+
const { columns = [] } = table;
|
|
88
|
+
const filterColumns = columns.filter(({ cellType }) => !actionCellTypes.includes(cellType));
|
|
89
|
+
const formatDataVal = formatColumnValues(filterColumns, tableData);
|
|
90
|
+
const jsonse = JSON.stringify(formatDataVal);
|
|
91
|
+
const exportData = new Blob([jsonse], { type: 'application/json' });
|
|
92
|
+
const JsonURL = window.URL.createObjectURL(exportData);
|
|
93
|
+
let tempLink = '';
|
|
94
|
+
tempLink = document.createElement('a');
|
|
95
|
+
tempLink.setAttribute('href', JsonURL);
|
|
96
|
+
tempLink.setAttribute('download', createFileName(downloadFileName || '', 'json'));
|
|
78
97
|
document.body.appendChild(tempLink);
|
|
79
98
|
tempLink.click();
|
|
80
99
|
document.body.removeChild(tempLink);
|