@bento-core/paginated-table 1.0.1-CDS.0 → 1.0.1-CDS.2

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.
Files changed (31) hide show
  1. package/Add_ALL_Files__BLUE_ButtonREADME.md +86 -0
  2. package/Add_Selected_Files_Orange_button_README.md +81 -0
  3. package/{dist/table/README.md → README.md} +124 -3
  4. package/dist/index.js +13 -0
  5. package/dist/table/ClientController.js +1 -0
  6. package/dist/table/PaginatedTable.js +64 -14
  7. package/dist/table/TableService.js +5 -2
  8. package/dist/table/state/Actions.js +21 -3
  9. package/dist/table/state/Reducer.js +12 -0
  10. package/dist/wrapper/WrapperService.js +1 -1
  11. package/dist/wrapper/components/AddAllFiles/AddAllView.js +17 -13
  12. package/dist/wrapper/components/AddSelectedFiles/AddSelectedFilesController.js +24 -5
  13. package/dist/wrapper/components/AddSelectedFiles/AddSelectedFilesView.js +1 -0
  14. package/dist/wrapper/components/AddToCartDialog/AddToCartDialogView.js +11 -3
  15. package/dist/wrapper/components/Snackbar/Snackbar.js +1 -1
  16. package/dist/wrapper/components/util.js +33 -0
  17. package/package.json +3 -3
  18. package/src/index.js +4 -0
  19. package/src/table/ClientController.js +1 -0
  20. package/src/table/PaginatedTable.js +70 -14
  21. package/src/table/TableService.js +5 -2
  22. package/src/table/state/Actions.js +18 -0
  23. package/src/table/state/Reducer.js +17 -0
  24. package/src/wrapper/WrapperService.js +1 -1
  25. package/src/wrapper/components/AddAllFiles/AddAllView.js +16 -10
  26. package/src/wrapper/components/AddSelectedFiles/AddSelectedFilesController.js +20 -4
  27. package/src/wrapper/components/AddSelectedFiles/AddSelectedFilesView.js +1 -1
  28. package/src/wrapper/components/AddToCartDialog/AddToCartDialogView.js +20 -8
  29. package/src/wrapper/components/Snackbar/Snackbar.js +1 -1
  30. package/src/wrapper/components/util.js +26 -0
  31. package/src/table/README.md +0 -253
@@ -12,10 +12,16 @@ var _ContextProvider = require("../../../table/ContextProvider");
12
12
  var _Actions = require("../../../table/state/Actions");
13
13
  var _AddSelectedFilesView = _interopRequireDefault(require("./AddSelectedFilesView"));
14
14
  var _WrapperService = require("../../WrapperService");
15
+ var _util = _interopRequireDefault(require("../util"));
15
16
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
16
17
  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); }
17
18
  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; }
18
19
  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); }
20
+ 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; }
21
+ 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; }
22
+ 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; }
23
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
24
+ 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
25
  const AddSelectedFilesController = props => {
20
26
  const {
21
27
  clsName,
@@ -26,7 +32,10 @@ const AddSelectedFilesController = props => {
26
32
  addFiles,
27
33
  setOpenSnackbar,
28
34
  setAlterDisplay,
29
- client
35
+ client,
36
+ maxFileLimit = 1000,
37
+ applyActiveFilter = false,
38
+ activeFilters = {}
30
39
  } = props;
31
40
  const tableContext = (0, _react.useContext)(_ContextProvider.TableContext);
32
41
  const {
@@ -36,8 +45,13 @@ const AddSelectedFilesController = props => {
36
45
  selectedRows = [],
37
46
  dispatch
38
47
  } = context;
39
- const variables = {};
40
- variables[dataKey] = selectedRows;
48
+ const activeFilterItems = applyActiveFilter ? activeFilters : {};
49
+ const variables = _objectSpread(_objectSpread({
50
+ first: 10000
51
+ }, activeFilterItems), {}, {
52
+ [dataKey]: selectedRows
53
+ });
54
+
41
55
  // add selected files id
42
56
  const addSelectedFiles = () => {
43
57
  const fileIds = (0, _WrapperService.getFilesID)({
@@ -46,9 +60,14 @@ const AddSelectedFilesController = props => {
46
60
  fileIds: selectedRows,
47
61
  query: addFileQuery
48
62
  });
63
+ let filesInCart = 0;
64
+ if (localStorage.getItem('CartFileIds')) {
65
+ const filesId = JSON.parse(localStorage.getItem('CartFileIds')) || [];
66
+ filesInCart = filesId.length;
67
+ }
49
68
  fileIds().then(response => {
50
- const ids = response[responseKeys[0]] || [];
51
- if (ids.length >= 1000) {
69
+ const ids = (0, _util.default)(response, responseKeys);
70
+ if (ids.length + filesInCart >= maxFileLimit) {
52
71
  setAlterDisplay(true);
53
72
  } else {
54
73
  addFiles(ids);
@@ -35,6 +35,7 @@ const ToolTipView = props => {
35
35
  arrow: classes.customArrow
36
36
  }
37
37
  }, /*#__PURE__*/_react.default.createElement("img", {
38
+ className: "add_selected_file_tooltip_icon",
38
39
  src: icon || src,
39
40
  alt: alt
40
41
  }));
@@ -15,7 +15,9 @@ function AddToCartDialogView(props) {
15
15
  onYesClick,
16
16
  onNoClick,
17
17
  cartWillFull = false,
18
- alertMessage
18
+ alertMessage,
19
+ DisplayCustomText,
20
+ activeFilters
19
21
  } = props;
20
22
  if (cartWillFull) {
21
23
  return /*#__PURE__*/_react.default.createElement(_AddToCartDialogAlertView.default, {
@@ -28,9 +30,15 @@ function AddToCartDialogView(props) {
28
30
  open: open,
29
31
  "aria-labelledby": "alert-dialog-title",
30
32
  "aria-describedby": "alert-dialog-description"
31
- }, /*#__PURE__*/_react.default.createElement(_core.DialogContent, null, /*#__PURE__*/_react.default.createElement(_core.DialogContentText, {
33
+ }, /*#__PURE__*/_react.default.createElement(_core.DialogContent, null, DisplayCustomText ? /*#__PURE__*/_react.default.createElement(DisplayCustomText, {
34
+ onYesClick: onYesClick,
35
+ onNoClick: onNoClick,
36
+ activeFilters: activeFilters
37
+ }) : /*#__PURE__*/_react.default.createElement(_core.DialogContentText, {
32
38
  id: "alert-dialog-description"
33
- }, "Are you sure to add All Files", ' ', numberOfFilesSelected, ' ', "to cart")), /*#__PURE__*/_react.default.createElement(_core.DialogActions, null, /*#__PURE__*/_react.default.createElement(_core.Button, {
39
+ }, "Are you sure to add All Files", ' ', numberOfFilesSelected, ' ', "to cart")), /*#__PURE__*/_react.default.createElement(_core.DialogActions, {
40
+ className: "dialog_actions"
41
+ }, /*#__PURE__*/_react.default.createElement(_core.Button, {
34
42
  className: "yesBtn",
35
43
  onClick: () => onYesClick()
36
44
  }, "Yes"), /*#__PURE__*/_react.default.createElement(_core.Button, {
@@ -33,7 +33,7 @@ const SnackbarView = props => {
33
33
  className: "snackBarMessageIcon"
34
34
  }, /*#__PURE__*/_react.default.createElement(_SuccessOutlined.default, null), ' '), /*#__PURE__*/_react.default.createElement("span", {
35
35
  className: "snackBarText"
36
- }, count, ' ', "File(s) successfully added to your cart"))
36
+ }, count, ' ', "File(s) successfully added to My Files."))
37
37
  }));
38
38
  };
39
39
  var _default = SnackbarView;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ /**
8
+ * max two response keys
9
+ * add file query response handler
10
+ * return - list of files name/id
11
+ */
12
+ const addFilesResponseHandler = function addFilesResponseHandler(response) {
13
+ let responseKeys = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
14
+ if (responseKeys.length === 2) {
15
+ const data = response[responseKeys[0]];
16
+ if (data && data.length > 0) {
17
+ const isArray = Array.isArray(data[0][responseKeys[1]]);
18
+ const ids = data.reduce((acc, id) => {
19
+ if (id && id[responseKeys[1]]) {
20
+ // if object convert to array
21
+ const items = isArray ? id[responseKeys[1]] : [id[responseKeys[1]]];
22
+ acc.push(...items);
23
+ }
24
+ return acc;
25
+ }, []);
26
+ return ids;
27
+ }
28
+ return [];
29
+ }
30
+ return response[responseKeys[0]] || [];
31
+ };
32
+ var _default = addFilesResponseHandler;
33
+ exports.default = _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bento-core/paginated-table",
3
- "version": "1.0.1-CDS.0",
3
+ "version": "1.0.1-CDS.2",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -14,7 +14,7 @@
14
14
  },
15
15
  "dependencies": {
16
16
  "@bento-core/cart": "^1.0.1-CDS.0",
17
- "@bento-core/table": "^1.0.0",
17
+ "@bento-core/table": "^1.0.1-CDS.0",
18
18
  "@bento-core/tool-tip": "^1.0.0",
19
19
  "@bento-core/util": "^1.0.0"
20
20
  },
@@ -28,5 +28,5 @@
28
28
  },
29
29
  "author": "CTOS Bento Team",
30
30
  "license": "ISC",
31
- "gitHead": "21403ee7ea6a9e2a757be8bac4b9fb6c5f356686"
31
+ "gitHead": "7b3aaef031248be613da70582863625cf729fcce"
32
32
  }
package/src/index.js CHANGED
@@ -12,7 +12,11 @@ export {
12
12
  onPageChange,
13
13
  onRowSeclect,
14
14
  setTotalRowCount,
15
+ customPaginationAction,
15
16
  } from './table/state/Actions';
16
17
  export { default as Wrapper, types } from './wrapper/Wrapper';
17
18
  export { btnTypes } from './wrapper/components/AddFiles';
18
19
  export { getQueryVariables } from './wrapper/WrapperService';
20
+ export {
21
+ default as ButtonView,
22
+ } from './wrapper/components/ButtonView';
@@ -55,6 +55,7 @@ const TableController = ((props) => {
55
55
  <>
56
56
  <TableView
57
57
  {...props}
58
+ totalRows={tblRows}
58
59
  tableRows={displayRows}
59
60
  />
60
61
  </>
@@ -1,4 +1,8 @@
1
- import React, { useContext, useEffect, useReducer } from 'react';
1
+ import React, {
2
+ useContext,
3
+ useEffect,
4
+ useReducer,
5
+ } from 'react';
2
6
  import ServerTableView from './ServerController';
3
7
  import ClientTableView from './ClientController';
4
8
  import {
@@ -9,6 +13,8 @@ import {
9
13
  onColumnSort,
10
14
  onPageAndTotalCountChange,
11
15
  onColumnViewChange,
16
+ onRowDelete,
17
+ onClearCart,
12
18
  } from './state/Actions';
13
19
  import { TableContext } from './ContextProvider';
14
20
  import reducer from './state/Reducer';
@@ -21,6 +27,7 @@ const PaginatedTable = ({
21
27
  activeTab = true,
22
28
  server = true,
23
29
  tblRows = [],
30
+ paginationOptions = {},
24
31
  }) => {
25
32
  /**
26
33
  * Initailize useReducer state
@@ -74,6 +81,17 @@ const PaginatedTable = ({
74
81
  const handleChangePage = (event, newPage) => {
75
82
  dispatch(onPageChange({ pageNumb: newPage }));
76
83
  };
84
+ // custonize pagination behavior
85
+ const {
86
+ customizeOnRowSelect,
87
+ customizeToggleSelectAll,
88
+ customizeSortByColumn,
89
+ customizeChangePage,
90
+ customizeChangeRowsPerPage,
91
+ customizeColumnViewChange,
92
+ customizeDeleteRow,
93
+ customizeDeleteAllRows,
94
+ } = paginationOptions;
77
95
 
78
96
  /**
79
97
  * update selected Ids
@@ -120,7 +138,7 @@ const PaginatedTable = ({
120
138
  const handleColumnViewChange = (column) => {
121
139
  const columns = table.columns.map((col) => {
122
140
  const updateColumnView = { ...col };
123
- if (col.dataField === column.dataField) {
141
+ if (col.dataField && col.dataField === column.dataField) {
124
142
  updateColumnView.display = !column.display;
125
143
  }
126
144
  return updateColumnView;
@@ -130,6 +148,39 @@ const PaginatedTable = ({
130
148
  columns,
131
149
  }));
132
150
  };
151
+
152
+ /**
153
+ * handle delete row from table
154
+ * remove selected rows
155
+ */
156
+ const onDeleteRow = (row) => {
157
+ let selectedIds = table.selectedRows;
158
+ // if del row is selected remove from selected rows
159
+ if (row.isChecked) {
160
+ const delId = row[table.dataKey];
161
+ selectedIds = table.selectedRows.reduce((acc, id) => {
162
+ if (delId !== id) {
163
+ acc.push(id);
164
+ }
165
+ return acc;
166
+ }, []);
167
+ }
168
+ dispatch(onRowDelete({
169
+ deletedRow: row,
170
+ selectedRows: selectedIds,
171
+ }));
172
+ };
173
+
174
+ /**
175
+ * clear selected rows when all files are removed from myCart/ My file
176
+ */
177
+ const onDeleteAllRows = () => {
178
+ dispatch(onClearCart({
179
+ deletedRows: table.selectedRows,
180
+ selectedRows: [],
181
+ }));
182
+ };
183
+
133
184
  /**
134
185
  * A. client table
135
186
  * table data provide by bento app (tblRows)
@@ -141,12 +192,14 @@ const PaginatedTable = ({
141
192
  <ClientTableView
142
193
  tblRows={tblRows}
143
194
  table={table}
144
- onRowsPerPageChange={handleChangeRowsPerPage}
145
- onPageChange={handleChangePage}
146
- onRowSelectChange={onRowSelectHandler}
147
- onToggleSelectAll={handleToggleSelectAll}
148
- onSortByColumn={handleSortByColumn}
149
- onColumnViewChange={handleColumnViewChange}
195
+ onRowsPerPageChange={customizeChangeRowsPerPage || handleChangeRowsPerPage}
196
+ onPageChange={customizeChangePage || handleChangePage}
197
+ onRowSelectChange={customizeOnRowSelect || onRowSelectHandler}
198
+ onToggleSelectAll={customizeToggleSelectAll || handleToggleSelectAll}
199
+ onSortByColumn={customizeSortByColumn || handleSortByColumn}
200
+ onColumnViewChange={customizeColumnViewChange || handleColumnViewChange}
201
+ onDeleteRow={customizeDeleteRow || onDeleteRow}
202
+ onDeleteAllFiles={customizeDeleteAllRows || onDeleteAllRows}
150
203
  themeConfig={themeConfig}
151
204
  />
152
205
  </>
@@ -170,12 +223,15 @@ const PaginatedTable = ({
170
223
  queryVariables={queryVariables}
171
224
  totalRowCount={totalRowCount}
172
225
  table={table}
173
- onRowsPerPageChange={handleChangeRowsPerPage}
174
- onPageChange={handleChangePage}
175
- onRowSelectChange={onRowSelectHandler}
176
- onToggleSelectAll={handleToggleSelectAll}
177
- onSortByColumn={handleSortByColumn}
178
- onColumnViewChange={handleColumnViewChange}
226
+ server={server}
227
+ onRowsPerPageChange={customizeChangeRowsPerPage || handleChangeRowsPerPage}
228
+ onPageChange={customizeChangePage || handleChangePage}
229
+ onRowSelectChange={customizeOnRowSelect || onRowSelectHandler}
230
+ onToggleSelectAll={customizeToggleSelectAll || handleToggleSelectAll}
231
+ onSortByColumn={customizeSortByColumn || handleSortByColumn}
232
+ onColumnViewChange={customizeColumnViewChange || handleColumnViewChange}
233
+ onDeleteRow={customizeDeleteRow || onDeleteRow}
234
+ onDeleteAllFiles={customizeDeleteAllRows || onDeleteAllRows}
179
235
  themeConfig={themeConfig}
180
236
  />
181
237
  </>
@@ -8,10 +8,13 @@ import { useEffect, useState } from 'react';
8
8
  * @returns
9
9
  */
10
10
  export const setSelectedRows = (rows = [], table) => {
11
- const { selectedRows, dataKey } = table;
11
+ const { selectedRows, dataKey, deletedRow } = table;
12
+ // checked selected row if deleted
13
+ const checkedRows = deletedRow?.isChecked
14
+ ? [...selectedRows, deletedRow[dataKey]] : selectedRows;
12
15
  const updateRows = [...rows].map((row) => {
13
16
  const isChecked = dataKey
14
- ? (selectedRows.indexOf(row[dataKey]) !== -1) : false;
17
+ ? (checkedRows.indexOf(row[dataKey]) !== -1) : false;
15
18
  return { ...row, isChecked };
16
19
  }, []);
17
20
  return updateRows;
@@ -7,6 +7,9 @@ export const actionTypes = {
7
7
  ON_ROW_SELECT: 'ON_ROW_SELECT',
8
8
  SET_TOTAL_ROW_COUNT: 'SET_TOTAL_ROW_COUNT',
9
9
  ON_PAGE_AND_TOTAL_COUNT_CHANGE: 'ON_PAGE_AND_TOTAL_COUNT_CHANGE',
10
+ CUSTOMIZE_PAGINATION_ACTION: 'CUSTOMIZE_PAGINATION_ACTION',
11
+ ON_ROWS_DELETE: 'ON_ROWS_DELETE',
12
+ ON_ROW_DELETE: 'ON_ROW_DELETE',
10
13
  };
11
14
 
12
15
  export const onColumnViewChange = (columns) => ({
@@ -48,3 +51,18 @@ export const setTotalRowCount = (count) => ({
48
51
  type: actionTypes.SET_TOTAL_ROW_COUNT,
49
52
  payload: count,
50
53
  });
54
+
55
+ export const customPaginationAction = (value) => ({
56
+ type: actionTypes.CUSTOMIZE_PAGINATION_ACTION,
57
+ payload: value,
58
+ });
59
+
60
+ export const onClearCart = (value) => ({
61
+ type: actionTypes.ON_ROWS_DELETE,
62
+ payload: value,
63
+ });
64
+
65
+ export const onRowDelete = (value) => ({
66
+ type: actionTypes.ON_ROW_DELETE,
67
+ payload: value,
68
+ });
@@ -3,6 +3,11 @@ import { actionTypes } from './Actions';
3
3
  const reducer = (state, action) => {
4
4
  const { type, payload } = action;
5
5
  switch (type) {
6
+ case actionTypes.CUSTOMIZE_PAGINATION_ACTION:
7
+ return {
8
+ ...state,
9
+ ...payload,
10
+ };
6
11
  case actionTypes.ON_COLUMN_SORT:
7
12
  return {
8
13
  ...state,
@@ -41,6 +46,18 @@ const reducer = (state, action) => {
41
46
  ...state,
42
47
  totalRowCount: payload,
43
48
  };
49
+ case actionTypes.ON_ROW_DELETE:
50
+ return {
51
+ ...state,
52
+ deletedRow: payload.deletedRow,
53
+ selectedRows: payload.selectedRows,
54
+ };
55
+ case actionTypes.ON_ROWS_DELETE:
56
+ return {
57
+ ...state,
58
+ deletedRows: payload.deleteRows,
59
+ selectedRows: payload.selectedRows,
60
+ };
44
61
  default:
45
62
  return state;
46
63
  }
@@ -3,7 +3,7 @@
3
3
  */
4
4
  export const getQueryVariables = (variables) => {
5
5
  const queryVariables = { ...variables };
6
- queryVariables.first = 100000;
6
+ queryVariables.first = 10000;
7
7
  return queryVariables;
8
8
  };
9
9
 
@@ -3,6 +3,8 @@ import { Button } from '@material-ui/core';
3
3
  import clsx from 'clsx';
4
4
  import { getFilesID } from '../../WrapperService';
5
5
  import AddToCartDialogView from '../AddToCartDialog/AddToCartDialogView';
6
+ import ToolTipView from '../TooltipView';
7
+ import addFilesResponseHandler from '../util';
6
8
 
7
9
  const AddAllFilesComponent = (props) => {
8
10
  const {
@@ -16,6 +18,9 @@ const AddAllFilesComponent = (props) => {
16
18
  setAlterDisplay,
17
19
  setOpenSnackbar,
18
20
  client,
21
+ tooltipCofig,
22
+ maxFileLimit = 1000,
23
+ DisplayCustomText,
19
24
  } = props;
20
25
  /**
21
26
  * conditionally display dialog view
@@ -33,19 +38,17 @@ const AddAllFilesComponent = (props) => {
33
38
  variables: activeFilters,
34
39
  query: addFileQuery,
35
40
  });
41
+ let filesInCart = 0;
42
+ if (localStorage.getItem('CartFileIds')) {
43
+ const filesId = JSON.parse(localStorage.getItem('CartFileIds')) || [];
44
+ filesInCart = filesId.length;
45
+ }
46
+
36
47
  fileIds().then((response) => {
37
48
  const data = response[responseKeys[0]];
38
49
  if (data && data.length > 0) {
39
- const isArray = Array.isArray(data[0][responseKeys[1]]);
40
- const ids = data.reduce((acc, id) => {
41
- if (id && id[responseKeys[1]]) {
42
- // if object convert to array
43
- const items = isArray ? id[responseKeys[1]] : [id[responseKeys[1]]];
44
- acc.push(...items);
45
- }
46
- return acc;
47
- }, []);
48
- if (ids.length > 1000) {
50
+ const ids = addFilesResponseHandler(response, responseKeys);
51
+ if (ids.length + filesInCart > maxFileLimit) {
49
52
  setAlterDisplay(true);
50
53
  } else {
51
54
  setOpen(true);
@@ -76,10 +79,13 @@ const AddAllFilesComponent = (props) => {
76
79
  >
77
80
  {title}
78
81
  </Button>
82
+ {tooltipCofig && (<ToolTipView {...props} />)}
79
83
  <AddToCartDialogView
80
84
  open={openAddDialog}
81
85
  onYesClick={addFilesToCart}
82
86
  onNoClick={toggleOpen}
87
+ DisplayCustomText={DisplayCustomText}
88
+ activeFilters={activeFilters}
83
89
  />
84
90
  </>
85
91
  );
@@ -6,6 +6,7 @@ import { TableContext } from '../../../table/ContextProvider';
6
6
  import { onRowSeclect } from '../../../table/state/Actions';
7
7
  import AddSelectedFileComponent from './AddSelectedFilesView';
8
8
  import { getFilesID } from '../../WrapperService';
9
+ import addFilesResponseHandler from '../util';
9
10
 
10
11
  const AddSelectedFilesController = (props) => {
11
12
  const {
@@ -18,6 +19,9 @@ const AddSelectedFilesController = (props) => {
18
19
  setOpenSnackbar,
19
20
  setAlterDisplay,
20
21
  client,
22
+ maxFileLimit = 1000,
23
+ applyActiveFilter = false,
24
+ activeFilters = {},
21
25
  } = props;
22
26
 
23
27
  const tableContext = useContext(TableContext);
@@ -26,8 +30,15 @@ const AddSelectedFilesController = (props) => {
26
30
  selectedRows = [],
27
31
  dispatch,
28
32
  } = context;
29
- const variables = {};
30
- variables[dataKey] = selectedRows;
33
+
34
+ const activeFilterItems = applyActiveFilter ? activeFilters : {};
35
+
36
+ const variables = {
37
+ first: 10000,
38
+ ...activeFilterItems,
39
+ [dataKey]: selectedRows,
40
+ };
41
+
31
42
  // add selected files id
32
43
  const addSelectedFiles = () => {
33
44
  const fileIds = getFilesID({
@@ -36,10 +47,15 @@ const AddSelectedFilesController = (props) => {
36
47
  fileIds: selectedRows,
37
48
  query: addFileQuery,
38
49
  });
50
+ let filesInCart = 0;
51
+ if (localStorage.getItem('CartFileIds')) {
52
+ const filesId = JSON.parse(localStorage.getItem('CartFileIds')) || [];
53
+ filesInCart = filesId.length;
54
+ }
39
55
 
40
56
  fileIds().then((response) => {
41
- const ids = response[responseKeys[0]] || [];
42
- if (ids.length >= 1000) {
57
+ const ids = addFilesResponseHandler(response, responseKeys);
58
+ if (ids.length + filesInCart >= maxFileLimit) {
43
59
  setAlterDisplay(true);
44
60
  } else {
45
61
  addFiles(ids);
@@ -30,7 +30,7 @@ export const ToolTipView = (props) => {
30
30
  arrow: classes.customArrow,
31
31
  }}
32
32
  >
33
- <img src={icon || src} alt={alt} />
33
+ <img className="add_selected_file_tooltip_icon" src={icon || src} alt={alt} />
34
34
  </ToolTip>
35
35
  );
36
36
  };
@@ -12,6 +12,8 @@ function AddToCartDialogView(props) {
12
12
  onNoClick,
13
13
  cartWillFull = false,
14
14
  alertMessage,
15
+ DisplayCustomText,
16
+ activeFilters,
15
17
  } = props;
16
18
 
17
19
  if (cartWillFull) {
@@ -32,15 +34,25 @@ function AddToCartDialogView(props) {
32
34
  aria-describedby="alert-dialog-description"
33
35
  >
34
36
  <DialogContent>
35
- <DialogContentText id="alert-dialog-description">
36
- Are you sure to add All Files
37
- {' '}
38
- {numberOfFilesSelected}
39
- {' '}
40
- to cart
41
- </DialogContentText>
37
+ {
38
+ DisplayCustomText ? (
39
+ <DisplayCustomText
40
+ onYesClick={onYesClick}
41
+ onNoClick={onNoClick}
42
+ activeFilters={activeFilters}
43
+ />
44
+ ) : (
45
+ <DialogContentText id="alert-dialog-description">
46
+ Are you sure to add All Files
47
+ {' '}
48
+ {numberOfFilesSelected}
49
+ {' '}
50
+ to cart
51
+ </DialogContentText>
52
+ )
53
+ }
42
54
  </DialogContent>
43
- <DialogActions>
55
+ <DialogActions className="dialog_actions">
44
56
  <Button className="yesBtn" onClick={() => onYesClick()}>
45
57
  Yes
46
58
  </Button>
@@ -31,7 +31,7 @@ const SnackbarView = (props) => {
31
31
  <span className="snackBarText">
32
32
  {count}
33
33
  {' '}
34
- File(s) successfully added to your cart
34
+ File(s) successfully added to My Files.
35
35
  </span>
36
36
  </div>
37
37
  )}
@@ -0,0 +1,26 @@
1
+ /**
2
+ * max two response keys
3
+ * add file query response handler
4
+ * return - list of files name/id
5
+ */
6
+ const addFilesResponseHandler = (response, responseKeys = []) => {
7
+ if (responseKeys.length === 2) {
8
+ const data = response[responseKeys[0]];
9
+ if (data && data.length > 0) {
10
+ const isArray = Array.isArray(data[0][responseKeys[1]]);
11
+ const ids = data.reduce((acc, id) => {
12
+ if (id && id[responseKeys[1]]) {
13
+ // if object convert to array
14
+ const items = isArray ? id[responseKeys[1]] : [id[responseKeys[1]]];
15
+ acc.push(...items);
16
+ }
17
+ return acc;
18
+ }, []);
19
+ return ids;
20
+ }
21
+ return [];
22
+ }
23
+ return response[responseKeys[0]] || [];
24
+ };
25
+
26
+ export default addFilesResponseHandler;