@bento-core/table 1.0.0-c3dc.30 → 1.0.0-c3dc.32

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.
@@ -30,7 +30,8 @@ const defaultTheme = () => ({
30
30
  MuiList: {
31
31
  root: {
32
32
  '&.viewColumnList': {
33
- padding: '8px 20px 8px 10px'
33
+ padding: '8px 20px 8px 20px',
34
+ bottom: '5px'
34
35
  }
35
36
  }
36
37
  },
@@ -58,8 +59,11 @@ const defaultTheme = () => ({
58
59
  },
59
60
  MuiSvgIcon: {
60
61
  root: {
61
- '&.checkBoxIcon': {
62
- color: '#0B3556'
62
+ '&.checkBox': {
63
+ padding: '0px 5px 0px 0px',
64
+ position: 'absolute',
65
+ top: '0px',
66
+ left: '-10px'
63
67
  }
64
68
  }
65
69
  }
@@ -19,15 +19,15 @@ function _toPrimitive(input, hint) { if (typeof input !== "object" || input ===
19
19
  const downloadAreaStyle = {
20
20
  display: 'flex',
21
21
  borderTop: '1px solid #8A7F7C',
22
- paddingRight: '41px'
22
+ paddingRight: '48px'
23
23
  };
24
24
  const ExtendedView = _ref => {
25
25
  let {
26
26
  table,
27
27
  onColumnViewChange,
28
+ onAllColumnViewChange,
28
29
  onRowsPerPageChange,
29
30
  onPageChange,
30
- numSelected = 0,
31
31
  customTheme,
32
32
  queryVariables
33
33
  } = _ref;
@@ -48,11 +48,7 @@ const ExtendedView = _ref => {
48
48
  });
49
49
  return /*#__PURE__*/_react.default.createElement(_core.ThemeProvider, {
50
50
  theme: themeConfig
51
- }, numSelected === 0 && (download || manageViewColumns) && /*#__PURE__*/_react.default.createElement(_ManageColumnView.default, {
52
- table: table,
53
- manageViewColumns: manageViewColumns,
54
- onColumnViewChange: onColumnViewChange
55
- }), pagination && /*#__PURE__*/_react.default.createElement("div", {
51
+ }, pagination && /*#__PURE__*/_react.default.createElement("div", {
56
52
  className: "downloadArea",
57
53
  style: table.paginationCustomStyle && table.paginationCustomStyle.topPagination ? table.paginationCustomStyle.topPagination : downloadAreaStyle
58
54
  }, table.showSearchBox && /*#__PURE__*/_react.default.createElement(table.SearchBox, null), /*#__PURE__*/_react.default.createElement(_CustomPagination.default, {
@@ -66,7 +62,12 @@ const ExtendedView = _ref => {
66
62
  onRowsPerPageChange: onRowsPerPageChange,
67
63
  queryVariables: queryVariables,
68
64
  table: table
69
- }), table.showDownloadIcon !== false && /*#__PURE__*/_react.default.createElement(_DownloadButtonView.default, {
65
+ }), manageViewColumns && /*#__PURE__*/_react.default.createElement(_ManageColumnView.default, {
66
+ table: table,
67
+ manageViewColumns: manageViewColumns,
68
+ onColumnViewChange: onColumnViewChange,
69
+ onAllColumnViewChange: onAllColumnViewChange
70
+ }), download && /*#__PURE__*/_react.default.createElement(_DownloadButtonView.default, {
70
71
  count: table.totalRowCount || 0,
71
72
  queryVariables: queryVariables,
72
73
  table: table,
package/dist/TableView.js CHANGED
@@ -11,8 +11,10 @@ var _CustomPagination = _interopRequireDefault(require("./pagination/CustomPagin
11
11
  var _CustomTblBody = _interopRequireDefault(require("./body/CustomTblBody"));
12
12
  var _CustomToolbar = _interopRequireDefault(require("./toolbar/CustomToolbar"));
13
13
  var _DownloadButtonView = _interopRequireDefault(require("./toolbar/DownloadButtonView"));
14
+ var _ManageColumnView = _interopRequireDefault(require("./toolbar/ManageColumnView"));
14
15
  var _DisplayErrMsg = _interopRequireDefault(require("./errMsg/DisplayErrMsg"));
15
16
  var _ExtendedView = _interopRequireDefault(require("./ExtendedView"));
17
+ var _DefaultThemConfig = _interopRequireDefault(require("./DefaultThemConfig"));
16
18
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
19
  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; }
18
20
  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; }
@@ -36,7 +38,7 @@ const CustomTableContainer = props => {
36
38
  const downloadAreaStyle = {
37
39
  display: 'flex',
38
40
  borderTop: '1px solid #8A7F7C',
39
- paddingRight: '41px'
41
+ paddingRight: '48px'
40
42
  };
41
43
  const cartDownloadAreaStyle = {
42
44
  display: 'flex',
@@ -45,7 +47,7 @@ const cartDownloadAreaStyle = {
45
47
  paddingRight: '40px'
46
48
  };
47
49
  const TableView = _ref => {
48
- var _table$selectedRows, _table$selectedRows2;
50
+ var _table$selectedRows;
49
51
  let {
50
52
  tableRows = [],
51
53
  table,
@@ -56,19 +58,28 @@ const TableView = _ref => {
56
58
  totalRowCount,
57
59
  onSortByColumn,
58
60
  onColumnViewChange,
61
+ onAllColumnViewChange,
59
62
  themeConfig = {},
60
63
  queryVariables
61
64
  } = _ref;
65
+ const {
66
+ extendedViewConfig
67
+ } = table;
68
+ const {
69
+ manageViewColumns = false,
70
+ download = false,
71
+ downloadButtonConfig
72
+ } = extendedViewConfig;
62
73
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_ExtendedView.default, {
63
74
  table: table,
64
75
  onColumnViewChange: onColumnViewChange,
76
+ onAllColumnViewChange: onAllColumnViewChange,
65
77
  onRowsPerPageChange: onRowsPerPageChange,
66
78
  onPageChange: onPageChange,
67
- numSelected: (table === null || table === void 0 ? void 0 : (_table$selectedRows = table.selectedRows) === null || _table$selectedRows === void 0 ? void 0 : _table$selectedRows.length) || 0,
68
79
  customTheme: themeConfig.extendedView,
69
80
  queryVariables: queryVariables
70
81
  }), /*#__PURE__*/_react.default.createElement(_CustomToolbar.default, {
71
- numSelected: (table === null || table === void 0 ? void 0 : (_table$selectedRows2 = table.selectedRows) === null || _table$selectedRows2 === void 0 ? void 0 : _table$selectedRows2.length) || 0,
82
+ numSelected: (table === null || table === void 0 ? void 0 : (_table$selectedRows = table.selectedRows) === null || _table$selectedRows === void 0 ? void 0 : _table$selectedRows.length) || 0,
72
83
  table: table,
73
84
  onColumnViewChange: onColumnViewChange,
74
85
  customTheme: themeConfig.toolbar
@@ -89,7 +100,11 @@ const TableView = _ref => {
89
100
  }))), tableRows.length === 0 && /*#__PURE__*/_react.default.createElement(_DisplayErrMsg.default, {
90
101
  customTheme: themeConfig.displayErr,
91
102
  table: table
92
- }), /*#__PURE__*/_react.default.createElement("div", {
103
+ }), /*#__PURE__*/_react.default.createElement(_core.ThemeProvider, {
104
+ theme: (0, _core.createTheme)({
105
+ overrides: _objectSpread(_objectSpread({}, (0, _DefaultThemConfig.default)()), themeConfig.extendedView)
106
+ })
107
+ }, /*#__PURE__*/_react.default.createElement("div", {
93
108
  className: "downloadArea",
94
109
  style: table.paginationAPIField === 'filesInList' ? cartDownloadAreaStyle : table.paginationCustomStyle && table.paginationCustomStyle.bottomPagination ? table.paginationCustomStyle.bottomPagination : downloadAreaStyle
95
110
  }, /*#__PURE__*/_react.default.createElement(_CustomPagination.default, {
@@ -101,12 +116,17 @@ const TableView = _ref => {
101
116
  page: table.page || 0,
102
117
  onPageChange: onPageChange,
103
118
  onRowsPerPageChange: onRowsPerPageChange
104
- }), table.showDownloadIcon !== false && /*#__PURE__*/_react.default.createElement(_DownloadButtonView.default, {
119
+ }), manageViewColumns && /*#__PURE__*/_react.default.createElement(_ManageColumnView.default, {
120
+ table: table,
121
+ manageViewColumns: manageViewColumns,
122
+ onColumnViewChange: onColumnViewChange,
123
+ onAllColumnViewChange: onAllColumnViewChange
124
+ }), download && /*#__PURE__*/_react.default.createElement(_DownloadButtonView.default, {
105
125
  count: table.totalRowCount || 0,
106
126
  queryVariables: queryVariables,
107
127
  table: table,
108
- buttonConfig: table.extendedViewConfig.downloadButtonConfig
109
- })));
128
+ buttonConfig: downloadButtonConfig
129
+ }))));
110
130
  };
111
131
  var _default = TableView;
112
132
  exports.default = _default;
@@ -46,12 +46,12 @@ const CPIModal = _ref => {
46
46
  } = _ref;
47
47
  const [sortBy, setSortBy] = (0, _react.useState)('associated_id');
48
48
  const [sortOrder, setSortOrder] = (0, _react.useState)('asc');
49
- const [data, setData] = (0, _react.useState)(row.cpi_data);
50
- (0, _react.useEffect)(() => {
51
- setData(row.cpi_data);
52
- }, [row]);
49
+ const [data, setData] = (0, _react.useState)(() => {
50
+ const result = row.cpi_data;
51
+ return result;
52
+ });
53
53
  const sortingData = (column, newOrder) => {
54
- const sortedData = [...data].sort((a, b) => a[column].localeCompare(b[column]));
54
+ const sortedData = data.sort((a, b) => a[column].localeCompare(b[column]));
55
55
  if (newOrder === 'desc') {
56
56
  return sortedData.reverse();
57
57
  }
@@ -27,14 +27,16 @@ const DownloadButton = _ref => {
27
27
  let {
28
28
  count,
29
29
  queryVariables,
30
- table
30
+ table,
31
+ buttonConfig
31
32
  } = _ref;
32
33
  const [listDisplay, setListDisplay] = (0, _react.useState)('none');
34
+ const [isDownloading, setIsDownloading] = (0, _react.useState)(false);
33
35
  const dropdownSelection = (0, _react.useRef)(null);
34
36
  const useOutsideAlerter = ref => {
35
37
  (0, _react.useEffect)(() => {
36
38
  function handleClickOutside(event) {
37
- if (!(event.target.getAttribute('id') && event.target.getAttribute('id').includes('dropdownListItem'))) {
39
+ if (ref.current && !ref.current.contains(event.target)) {
38
40
  setListDisplay('none');
39
41
  }
40
42
  }
@@ -42,13 +44,14 @@ const DownloadButton = _ref => {
42
44
  return () => {
43
45
  document.removeEventListener('mousedown', handleClickOutside);
44
46
  };
45
- }, [ref]);
47
+ }, []);
46
48
  };
47
49
  useOutsideAlerter(dropdownSelection);
48
50
  if (table.paginationAPIField === 'filesInList') {
49
51
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null);
50
52
  }
51
53
  const client = (0, _client.useApolloClient)();
54
+ const downloadLimit = buttonConfig === null || buttonConfig === void 0 ? void 0 : buttonConfig.downloadLimit;
52
55
  function cleanData(result) {
53
56
  function hasHTMLTags(str) {
54
57
  const htmlTagPattern = /<\/?[a-z][\s\S]*>/i; // Regex to match HTML tags
@@ -69,57 +72,146 @@ const DownloadButton = _ref => {
69
72
  });
70
73
  return cleanedResult;
71
74
  }
72
- async function downloadSCSVFile() {
75
+
76
+ // --- retry helper (recursive ESLINT no await-in-loop — we want this to be sequential) ---
77
+ async function retry(fn) {
78
+ let retries = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 3;
79
+ let attempt = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
80
+ try {
81
+ return await fn();
82
+ } catch (err) {
83
+ if (attempt >= retries) throw err;
84
+ return retry(fn, retries, attempt + 1);
85
+ }
86
+ }
87
+ async function fetchCountWithRetry() {
73
88
  const {
74
- query,
75
- paginationAPIField
89
+ statsQuery,
90
+ statsQueryName,
91
+ statsField
76
92
  } = table;
77
- const result = await client.query({
78
- query,
79
- variables: _objectSpread(_objectSpread({}, queryVariables), {}, {
80
- page: 0,
81
- first: 10000,
82
- order_by: table.sortBy,
83
- sort_direction: table.sortOrder
84
- })
85
- }).then(response => {
86
- if (paginationAPIField && response && response.data) {
87
- return response.data[paginationAPIField];
88
- }
89
- return response.data;
90
- });
91
- (0, _downloadTable.downloadData)(cleanData(result), table, table.downloadFileName, 'csv');
93
+ return retry(() => client.query({
94
+ query: statsQuery,
95
+ variables: queryVariables
96
+ }).then(_ref2 => {
97
+ let {
98
+ data
99
+ } = _ref2;
100
+ const queryResponse = data[statsQueryName];
101
+ return {
102
+ totalCount: queryResponse[statsField],
103
+ pageSize: downloadLimit || queryResponse.pageSize || 5000
104
+ };
105
+ }));
92
106
  }
93
- async function downloadJsonFile() {
107
+ async function fetchDownloadWithRetry(variables) {
94
108
  const {
95
109
  query,
96
110
  paginationAPIField
97
111
  } = table;
98
- const result = await client.query({
112
+ return retry(() => client.query({
99
113
  query,
100
- variables: _objectSpread(_objectSpread({}, queryVariables), {}, {
101
- page: 0,
102
- first: 10000,
103
- order_by: table.sortBy,
104
- sort_direction: table.sortOrder
105
- })
114
+ variables
106
115
  }).then(response => {
107
116
  if (paginationAPIField && response && response.data) {
108
117
  return response.data[paginationAPIField];
109
118
  }
110
119
  return response.data;
111
- });
112
- (0, _downloadTable.downloadData)(cleanData(result), table, table.downloadFileName, 'json');
120
+ }));
121
+ }
122
+ async function downloadFile(type) {
123
+ setIsDownloading(true);
124
+ try {
125
+ const {
126
+ totalCount,
127
+ pageSize
128
+ } = await fetchCountWithRetry();
129
+ let completedEntries = 0;
130
+ let allData = [];
131
+ while (completedEntries < totalCount) {
132
+ const variables = _objectSpread(_objectSpread({}, queryVariables), {}, {
133
+ offset: Math.floor(completedEntries / pageSize) * pageSize,
134
+ first: Math.min(pageSize, totalCount - completedEntries),
135
+ order_by: table.sortBy,
136
+ sort_direction: table.sortOrder
137
+ });
138
+ // eslint-disable-next-line no-await-in-loop
139
+ const data = await fetchDownloadWithRetry(variables);
140
+ allData = allData.concat(data);
141
+ completedEntries += data.length;
142
+ }
143
+ (0, _downloadTable.downloadData)(cleanData(allData), table, table.downloadFileName, type);
144
+ } catch (error) {
145
+ console.error('Error fetching count:', error);
146
+ } finally {
147
+ setIsDownloading(false);
148
+ }
149
+ }
150
+ async function downloadFileParallel(type) {
151
+ let concurrency = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 5;
152
+ setIsDownloading(true);
153
+ try {
154
+ const {
155
+ totalCount,
156
+ pageSize
157
+ } = await fetchCountWithRetry();
158
+ const totalChunks = Math.ceil(totalCount / pageSize);
159
+ const results = new Array(totalChunks);
160
+ for (let i = 0; i < totalChunks; i += concurrency) {
161
+ const batch = [];
162
+ for (let j = i; j < Math.min(i + concurrency, totalChunks); j += 1) {
163
+ const offset = j * pageSize;
164
+ const first = Math.min(pageSize, totalCount - offset);
165
+ const variables = _objectSpread(_objectSpread({}, queryVariables), {}, {
166
+ offset,
167
+ first,
168
+ order_by: table.sortBy,
169
+ sort_direction: table.sortOrder
170
+ });
171
+ batch.push(fetchDownloadWithRetry(variables).then(data => ({
172
+ index: j,
173
+ data
174
+ })));
175
+ }
176
+
177
+ // eslint-disable-next-line no-await-in-loop
178
+ const batchResults = await Promise.all(batch);
179
+ batchResults.forEach(_ref3 => {
180
+ let {
181
+ index,
182
+ data
183
+ } = _ref3;
184
+ results[index] = data;
185
+ });
186
+ }
187
+ const allData = results.flat();
188
+ (0, _downloadTable.downloadData)(cleanData(allData), table, table.downloadFileName, type);
189
+ } catch (error) {
190
+ console.error('Error fetching count:', error);
191
+ } finally {
192
+ setIsDownloading(false);
193
+ }
113
194
  }
114
195
  const downloadTableCSV = (0, _react.useCallback)(() => {
115
- downloadSCSVFile();
196
+ if (isDownloading) return;
197
+ if (table.asyncDownload) {
198
+ downloadFileParallel('csv');
199
+ } else {
200
+ downloadFile('csv');
201
+ }
116
202
  setListDisplay('none');
117
- }, [queryVariables, table]);
203
+ }, [queryVariables, table, isDownloading]);
118
204
  const downloadTableJson = (0, _react.useCallback)(() => {
119
- downloadJsonFile();
205
+ if (isDownloading) return;
206
+ if (table.asyncDownload) {
207
+ downloadFileParallel('json');
208
+ } else {
209
+ downloadFile('json');
210
+ }
120
211
  setListDisplay('none');
121
- }, [queryVariables, table]);
212
+ }, [queryVariables, table, isDownloading]);
122
213
  const handleClickButton = () => {
214
+ if (isDownloading) return;
123
215
  if (listDisplay === 'none') {
124
216
  setListDisplay('block');
125
217
  } else {
@@ -128,25 +220,24 @@ const DownloadButton = _ref => {
128
220
  };
129
221
  const useStyles = (0, _core.makeStyles)({
130
222
  dropdown: {
131
- width: '60px',
132
- height: '25px',
133
- marginTop: '8px',
223
+ width: '48px',
224
+ height: '36px',
134
225
  paddingLeft: '5px',
135
- border: '0.75px solid #606060',
226
+ border: listDisplay === 'none' ? '0.75px solid #606060' : '1.5px solid #5666BD',
136
227
  borderRadius: '5px',
137
228
  display: 'inline-block',
138
229
  position: 'relative',
139
- alignSelf: 'center'
230
+ margin: '5px 0px'
140
231
  },
141
232
  dropdownList: {
142
233
  display: 'block',
143
234
  position: 'absolute',
144
235
  width: '60px',
145
- marginTop: '3px',
146
- marginLeft: '-5px',
236
+ top: '38px',
237
+ left: '-13.5px',
147
238
  overflow: 'auto',
148
- zIndex: '20',
149
- border: '1.5px solid #41545E',
239
+ zIndex: '11',
240
+ border: '1.5px solid #5666BD',
150
241
  borderRadius: '5px',
151
242
  background: '#ffffff'
152
243
  },
@@ -157,33 +248,48 @@ const DownloadButton = _ref => {
157
248
  fontWeight: 400,
158
249
  lineHeight: '21px',
159
250
  '&:hover': {
160
- background: '#D7D7D7',
251
+ background: '#C9CFF4',
161
252
  cursor: 'pointer'
162
253
  }
163
254
  },
164
255
  arrowdownIcon: {
165
- marginLeft: '5px',
166
- fill: '#606060'
256
+ fill: '#606060',
257
+ marginTop: '2px',
258
+ width: '20px',
259
+ height: '20px'
167
260
  },
168
261
  arrowdownIconDisabled: {
169
262
  marginLeft: '5px',
170
263
  fill: '#00000042'
264
+ },
265
+ tooltip: {
266
+ marginTop: '5px'
171
267
  }
172
268
  });
173
269
  const classes = useStyles();
174
270
  return /*#__PURE__*/_react.default.createElement("div", {
175
- className: classes.dropdown
271
+ ref: dropdownSelection,
272
+ className: classes.dropdown,
273
+ style: isDownloading ? {
274
+ cursor: 'wait'
275
+ } : {}
176
276
  }, /*#__PURE__*/_react.default.createElement(_core.Tooltip, {
177
- title: table.downloadButtonTooltipText || 'Download filtered results'
277
+ title: isDownloading ? 'Download in progress...' : table.downloadButtonTooltipText || 'Download filtered results',
278
+ className: classes.tooltip
178
279
  }, count !== 0 ? /*#__PURE__*/_react.default.createElement(_core.IconButton, {
179
280
  onClick: handleClickButton,
180
281
  style: {
181
- padding: '0'
182
- }
282
+ padding: '0',
283
+ backgroundColor: 'transparent'
284
+ },
285
+ disabled: isDownloading
183
286
  }, /*#__PURE__*/_react.default.createElement(_icons.CloudDownload, null), /*#__PURE__*/_react.default.createElement(_KeyboardArrowDownOutlined.default, {
184
287
  className: classes.arrowdownIcon
185
288
  })) : /*#__PURE__*/_react.default.createElement(_core.IconButton, {
186
- disabled: true
289
+ disabled: true,
290
+ style: {
291
+ backgroundColor: 'transparent'
292
+ }
187
293
  }, /*#__PURE__*/_react.default.createElement(_icons.CloudDownload, null), /*#__PURE__*/_react.default.createElement(_KeyboardArrowDownOutlined.default, {
188
294
  className: classes.arrowdownIconDisabled
189
295
  }))), /*#__PURE__*/_react.default.createElement("div", {