@bento-core/table 1.0.0-c3dc.25 → 1.0.0-c3dc.27

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.
@@ -7,37 +7,58 @@ 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 _icons = require("@material-ui/icons");
11
+ var _rightArrow = _interopRequireDefault(require("../assets/rightArrow.svg"));
12
+ var _leftArrow = _interopRequireDefault(require("../assets/leftArrow.svg"));
10
13
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
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; }
12
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; }
13
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; }
14
17
  function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
15
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); }
16
- const defaultTheme = {
17
- MuiTablePagination: {
18
- root: {
19
- paddingRight: '50px',
20
- borderTop: '3px solid #42779a'
21
- },
22
- toolbar: {
23
- minHeight: '45px'
24
- }
19
+ const useStyles = (0, _core.makeStyles)(() => ({
20
+ paginationRoot: {
21
+ display: 'flex',
22
+ justifyContent: 'flex-end',
23
+ // Moves pagination to the right
24
+ paddingRight: '10px' // Optional spacing
25
25
  },
26
- MuiTypography: {
27
- body2: {
28
- fontSize: '14px',
29
- textTransform: 'uppercase'
26
+
27
+ actionsContainer: {
28
+ display: 'flex',
29
+ justifyContent: 'flex-end' // Align pagination buttons to the right
30
+ }
31
+ }));
32
+
33
+ const defaultTheme = (0, _core.createMuiTheme)({
34
+ overrides: {
35
+ MuiTablePagination: {
36
+ root: {
37
+ paddingRight: '50px',
38
+ width: '100%'
39
+ },
40
+ toolbar: {
41
+ minHeight: '45px',
42
+ display: 'flex',
43
+ alignItems: 'center'
44
+ }
30
45
  },
31
- root: {
32
- fontSize: '14px'
33
- }
34
- },
35
- MuiIconButton: {
36
- root: {
37
- padding: '2px'
46
+ MuiTypography: {
47
+ body2: {
48
+ fontSize: '14px',
49
+ textTransform: 'uppercase'
50
+ },
51
+ root: {
52
+ fontSize: '14px'
53
+ }
54
+ },
55
+ MuiIconButton: {
56
+ root: {
57
+ padding: '2px'
58
+ }
38
59
  }
39
60
  }
40
- };
61
+ });
41
62
  const CustomPagination = _ref => {
42
63
  let {
43
64
  rowsPerPageOptions,
@@ -48,11 +69,15 @@ const CustomPagination = _ref => {
48
69
  onRowsPerPageChange,
49
70
  customTheme = {}
50
71
  } = _ref;
72
+ const classes = useStyles();
51
73
  return /*#__PURE__*/_react.default.createElement(_core.ThemeProvider, {
52
- theme: (0, _core.createTheme)({
53
- overrides: _objectSpread(_objectSpread({}, defaultTheme), customTheme)
74
+ theme: (0, _core.createMuiTheme)({
75
+ overrides: _objectSpread(_objectSpread({}, defaultTheme.overrides), customTheme)
54
76
  })
55
77
  }, /*#__PURE__*/_react.default.createElement(_core.TablePagination, {
78
+ labelRowsPerPage: /*#__PURE__*/_react.default.createElement("span", {
79
+ id: "rows-per-page-label"
80
+ }, "Rows per page:"),
56
81
  rowsPerPageOptions: rowsPerPageOptions,
57
82
  component: "div",
58
83
  count: count,
@@ -60,18 +85,45 @@ const CustomPagination = _ref => {
60
85
  page: page,
61
86
  onPageChange: onPageChange,
62
87
  onRowsPerPageChange: onRowsPerPageChange,
63
- labelRowsPerPage: /*#__PURE__*/_react.default.createElement("span", {
64
- id: "rows-per-page-label"
65
- }, "Rows per page:"),
66
88
  SelectProps: {
89
+ IconComponent: _icons.ArrowDropDown,
67
90
  inputProps: {
68
- 'aria-label': 'rows per page dropdown selector',
91
+ 'aria-label': 'Selection dropdown for displaying the number of results per page',
69
92
  'aria-labelledby': 'rows-per-page-label',
70
93
  style: {
71
94
  visibility: 'hidden'
72
95
  }
73
96
  }
74
- }
97
+ },
98
+ nextIconButtonProps: {
99
+ 'aria-label': 'Next page'
100
+ },
101
+ backIconButtonProps: {
102
+ 'aria-label': 'Previous page'
103
+ },
104
+ ActionsComponent: () => /*#__PURE__*/_react.default.createElement("div", {
105
+ className: classes.actionsContainer
106
+ }, /*#__PURE__*/_react.default.createElement(_core.IconButton, {
107
+ onClick: event => onPageChange(event, page - 1),
108
+ disabled: page === 0,
109
+ "aria-label": "Previous page"
110
+ }, /*#__PURE__*/_react.default.createElement("img", {
111
+ src: _leftArrow.default,
112
+ style: {
113
+ opacity: page === 0 ? 0.2 : 1
114
+ },
115
+ alt: "Left Arrow"
116
+ })), /*#__PURE__*/_react.default.createElement(_core.IconButton, {
117
+ onClick: event => onPageChange(event, page + 1),
118
+ disabled: page >= Math.ceil(count / rowsPerPage) - 1,
119
+ "aria-label": "Next page"
120
+ }, /*#__PURE__*/_react.default.createElement("img", {
121
+ src: _rightArrow.default,
122
+ style: {
123
+ opacity: page >= Math.ceil(count / rowsPerPage) - 1 ? 0.2 : 1
124
+ },
125
+ alt: "Right Arrow"
126
+ })))
75
127
  }));
76
128
  };
77
129
  CustomPagination.propTypes = {
@@ -7,8 +7,10 @@ exports.default = void 0;
7
7
  var _react = _interopRequireWildcard(require("react"));
8
8
  var _client = require("@apollo/client");
9
9
  var _core = require("@material-ui/core");
10
+ var _KeyboardArrowDownOutlined = _interopRequireDefault(require("@material-ui/icons/KeyboardArrowDownOutlined"));
10
11
  var _icons = require("@material-ui/icons");
11
12
  var _downloadTable = require("../util/downloadTable");
13
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
14
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
13
15
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
14
16
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
@@ -16,23 +18,57 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
16
18
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
17
19
  function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
18
20
  function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
21
+ // const downloadButtonStyle = {
22
+ // color: '#d1d2d3',
23
+ // marginTop: '7px',
24
+ // };
25
+
19
26
  const DownloadButton = _ref => {
20
27
  let {
21
- download,
22
- rows,
23
- table,
28
+ count,
24
29
  queryVariables,
25
- server
30
+ table
26
31
  } = _ref;
27
- if (!download) {
28
- return null;
32
+ const [listDisplay, setListDisplay] = (0, _react.useState)('none');
33
+ const dropdownSelection = (0, _react.useRef)(null);
34
+ const useOutsideAlerter = ref => {
35
+ (0, _react.useEffect)(() => {
36
+ function handleClickOutside(event) {
37
+ if (!(event.target.getAttribute('id') && event.target.getAttribute('id').includes('dropdownListItem'))) {
38
+ setListDisplay('none');
39
+ }
40
+ }
41
+ document.addEventListener('mousedown', handleClickOutside);
42
+ return () => {
43
+ document.removeEventListener('mousedown', handleClickOutside);
44
+ };
45
+ }, [ref]);
46
+ };
47
+ useOutsideAlerter(dropdownSelection);
48
+ if (table.paginationAPIField === 'filesInList') {
49
+ return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null);
29
50
  }
30
- const {
31
- downloadCsv = 'download',
32
- downloadTable,
33
- downloadFileName
34
- } = download;
35
51
  const client = (0, _client.useApolloClient)();
52
+ function cleanData(result) {
53
+ function hasHTMLTags(str) {
54
+ const htmlTagPattern = /<\/?[a-z][\s\S]*>/i; // Regex to match HTML tags
55
+ return htmlTagPattern.test(str);
56
+ }
57
+ const cleanedResult = result.map(res => {
58
+ const newObj = {};
59
+ Object.keys(res).forEach(key => {
60
+ if (hasHTMLTags(res[key])) {
61
+ const div = document.createElement('div');
62
+ div.innerHTML = res[key];
63
+ newObj[key] = div.textContent || div.innerText || res[key];
64
+ } else {
65
+ newObj[key] = res[key];
66
+ }
67
+ });
68
+ return newObj;
69
+ });
70
+ return cleanedResult;
71
+ }
36
72
  async function downloadSCSVFile() {
37
73
  const {
38
74
  query,
@@ -42,7 +78,9 @@ const DownloadButton = _ref => {
42
78
  query,
43
79
  variables: _objectSpread(_objectSpread({}, queryVariables), {}, {
44
80
  page: 0,
45
- first: 10000
81
+ first: 10000,
82
+ order_by: table.sortBy,
83
+ sort_direction: table.sortOrder
46
84
  })
47
85
  }).then(response => {
48
86
  if (paginationAPIField && response && response.data) {
@@ -50,26 +88,118 @@ const DownloadButton = _ref => {
50
88
  }
51
89
  return response.data;
52
90
  });
53
- (0, _downloadTable.downloadJson)(result, table, downloadFileName);
91
+ (0, _downloadTable.downloadData)(cleanData(result), table, table.downloadFileName, 'csv');
92
+ }
93
+ async function downloadJsonFile() {
94
+ const {
95
+ query,
96
+ paginationAPIField
97
+ } = table;
98
+ const result = await client.query({
99
+ query,
100
+ variables: _objectSpread(_objectSpread({}, queryVariables), {}, {
101
+ page: 0,
102
+ first: 10000,
103
+ order_by: table.sortBy,
104
+ sort_direction: table.sortOrder
105
+ })
106
+ }).then(response => {
107
+ if (paginationAPIField && response && response.data) {
108
+ return response.data[paginationAPIField];
109
+ }
110
+ return response.data;
111
+ });
112
+ (0, _downloadTable.downloadData)(cleanData(result), table, table.downloadFileName, 'json');
54
113
  }
55
114
  const downloadTableCSV = (0, _react.useCallback)(() => {
56
- // custom download from bento app
57
- if (downloadTable) {
58
- downloadTable(queryVariables);
59
- } else if (!downloadTable && !server) {
60
- // download client table
61
- (0, _downloadTable.downloadJson)(rows, table, downloadFileName);
115
+ downloadSCSVFile();
116
+ setListDisplay('none');
117
+ }, [queryVariables, table]);
118
+ const downloadTableJson = (0, _react.useCallback)(() => {
119
+ downloadJsonFile();
120
+ setListDisplay('none');
121
+ }, [queryVariables, table]);
122
+ const handleClickButton = () => {
123
+ if (listDisplay === 'none') {
124
+ setListDisplay('block');
62
125
  } else {
63
- // donwload server table
64
- downloadSCSVFile();
126
+ setListDisplay('none');
127
+ }
128
+ };
129
+ const useStyles = (0, _core.makeStyles)({
130
+ dropdown: {
131
+ width: '60px',
132
+ height: '25px',
133
+ marginTop: '8px',
134
+ paddingLeft: '5px',
135
+ border: '0.75px solid #606060',
136
+ borderRadius: '5px',
137
+ display: 'inline-block',
138
+ position: 'relative',
139
+ alignSelf: 'center'
140
+ },
141
+ dropdownList: {
142
+ display: 'block',
143
+ position: 'absolute',
144
+ width: '60px',
145
+ marginTop: '3px',
146
+ marginLeft: '-5px',
147
+ overflow: 'auto',
148
+ zIndex: '20',
149
+ border: '1.5px solid #41545E',
150
+ borderRadius: '5px',
151
+ background: '#ffffff'
152
+ },
153
+ dropdownListItem: {
154
+ padding: '2px 4px',
155
+ font: 'Poppins',
156
+ fontSize: '14px',
157
+ fontWeight: 400,
158
+ lineHeight: '21px',
159
+ '&:hover': {
160
+ background: '#D7D7D7',
161
+ cursor: 'pointer'
162
+ }
163
+ },
164
+ arrowdownIcon: {
165
+ marginLeft: '5px',
166
+ fill: '#606060'
167
+ },
168
+ arrowdownIconDisabled: {
169
+ marginLeft: '5px',
170
+ fill: '#00000042'
171
+ }
172
+ });
173
+ const classes = useStyles();
174
+ return /*#__PURE__*/_react.default.createElement("div", {
175
+ className: classes.dropdown
176
+ }, /*#__PURE__*/_react.default.createElement(_core.Tooltip, {
177
+ title: table.downloadButtonTooltipText || 'Download filtered results'
178
+ }, count !== 0 ? /*#__PURE__*/_react.default.createElement(_core.IconButton, {
179
+ onClick: handleClickButton,
180
+ style: {
181
+ padding: '0'
182
+ }
183
+ }, /*#__PURE__*/_react.default.createElement(_icons.CloudDownload, null), /*#__PURE__*/_react.default.createElement(_KeyboardArrowDownOutlined.default, {
184
+ className: classes.arrowdownIcon
185
+ })) : /*#__PURE__*/_react.default.createElement(_core.IconButton, {
186
+ disabled: true
187
+ }, /*#__PURE__*/_react.default.createElement(_icons.CloudDownload, null), /*#__PURE__*/_react.default.createElement(_KeyboardArrowDownOutlined.default, {
188
+ className: classes.arrowdownIconDisabled
189
+ }))), /*#__PURE__*/_react.default.createElement("div", {
190
+ className: classes.dropdownList,
191
+ style: {
192
+ display: listDisplay
65
193
  }
66
- }, [queryVariables]);
67
- return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_core.Tooltip, {
68
- title: downloadCsv,
69
- className: "download-icon"
70
- }, /*#__PURE__*/_react.default.createElement(_core.IconButton, {
194
+ }, /*#__PURE__*/_react.default.createElement("div", {
195
+ id: "dropdownListItemCSV",
196
+ className: classes.dropdownListItem,
71
197
  onClick: downloadTableCSV
72
- }, /*#__PURE__*/_react.default.createElement(_icons.CloudDownload, null))));
198
+ }, "CSV"), /*#__PURE__*/_react.default.createElement("div", {
199
+ id: "dropdownListItemJSON",
200
+ className: classes.dropdownListItem,
201
+ onClick: downloadTableJson
202
+ }, "JSON")));
73
203
  };
74
204
  var _default = DownloadButton;
75
205
  exports.default = _default;
@@ -20,7 +20,7 @@ const ManageColumnView = _ref => {
20
20
  return null;
21
21
  }
22
22
  const [anchorEl, setAnchorEl] = (0, _react.useState)(null);
23
- const toggleDisplay = event => {
23
+ const handleClick = event => {
24
24
  setAnchorEl(event.currentTarget);
25
25
  };
26
26
  const handleClose = () => setAnchorEl(null);
@@ -33,8 +33,7 @@ const ManageColumnView = _ref => {
33
33
  title: manageViewColumns.title
34
34
  }, /*#__PURE__*/_react.default.createElement(_core.IconButton, {
35
35
  variant: "contained",
36
- onClick: toggleDisplay,
37
- className: "manageViewColumnBtn"
36
+ onClick: handleClick
38
37
  }, /*#__PURE__*/_react.default.createElement(_icons.ViewColumn, null))), /*#__PURE__*/_react.default.createElement(_core.Popover, {
39
38
  open: open,
40
39
  anchorEl: anchorEl,
@@ -56,23 +55,22 @@ const ManageColumnView = _ref => {
56
55
  className: "viewColumnListItem"
57
56
  }, /*#__PURE__*/_react.default.createElement(_core.Checkbox, {
58
57
  icon: /*#__PURE__*/_react.default.createElement(_icons.CheckBoxOutlineBlank, {
58
+ style: {
59
+ fontSize: 18
60
+ },
59
61
  className: "checkBoxIcon"
60
62
  }),
61
63
  onClick: () => onColumnViewChange(column),
62
64
  checked: column.display,
63
65
  checkedIcon: /*#__PURE__*/_react.default.createElement(_icons.CheckBox, {
66
+ style: {
67
+ fontSize: 18
68
+ },
64
69
  className: "checkBoxIcon"
65
70
  }),
66
71
  disableRipple: true,
67
72
  color: "secondary",
68
- className: "checkBox",
69
- inputProps: {
70
- 'aria-label': 'checkbox'
71
- }
72
- }), column.icon && /*#__PURE__*/_react.default.createElement("img", {
73
- src: column.icon,
74
- alt: column.header,
75
- className: column.dataField
73
+ className: "checkBox"
76
74
  }), /*#__PURE__*/_react.default.createElement(_core.Typography, null, column.header))))));
77
75
  };
78
76
  const styles = () => ({
@@ -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.COMMA = exports.CHECKBOX = void 0;
7
7
  const CHECKBOX = 'CHECKBOX';
8
8
  exports.CHECKBOX = CHECKBOX;
9
9
  const DELETE = 'DELETE';
@@ -20,6 +20,12 @@ 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;
27
+ const COMMA = 'COMMA';
28
+ exports.COMMA = COMMA;
23
29
  const cellTypes = {
24
30
  CUSTOM_ELEM,
25
31
  LINK,
@@ -27,9 +33,15 @@ const cellTypes = {
27
33
  CHECKBOX,
28
34
  DELETE,
29
35
  DEFAULT,
30
- FORMAT_DATA
36
+ FORMAT_DATA,
37
+ COMMA
31
38
  };
32
39
  exports.cellTypes = cellTypes;
40
+ const cellStyles = {
41
+ TRANSFORM,
42
+ EXPAND
43
+ };
44
+ exports.cellStyles = cellStyles;
33
45
  const actionCellTypes = [CHECKBOX, DELETE];
34
46
  exports.actionCellTypes = actionCellTypes;
35
47
  const FORMAT_DATA_CELLS = [FORMAT_BYTES];
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.convertToCSV = convertToCSV;
7
7
  exports.createFileName = createFileName;
8
- exports.downloadJson = downloadJson;
8
+ exports.downloadData = downloadData;
9
9
  var _Dataformat = require("./Dataformat");
10
10
  var _Types = require("./Types");
11
11
  function createFileName(fileName) {
@@ -32,7 +32,7 @@ function createFileName(fileName) {
32
32
  if (seconds < 10) {
33
33
  seconds = "0".concat(seconds);
34
34
  }
35
- return "".concat(fileName, " ").concat(todaysDate, " ").concat(hours, "-").concat(minutes, "-").concat(seconds, '.csv');
35
+ return "".concat(fileName, " ").concat(todaysDate, " ").concat(hours, "-").concat(minutes, "-").concat(seconds);
36
36
  }
37
37
  function convertToCSV(jsonse, keysToInclude, header) {
38
38
  const objArray = jsonse;
@@ -45,8 +45,17 @@ function convertToCSV(jsonse, keysToInclude, header) {
45
45
  if (line !== '') line += ',';
46
46
  if (keyName === 'file_size') {
47
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 if (keyName === 'participant') {
55
+ line += entry[keyName].participant_id;
48
56
  } else {
49
- line += entry[keyName] !== null ? "\"".concat(entry[keyName], "\"") : ' ';
57
+ const newLine = entry[keyName] !== null ? String(entry[keyName]).replace(/"/g, '""') : '';
58
+ line += "\"".concat(newLine, "\"");
50
59
  }
51
60
  return line;
52
61
  });
@@ -60,48 +69,81 @@ function convertToCSV(jsonse, keysToInclude, header) {
60
69
  });
61
70
  return str;
62
71
  }
63
- function downloadJson(tableData, table, downloadFileName) {
72
+ function downloadData(tableData, table, downloadFileName) {
73
+ let format = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'csv';
64
74
  const {
65
75
  columns = []
66
76
  } = table;
67
77
  const filterColumns = columns.filter(_ref => {
68
78
  let {
69
- cellType
79
+ cellType,
80
+ doNotDownload
70
81
  } = _ref;
71
- return !_Types.actionCellTypes.includes(cellType);
82
+ return !_Types.actionCellTypes.includes(cellType) && !doNotDownload;
72
83
  });
73
- const formatDataVal = (0, _Dataformat.formatColumnValues)(filterColumns, tableData);
74
- const jsonse = JSON.stringify(formatDataVal);
75
- const keysToInclude = columns.filter(_ref2 => {
76
- let {
77
- dataField
78
- } = _ref2;
79
- return dataField;
80
- }).map(_ref3 => {
81
- let {
82
- dataField
83
- } = _ref3;
84
- return dataField;
85
- });
86
- const headers = columns.filter(_ref4 => {
87
- let {
88
- dataField
89
- } = _ref4;
90
- return dataField;
91
- }).map(_ref5 => {
92
- let {
93
- header
94
- } = _ref5;
95
- return header;
84
+ let formatDataVal = (0, _Dataformat.formatColumnValues)(filterColumns, tableData);
85
+ formatDataVal = formatDataVal.map(item => {
86
+ const updatedItem = {};
87
+ filterColumns.forEach(_ref2 => {
88
+ let {
89
+ dataField
90
+ } = _ref2;
91
+ updatedItem[dataField] = item[dataField];
92
+ });
93
+ return updatedItem;
96
94
  });
97
- const csv = convertToCSV(jsonse, keysToInclude, headers);
98
- const exportData = new Blob([csv], {
99
- type: 'text/csv'
95
+ let fileContent;
96
+ let fileType;
97
+ if (format === 'json') {
98
+ filterColumns.forEach(column => {
99
+ const mapData = data => {
100
+ var _dataObject$column$da;
101
+ const dataObject = data;
102
+ if (dataObject !== null && dataObject !== void 0 && (_dataObject$column$da = dataObject[column.dataField]) !== null && _dataObject$column$da !== void 0 && _dataObject$column$da.participant_id) {
103
+ var _dataObject$column$da2;
104
+ dataObject[column.dataField] = dataObject === null || dataObject === void 0 ? void 0 : (_dataObject$column$da2 = dataObject[column.dataField]) === null || _dataObject$column$da2 === void 0 ? void 0 : _dataObject$column$da2.participant_id;
105
+ }
106
+ return dataObject;
107
+ };
108
+ formatDataVal = formatDataVal.map(mapData);
109
+ formatDataVal = JSON.parse(JSON.stringify(formatDataVal).split("\"".concat(column.dataField, "\":")).join("\"".concat(column.header, "\":")));
110
+ });
111
+ fileContent = JSON.stringify(formatDataVal);
112
+ fileType = 'application/json';
113
+ } else {
114
+ const jsonse = JSON.stringify(formatDataVal);
115
+ const keysToInclude = filterColumns.filter(_ref3 => {
116
+ let {
117
+ dataField
118
+ } = _ref3;
119
+ return dataField;
120
+ }).map(_ref4 => {
121
+ let {
122
+ dataField
123
+ } = _ref4;
124
+ return dataField;
125
+ });
126
+ const headers = filterColumns.filter(_ref5 => {
127
+ let {
128
+ dataField
129
+ } = _ref5;
130
+ return dataField;
131
+ }).map(_ref6 => {
132
+ let {
133
+ header,
134
+ downloadHeader
135
+ } = _ref6;
136
+ return downloadHeader || header;
137
+ });
138
+ fileContent = convertToCSV(jsonse, keysToInclude, headers);
139
+ fileType = 'text/csv';
140
+ }
141
+ const exportData = new Blob([fileContent], {
142
+ type: fileType
100
143
  });
101
- const JsonURL = window.URL.createObjectURL(exportData);
102
- let tempLink = '';
103
- tempLink = document.createElement('a');
104
- tempLink.setAttribute('href', JsonURL);
144
+ const fileURL = window.URL.createObjectURL(exportData);
145
+ const tempLink = document.createElement('a');
146
+ tempLink.setAttribute('href', fileURL);
105
147
  tempLink.setAttribute('download', createFileName(downloadFileName || ''));
106
148
  document.body.appendChild(tempLink);
107
149
  tempLink.click();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bento-core/table",
3
- "version": "1.0.0-c3dc.25",
3
+ "version": "1.0.0-c3dc.27",
4
4
  "main": "dist/index.js",
5
5
  "scripts": {
6
6
  "build": "cross-env-shell rm -rf dist && NODE_ENV=production BABEL_ENV=es babel src --out-dir dist --copy-files",
@@ -80,13 +80,16 @@ export function downloadData(tableData, table, downloadFileName, format = 'csv')
80
80
 
81
81
  if (format === 'json') {
82
82
  filterColumns.forEach((column) => {
83
- let jsonKey = column.dataField;
84
-
85
- if (column.useKey) {
86
- jsonKey = column.header;
87
- }
83
+ const mapData = (data) => {
84
+ const dataObject = data;
85
+ if (dataObject?.[column.dataField]?.participant_id) {
86
+ dataObject[column.dataField] = dataObject?.[column.dataField]?.participant_id;
87
+ }
88
+ return dataObject;
89
+ };
90
+ formatDataVal = formatDataVal.map(mapData);
88
91
  formatDataVal = JSON.parse(
89
- JSON.stringify(formatDataVal).split(`"${jsonKey}":`).join(`"${column.header}":`),
92
+ JSON.stringify(formatDataVal).split(`"${column.dataField}":`).join(`"${column.header}":`),
90
93
  );
91
94
  });
92
95
  fileContent = JSON.stringify(formatDataVal);