@bento-core/table 1.0.1-ccdihub.6 → 1.0.1-ccdihub.60

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.
@@ -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(_DownloadButtonView.default, {
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(_CustomPagination.default, {
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(_CustomPagination.default, {
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;
@@ -51,7 +51,7 @@ const CustomHeaderCell = _ref => {
51
51
  // return default view
52
52
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, children);
53
53
  }, []);
54
- if (!sortable) {
54
+ if (sortable !== undefined && !sortable) {
55
55
  return /*#__PURE__*/_react.default.createElement(_TableCell.default, {
56
56
  scope: "col"
57
57
  }, header);
@@ -10,7 +10,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
10
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
11
  const label = {
12
12
  inputProps: {
13
- 'aria-label': 'Checkbox item'
13
+ 'aria-label': 'Select all checkbox'
14
14
  }
15
15
  };
16
16
  const CheckboxView = _ref => {
@@ -21,7 +21,11 @@ const CheckboxView = _ref => {
21
21
  } = _ref;
22
22
  return /*#__PURE__*/_react.default.createElement(_core.TableCell, {
23
23
  padding: "checkbox"
24
- }, /*#__PURE__*/_react.default.createElement(_core.Checkbox, _extends({}, label, {
24
+ }, /*#__PURE__*/_react.default.createElement("span", {
25
+ style: {
26
+ display: 'none'
27
+ }
28
+ }, "Select all"), /*#__PURE__*/_react.default.createElement(_core.Checkbox, _extends({}, label, {
25
29
  color: "primary",
26
30
  indeterminate: includeSelectedIds,
27
31
  checked: includeSelectedIds,
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,6 +54,7 @@ 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,
@@ -61,10 +63,10 @@ const CustomPagination = _ref => {
61
63
  onPageChange: onPageChange,
62
64
  onRowsPerPageChange: onRowsPerPageChange,
63
65
  SelectProps: {
66
+ IconComponent: _KeyboardArrowDownOutlined.default,
64
67
  inputProps: {
65
68
  'aria-label': 'Selection dropdown for displaying the number of results per page'
66
- },
67
- native: true
69
+ }
68
70
  }
69
71
  }));
70
72
  };
@@ -4,20 +4,175 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var _react = _interopRequireDefault(require("react"));
7
+ var _react = _interopRequireWildcard(require("react"));
8
+ var _client = require("@apollo/client");
8
9
  var _core = require("@material-ui/core");
10
+ var _KeyboardArrowDownOutlined = _interopRequireDefault(require("@material-ui/icons/KeyboardArrowDownOutlined"));
9
11
  var _icons = require("@material-ui/icons");
12
+ var _downloadTable = require("../util/downloadTable");
10
13
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
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); }
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; }
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; }
17
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
18
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
19
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
20
+ function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
21
+ const downloadButtonStyle = {
22
+ color: '#d1d2d3',
23
+ marginTop: '7px'
24
+ };
11
25
  const DownloadButton = _ref => {
12
26
  let {
13
- download
27
+ count,
28
+ queryVariables,
29
+ table
14
30
  } = _ref;
15
- if (!download) {
16
- return null;
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('id') && event.target.getAttribute('id').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);
47
+ if (table.paginationAPIField === 'filesInList') {
48
+ return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null);
49
+ }
50
+ if (count === 0) {
51
+ return /*#__PURE__*/_react.default.createElement(_icons.CloudDownload, {
52
+ className: "disableButton",
53
+ style: downloadButtonStyle
54
+ });
55
+ }
56
+ const client = (0, _client.useApolloClient)();
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
+ order_by: table.sortBy,
68
+ sort_direction: table.sortOrder
69
+ })
70
+ }).then(response => {
71
+ if (paginationAPIField && response && response.data) {
72
+ return response.data[paginationAPIField];
73
+ }
74
+ return response.data;
75
+ });
76
+ (0, _downloadTable.downloadCSV)(result, table, table.downloadFileName);
77
+ }
78
+ async function downloadJsonFile() {
79
+ const {
80
+ query,
81
+ paginationAPIField
82
+ } = table;
83
+ const result = await client.query({
84
+ query,
85
+ variables: _objectSpread(_objectSpread({}, queryVariables), {}, {
86
+ page: 0,
87
+ first: 10000,
88
+ order_by: table.sortBy,
89
+ sort_direction: table.sortOrder
90
+ })
91
+ }).then(response => {
92
+ if (paginationAPIField && response && response.data) {
93
+ return response.data[paginationAPIField];
94
+ }
95
+ return response.data;
96
+ });
97
+ (0, _downloadTable.downloadJson)(result, table, table.downloadFileName);
17
98
  }
18
- return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_core.Tooltip, {
19
- title: download.downloadCsv
20
- }, /*#__PURE__*/_react.default.createElement(_core.IconButton, null, /*#__PURE__*/_react.default.createElement(_icons.CloudDownload, null))));
99
+ const downloadTableCSV = (0, _react.useCallback)(() => {
100
+ downloadSCSVFile();
101
+ setListDisplay('none');
102
+ }, [queryVariables, table]);
103
+ const downloadTableJson = (0, _react.useCallback)(() => {
104
+ downloadJsonFile();
105
+ setListDisplay('none');
106
+ }, [queryVariables, table]);
107
+ const handleClickButton = () => {
108
+ if (listDisplay === 'none') {
109
+ setListDisplay('block');
110
+ } else {
111
+ setListDisplay('none');
112
+ }
113
+ };
114
+ const useStyles = (0, _core.makeStyles)({
115
+ dropdown: {
116
+ width: '60px',
117
+ height: '25px',
118
+ marginTop: '8px',
119
+ paddingLeft: '5px',
120
+ border: '0.75px solid #606060',
121
+ borderRadius: '5px',
122
+ display: 'inline-block',
123
+ position: 'relative'
124
+ },
125
+ dropdownList: {
126
+ display: 'block',
127
+ position: 'absolute',
128
+ width: '60px',
129
+ marginTop: '3px',
130
+ marginLeft: '-5px',
131
+ overflow: 'auto',
132
+ zIndex: '5',
133
+ border: '1.5px solid #41545E',
134
+ borderRadius: '5px',
135
+ background: '#ffffff'
136
+ },
137
+ dropdownListItem: {
138
+ padding: '2px 4px',
139
+ font: 'Poppins',
140
+ fontSize: '14px',
141
+ fontWeight: 400,
142
+ lineHeight: '21px',
143
+ '&:hover': {
144
+ background: '#D7D7D7',
145
+ cursor: 'pointer'
146
+ }
147
+ },
148
+ arrowdownIcon: {
149
+ marginLeft: '5px',
150
+ fill: '#606060'
151
+ }
152
+ });
153
+ const classes = useStyles();
154
+ return /*#__PURE__*/_react.default.createElement("div", {
155
+ className: classes.dropdown
156
+ }, /*#__PURE__*/_react.default.createElement(_core.Tooltip, {
157
+ title: "Download filtered results"
158
+ }, /*#__PURE__*/_react.default.createElement(_core.IconButton, {
159
+ onClick: handleClickButton
160
+ }, /*#__PURE__*/_react.default.createElement(_icons.CloudDownload, null), /*#__PURE__*/_react.default.createElement(_KeyboardArrowDownOutlined.default, {
161
+ className: classes.arrowdownIcon
162
+ }))), /*#__PURE__*/_react.default.createElement("div", {
163
+ className: classes.dropdownList,
164
+ style: {
165
+ display: listDisplay
166
+ }
167
+ }, /*#__PURE__*/_react.default.createElement("div", {
168
+ id: "dropdownListItemCSV",
169
+ className: classes.dropdownListItem,
170
+ onClick: downloadTableCSV
171
+ }, "CSV"), /*#__PURE__*/_react.default.createElement("div", {
172
+ id: "dropdownListItemJSON",
173
+ className: classes.dropdownListItem,
174
+ onClick: downloadTableJson
175
+ }, "JSON")));
21
176
  };
22
177
  var _default = DownloadButton;
23
178
  exports.default = _default;
@@ -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;
@@ -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,144 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.convertToCSV = convertToCSV;
7
+ exports.createFileName = createFileName;
8
+ exports.downloadCSV = downloadCSV;
9
+ exports.downloadJson = downloadJson;
10
+ var _Dataformat = require("./Dataformat");
11
+ var _Types = require("./Types");
12
+ function createFileName(fileName, type) {
13
+ const date = new Date();
14
+ const yyyy = date.getFullYear();
15
+ let dd = date.getDate();
16
+ let mm = date.getMonth() + 1;
17
+ if (dd < 10) {
18
+ dd = "0".concat(dd);
19
+ }
20
+ if (mm < 10) {
21
+ mm = "0".concat(mm);
22
+ }
23
+ const todaysDate = "".concat(yyyy, "-").concat(mm, "-").concat(dd);
24
+ let hours = date.getHours();
25
+ let minutes = date.getMinutes();
26
+ let seconds = date.getSeconds();
27
+ if (hours < 10) {
28
+ hours = "0".concat(hours);
29
+ }
30
+ if (minutes < 10) {
31
+ minutes = "0".concat(minutes);
32
+ }
33
+ if (seconds < 10) {
34
+ seconds = "0".concat(seconds);
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');
40
+ }
41
+ function convertToCSV(jsonse, keysToInclude, header) {
42
+ const objArray = jsonse;
43
+ // To Do empty object just print headers
44
+ const array = typeof objArray !== 'object' ? JSON.parse(objArray) : objArray;
45
+ let str = header.join(',');
46
+ array.map((entry, index) => {
47
+ let line = '';
48
+ keysToInclude.map(keyName => {
49
+ if (line !== '') line += ',';
50
+ if (keyName === 'file_size') {
51
+ line += entry[keyName] !== null ? "\"".concat((0, _Dataformat.formatBytes)(entry[keyName]), "\"") : ' ';
52
+ } else if (keyName === 'age_at_diagnosis' || keyName === 'participant_age_at_collection') {
53
+ if (entry[keyName] === -999) {
54
+ line += 'Not Reported';
55
+ } else {
56
+ line += entry[keyName] !== null ? "\"".concat(entry[keyName], "\"") : ' ';
57
+ }
58
+ } else {
59
+ line += entry[keyName] !== null ? "\"".concat(entry[keyName], "\"") : ' ';
60
+ }
61
+ return line;
62
+ });
63
+ if (index === 0) {
64
+ // str = header.join(',');
65
+ str += "\r\n".concat(line, "\r\n");
66
+ } else {
67
+ str += "".concat(line, "\r\n");
68
+ }
69
+ return str;
70
+ });
71
+ return str;
72
+ }
73
+ function downloadCSV(tableData, table, downloadFileName) {
74
+ const {
75
+ columns = []
76
+ } = table;
77
+ const filterColumns = columns.filter(_ref => {
78
+ let {
79
+ cellType
80
+ } = _ref;
81
+ return !_Types.actionCellTypes.includes(cellType);
82
+ });
83
+ const formatDataVal = (0, _Dataformat.formatColumnValues)(filterColumns, tableData);
84
+ const jsonse = JSON.stringify(formatDataVal);
85
+ const keysToInclude = columns.filter(_ref2 => {
86
+ let {
87
+ dataField
88
+ } = _ref2;
89
+ return dataField;
90
+ }).map(_ref3 => {
91
+ let {
92
+ dataField
93
+ } = _ref3;
94
+ return dataField;
95
+ });
96
+ const headers = columns.filter(_ref4 => {
97
+ let {
98
+ dataField
99
+ } = _ref4;
100
+ return dataField;
101
+ }).map(_ref5 => {
102
+ let {
103
+ header,
104
+ downloadHeader
105
+ } = _ref5;
106
+ return downloadHeader || header;
107
+ });
108
+ const csv = convertToCSV(jsonse, keysToInclude, headers);
109
+ const exportData = new Blob([csv], {
110
+ type: 'text/csv'
111
+ });
112
+ const JsonURL = window.URL.createObjectURL(exportData);
113
+ let tempLink = '';
114
+ tempLink = document.createElement('a');
115
+ tempLink.setAttribute('href', JsonURL);
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'));
141
+ document.body.appendChild(tempLink);
142
+ tempLink.click();
143
+ document.body.removeChild(tempLink);
144
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bento-core/table",
3
- "version": "1.0.1-ccdihub.6",
3
+ "version": "1.0.1-ccdihub.60",
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
  }
@@ -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) {
@@ -32,9 +39,9 @@ const ExtendedView = ({
32
39
  <ThemeProvider theme={themeConfig}>
33
40
  {(numSelected === 0 && (download || manageViewColumns)) && (
34
41
  <Toolbar className="downloadColumnView">
35
- <DownloadButton
42
+ {/* <DownloadButton
36
43
  download={download}
37
- />
44
+ /> */}
38
45
  <ManageColumnView
39
46
  table={table}
40
47
  manageViewColumns={manageViewColumns}
@@ -44,16 +51,25 @@ const ExtendedView = ({
44
51
  )}
45
52
  {
46
53
  (pagination) && (
47
- <CustomPagination
48
- customTheme={customTheme.tblTopPgn}
49
- rowsPerPageOptions={[10, 25, 50, 100]}
50
- component="div"
51
- count={table.totalRowCount || 0}
52
- rowsPerPage={table.rowsPerPage || 10}
53
- page={table.page || 0}
54
- onPageChange={onPageChange}
55
- onRowsPerPageChange={onRowsPerPageChange}
56
- />
54
+ <div className="downloadArea" style={downloadAreaStyle}>
55
+ <CustomPagination
56
+ customTheme={customTheme.tblTopPgn}
57
+ rowsPerPageOptions={[10, 25, 50, 100]}
58
+ component="div"
59
+ count={table.totalRowCount || 0}
60
+ rowsPerPage={table.rowsPerPage || 10}
61
+ page={table.page || 0}
62
+ onPageChange={onPageChange}
63
+ onRowsPerPageChange={onRowsPerPageChange}
64
+ queryVariables={queryVariables}
65
+ table={table}
66
+ />
67
+ <DownloadButton
68
+ count={table.totalRowCount || 0}
69
+ queryVariables={queryVariables}
70
+ table={table}
71
+ />
72
+ </div>
57
73
  )
58
74
  }
59
75
  </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
- <CustomPagination
82
- customTheme={themeConfig.tblPgn}
83
- rowsPerPageOptions={[10, 25, 50, 100]}
84
- component="div"
85
- count={table.totalRowCount || 0}
86
- rowsPerPage={table.rowsPerPage || 10}
87
- page={table.page || 0}
88
- onPageChange={onPageChange}
89
- onRowsPerPageChange={onRowsPerPageChange}
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
 
@@ -46,7 +46,7 @@ const CustomHeaderCell = ({
46
46
  return <>{children}</>;
47
47
  }, []);
48
48
 
49
- if (!sortable) {
49
+ if (sortable !== undefined && !sortable) {
50
50
  return (
51
51
  <TableCell
52
52
  scope="col"
@@ -4,7 +4,7 @@ import {
4
4
  Checkbox,
5
5
  } from '@material-ui/core';
6
6
 
7
- const label = { inputProps: { 'aria-label': 'Checkbox item' } };
7
+ const label = { inputProps: { 'aria-label': 'Select all checkbox' } };
8
8
 
9
9
  const CheckboxView = ({
10
10
  includeSelectedIds,
@@ -12,6 +12,7 @@ const CheckboxView = ({
12
12
  Ids,
13
13
  }) => (
14
14
  <TableCell padding="checkbox">
15
+ <span style={{ display: 'none' }}>Select all</span>
15
16
  <Checkbox
16
17
  {...label}
17
18
  color="primary"
package/src/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  export { default as TableView } from './TableView';
2
2
  export {
3
3
  cellTypes,
4
+ cellStyles,
4
5
  headerTypes,
5
6
  ComponentTypes,
6
7
  dataFormatTypes,
@@ -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}
@@ -51,8 +53,8 @@ const CustomPagination = ({
51
53
  onPageChange={onPageChange}
52
54
  onRowsPerPageChange={onRowsPerPageChange}
53
55
  SelectProps={{
56
+ IconComponent: KeyboardArrowDownOutlinedIcon,
54
57
  inputProps: { 'aria-label': 'Selection dropdown for displaying the number of results per page' },
55
- native: true,
56
58
  }}
57
59
  />
58
60
  </ThemeProvider>
@@ -1,25 +1,180 @@
1
- import React from 'react';
1
+ import React, {
2
+ useState,
3
+ useEffect,
4
+ useRef,
5
+ useCallback,
6
+ } from 'react';
7
+ import { useApolloClient } from '@apollo/client';
2
8
  import {
3
9
  IconButton,
4
10
  Tooltip,
11
+ makeStyles,
5
12
  } from '@material-ui/core';
13
+ import KeyboardArrowDownOutlinedIcon from '@material-ui/icons/KeyboardArrowDownOutlined';
6
14
  import { CloudDownload } from '@material-ui/icons';
15
+ import { downloadCSV, downloadJson } from '../util/downloadTable';
16
+
17
+ const downloadButtonStyle = {
18
+ color: '#d1d2d3',
19
+ marginTop: '7px',
20
+ };
7
21
 
8
22
  const DownloadButton = ({
9
- download,
23
+ count,
24
+ queryVariables,
25
+ table,
10
26
  }) => {
11
- if (!download) {
12
- return null;
27
+ const [listDisplay, setListDisplay] = useState('none');
28
+ const dropdownSelection = useRef(null);
29
+ const useOutsideAlerter = (ref) => {
30
+ useEffect(() => {
31
+ function handleClickOutside(event) {
32
+ if (!(event.target.getAttribute('id') && event.target.getAttribute('id').includes('dropdownListItem'))) {
33
+ setListDisplay('none');
34
+ }
35
+ }
36
+ document.addEventListener('mousedown', handleClickOutside);
37
+ return () => {
38
+ document.removeEventListener('mousedown', handleClickOutside);
39
+ };
40
+ }, [ref]);
41
+ };
42
+ useOutsideAlerter(dropdownSelection);
43
+
44
+ if (table.paginationAPIField === 'filesInList') {
45
+ return <></>;
46
+ }
47
+ if (count === 0) {
48
+ return <CloudDownload className="disableButton" style={downloadButtonStyle} />;
49
+ }
50
+
51
+ const client = useApolloClient();
52
+
53
+ async function downloadSCSVFile() {
54
+ const {
55
+ query,
56
+ paginationAPIField,
57
+ } = table;
58
+
59
+ const result = await client.query({
60
+ query,
61
+ variables: {
62
+ ...queryVariables,
63
+ page: 0,
64
+ first: 10000,
65
+ order_by: table.sortBy,
66
+ sort_direction: table.sortOrder,
67
+ },
68
+ })
69
+ .then((response) => {
70
+ if (paginationAPIField && response && response.data) {
71
+ return response.data[paginationAPIField];
72
+ }
73
+ return response.data;
74
+ });
75
+ downloadCSV(result, table, table.downloadFileName);
13
76
  }
14
77
 
78
+ async function downloadJsonFile() {
79
+ const {
80
+ query,
81
+ paginationAPIField,
82
+ } = table;
83
+
84
+ const result = await client.query({
85
+ query,
86
+ variables: {
87
+ ...queryVariables,
88
+ page: 0,
89
+ first: 10000,
90
+ order_by: table.sortBy,
91
+ sort_direction: table.sortOrder,
92
+ },
93
+ })
94
+ .then((response) => {
95
+ if (paginationAPIField && response && response.data) {
96
+ return response.data[paginationAPIField];
97
+ }
98
+ return response.data;
99
+ });
100
+ downloadJson(result, table, table.downloadFileName);
101
+ }
102
+
103
+ const downloadTableCSV = useCallback(() => {
104
+ downloadSCSVFile();
105
+ setListDisplay('none');
106
+ }, [queryVariables, table]);
107
+
108
+ const downloadTableJson = useCallback(() => {
109
+ downloadJsonFile();
110
+ setListDisplay('none');
111
+ }, [queryVariables, table]);
112
+
113
+ const handleClickButton = () => {
114
+ if (listDisplay === 'none') {
115
+ setListDisplay('block');
116
+ } else {
117
+ setListDisplay('none');
118
+ }
119
+ };
120
+
121
+ const useStyles = makeStyles({
122
+ dropdown: {
123
+ width: '60px',
124
+ height: '25px',
125
+ marginTop: '8px',
126
+ paddingLeft: '5px',
127
+ border: '0.75px solid #606060',
128
+ borderRadius: '5px',
129
+ display: 'inline-block',
130
+ position: 'relative',
131
+ },
132
+ dropdownList: {
133
+ display: 'block',
134
+ position: 'absolute',
135
+ width: '60px',
136
+ marginTop: '3px',
137
+ marginLeft: '-5px',
138
+ overflow: 'auto',
139
+ zIndex: '5',
140
+ border: '1.5px solid #41545E',
141
+ borderRadius: '5px',
142
+ background: '#ffffff',
143
+ },
144
+ dropdownListItem: {
145
+ padding: '2px 4px',
146
+ font: 'Poppins',
147
+ fontSize: '14px',
148
+ fontWeight: 400,
149
+ lineHeight: '21px',
150
+ '&:hover': {
151
+ background: '#D7D7D7',
152
+ cursor: 'pointer',
153
+ },
154
+ },
155
+ arrowdownIcon: {
156
+ marginLeft: '5px',
157
+ fill: '#606060',
158
+ },
159
+ });
160
+
161
+ const classes = useStyles();
162
+
15
163
  return (
16
- <>
17
- <Tooltip title={download.downloadCsv}>
18
- <IconButton>
164
+ <div className={classes.dropdown}>
165
+ <Tooltip title="Download filtered results">
166
+ <IconButton
167
+ onClick={handleClickButton}
168
+ >
19
169
  <CloudDownload />
170
+ <KeyboardArrowDownOutlinedIcon className={classes.arrowdownIcon} />
20
171
  </IconButton>
21
172
  </Tooltip>
22
- </>
173
+ <div className={classes.dropdownList} style={{ display: listDisplay }}>
174
+ <div id="dropdownListItemCSV" className={classes.dropdownListItem} onClick={downloadTableCSV}>CSV</div>
175
+ <div id="dropdownListItemJSON" className={classes.dropdownListItem} onClick={downloadTableJson}>JSON</div>
176
+ </div>
177
+ </div>
23
178
  );
24
179
  };
25
180
 
@@ -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,100 @@
1
+ import { formatBytes, formatColumnValues } from './Dataformat';
2
+ import { actionCellTypes } from './Types';
3
+
4
+ export function createFileName(fileName, type) {
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
+ if (type === 'csv') {
27
+ return `${fileName} ${todaysDate} ${hours}-${minutes}-${seconds}${'.csv'}`;
28
+ }
29
+ return `${fileName} ${todaysDate} ${hours}-${minutes}-${seconds}${'.json'}`;
30
+ }
31
+
32
+ export function convertToCSV(jsonse, keysToInclude, header) {
33
+ const objArray = jsonse;
34
+ // To Do empty object just print headers
35
+ const array = typeof objArray !== 'object' ? JSON.parse(objArray) : objArray;
36
+ let str = header.join(',');
37
+ array.map((entry, index) => {
38
+ let line = '';
39
+ keysToInclude.map((keyName) => {
40
+ if (line !== '') line += ',';
41
+ if (keyName === 'file_size') {
42
+ line += entry[keyName] !== null ? `"${formatBytes(entry[keyName])}"` : ' ';
43
+ } else if (keyName === 'age_at_diagnosis' || keyName === 'participant_age_at_collection') {
44
+ if (entry[keyName] === -999) {
45
+ line += 'Not Reported';
46
+ } else {
47
+ line += entry[keyName] !== null ? `"${entry[keyName]}"` : ' ';
48
+ }
49
+ } else {
50
+ line += entry[keyName] !== null ? `"${entry[keyName]}"` : ' ';
51
+ }
52
+ return line;
53
+ });
54
+ if (index === 0) {
55
+ // str = header.join(',');
56
+ str += `\r\n${line}\r\n`;
57
+ } else {
58
+ str += `${line}\r\n`;
59
+ }
60
+ return str;
61
+ });
62
+ return str;
63
+ }
64
+
65
+ export function downloadCSV(tableData, table, downloadFileName) {
66
+ const { columns = [] } = table;
67
+ const filterColumns = columns.filter(({ cellType }) => !actionCellTypes.includes(cellType));
68
+ const formatDataVal = formatColumnValues(filterColumns, tableData);
69
+ const jsonse = JSON.stringify(formatDataVal);
70
+ const keysToInclude = columns.filter(({ dataField }) => dataField)
71
+ .map(({ dataField }) => dataField);
72
+ const headers = columns.filter(({ dataField }) => dataField)
73
+ .map(({ header, downloadHeader }) => (downloadHeader || header));
74
+ const csv = convertToCSV(jsonse, keysToInclude, headers);
75
+ const exportData = new Blob([csv], { type: 'text/csv' });
76
+ const JsonURL = window.URL.createObjectURL(exportData);
77
+ let tempLink = '';
78
+ tempLink = document.createElement('a');
79
+ tempLink.setAttribute('href', JsonURL);
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'));
97
+ document.body.appendChild(tempLink);
98
+ tempLink.click();
99
+ document.body.removeChild(tempLink);
100
+ }