@bento-core/table 0.3.0 → 1.0.0-c3dc.0
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 +20 -7
- package/dist/TableView.js +26 -4
- package/dist/body/components/CheckBoxView.js +8 -2
- package/dist/header/CustomCell.js +7 -1
- package/dist/header/components/CheckBoxView.js +16 -8
- package/dist/index.js +6 -0
- package/dist/pagination/CustomPagination.js +9 -1
- package/dist/toolbar/DownloadButtonView.js +53 -8
- package/dist/util/Dataformat.js +41 -1
- package/dist/util/Types.js +10 -1
- package/dist/util/downloadTable.js +116 -0
- package/package.json +14 -5
- package/src/ExtendedView.js +33 -11
- package/src/TableView.js +34 -10
- package/src/body/components/CheckBoxView.js +3 -0
- package/src/header/CustomCell.js +11 -0
- package/src/header/components/CheckBoxView.js +9 -10
- package/src/index.js +1 -0
- package/src/pagination/CustomPagination.js +6 -0
- package/src/toolbar/DownloadButtonView.js +86 -10
- package/src/util/Dataformat.js +25 -0
- package/src/util/Types.js +7 -0
- package/src/util/downloadTable.js +81 -0
package/dist/ExtendedView.js
CHANGED
|
@@ -16,6 +16,11 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
16
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
17
|
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
18
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 downloadAreaStyle = {
|
|
20
|
+
display: 'flex',
|
|
21
|
+
borderTop: '1px solid #8A7F7C',
|
|
22
|
+
paddingRight: '41px'
|
|
23
|
+
};
|
|
19
24
|
const ExtendedView = _ref => {
|
|
20
25
|
let {
|
|
21
26
|
table,
|
|
@@ -23,7 +28,8 @@ const ExtendedView = _ref => {
|
|
|
23
28
|
onRowsPerPageChange,
|
|
24
29
|
onPageChange,
|
|
25
30
|
numSelected = 0,
|
|
26
|
-
customTheme
|
|
31
|
+
customTheme,
|
|
32
|
+
queryVariables
|
|
27
33
|
} = _ref;
|
|
28
34
|
const {
|
|
29
35
|
extendedViewConfig
|
|
@@ -43,13 +49,14 @@ const ExtendedView = _ref => {
|
|
|
43
49
|
theme: themeConfig
|
|
44
50
|
}, numSelected === 0 && (download || manageViewColumns) && /*#__PURE__*/_react.default.createElement(_core.Toolbar, {
|
|
45
51
|
className: "downloadColumnView"
|
|
46
|
-
}, /*#__PURE__*/_react.default.createElement(
|
|
47
|
-
download: download
|
|
48
|
-
}), /*#__PURE__*/_react.default.createElement(_ManageColumnView.default, {
|
|
52
|
+
}, /*#__PURE__*/_react.default.createElement(_ManageColumnView.default, {
|
|
49
53
|
table: table,
|
|
50
54
|
manageViewColumns: manageViewColumns,
|
|
51
55
|
onColumnViewChange: onColumnViewChange
|
|
52
|
-
})), pagination && /*#__PURE__*/_react.default.createElement(
|
|
56
|
+
})), pagination && /*#__PURE__*/_react.default.createElement("div", {
|
|
57
|
+
className: "downloadArea",
|
|
58
|
+
style: downloadAreaStyle
|
|
59
|
+
}, /*#__PURE__*/_react.default.createElement(_CustomPagination.default, {
|
|
53
60
|
customTheme: customTheme.tblTopPgn,
|
|
54
61
|
rowsPerPageOptions: [10, 25, 50, 100],
|
|
55
62
|
component: "div",
|
|
@@ -57,8 +64,14 @@ const ExtendedView = _ref => {
|
|
|
57
64
|
rowsPerPage: table.rowsPerPage || 10,
|
|
58
65
|
page: table.page || 0,
|
|
59
66
|
onPageChange: onPageChange,
|
|
60
|
-
onRowsPerPageChange: onRowsPerPageChange
|
|
61
|
-
|
|
67
|
+
onRowsPerPageChange: onRowsPerPageChange,
|
|
68
|
+
queryVariables: queryVariables,
|
|
69
|
+
table: table
|
|
70
|
+
}), /*#__PURE__*/_react.default.createElement(_DownloadButtonView.default, {
|
|
71
|
+
count: table.totalRowCount || 0,
|
|
72
|
+
queryVariables: queryVariables,
|
|
73
|
+
table: table
|
|
74
|
+
})));
|
|
62
75
|
};
|
|
63
76
|
var _default = ExtendedView;
|
|
64
77
|
exports.default = _default;
|
package/dist/TableView.js
CHANGED
|
@@ -12,6 +12,7 @@ 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"));
|
|
15
16
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
16
17
|
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; }
|
|
17
18
|
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; }
|
|
@@ -32,6 +33,18 @@ const CustomTableContainer = props => {
|
|
|
32
33
|
component: _core.Paper
|
|
33
34
|
}, children));
|
|
34
35
|
};
|
|
36
|
+
const downloadAreaStyle = {
|
|
37
|
+
display: 'flex',
|
|
38
|
+
borderTop: '1px solid #8A7F7C',
|
|
39
|
+
borderBottom: '1px solid #8A7F7C',
|
|
40
|
+
paddingRight: '41px'
|
|
41
|
+
};
|
|
42
|
+
const cartDownloadAreaStyle = {
|
|
43
|
+
display: 'flex',
|
|
44
|
+
borderTop: '5px solid #e7e5e5',
|
|
45
|
+
borderBottom: '3px solid #e7e5e5',
|
|
46
|
+
paddingRight: '40px'
|
|
47
|
+
};
|
|
35
48
|
const TableView = _ref => {
|
|
36
49
|
var _table$selectedRows, _table$selectedRows2;
|
|
37
50
|
let {
|
|
@@ -44,7 +57,8 @@ const TableView = _ref => {
|
|
|
44
57
|
totalRowCount,
|
|
45
58
|
onSortByColumn,
|
|
46
59
|
onColumnViewChange,
|
|
47
|
-
themeConfig = {}
|
|
60
|
+
themeConfig = {},
|
|
61
|
+
queryVariables
|
|
48
62
|
} = _ref;
|
|
49
63
|
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_ExtendedView.default, {
|
|
50
64
|
table: table,
|
|
@@ -52,7 +66,8 @@ const TableView = _ref => {
|
|
|
52
66
|
onRowsPerPageChange: onRowsPerPageChange,
|
|
53
67
|
onPageChange: onPageChange,
|
|
54
68
|
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
|
|
69
|
+
customTheme: themeConfig.extendedView,
|
|
70
|
+
queryVariables: queryVariables
|
|
56
71
|
}), /*#__PURE__*/_react.default.createElement(_CustomToolbar.default, {
|
|
57
72
|
numSelected: (table === null || table === void 0 ? void 0 : (_table$selectedRows2 = table.selectedRows) === null || _table$selectedRows2 === void 0 ? void 0 : _table$selectedRows2.length) || 0,
|
|
58
73
|
table: table,
|
|
@@ -75,7 +90,10 @@ const TableView = _ref => {
|
|
|
75
90
|
}))), tableRows.length === 0 && /*#__PURE__*/_react.default.createElement(_DisplayErrMsg.default, {
|
|
76
91
|
customTheme: themeConfig.displayErr,
|
|
77
92
|
table: table
|
|
78
|
-
}), /*#__PURE__*/_react.default.createElement(
|
|
93
|
+
}), /*#__PURE__*/_react.default.createElement("div", {
|
|
94
|
+
className: "downloadArea",
|
|
95
|
+
style: table.paginationAPIField === 'filesInList' ? cartDownloadAreaStyle : downloadAreaStyle
|
|
96
|
+
}, /*#__PURE__*/_react.default.createElement(_CustomPagination.default, {
|
|
79
97
|
customTheme: themeConfig.tblPgn,
|
|
80
98
|
rowsPerPageOptions: [10, 25, 50, 100],
|
|
81
99
|
component: "div",
|
|
@@ -84,7 +102,11 @@ const TableView = _ref => {
|
|
|
84
102
|
page: table.page || 0,
|
|
85
103
|
onPageChange: onPageChange,
|
|
86
104
|
onRowsPerPageChange: onRowsPerPageChange
|
|
87
|
-
})
|
|
105
|
+
}), /*#__PURE__*/_react.default.createElement(_DownloadButtonView.default, {
|
|
106
|
+
count: table.totalRowCount || 0,
|
|
107
|
+
queryVariables: queryVariables,
|
|
108
|
+
table: table
|
|
109
|
+
})));
|
|
88
110
|
};
|
|
89
111
|
var _default = TableView;
|
|
90
112
|
exports.default = _default;
|
|
@@ -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': 'Checkbox item'
|
|
14
|
+
}
|
|
15
|
+
};
|
|
10
16
|
const CheckboxView = _ref => {
|
|
11
17
|
let {
|
|
12
18
|
row,
|
|
@@ -14,11 +20,11 @@ const CheckboxView = _ref => {
|
|
|
14
20
|
} = _ref;
|
|
15
21
|
return /*#__PURE__*/_react.default.createElement(_core.TableCell, {
|
|
16
22
|
padding: "checkbox"
|
|
17
|
-
}, /*#__PURE__*/_react.default.createElement(_core.Checkbox, {
|
|
23
|
+
}, /*#__PURE__*/_react.default.createElement(_core.Checkbox, _extends({}, label, {
|
|
18
24
|
disableRipple: true,
|
|
19
25
|
onClick: event => onRowSelectChange(event, row),
|
|
20
26
|
checked: row.isChecked
|
|
21
|
-
}));
|
|
27
|
+
})));
|
|
22
28
|
};
|
|
23
29
|
var _default = CheckboxView;
|
|
24
30
|
exports.default = _default;
|
|
@@ -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;
|
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,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 _KeyboardArrowDownOutlined = _interopRequireDefault(require("@material-ui/icons/KeyboardArrowDownOutlined"));
|
|
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; }
|
|
@@ -53,13 +54,20 @@ const CustomPagination = _ref => {
|
|
|
53
54
|
overrides: _objectSpread(_objectSpread({}, defaultTheme), customTheme)
|
|
54
55
|
})
|
|
55
56
|
}, /*#__PURE__*/_react.default.createElement(_core.TablePagination, {
|
|
57
|
+
labelRowsPerPage: "Results per Page:",
|
|
56
58
|
rowsPerPageOptions: rowsPerPageOptions,
|
|
57
59
|
component: "div",
|
|
58
60
|
count: count,
|
|
59
61
|
rowsPerPage: rowsPerPage,
|
|
60
62
|
page: page,
|
|
61
63
|
onPageChange: onPageChange,
|
|
62
|
-
onRowsPerPageChange: onRowsPerPageChange
|
|
64
|
+
onRowsPerPageChange: onRowsPerPageChange,
|
|
65
|
+
SelectProps: {
|
|
66
|
+
IconComponent: _KeyboardArrowDownOutlined.default,
|
|
67
|
+
inputProps: {
|
|
68
|
+
'aria-label': 'Selection dropdown for displaying the number of results per page'
|
|
69
|
+
}
|
|
70
|
+
}
|
|
63
71
|
}));
|
|
64
72
|
};
|
|
65
73
|
CustomPagination.propTypes = {
|
|
@@ -4,20 +4,65 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
var _react =
|
|
7
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
8
|
+
var _client = require("@apollo/client");
|
|
8
9
|
var _core = require("@material-ui/core");
|
|
9
10
|
var _icons = require("@material-ui/icons");
|
|
10
|
-
|
|
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
|
+
};
|
|
11
23
|
const DownloadButton = _ref => {
|
|
12
24
|
let {
|
|
13
|
-
|
|
25
|
+
count,
|
|
26
|
+
queryVariables,
|
|
27
|
+
table
|
|
14
28
|
} = _ref;
|
|
15
|
-
if (
|
|
16
|
-
return null;
|
|
29
|
+
if (table.paginationAPIField === 'filesInList') {
|
|
30
|
+
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null);
|
|
31
|
+
}
|
|
32
|
+
if (count === 0) {
|
|
33
|
+
return /*#__PURE__*/_react.default.createElement(_icons.CloudDownload, {
|
|
34
|
+
className: "disableButton",
|
|
35
|
+
style: downloadButtonStyle
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
const client = (0, _client.useApolloClient)();
|
|
39
|
+
async function downloadSCSVFile() {
|
|
40
|
+
const {
|
|
41
|
+
query,
|
|
42
|
+
paginationAPIField
|
|
43
|
+
} = table;
|
|
44
|
+
const result = await client.query({
|
|
45
|
+
query,
|
|
46
|
+
variables: _objectSpread(_objectSpread({}, queryVariables), {}, {
|
|
47
|
+
page: 0,
|
|
48
|
+
first: 10000
|
|
49
|
+
})
|
|
50
|
+
}).then(response => {
|
|
51
|
+
if (paginationAPIField && response && response.data) {
|
|
52
|
+
return response.data[paginationAPIField];
|
|
53
|
+
}
|
|
54
|
+
return response.data;
|
|
55
|
+
});
|
|
56
|
+
(0, _downloadTable.downloadJson)(result, table, table.downloadFileName);
|
|
17
57
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
},
|
|
58
|
+
const downloadTableCSV = (0, _react.useCallback)(() => {
|
|
59
|
+
downloadSCSVFile();
|
|
60
|
+
}, [queryVariables]);
|
|
61
|
+
return /*#__PURE__*/_react.default.createElement(_core.Tooltip, {
|
|
62
|
+
title: "Download filtered results as a CSV"
|
|
63
|
+
}, /*#__PURE__*/_react.default.createElement(_core.IconButton, {
|
|
64
|
+
onClick: downloadTableCSV
|
|
65
|
+
}, /*#__PURE__*/_react.default.createElement(_icons.CloudDownload, null)));
|
|
21
66
|
};
|
|
22
67
|
var _default = DownloadButton;
|
|
23
68
|
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;
|
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];
|
|
@@ -0,0 +1,116 @@
|
|
|
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 if (keyName === 'age_at_diagnosis' || keyName === 'participant_age_at_collection') {
|
|
49
|
+
if (entry[keyName] === -999) {
|
|
50
|
+
line += 'Not Reported';
|
|
51
|
+
} else {
|
|
52
|
+
line += entry[keyName] !== null ? "\"".concat(entry[keyName], "\"") : ' ';
|
|
53
|
+
}
|
|
54
|
+
} else {
|
|
55
|
+
line += entry[keyName] !== null ? "\"".concat(entry[keyName], "\"") : ' ';
|
|
56
|
+
}
|
|
57
|
+
return line;
|
|
58
|
+
});
|
|
59
|
+
if (index === 0) {
|
|
60
|
+
// str = header.join(',');
|
|
61
|
+
str += "\r\n".concat(line, "\r\n");
|
|
62
|
+
} else {
|
|
63
|
+
str += "".concat(line, "\r\n");
|
|
64
|
+
}
|
|
65
|
+
return str;
|
|
66
|
+
});
|
|
67
|
+
return str;
|
|
68
|
+
}
|
|
69
|
+
function downloadJson(tableData, table, downloadFileName) {
|
|
70
|
+
const {
|
|
71
|
+
columns = []
|
|
72
|
+
} = table;
|
|
73
|
+
const filterColumns = columns.filter(_ref => {
|
|
74
|
+
let {
|
|
75
|
+
cellType
|
|
76
|
+
} = _ref;
|
|
77
|
+
return !_Types.actionCellTypes.includes(cellType);
|
|
78
|
+
});
|
|
79
|
+
const formatDataVal = (0, _Dataformat.formatColumnValues)(filterColumns, tableData);
|
|
80
|
+
const jsonse = JSON.stringify(formatDataVal);
|
|
81
|
+
const keysToInclude = columns.filter(_ref2 => {
|
|
82
|
+
let {
|
|
83
|
+
dataField
|
|
84
|
+
} = _ref2;
|
|
85
|
+
return dataField;
|
|
86
|
+
}).map(_ref3 => {
|
|
87
|
+
let {
|
|
88
|
+
dataField
|
|
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;
|
|
103
|
+
});
|
|
104
|
+
const csv = convertToCSV(jsonse, keysToInclude, headers);
|
|
105
|
+
const exportData = new Blob([csv], {
|
|
106
|
+
type: 'text/csv'
|
|
107
|
+
});
|
|
108
|
+
const JsonURL = window.URL.createObjectURL(exportData);
|
|
109
|
+
let tempLink = '';
|
|
110
|
+
tempLink = document.createElement('a');
|
|
111
|
+
tempLink.setAttribute('href', JsonURL);
|
|
112
|
+
tempLink.setAttribute('download', createFileName(downloadFileName || ''));
|
|
113
|
+
document.body.appendChild(tempLink);
|
|
114
|
+
tempLink.click();
|
|
115
|
+
document.body.removeChild(tempLink);
|
|
116
|
+
}
|
package/package.json
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bento-core/table",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "",
|
|
3
|
+
"version": "1.0.0-c3dc.0",
|
|
5
4
|
"main": "dist/index.js",
|
|
6
5
|
"scripts": {
|
|
7
|
-
"build": "npm run lint && rm -rf dist && NODE_ENV=production BABEL_ENV=es babel src --out-dir dist --copy-files",
|
|
6
|
+
"build": "npm run lint && cross-env-shell rm -rf dist && NODE_ENV=production BABEL_ENV=es babel src --out-dir dist --copy-files",
|
|
8
7
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
9
8
|
"lint": "eslint src"
|
|
10
9
|
},
|
|
11
|
-
"repository":
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/CBIIT/bento-frontend.git"
|
|
13
|
+
},
|
|
12
14
|
"publishConfig": {
|
|
13
15
|
"access": "public"
|
|
14
16
|
},
|
|
@@ -22,5 +24,12 @@
|
|
|
22
24
|
},
|
|
23
25
|
"author": "CTOS Bento Team",
|
|
24
26
|
"license": "ISC",
|
|
25
|
-
"
|
|
27
|
+
"bugs": {
|
|
28
|
+
"url": "https://github.com/CBIIT/bento-frontend/issues"
|
|
29
|
+
},
|
|
30
|
+
"homepage": "https://github.com/CBIIT/bento-frontend#readme",
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@apollo/client": "^3.8.3"
|
|
33
|
+
},
|
|
34
|
+
"description": ""
|
|
26
35
|
}
|
package/src/ExtendedView.js
CHANGED
|
@@ -9,6 +9,12 @@ import ManageColumnView from './toolbar/ManageColumnView';
|
|
|
9
9
|
import defaultTheme from './DefaultThemConfig';
|
|
10
10
|
import DownloadButton from './toolbar/DownloadButtonView';
|
|
11
11
|
|
|
12
|
+
const downloadAreaStyle = {
|
|
13
|
+
display: 'flex',
|
|
14
|
+
borderTop: '1px solid #8A7F7C',
|
|
15
|
+
paddingRight: '41px',
|
|
16
|
+
};
|
|
17
|
+
|
|
12
18
|
const ExtendedView = ({
|
|
13
19
|
table,
|
|
14
20
|
onColumnViewChange,
|
|
@@ -16,6 +22,7 @@ const ExtendedView = ({
|
|
|
16
22
|
onPageChange,
|
|
17
23
|
numSelected = 0,
|
|
18
24
|
customTheme,
|
|
25
|
+
queryVariables,
|
|
19
26
|
}) => {
|
|
20
27
|
const { extendedViewConfig } = table;
|
|
21
28
|
if (!extendedViewConfig) {
|
|
@@ -25,6 +32,7 @@ const ExtendedView = ({
|
|
|
25
32
|
download = false,
|
|
26
33
|
manageViewColumns = false,
|
|
27
34
|
pagination = false,
|
|
35
|
+
downloadButtonConfig,
|
|
28
36
|
} = extendedViewConfig;
|
|
29
37
|
|
|
30
38
|
const themeConfig = createTheme({ overrides: { ...defaultTheme(), ...customTheme } });
|
|
@@ -33,7 +41,10 @@ const ExtendedView = ({
|
|
|
33
41
|
{(numSelected === 0 && (download || manageViewColumns)) && (
|
|
34
42
|
<Toolbar className="downloadColumnView">
|
|
35
43
|
<DownloadButton
|
|
36
|
-
|
|
44
|
+
count={table.totalRowCount || 0}
|
|
45
|
+
queryVariables={queryVariables}
|
|
46
|
+
table={table}
|
|
47
|
+
buttonConfig={downloadButtonConfig}
|
|
37
48
|
/>
|
|
38
49
|
<ManageColumnView
|
|
39
50
|
table={table}
|
|
@@ -44,16 +55,27 @@ const ExtendedView = ({
|
|
|
44
55
|
)}
|
|
45
56
|
{
|
|
46
57
|
(pagination) && (
|
|
47
|
-
<
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
58
|
+
<div className="downloadArea" style={downloadAreaStyle}>
|
|
59
|
+
<CustomPagination
|
|
60
|
+
customTheme={customTheme.tblTopPgn}
|
|
61
|
+
rowsPerPageOptions={[10, 25, 50, 100]}
|
|
62
|
+
component="div"
|
|
63
|
+
count={table.totalRowCount || 0}
|
|
64
|
+
rowsPerPage={table.rowsPerPage || 10}
|
|
65
|
+
page={table.page || 0}
|
|
66
|
+
onPageChange={onPageChange}
|
|
67
|
+
onRowsPerPageChange={onRowsPerPageChange}
|
|
68
|
+
queryVariables={queryVariables}
|
|
69
|
+
table={table}
|
|
70
|
+
/>
|
|
71
|
+
{/* TODO: Commented out this section, Make this options configrable on Bento. */}
|
|
72
|
+
{/* <DownloadButton
|
|
73
|
+
count={table.totalRowCount || 0}
|
|
74
|
+
queryVariables={queryVariables}
|
|
75
|
+
table={table}
|
|
76
|
+
isIcon={false}
|
|
77
|
+
/> */}
|
|
78
|
+
</div>
|
|
57
79
|
)
|
|
58
80
|
}
|
|
59
81
|
</ThemeProvider>
|
package/src/TableView.js
CHANGED
|
@@ -12,6 +12,7 @@ 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';
|
|
15
16
|
|
|
16
17
|
const CustomTableContainer = (props) => {
|
|
17
18
|
const { children, customTheme } = props;
|
|
@@ -25,6 +26,20 @@ const CustomTableContainer = (props) => {
|
|
|
25
26
|
);
|
|
26
27
|
};
|
|
27
28
|
|
|
29
|
+
const downloadAreaStyle = {
|
|
30
|
+
display: 'flex',
|
|
31
|
+
borderTop: '1px solid #8A7F7C',
|
|
32
|
+
borderBottom: '1px solid #8A7F7C',
|
|
33
|
+
paddingRight: '41px',
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const cartDownloadAreaStyle = {
|
|
37
|
+
display: 'flex',
|
|
38
|
+
borderTop: '5px solid #e7e5e5',
|
|
39
|
+
borderBottom: '3px solid #e7e5e5',
|
|
40
|
+
paddingRight: '40px',
|
|
41
|
+
};
|
|
42
|
+
|
|
28
43
|
const TableView = ({
|
|
29
44
|
tableRows = [],
|
|
30
45
|
table,
|
|
@@ -36,6 +51,7 @@ const TableView = ({
|
|
|
36
51
|
onSortByColumn,
|
|
37
52
|
onColumnViewChange,
|
|
38
53
|
themeConfig = {},
|
|
54
|
+
queryVariables,
|
|
39
55
|
}) => (
|
|
40
56
|
<>
|
|
41
57
|
<ExtendedView
|
|
@@ -45,6 +61,7 @@ const TableView = ({
|
|
|
45
61
|
onPageChange={onPageChange}
|
|
46
62
|
numSelected={table?.selectedRows?.length || 0}
|
|
47
63
|
customTheme={themeConfig.extendedView}
|
|
64
|
+
queryVariables={queryVariables}
|
|
48
65
|
/>
|
|
49
66
|
<CustomToolbar
|
|
50
67
|
numSelected={table?.selectedRows?.length || 0}
|
|
@@ -78,16 +95,23 @@ const TableView = ({
|
|
|
78
95
|
table={table}
|
|
79
96
|
/>
|
|
80
97
|
)}
|
|
81
|
-
<
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
98
|
+
<div className="downloadArea" style={table.paginationAPIField === 'filesInList' ? cartDownloadAreaStyle : downloadAreaStyle}>
|
|
99
|
+
<CustomPagination
|
|
100
|
+
customTheme={themeConfig.tblPgn}
|
|
101
|
+
rowsPerPageOptions={[10, 25, 50, 100]}
|
|
102
|
+
component="div"
|
|
103
|
+
count={table.totalRowCount || 0}
|
|
104
|
+
rowsPerPage={table.rowsPerPage || 10}
|
|
105
|
+
page={table.page || 0}
|
|
106
|
+
onPageChange={onPageChange}
|
|
107
|
+
onRowsPerPageChange={onRowsPerPageChange}
|
|
108
|
+
/>
|
|
109
|
+
<DownloadButton
|
|
110
|
+
count={table.totalRowCount || 0}
|
|
111
|
+
queryVariables={queryVariables}
|
|
112
|
+
table={table}
|
|
113
|
+
/>
|
|
114
|
+
</div>
|
|
91
115
|
</>
|
|
92
116
|
);
|
|
93
117
|
|
|
@@ -4,12 +4,15 @@ import {
|
|
|
4
4
|
TableCell,
|
|
5
5
|
} from '@material-ui/core';
|
|
6
6
|
|
|
7
|
+
const label = { inputProps: { 'aria-label': 'Checkbox item' } };
|
|
8
|
+
|
|
7
9
|
const CheckboxView = ({
|
|
8
10
|
row,
|
|
9
11
|
onRowSelectChange,
|
|
10
12
|
}) => (
|
|
11
13
|
<TableCell padding="checkbox">
|
|
12
14
|
<Checkbox
|
|
15
|
+
{...label}
|
|
13
16
|
disableRipple
|
|
14
17
|
onClick={(event) => onRowSelectChange(event, row)}
|
|
15
18
|
checked={row.isChecked}
|
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
|
);
|
package/src/index.js
CHANGED
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
TablePagination,
|
|
6
6
|
ThemeProvider,
|
|
7
7
|
} from '@material-ui/core';
|
|
8
|
+
import KeyboardArrowDownOutlinedIcon from '@material-ui/icons/KeyboardArrowDownOutlined';
|
|
8
9
|
|
|
9
10
|
const defaultTheme = {
|
|
10
11
|
MuiTablePagination: {
|
|
@@ -43,6 +44,7 @@ const CustomPagination = ({
|
|
|
43
44
|
}) => (
|
|
44
45
|
<ThemeProvider theme={createTheme({ overrides: { ...defaultTheme, ...customTheme } })}>
|
|
45
46
|
<TablePagination
|
|
47
|
+
labelRowsPerPage="Results per Page:"
|
|
46
48
|
rowsPerPageOptions={rowsPerPageOptions}
|
|
47
49
|
component="div"
|
|
48
50
|
count={count}
|
|
@@ -50,6 +52,10 @@ const CustomPagination = ({
|
|
|
50
52
|
page={page}
|
|
51
53
|
onPageChange={onPageChange}
|
|
52
54
|
onRowsPerPageChange={onRowsPerPageChange}
|
|
55
|
+
SelectProps={{
|
|
56
|
+
IconComponent: KeyboardArrowDownOutlinedIcon,
|
|
57
|
+
inputProps: { 'aria-label': 'Selection dropdown for displaying the number of results per page' },
|
|
58
|
+
}}
|
|
53
59
|
/>
|
|
54
60
|
</ThemeProvider>
|
|
55
61
|
);
|
|
@@ -1,24 +1,100 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { useCallback } from 'react';
|
|
2
|
+
import { useApolloClient } from '@apollo/client';
|
|
2
3
|
import {
|
|
3
4
|
IconButton,
|
|
4
5
|
Tooltip,
|
|
6
|
+
Button,
|
|
5
7
|
} from '@material-ui/core';
|
|
8
|
+
// import ToolTip from '@bento-core/tool-tip';
|
|
6
9
|
import { CloudDownload } from '@material-ui/icons';
|
|
10
|
+
import { downloadJson } from '../util/downloadTable';
|
|
11
|
+
|
|
12
|
+
const downloadButtonStyle = {
|
|
13
|
+
color: '#d1d2d3',
|
|
14
|
+
marginTop: '7px',
|
|
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
|
+
};
|
|
7
31
|
|
|
8
32
|
const DownloadButton = ({
|
|
9
|
-
|
|
33
|
+
count,
|
|
34
|
+
queryVariables,
|
|
35
|
+
table,
|
|
36
|
+
buttonConfig = {},
|
|
37
|
+
isIcon = false,
|
|
10
38
|
}) => {
|
|
11
|
-
if (
|
|
12
|
-
return
|
|
39
|
+
if (table.paginationAPIField === 'filesInList') {
|
|
40
|
+
return <></>;
|
|
41
|
+
}
|
|
42
|
+
if (count === 0) {
|
|
43
|
+
return <CloudDownload className="disableButton" style={downloadButtonStyle} />;
|
|
13
44
|
}
|
|
14
45
|
|
|
15
|
-
|
|
46
|
+
const client = useApolloClient();
|
|
47
|
+
|
|
48
|
+
async function downloadSCSVFile() {
|
|
49
|
+
const {
|
|
50
|
+
query,
|
|
51
|
+
paginationAPIField,
|
|
52
|
+
} = table;
|
|
53
|
+
|
|
54
|
+
const result = await client.query({
|
|
55
|
+
query,
|
|
56
|
+
variables: {
|
|
57
|
+
...queryVariables,
|
|
58
|
+
page: 0,
|
|
59
|
+
first: 10000,
|
|
60
|
+
},
|
|
61
|
+
})
|
|
62
|
+
.then((response) => {
|
|
63
|
+
if (paginationAPIField && response && response.data) {
|
|
64
|
+
return response.data[paginationAPIField];
|
|
65
|
+
}
|
|
66
|
+
return response.data;
|
|
67
|
+
});
|
|
68
|
+
downloadJson(result, table, table.downloadFileName);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const downloadTableCSV = useCallback(() => {
|
|
72
|
+
downloadSCSVFile();
|
|
73
|
+
}, [queryVariables]);
|
|
74
|
+
|
|
75
|
+
const {
|
|
76
|
+
buttonStyle, title = 'DOWNLOAD CSV', cloudIcon = false,
|
|
77
|
+
} = buttonConfig;
|
|
78
|
+
|
|
79
|
+
return isIcon ? (
|
|
80
|
+
<Tooltip title="Download filtered results as a CSV">
|
|
81
|
+
<IconButton
|
|
82
|
+
onClick={downloadTableCSV}
|
|
83
|
+
>
|
|
84
|
+
<CloudDownload />
|
|
85
|
+
</IconButton>
|
|
86
|
+
</Tooltip>
|
|
87
|
+
) : (
|
|
16
88
|
<>
|
|
17
|
-
<
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
89
|
+
<Button
|
|
90
|
+
onClick={downloadTableCSV}
|
|
91
|
+
style={buttonStyle || DEFAULT_BUTTON_STYLE}
|
|
92
|
+
disableRipple
|
|
93
|
+
>
|
|
94
|
+
{title}
|
|
95
|
+
{' '}
|
|
96
|
+
{cloudIcon ? <CloudDownload style={{ margin: '6px 0px 10px 10px' }} /> : ''}
|
|
97
|
+
</Button>
|
|
22
98
|
</>
|
|
23
99
|
);
|
|
24
100
|
};
|
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
|
+
};
|
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];
|
|
@@ -0,0 +1,81 @@
|
|
|
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 if (keyName === 'age_at_diagnosis' || keyName === 'participant_age_at_collection') {
|
|
41
|
+
if (entry[keyName] === -999) {
|
|
42
|
+
line += 'Not Reported';
|
|
43
|
+
} else {
|
|
44
|
+
line += entry[keyName] !== null ? `"${entry[keyName]}"` : ' ';
|
|
45
|
+
}
|
|
46
|
+
} else {
|
|
47
|
+
line += entry[keyName] !== null ? `"${entry[keyName]}"` : ' ';
|
|
48
|
+
}
|
|
49
|
+
return line;
|
|
50
|
+
});
|
|
51
|
+
if (index === 0) {
|
|
52
|
+
// str = header.join(',');
|
|
53
|
+
str += `\r\n${line}\r\n`;
|
|
54
|
+
} else {
|
|
55
|
+
str += `${line}\r\n`;
|
|
56
|
+
}
|
|
57
|
+
return str;
|
|
58
|
+
});
|
|
59
|
+
return str;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function downloadJson(tableData, table, downloadFileName) {
|
|
63
|
+
const { columns = [] } = table;
|
|
64
|
+
const filterColumns = columns.filter(({ cellType }) => !actionCellTypes.includes(cellType));
|
|
65
|
+
const formatDataVal = formatColumnValues(filterColumns, tableData);
|
|
66
|
+
const jsonse = JSON.stringify(formatDataVal);
|
|
67
|
+
const keysToInclude = columns.filter(({ dataField }) => dataField)
|
|
68
|
+
.map(({ dataField }) => dataField);
|
|
69
|
+
const headers = columns.filter(({ dataField }) => dataField)
|
|
70
|
+
.map(({ header, downloadHeader }) => (downloadHeader || header));
|
|
71
|
+
const csv = convertToCSV(jsonse, keysToInclude, headers);
|
|
72
|
+
const exportData = new Blob([csv], { type: 'text/csv' });
|
|
73
|
+
const JsonURL = window.URL.createObjectURL(exportData);
|
|
74
|
+
let tempLink = '';
|
|
75
|
+
tempLink = document.createElement('a');
|
|
76
|
+
tempLink.setAttribute('href', JsonURL);
|
|
77
|
+
tempLink.setAttribute('download', createFileName(downloadFileName || ''));
|
|
78
|
+
document.body.appendChild(tempLink);
|
|
79
|
+
tempLink.click();
|
|
80
|
+
document.body.removeChild(tempLink);
|
|
81
|
+
}
|