@bento-core/table 1.0.1-ccdihub.3 → 1.0.1-ccdihub.30
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 +5 -2
- package/dist/TableView.js +4 -2
- package/dist/header/CustomCell.js +7 -1
- package/dist/header/components/CheckBoxView.js +16 -8
- package/dist/pagination/CustomPagination.js +25 -3
- package/dist/pagination/components/DownloadButton.js +66 -0
- package/dist/util/Dataformat.js +41 -1
- package/dist/util/downloadTable.js +109 -0
- package/package.json +4 -1
- package/src/ExtendedView.js +3 -0
- package/src/TableView.js +2 -0
- package/src/header/CustomCell.js +11 -0
- package/src/header/components/CheckBoxView.js +9 -10
- package/src/pagination/CustomPagination.js +30 -9
- package/src/pagination/components/DownloadButton.js +68 -0
- package/src/util/Dataformat.js +25 -0
- package/src/util/downloadTable.js +74 -0
package/dist/ExtendedView.js
CHANGED
|
@@ -23,7 +23,8 @@ const ExtendedView = _ref => {
|
|
|
23
23
|
onRowsPerPageChange,
|
|
24
24
|
onPageChange,
|
|
25
25
|
numSelected = 0,
|
|
26
|
-
customTheme
|
|
26
|
+
customTheme,
|
|
27
|
+
queryVariables
|
|
27
28
|
} = _ref;
|
|
28
29
|
const {
|
|
29
30
|
extendedViewConfig
|
|
@@ -57,7 +58,9 @@ const ExtendedView = _ref => {
|
|
|
57
58
|
rowsPerPage: table.rowsPerPage || 10,
|
|
58
59
|
page: table.page || 0,
|
|
59
60
|
onPageChange: onPageChange,
|
|
60
|
-
onRowsPerPageChange: onRowsPerPageChange
|
|
61
|
+
onRowsPerPageChange: onRowsPerPageChange,
|
|
62
|
+
queryVariables: queryVariables,
|
|
63
|
+
table: table
|
|
61
64
|
}));
|
|
62
65
|
};
|
|
63
66
|
var _default = ExtendedView;
|
package/dist/TableView.js
CHANGED
|
@@ -44,7 +44,8 @@ const TableView = _ref => {
|
|
|
44
44
|
totalRowCount,
|
|
45
45
|
onSortByColumn,
|
|
46
46
|
onColumnViewChange,
|
|
47
|
-
themeConfig = {}
|
|
47
|
+
themeConfig = {},
|
|
48
|
+
queryVariables
|
|
48
49
|
} = _ref;
|
|
49
50
|
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_ExtendedView.default, {
|
|
50
51
|
table: table,
|
|
@@ -52,7 +53,8 @@ const TableView = _ref => {
|
|
|
52
53
|
onRowsPerPageChange: onRowsPerPageChange,
|
|
53
54
|
onPageChange: onPageChange,
|
|
54
55
|
numSelected: (table === null || table === void 0 ? void 0 : (_table$selectedRows = table.selectedRows) === null || _table$selectedRows === void 0 ? void 0 : _table$selectedRows.length) || 0,
|
|
55
|
-
customTheme: themeConfig.extendedView
|
|
56
|
+
customTheme: themeConfig.extendedView,
|
|
57
|
+
queryVariables: queryVariables
|
|
56
58
|
}), /*#__PURE__*/_react.default.createElement(_CustomToolbar.default, {
|
|
57
59
|
numSelected: (table === null || table === void 0 ? void 0 : (_table$selectedRows2 = table.selectedRows) === null || _table$selectedRows2 === void 0 ? void 0 : _table$selectedRows2.length) || 0,
|
|
58
60
|
table: table,
|
|
@@ -29,7 +29,8 @@ const CustomHeaderCell = _ref => {
|
|
|
29
29
|
tooltipText,
|
|
30
30
|
header,
|
|
31
31
|
headerType,
|
|
32
|
-
customColHeaderRender
|
|
32
|
+
customColHeaderRender,
|
|
33
|
+
sortable
|
|
33
34
|
} = column;
|
|
34
35
|
const Tooltip = (0, _react.useCallback)(_ref2 => {
|
|
35
36
|
let {
|
|
@@ -50,6 +51,11 @@ const CustomHeaderCell = _ref => {
|
|
|
50
51
|
// return default view
|
|
51
52
|
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, children);
|
|
52
53
|
}, []);
|
|
54
|
+
if (sortable !== undefined && !sortable) {
|
|
55
|
+
return /*#__PURE__*/_react.default.createElement(_TableCell.default, {
|
|
56
|
+
scope: "col"
|
|
57
|
+
}, header);
|
|
58
|
+
}
|
|
53
59
|
return /*#__PURE__*/_react.default.createElement(_TableCell.default, {
|
|
54
60
|
scope: "col",
|
|
55
61
|
active: sortBy === dataField,
|
|
@@ -7,6 +7,12 @@ exports.default = void 0;
|
|
|
7
7
|
var _react = _interopRequireDefault(require("react"));
|
|
8
8
|
var _core = require("@material-ui/core");
|
|
9
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
|
+
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
11
|
+
const label = {
|
|
12
|
+
inputProps: {
|
|
13
|
+
'aria-label': 'Select all checkbox'
|
|
14
|
+
}
|
|
15
|
+
};
|
|
10
16
|
const CheckboxView = _ref => {
|
|
11
17
|
let {
|
|
12
18
|
includeSelectedIds,
|
|
@@ -15,14 +21,16 @@ const CheckboxView = _ref => {
|
|
|
15
21
|
} = _ref;
|
|
16
22
|
return /*#__PURE__*/_react.default.createElement(_core.TableCell, {
|
|
17
23
|
padding: "checkbox"
|
|
18
|
-
}, /*#__PURE__*/_react.default.createElement(
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
}, /*#__PURE__*/_react.default.createElement("span", {
|
|
25
|
+
style: {
|
|
26
|
+
display: 'none'
|
|
27
|
+
}
|
|
28
|
+
}, "Select all"), /*#__PURE__*/_react.default.createElement(_core.Checkbox, _extends({}, label, {
|
|
29
|
+
color: "primary",
|
|
30
|
+
indeterminate: includeSelectedIds,
|
|
31
|
+
checked: includeSelectedIds,
|
|
32
|
+
onChange: event => toggleSelectAll(event, Ids, includeSelectedIds)
|
|
33
|
+
})));
|
|
26
34
|
};
|
|
27
35
|
var _default = CheckboxView;
|
|
28
36
|
exports.default = _default;
|
|
@@ -7,6 +7,7 @@ exports.default = void 0;
|
|
|
7
7
|
var _react = _interopRequireDefault(require("react"));
|
|
8
8
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
9
9
|
var _core = require("@material-ui/core");
|
|
10
|
+
var _DownloadButton = _interopRequireDefault(require("./components/DownloadButton"));
|
|
10
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
12
|
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; }
|
|
12
13
|
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; }
|
|
@@ -38,6 +39,12 @@ const defaultTheme = {
|
|
|
38
39
|
}
|
|
39
40
|
}
|
|
40
41
|
};
|
|
42
|
+
const downloadAreaStyle = {
|
|
43
|
+
display: 'flex',
|
|
44
|
+
borderTop: '1px solid #8A7F7C',
|
|
45
|
+
borderBottom: '1px solid #8A7F7C',
|
|
46
|
+
paddingRight: '41px'
|
|
47
|
+
};
|
|
41
48
|
const CustomPagination = _ref => {
|
|
42
49
|
let {
|
|
43
50
|
rowsPerPageOptions,
|
|
@@ -46,12 +53,17 @@ const CustomPagination = _ref => {
|
|
|
46
53
|
page,
|
|
47
54
|
onPageChange,
|
|
48
55
|
onRowsPerPageChange,
|
|
49
|
-
customTheme = {}
|
|
56
|
+
customTheme = {},
|
|
57
|
+
queryVariables,
|
|
58
|
+
table
|
|
50
59
|
} = _ref;
|
|
51
60
|
return /*#__PURE__*/_react.default.createElement(_core.ThemeProvider, {
|
|
52
61
|
theme: (0, _core.createTheme)({
|
|
53
62
|
overrides: _objectSpread(_objectSpread({}, defaultTheme), customTheme)
|
|
54
63
|
})
|
|
64
|
+
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
65
|
+
className: "downloadArea",
|
|
66
|
+
style: downloadAreaStyle
|
|
55
67
|
}, /*#__PURE__*/_react.default.createElement(_core.TablePagination, {
|
|
56
68
|
rowsPerPageOptions: rowsPerPageOptions,
|
|
57
69
|
component: "div",
|
|
@@ -59,8 +71,18 @@ const CustomPagination = _ref => {
|
|
|
59
71
|
rowsPerPage: rowsPerPage,
|
|
60
72
|
page: page,
|
|
61
73
|
onPageChange: onPageChange,
|
|
62
|
-
onRowsPerPageChange: onRowsPerPageChange
|
|
63
|
-
|
|
74
|
+
onRowsPerPageChange: onRowsPerPageChange,
|
|
75
|
+
SelectProps: {
|
|
76
|
+
inputProps: {
|
|
77
|
+
'aria-label': 'Selection dropdown for displaying the number of results per page'
|
|
78
|
+
},
|
|
79
|
+
native: true
|
|
80
|
+
}
|
|
81
|
+
}), /*#__PURE__*/_react.default.createElement(_DownloadButton.default, {
|
|
82
|
+
count: count,
|
|
83
|
+
queryVariables: queryVariables,
|
|
84
|
+
table: table
|
|
85
|
+
})));
|
|
64
86
|
};
|
|
65
87
|
CustomPagination.propTypes = {
|
|
66
88
|
rowsPerPageOptions: _propTypes.default.arrayOf(_propTypes.default.number).isRequired,
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
8
|
+
var _client = require("@apollo/client");
|
|
9
|
+
var _core = require("@material-ui/core");
|
|
10
|
+
var _icons = require("@material-ui/icons");
|
|
11
|
+
var _downloadTable = require("../../util/downloadTable");
|
|
12
|
+
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
|
+
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
|
+
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; }
|
|
15
|
+
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; }
|
|
16
|
+
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
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
18
|
+
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
|
+
color: '#d1d2d3',
|
|
21
|
+
marginTop: '7px'
|
|
22
|
+
};
|
|
23
|
+
const DownloadButton = _ref => {
|
|
24
|
+
let {
|
|
25
|
+
count,
|
|
26
|
+
queryVariables,
|
|
27
|
+
table
|
|
28
|
+
} = _ref;
|
|
29
|
+
if (count === 0) {
|
|
30
|
+
return /*#__PURE__*/_react.default.createElement(_icons.CloudDownload, {
|
|
31
|
+
style: downloadButtonStyle
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
const client = (0, _client.useApolloClient)();
|
|
35
|
+
const downloadFile = 'CCDI Inventory';
|
|
36
|
+
async function downloadSCSVFile() {
|
|
37
|
+
const {
|
|
38
|
+
query,
|
|
39
|
+
paginationAPIField
|
|
40
|
+
} = table;
|
|
41
|
+
const downloadFileName = downloadFile.concat(paginationAPIField.replace('Overview', ''), ' download');
|
|
42
|
+
const result = await client.query({
|
|
43
|
+
query,
|
|
44
|
+
variables: _objectSpread(_objectSpread({}, queryVariables), {}, {
|
|
45
|
+
page: 0,
|
|
46
|
+
first: 25000
|
|
47
|
+
})
|
|
48
|
+
}).then(response => {
|
|
49
|
+
if (paginationAPIField && response && response.data) {
|
|
50
|
+
return response.data[paginationAPIField];
|
|
51
|
+
}
|
|
52
|
+
return response.data;
|
|
53
|
+
});
|
|
54
|
+
(0, _downloadTable.downloadJson)(result, table, downloadFileName);
|
|
55
|
+
}
|
|
56
|
+
const downloadTableCSV = (0, _react.useCallback)(() => {
|
|
57
|
+
downloadSCSVFile();
|
|
58
|
+
}, [queryVariables]);
|
|
59
|
+
return /*#__PURE__*/_react.default.createElement(_core.Tooltip, {
|
|
60
|
+
title: "Download filtered results as a CSV"
|
|
61
|
+
}, /*#__PURE__*/_react.default.createElement(_core.IconButton, {
|
|
62
|
+
onClick: downloadTableCSV
|
|
63
|
+
}, /*#__PURE__*/_react.default.createElement(_icons.CloudDownload, null)));
|
|
64
|
+
};
|
|
65
|
+
var _default = DownloadButton;
|
|
66
|
+
exports.default = _default;
|
package/dist/util/Dataformat.js
CHANGED
|
@@ -4,6 +4,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.formatBytes = formatBytes;
|
|
7
|
+
exports.formatColumnValues = void 0;
|
|
8
|
+
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; }
|
|
9
|
+
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; }
|
|
10
|
+
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; }
|
|
11
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
12
|
+
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); }
|
|
7
13
|
/* eslint-disable import/prefer-default-export */
|
|
8
14
|
function formatBytes(bytes) {
|
|
9
15
|
let decimals = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 2;
|
|
@@ -12,4 +18,38 @@ function formatBytes(bytes) {
|
|
|
12
18
|
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
|
|
13
19
|
const i = Math.floor(Math.log(bytes) / Math.log(1024));
|
|
14
20
|
return "".concat(parseFloat((bytes / 1024 ** i).toFixed(dm)), " ").concat(sizes[i]);
|
|
15
|
-
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* convert zero (0) value to custom val
|
|
25
|
+
* @param {*} columns
|
|
26
|
+
* @param {*} data
|
|
27
|
+
* @returns
|
|
28
|
+
*/
|
|
29
|
+
const formatColumnValues = (columns, data) => {
|
|
30
|
+
const formatColumns = columns.filter(_ref => {
|
|
31
|
+
let {
|
|
32
|
+
columnDefaultValues
|
|
33
|
+
} = _ref;
|
|
34
|
+
return columnDefaultValues;
|
|
35
|
+
});
|
|
36
|
+
if (formatColumns.length > 0) {
|
|
37
|
+
const formatCoumnData = [...data].reduce((acc, item) => {
|
|
38
|
+
const updateRow = _objectSpread({}, item);
|
|
39
|
+
formatColumns.forEach(col => {
|
|
40
|
+
const {
|
|
41
|
+
columnDefaultValues,
|
|
42
|
+
dataField
|
|
43
|
+
} = col;
|
|
44
|
+
if (columnDefaultValues[item[dataField]]) {
|
|
45
|
+
updateRow[dataField] = columnDefaultValues[item[dataField]];
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
acc.push(updateRow);
|
|
49
|
+
return acc;
|
|
50
|
+
}, []);
|
|
51
|
+
return formatCoumnData;
|
|
52
|
+
}
|
|
53
|
+
return data;
|
|
54
|
+
};
|
|
55
|
+
exports.formatColumnValues = formatColumnValues;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.convertToCSV = convertToCSV;
|
|
7
|
+
exports.createFileName = createFileName;
|
|
8
|
+
exports.downloadJson = downloadJson;
|
|
9
|
+
var _Dataformat = require("./Dataformat");
|
|
10
|
+
var _Types = require("./Types");
|
|
11
|
+
function createFileName(fileName) {
|
|
12
|
+
const date = new Date();
|
|
13
|
+
const yyyy = date.getFullYear();
|
|
14
|
+
let dd = date.getDate();
|
|
15
|
+
let mm = date.getMonth() + 1;
|
|
16
|
+
if (dd < 10) {
|
|
17
|
+
dd = "0".concat(dd);
|
|
18
|
+
}
|
|
19
|
+
if (mm < 10) {
|
|
20
|
+
mm = "0".concat(mm);
|
|
21
|
+
}
|
|
22
|
+
const todaysDate = "".concat(yyyy, "-").concat(mm, "-").concat(dd);
|
|
23
|
+
let hours = date.getHours();
|
|
24
|
+
let minutes = date.getMinutes();
|
|
25
|
+
let seconds = date.getSeconds();
|
|
26
|
+
if (hours < 10) {
|
|
27
|
+
hours = "0".concat(hours);
|
|
28
|
+
}
|
|
29
|
+
if (minutes < 10) {
|
|
30
|
+
minutes = "0".concat(minutes);
|
|
31
|
+
}
|
|
32
|
+
if (seconds < 10) {
|
|
33
|
+
seconds = "0".concat(seconds);
|
|
34
|
+
}
|
|
35
|
+
return "".concat(fileName, " ").concat(todaysDate, " ").concat(hours, "-").concat(minutes, "-").concat(seconds, '.csv');
|
|
36
|
+
}
|
|
37
|
+
function convertToCSV(jsonse, keysToInclude, header) {
|
|
38
|
+
const objArray = jsonse;
|
|
39
|
+
// To Do empty object just print headers
|
|
40
|
+
const array = typeof objArray !== 'object' ? JSON.parse(objArray) : objArray;
|
|
41
|
+
let str = header.join(',');
|
|
42
|
+
array.map((entry, index) => {
|
|
43
|
+
let line = '';
|
|
44
|
+
keysToInclude.map(keyName => {
|
|
45
|
+
if (line !== '') line += ',';
|
|
46
|
+
if (keyName === 'file_size') {
|
|
47
|
+
line += entry[keyName] !== null ? "\"".concat((0, _Dataformat.formatBytes)(entry[keyName]), "\"") : ' ';
|
|
48
|
+
} else {
|
|
49
|
+
line += entry[keyName] !== null ? "\"".concat(entry[keyName], "\"") : ' ';
|
|
50
|
+
}
|
|
51
|
+
return line;
|
|
52
|
+
});
|
|
53
|
+
if (index === 0) {
|
|
54
|
+
// str = header.join(',');
|
|
55
|
+
str += "\r\n".concat(line, "\r\n");
|
|
56
|
+
} else {
|
|
57
|
+
str += "".concat(line, "\r\n");
|
|
58
|
+
}
|
|
59
|
+
return str;
|
|
60
|
+
});
|
|
61
|
+
return str;
|
|
62
|
+
}
|
|
63
|
+
function downloadJson(tableData, table, downloadFileName) {
|
|
64
|
+
const {
|
|
65
|
+
columns = []
|
|
66
|
+
} = table;
|
|
67
|
+
const filterColumns = columns.filter(_ref => {
|
|
68
|
+
let {
|
|
69
|
+
cellType
|
|
70
|
+
} = _ref;
|
|
71
|
+
return !_Types.actionCellTypes.includes(cellType);
|
|
72
|
+
});
|
|
73
|
+
const formatDataVal = (0, _Dataformat.formatColumnValues)(filterColumns, tableData);
|
|
74
|
+
const jsonse = JSON.stringify(formatDataVal);
|
|
75
|
+
const keysToInclude = columns.filter(_ref2 => {
|
|
76
|
+
let {
|
|
77
|
+
dataField
|
|
78
|
+
} = _ref2;
|
|
79
|
+
return dataField;
|
|
80
|
+
}).map(_ref3 => {
|
|
81
|
+
let {
|
|
82
|
+
dataField
|
|
83
|
+
} = _ref3;
|
|
84
|
+
return dataField;
|
|
85
|
+
});
|
|
86
|
+
const headers = columns.filter(_ref4 => {
|
|
87
|
+
let {
|
|
88
|
+
dataField
|
|
89
|
+
} = _ref4;
|
|
90
|
+
return dataField;
|
|
91
|
+
}).map(_ref5 => {
|
|
92
|
+
let {
|
|
93
|
+
header
|
|
94
|
+
} = _ref5;
|
|
95
|
+
return header;
|
|
96
|
+
});
|
|
97
|
+
const csv = convertToCSV(jsonse, keysToInclude, headers);
|
|
98
|
+
const exportData = new Blob([csv], {
|
|
99
|
+
type: 'text/csv'
|
|
100
|
+
});
|
|
101
|
+
const JsonURL = window.URL.createObjectURL(exportData);
|
|
102
|
+
let tempLink = '';
|
|
103
|
+
tempLink = document.createElement('a');
|
|
104
|
+
tempLink.setAttribute('href', JsonURL);
|
|
105
|
+
tempLink.setAttribute('download', createFileName(downloadFileName || ''));
|
|
106
|
+
document.body.appendChild(tempLink);
|
|
107
|
+
tempLink.click();
|
|
108
|
+
document.body.removeChild(tempLink);
|
|
109
|
+
}
|
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.30",
|
|
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",
|
|
@@ -28,5 +28,8 @@
|
|
|
28
28
|
"url": "https://github.com/CBIIT/bento-frontend/issues"
|
|
29
29
|
},
|
|
30
30
|
"homepage": "https://github.com/CBIIT/bento-frontend#readme",
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@apollo/client": "^3.8.3"
|
|
33
|
+
},
|
|
31
34
|
"description": ""
|
|
32
35
|
}
|
package/src/ExtendedView.js
CHANGED
|
@@ -16,6 +16,7 @@ const ExtendedView = ({
|
|
|
16
16
|
onPageChange,
|
|
17
17
|
numSelected = 0,
|
|
18
18
|
customTheme,
|
|
19
|
+
queryVariables,
|
|
19
20
|
}) => {
|
|
20
21
|
const { extendedViewConfig } = table;
|
|
21
22
|
if (!extendedViewConfig) {
|
|
@@ -53,6 +54,8 @@ const ExtendedView = ({
|
|
|
53
54
|
page={table.page || 0}
|
|
54
55
|
onPageChange={onPageChange}
|
|
55
56
|
onRowsPerPageChange={onRowsPerPageChange}
|
|
57
|
+
queryVariables={queryVariables}
|
|
58
|
+
table={table}
|
|
56
59
|
/>
|
|
57
60
|
)
|
|
58
61
|
}
|
package/src/TableView.js
CHANGED
|
@@ -36,6 +36,7 @@ const TableView = ({
|
|
|
36
36
|
onSortByColumn,
|
|
37
37
|
onColumnViewChange,
|
|
38
38
|
themeConfig = {},
|
|
39
|
+
queryVariables,
|
|
39
40
|
}) => (
|
|
40
41
|
<>
|
|
41
42
|
<ExtendedView
|
|
@@ -45,6 +46,7 @@ const TableView = ({
|
|
|
45
46
|
onPageChange={onPageChange}
|
|
46
47
|
numSelected={table?.selectedRows?.length || 0}
|
|
47
48
|
customTheme={themeConfig.extendedView}
|
|
49
|
+
queryVariables={queryVariables}
|
|
48
50
|
/>
|
|
49
51
|
<CustomToolbar
|
|
50
52
|
numSelected={table?.selectedRows?.length || 0}
|
package/src/header/CustomCell.js
CHANGED
|
@@ -21,6 +21,7 @@ const CustomHeaderCell = ({
|
|
|
21
21
|
header,
|
|
22
22
|
headerType,
|
|
23
23
|
customColHeaderRender,
|
|
24
|
+
sortable,
|
|
24
25
|
} = column;
|
|
25
26
|
|
|
26
27
|
const Tooltip = useCallback(({ children }) => {
|
|
@@ -45,6 +46,16 @@ const CustomHeaderCell = ({
|
|
|
45
46
|
return <>{children}</>;
|
|
46
47
|
}, []);
|
|
47
48
|
|
|
49
|
+
if (sortable !== undefined && !sortable) {
|
|
50
|
+
return (
|
|
51
|
+
<TableCell
|
|
52
|
+
scope="col"
|
|
53
|
+
>
|
|
54
|
+
{header}
|
|
55
|
+
</TableCell>
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
|
|
48
59
|
return (
|
|
49
60
|
<TableCell
|
|
50
61
|
scope="col"
|
|
@@ -2,24 +2,23 @@ import React from 'react';
|
|
|
2
2
|
import {
|
|
3
3
|
TableCell,
|
|
4
4
|
Checkbox,
|
|
5
|
-
FormControlLabel,
|
|
6
5
|
} from '@material-ui/core';
|
|
7
6
|
|
|
7
|
+
const label = { inputProps: { 'aria-label': 'Select all checkbox' } };
|
|
8
|
+
|
|
8
9
|
const CheckboxView = ({
|
|
9
10
|
includeSelectedIds,
|
|
10
11
|
toggleSelectAll,
|
|
11
12
|
Ids,
|
|
12
13
|
}) => (
|
|
13
14
|
<TableCell padding="checkbox">
|
|
14
|
-
<
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
/>
|
|
22
|
-
)}
|
|
15
|
+
<span style={{ display: 'none' }}>Select all</span>
|
|
16
|
+
<Checkbox
|
|
17
|
+
{...label}
|
|
18
|
+
color="primary"
|
|
19
|
+
indeterminate={includeSelectedIds}
|
|
20
|
+
checked={includeSelectedIds}
|
|
21
|
+
onChange={(event) => toggleSelectAll(event, Ids, includeSelectedIds)}
|
|
23
22
|
/>
|
|
24
23
|
</TableCell>
|
|
25
24
|
);
|
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
TablePagination,
|
|
6
6
|
ThemeProvider,
|
|
7
7
|
} from '@material-ui/core';
|
|
8
|
+
import DownloadButton from './components/DownloadButton';
|
|
8
9
|
|
|
9
10
|
const defaultTheme = {
|
|
10
11
|
MuiTablePagination: {
|
|
@@ -32,6 +33,13 @@ const defaultTheme = {
|
|
|
32
33
|
},
|
|
33
34
|
};
|
|
34
35
|
|
|
36
|
+
const downloadAreaStyle = {
|
|
37
|
+
display: 'flex',
|
|
38
|
+
borderTop: '1px solid #8A7F7C',
|
|
39
|
+
borderBottom: '1px solid #8A7F7C',
|
|
40
|
+
paddingRight: '41px',
|
|
41
|
+
};
|
|
42
|
+
|
|
35
43
|
const CustomPagination = ({
|
|
36
44
|
rowsPerPageOptions,
|
|
37
45
|
count,
|
|
@@ -40,17 +48,30 @@ const CustomPagination = ({
|
|
|
40
48
|
onPageChange,
|
|
41
49
|
onRowsPerPageChange,
|
|
42
50
|
customTheme = {},
|
|
51
|
+
queryVariables,
|
|
52
|
+
table,
|
|
43
53
|
}) => (
|
|
44
54
|
<ThemeProvider theme={createTheme({ overrides: { ...defaultTheme, ...customTheme } })}>
|
|
45
|
-
<
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
55
|
+
<div className="downloadArea" style={downloadAreaStyle}>
|
|
56
|
+
<TablePagination
|
|
57
|
+
rowsPerPageOptions={rowsPerPageOptions}
|
|
58
|
+
component="div"
|
|
59
|
+
count={count}
|
|
60
|
+
rowsPerPage={rowsPerPage}
|
|
61
|
+
page={page}
|
|
62
|
+
onPageChange={onPageChange}
|
|
63
|
+
onRowsPerPageChange={onRowsPerPageChange}
|
|
64
|
+
SelectProps={{
|
|
65
|
+
inputProps: { 'aria-label': 'Selection dropdown for displaying the number of results per page' },
|
|
66
|
+
native: true,
|
|
67
|
+
}}
|
|
68
|
+
/>
|
|
69
|
+
<DownloadButton
|
|
70
|
+
count={count}
|
|
71
|
+
queryVariables={queryVariables}
|
|
72
|
+
table={table}
|
|
73
|
+
/>
|
|
74
|
+
</div>
|
|
54
75
|
</ThemeProvider>
|
|
55
76
|
);
|
|
56
77
|
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import React, { useCallback } from 'react';
|
|
2
|
+
import { useApolloClient } from '@apollo/client';
|
|
3
|
+
import {
|
|
4
|
+
IconButton,
|
|
5
|
+
Tooltip,
|
|
6
|
+
} from '@material-ui/core';
|
|
7
|
+
import { CloudDownload } from '@material-ui/icons';
|
|
8
|
+
import { downloadJson } from '../../util/downloadTable';
|
|
9
|
+
|
|
10
|
+
const downloadButtonStyle = {
|
|
11
|
+
color: '#d1d2d3',
|
|
12
|
+
marginTop: '7px',
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const DownloadButton = ({
|
|
16
|
+
count,
|
|
17
|
+
queryVariables,
|
|
18
|
+
table,
|
|
19
|
+
}) => {
|
|
20
|
+
if (count === 0) {
|
|
21
|
+
return <CloudDownload style={downloadButtonStyle} />;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const client = useApolloClient();
|
|
25
|
+
|
|
26
|
+
const downloadFile = 'CCDI Inventory';
|
|
27
|
+
|
|
28
|
+
async function downloadSCSVFile() {
|
|
29
|
+
const {
|
|
30
|
+
query,
|
|
31
|
+
paginationAPIField,
|
|
32
|
+
} = table;
|
|
33
|
+
|
|
34
|
+
const downloadFileName = downloadFile.concat(paginationAPIField.replace('Overview', ''), ' download');
|
|
35
|
+
|
|
36
|
+
const result = await client.query({
|
|
37
|
+
query,
|
|
38
|
+
variables: {
|
|
39
|
+
...queryVariables,
|
|
40
|
+
page: 0,
|
|
41
|
+
first: 25000,
|
|
42
|
+
},
|
|
43
|
+
})
|
|
44
|
+
.then((response) => {
|
|
45
|
+
if (paginationAPIField && response && response.data) {
|
|
46
|
+
return response.data[paginationAPIField];
|
|
47
|
+
}
|
|
48
|
+
return response.data;
|
|
49
|
+
});
|
|
50
|
+
downloadJson(result, table, downloadFileName);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const downloadTableCSV = useCallback(() => {
|
|
54
|
+
downloadSCSVFile();
|
|
55
|
+
}, [queryVariables]);
|
|
56
|
+
|
|
57
|
+
return (
|
|
58
|
+
<Tooltip title="Download filtered results as a CSV">
|
|
59
|
+
<IconButton
|
|
60
|
+
onClick={downloadTableCSV}
|
|
61
|
+
>
|
|
62
|
+
<CloudDownload />
|
|
63
|
+
</IconButton>
|
|
64
|
+
</Tooltip>
|
|
65
|
+
);
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export default DownloadButton;
|
package/src/util/Dataformat.js
CHANGED
|
@@ -6,3 +6,28 @@ export function formatBytes(bytes, decimals = 2) {
|
|
|
6
6
|
const i = Math.floor(Math.log(bytes) / Math.log(1024));
|
|
7
7
|
return `${parseFloat((bytes / (1024 ** i)).toFixed(dm))} ${sizes[i]}`;
|
|
8
8
|
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* convert zero (0) value to custom val
|
|
12
|
+
* @param {*} columns
|
|
13
|
+
* @param {*} data
|
|
14
|
+
* @returns
|
|
15
|
+
*/
|
|
16
|
+
export const formatColumnValues = (columns, data) => {
|
|
17
|
+
const formatColumns = columns.filter(({ columnDefaultValues }) => columnDefaultValues);
|
|
18
|
+
if (formatColumns.length > 0) {
|
|
19
|
+
const formatCoumnData = [...data].reduce((acc, item) => {
|
|
20
|
+
const updateRow = { ...item };
|
|
21
|
+
formatColumns.forEach((col) => {
|
|
22
|
+
const { columnDefaultValues, dataField } = col;
|
|
23
|
+
if (columnDefaultValues[item[dataField]]) {
|
|
24
|
+
updateRow[dataField] = columnDefaultValues[item[dataField]];
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
acc.push(updateRow);
|
|
28
|
+
return acc;
|
|
29
|
+
}, []);
|
|
30
|
+
return formatCoumnData;
|
|
31
|
+
}
|
|
32
|
+
return data;
|
|
33
|
+
};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { formatBytes, formatColumnValues } from './Dataformat';
|
|
2
|
+
import { actionCellTypes } from './Types';
|
|
3
|
+
|
|
4
|
+
export function createFileName(fileName) {
|
|
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
|
+
return `${fileName} ${todaysDate} ${hours}-${minutes}-${seconds}${'.csv'}`;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function convertToCSV(jsonse, keysToInclude, header) {
|
|
30
|
+
const objArray = jsonse;
|
|
31
|
+
// To Do empty object just print headers
|
|
32
|
+
const array = typeof objArray !== 'object' ? JSON.parse(objArray) : objArray;
|
|
33
|
+
let str = header.join(',');
|
|
34
|
+
array.map((entry, index) => {
|
|
35
|
+
let line = '';
|
|
36
|
+
keysToInclude.map((keyName) => {
|
|
37
|
+
if (line !== '') line += ',';
|
|
38
|
+
if (keyName === 'file_size') {
|
|
39
|
+
line += entry[keyName] !== null ? `"${formatBytes(entry[keyName])}"` : ' ';
|
|
40
|
+
} else {
|
|
41
|
+
line += entry[keyName] !== null ? `"${entry[keyName]}"` : ' ';
|
|
42
|
+
}
|
|
43
|
+
return line;
|
|
44
|
+
});
|
|
45
|
+
if (index === 0) {
|
|
46
|
+
// str = header.join(',');
|
|
47
|
+
str += `\r\n${line}\r\n`;
|
|
48
|
+
} else {
|
|
49
|
+
str += `${line}\r\n`;
|
|
50
|
+
}
|
|
51
|
+
return str;
|
|
52
|
+
});
|
|
53
|
+
return str;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function downloadJson(tableData, table, downloadFileName) {
|
|
57
|
+
const { columns = [] } = table;
|
|
58
|
+
const filterColumns = columns.filter(({ cellType }) => !actionCellTypes.includes(cellType));
|
|
59
|
+
const formatDataVal = formatColumnValues(filterColumns, tableData);
|
|
60
|
+
const jsonse = JSON.stringify(formatDataVal);
|
|
61
|
+
const keysToInclude = columns.filter(({ dataField }) => dataField)
|
|
62
|
+
.map(({ dataField }) => dataField);
|
|
63
|
+
const headers = columns.filter(({ dataField }) => dataField).map(({ header }) => header);
|
|
64
|
+
const csv = convertToCSV(jsonse, keysToInclude, headers);
|
|
65
|
+
const exportData = new Blob([csv], { type: 'text/csv' });
|
|
66
|
+
const JsonURL = window.URL.createObjectURL(exportData);
|
|
67
|
+
let tempLink = '';
|
|
68
|
+
tempLink = document.createElement('a');
|
|
69
|
+
tempLink.setAttribute('href', JsonURL);
|
|
70
|
+
tempLink.setAttribute('download', createFileName(downloadFileName || ''));
|
|
71
|
+
document.body.appendChild(tempLink);
|
|
72
|
+
tempLink.click();
|
|
73
|
+
document.body.removeChild(tempLink);
|
|
74
|
+
}
|