@bento-core/paginated-table 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/babel.config.json +20 -0
- package/dist/index.js +104 -0
- package/dist/table/ClientController.js +64 -0
- package/dist/table/ContextProvider.js +31 -0
- package/dist/table/PaginatedTable.js +190 -0
- package/dist/table/README.md +253 -0
- package/dist/table/ServerController.js +42 -0
- package/dist/table/TableService.js +103 -0
- package/dist/table/state/Actions.js +57 -0
- package/dist/table/state/Reducer.js +53 -0
- package/dist/wrapper/Wrapper.js +167 -0
- package/dist/wrapper/WrapperService.js +36 -0
- package/dist/wrapper/components/AddAllFiles/AddAllView.js +88 -0
- package/dist/wrapper/components/AddFiles.js +65 -0
- package/dist/wrapper/components/AddSelectedFiles/AddSelectedFilesController.js +68 -0
- package/dist/wrapper/components/AddSelectedFiles/AddSelectedFilesView.js +62 -0
- package/dist/wrapper/components/AddToCartDialog/AddToCartDialogAlertView.js +35 -0
- package/dist/wrapper/components/AddToCartDialog/AddToCartDialogController.js +36 -0
- package/dist/wrapper/components/AddToCartDialog/AddToCartDialogView.js +42 -0
- package/dist/wrapper/components/ButtonView.js +22 -0
- package/dist/wrapper/components/DownloadManifestBtn.js +71 -0
- package/dist/wrapper/components/ReduxAddFile.js +26 -0
- package/dist/wrapper/components/Snackbar/Snackbar.js +40 -0
- package/dist/wrapper/components/Snackbar/SnackbarRedux.js +16 -0
- package/dist/wrapper/components/Snackbar/SuccessOutlined.js +17 -0
- package/dist/wrapper/components/TextFieldView.js +34 -0
- package/dist/wrapper/components/TooltipView.js +40 -0
- package/package.json +28 -0
- package/src/index.js +18 -0
- package/src/table/ClientController.js +64 -0
- package/src/table/ContextProvider.js +27 -0
- package/src/table/PaginatedTable.js +185 -0
- package/src/table/README.md +253 -0
- package/src/table/ServerController.js +40 -0
- package/src/table/TableService.js +80 -0
- package/src/table/state/Actions.js +50 -0
- package/src/table/state/Reducer.js +49 -0
- package/src/wrapper/Wrapper.js +163 -0
- package/src/wrapper/WrapperService.js +25 -0
- package/src/wrapper/components/AddAllFiles/AddAllView.js +88 -0
- package/src/wrapper/components/AddFiles.js +75 -0
- package/src/wrapper/components/AddSelectedFiles/AddSelectedFilesController.js +69 -0
- package/src/wrapper/components/AddSelectedFiles/AddSelectedFilesView.js +65 -0
- package/src/wrapper/components/AddToCartDialog/AddToCartDialogAlertView.js +37 -0
- package/src/wrapper/components/AddToCartDialog/AddToCartDialogController.js +32 -0
- package/src/wrapper/components/AddToCartDialog/AddToCartDialogView.js +56 -0
- package/src/wrapper/components/ButtonView.js +24 -0
- package/src/wrapper/components/DownloadManifestBtn.js +64 -0
- package/src/wrapper/components/ReduxAddFile.js +19 -0
- package/src/wrapper/components/Snackbar/Snackbar.js +43 -0
- package/src/wrapper/components/Snackbar/SnackbarRedux.js +11 -0
- package/src/wrapper/components/Snackbar/SuccessOutlined.js +10 -0
- package/src/wrapper/components/TextFieldView.js +31 -0
- package/src/wrapper/components/TooltipView.js +35 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"presets": [
|
|
3
|
+
[
|
|
4
|
+
"@babel/env",
|
|
5
|
+
{
|
|
6
|
+
"targets": {
|
|
7
|
+
"edge": "17",
|
|
8
|
+
"firefox": "60",
|
|
9
|
+
"chrome": "67",
|
|
10
|
+
"safari": "11.1"
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
],
|
|
14
|
+
"@babel/preset-react"
|
|
15
|
+
],
|
|
16
|
+
"plugins": [
|
|
17
|
+
"@babel/plugin-transform-react-jsx",
|
|
18
|
+
"@babel/plugin-proposal-class-properties"
|
|
19
|
+
]
|
|
20
|
+
}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "TableContext", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function get() {
|
|
9
|
+
return _ContextProvider.TableContext;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "TableContextProvider", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function get() {
|
|
15
|
+
return _ContextProvider.default;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "TableView", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function get() {
|
|
21
|
+
return _PaginatedTable.default;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
Object.defineProperty(exports, "Wrapper", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function get() {
|
|
27
|
+
return _Wrapper.default;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
Object.defineProperty(exports, "btnTypes", {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function get() {
|
|
33
|
+
return _AddFiles.btnTypes;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
Object.defineProperty(exports, "getQueryVariables", {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
get: function get() {
|
|
39
|
+
return _WrapperService.getQueryVariables;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
Object.defineProperty(exports, "onChangeSortDirection", {
|
|
43
|
+
enumerable: true,
|
|
44
|
+
get: function get() {
|
|
45
|
+
return _Actions.onChangeSortDirection;
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
Object.defineProperty(exports, "onColumnSort", {
|
|
49
|
+
enumerable: true,
|
|
50
|
+
get: function get() {
|
|
51
|
+
return _Actions.onColumnSort;
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
Object.defineProperty(exports, "onColumnViewChange", {
|
|
55
|
+
enumerable: true,
|
|
56
|
+
get: function get() {
|
|
57
|
+
return _Actions.onColumnViewChange;
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
Object.defineProperty(exports, "onPageAndTotalCountChange", {
|
|
61
|
+
enumerable: true,
|
|
62
|
+
get: function get() {
|
|
63
|
+
return _Actions.onPageAndTotalCountChange;
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
Object.defineProperty(exports, "onPageChange", {
|
|
67
|
+
enumerable: true,
|
|
68
|
+
get: function get() {
|
|
69
|
+
return _Actions.onPageChange;
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
Object.defineProperty(exports, "onRowSeclect", {
|
|
73
|
+
enumerable: true,
|
|
74
|
+
get: function get() {
|
|
75
|
+
return _Actions.onRowSeclect;
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
Object.defineProperty(exports, "onRowsPerPageChange", {
|
|
79
|
+
enumerable: true,
|
|
80
|
+
get: function get() {
|
|
81
|
+
return _Actions.onRowsPerPageChange;
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
Object.defineProperty(exports, "setTotalRowCount", {
|
|
85
|
+
enumerable: true,
|
|
86
|
+
get: function get() {
|
|
87
|
+
return _Actions.setTotalRowCount;
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
Object.defineProperty(exports, "types", {
|
|
91
|
+
enumerable: true,
|
|
92
|
+
get: function get() {
|
|
93
|
+
return _Wrapper.types;
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
var _PaginatedTable = _interopRequireDefault(require("./table/PaginatedTable"));
|
|
97
|
+
var _ContextProvider = _interopRequireWildcard(require("./table/ContextProvider"));
|
|
98
|
+
var _Actions = require("./table/state/Actions");
|
|
99
|
+
var _Wrapper = _interopRequireWildcard(require("./wrapper/Wrapper"));
|
|
100
|
+
var _AddFiles = require("./wrapper/components/AddFiles");
|
|
101
|
+
var _WrapperService = require("./wrapper/WrapperService");
|
|
102
|
+
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); }
|
|
103
|
+
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; }
|
|
104
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _react = _interopRequireDefault(require("react"));
|
|
8
|
+
var _core = require("@material-ui/core");
|
|
9
|
+
var _table = require("@bento-core/table");
|
|
10
|
+
var _TableService = require("./TableService");
|
|
11
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
|
+
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); }
|
|
13
|
+
/**
|
|
14
|
+
* Updates table row when table state is changed 1. (paginated action) and 2. filter action
|
|
15
|
+
*/
|
|
16
|
+
const TableController = props => {
|
|
17
|
+
const {
|
|
18
|
+
tblRows,
|
|
19
|
+
table
|
|
20
|
+
} = props;
|
|
21
|
+
if (!tblRows) {
|
|
22
|
+
return /*#__PURE__*/_react.default.createElement(_core.Container, {
|
|
23
|
+
maxWidth: "xl"
|
|
24
|
+
}, /*#__PURE__*/_react.default.createElement(_core.CircularProgress, null));
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* update rows
|
|
28
|
+
* set selected rows isChecked to TRUE
|
|
29
|
+
*/
|
|
30
|
+
const updateRows = (0, _TableService.setSelectedRows)(tblRows, table);
|
|
31
|
+
const {
|
|
32
|
+
page = 0,
|
|
33
|
+
rowsPerPage = 10,
|
|
34
|
+
sortBy,
|
|
35
|
+
sortOrder
|
|
36
|
+
} = table;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* client table aplhanumeric sorting for column table
|
|
40
|
+
* uses string prototype function for sorting
|
|
41
|
+
*/
|
|
42
|
+
const alphaNumericSort = (a, b) => "".concat(a[sortBy]).localeCompare("".concat(b[sortBy]), undefined, {
|
|
43
|
+
numeric: true,
|
|
44
|
+
sensitivity: 'base'
|
|
45
|
+
});
|
|
46
|
+
/**
|
|
47
|
+
* sort base on table state
|
|
48
|
+
*/
|
|
49
|
+
const sortRows = (a, b) => {
|
|
50
|
+
if (sortOrder === 'asc') {
|
|
51
|
+
return alphaNumericSort(a, b);
|
|
52
|
+
}
|
|
53
|
+
return alphaNumericSort(b, a);
|
|
54
|
+
};
|
|
55
|
+
const sortedRows = [...updateRows].sort((a, b) => sortRows(a, b));
|
|
56
|
+
const startIndex = page * rowsPerPage;
|
|
57
|
+
const endIndex = startIndex + rowsPerPage;
|
|
58
|
+
const displayRows = [...sortedRows].slice(startIndex, endIndex);
|
|
59
|
+
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_table.TableView, _extends({}, props, {
|
|
60
|
+
tableRows: displayRows
|
|
61
|
+
})));
|
|
62
|
+
};
|
|
63
|
+
var _default = TableController;
|
|
64
|
+
exports.default = _default;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = exports.TableContext = void 0;
|
|
7
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
8
|
+
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); }
|
|
9
|
+
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; }
|
|
10
|
+
const TableContext = /*#__PURE__*/_react.default.createContext({
|
|
11
|
+
context: {},
|
|
12
|
+
setContext: () => {}
|
|
13
|
+
});
|
|
14
|
+
exports.TableContext = TableContext;
|
|
15
|
+
const TableContextProvider = _ref => {
|
|
16
|
+
let {
|
|
17
|
+
children
|
|
18
|
+
} = _ref;
|
|
19
|
+
const [context, setContext] = (0, _react.useState)({});
|
|
20
|
+
const setContextHandler = tblContext => {
|
|
21
|
+
setContext(tblContext);
|
|
22
|
+
};
|
|
23
|
+
return /*#__PURE__*/_react.default.createElement(TableContext.Provider, {
|
|
24
|
+
value: {
|
|
25
|
+
context,
|
|
26
|
+
setContext: setContextHandler
|
|
27
|
+
}
|
|
28
|
+
}, children);
|
|
29
|
+
};
|
|
30
|
+
var _default = TableContextProvider;
|
|
31
|
+
exports.default = _default;
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
8
|
+
var _ServerController = _interopRequireDefault(require("./ServerController"));
|
|
9
|
+
var _ClientController = _interopRequireDefault(require("./ClientController"));
|
|
10
|
+
var _Actions = require("./state/Actions");
|
|
11
|
+
var _ContextProvider = require("./ContextProvider");
|
|
12
|
+
var _Reducer = _interopRequireDefault(require("./state/Reducer"));
|
|
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 PaginatedTable = _ref => {
|
|
22
|
+
let {
|
|
23
|
+
queryVariables = {},
|
|
24
|
+
themeConfig = {},
|
|
25
|
+
totalRowCount = 0,
|
|
26
|
+
initState,
|
|
27
|
+
activeTab = true,
|
|
28
|
+
server = true,
|
|
29
|
+
tblRows = []
|
|
30
|
+
} = _ref;
|
|
31
|
+
/**
|
|
32
|
+
* Initailize useReducer state
|
|
33
|
+
* 1. table: state (Note: table includes cofiguration in addition to pagination state)
|
|
34
|
+
* 2. dispatch: dispatch action (as redux action) to update pagination state
|
|
35
|
+
* 3. Add all btn / Add file button also dispatch action to update table state
|
|
36
|
+
*/
|
|
37
|
+
const [table, dispatch] = (0, _react.useReducer)(_Reducer.default, {}, initState);
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* use context to provide table state to wrapper component
|
|
41
|
+
*/
|
|
42
|
+
const tableContext = (0, _react.useContext)(_ContextProvider.TableContext);
|
|
43
|
+
(0, _react.useEffect)(() => {
|
|
44
|
+
/**
|
|
45
|
+
* set table context
|
|
46
|
+
* 1. provide table state to other component (wrapper comp -> Add file button)
|
|
47
|
+
* 2. provide table dispatch action to other component (wrapper comp)
|
|
48
|
+
*/
|
|
49
|
+
tableContext.setContext(_objectSpread(_objectSpread({}, table), {}, {
|
|
50
|
+
dispatch
|
|
51
|
+
}));
|
|
52
|
+
}, [table]);
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* update state to props change
|
|
56
|
+
*/
|
|
57
|
+
(0, _react.useEffect)(() => {
|
|
58
|
+
const {
|
|
59
|
+
page,
|
|
60
|
+
rowsPerPage
|
|
61
|
+
} = table;
|
|
62
|
+
// validate table state - curr rowCount should be less than total row count after filter
|
|
63
|
+
// above validation steps when page is zero
|
|
64
|
+
// prevent currentRows denominator to be zero (newPage -> Nan)
|
|
65
|
+
if (page > 0 && totalRowCount <= page * rowsPerPage) {
|
|
66
|
+
const adjustRow = page === 1 ? 1 : 0;
|
|
67
|
+
const currentRows = page * rowsPerPage + adjustRow;
|
|
68
|
+
const newPage = Math.floor(totalRowCount / currentRows);
|
|
69
|
+
dispatch((0, _Actions.onPageAndTotalCountChange)({
|
|
70
|
+
page: newPage,
|
|
71
|
+
totalRowCount
|
|
72
|
+
}));
|
|
73
|
+
} else {
|
|
74
|
+
dispatch((0, _Actions.setTotalRowCount)(totalRowCount));
|
|
75
|
+
}
|
|
76
|
+
}, [totalRowCount]);
|
|
77
|
+
const handleChangeRowsPerPage = event => {
|
|
78
|
+
const noOfRows = parseInt(event.target.value, 10);
|
|
79
|
+
dispatch((0, _Actions.onRowsPerPageChange)({
|
|
80
|
+
rowsPerPage: noOfRows,
|
|
81
|
+
page: 0
|
|
82
|
+
}));
|
|
83
|
+
};
|
|
84
|
+
const handleChangePage = (event, newPage) => {
|
|
85
|
+
dispatch((0, _Actions.onPageChange)({
|
|
86
|
+
pageNumb: newPage
|
|
87
|
+
}));
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* update selected Ids
|
|
92
|
+
* @param {*} event
|
|
93
|
+
* @param {*} row
|
|
94
|
+
*/
|
|
95
|
+
const onRowSelectHandler = (event, row) => {
|
|
96
|
+
event.stopPropagation();
|
|
97
|
+
let selectedIds = [...table.selectedRows];
|
|
98
|
+
const selectedId = row[table.dataKey];
|
|
99
|
+
if (!row.isChecked) {
|
|
100
|
+
selectedIds.push(selectedId);
|
|
101
|
+
} else {
|
|
102
|
+
selectedIds = selectedIds.reduce((acc, id) => {
|
|
103
|
+
if (selectedId !== id) {
|
|
104
|
+
acc.push(id);
|
|
105
|
+
}
|
|
106
|
+
return acc;
|
|
107
|
+
}, []);
|
|
108
|
+
}
|
|
109
|
+
dispatch((0, _Actions.onRowSeclect)(selectedIds));
|
|
110
|
+
};
|
|
111
|
+
const handleToggleSelectAll = (event, Ids, includeIds) => {
|
|
112
|
+
if (event.target.checked && !includeIds) {
|
|
113
|
+
const selecedIds = Ids.concat(table.selectedRows);
|
|
114
|
+
dispatch((0, _Actions.onRowSeclect)(selecedIds));
|
|
115
|
+
} else {
|
|
116
|
+
const filterIds = table.selectedRows.filter(id => !Ids.includes(id));
|
|
117
|
+
dispatch((0, _Actions.onRowSeclect)(filterIds));
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
const handleSortByColumn = (column, order) => {
|
|
121
|
+
const {
|
|
122
|
+
sortBy
|
|
123
|
+
} = table;
|
|
124
|
+
const sort = order === 'asc' && sortBy === column ? 'desc' : 'asc';
|
|
125
|
+
dispatch((0, _Actions.onColumnSort)({
|
|
126
|
+
sort,
|
|
127
|
+
column
|
|
128
|
+
}));
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* manage columns view change
|
|
133
|
+
* hide/display columns from table
|
|
134
|
+
*/
|
|
135
|
+
const handleColumnViewChange = column => {
|
|
136
|
+
const columns = table.columns.map(col => {
|
|
137
|
+
const updateColumnView = _objectSpread({}, col);
|
|
138
|
+
if (col.dataField === column.dataField) {
|
|
139
|
+
updateColumnView.display = !column.display;
|
|
140
|
+
}
|
|
141
|
+
return updateColumnView;
|
|
142
|
+
});
|
|
143
|
+
dispatch((0, _Actions.onColumnViewChange)(_objectSpread(_objectSpread({}, table), {}, {
|
|
144
|
+
columns
|
|
145
|
+
})));
|
|
146
|
+
};
|
|
147
|
+
/**
|
|
148
|
+
* A. client table
|
|
149
|
+
* table data provide by bento app (tblRows)
|
|
150
|
+
* Rows display & column sorting by ClientController
|
|
151
|
+
*/
|
|
152
|
+
if (!server) {
|
|
153
|
+
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_ClientController.default, {
|
|
154
|
+
tblRows: tblRows,
|
|
155
|
+
table: table,
|
|
156
|
+
onRowsPerPageChange: handleChangeRowsPerPage,
|
|
157
|
+
onPageChange: handleChangePage,
|
|
158
|
+
onRowSelectChange: onRowSelectHandler,
|
|
159
|
+
onToggleSelectAll: handleToggleSelectAll,
|
|
160
|
+
onSortByColumn: handleSortByColumn,
|
|
161
|
+
onColumnViewChange: handleColumnViewChange,
|
|
162
|
+
themeConfig: themeConfig
|
|
163
|
+
}));
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* B. server table
|
|
168
|
+
* bento-core makes http call base on table state
|
|
169
|
+
*/
|
|
170
|
+
/**
|
|
171
|
+
* prevent loading data except for active tab
|
|
172
|
+
*/
|
|
173
|
+
if (!activeTab) {
|
|
174
|
+
return null;
|
|
175
|
+
}
|
|
176
|
+
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_ServerController.default, {
|
|
177
|
+
queryVariables: queryVariables,
|
|
178
|
+
totalRowCount: totalRowCount,
|
|
179
|
+
table: table,
|
|
180
|
+
onRowsPerPageChange: handleChangeRowsPerPage,
|
|
181
|
+
onPageChange: handleChangePage,
|
|
182
|
+
onRowSelectChange: onRowSelectHandler,
|
|
183
|
+
onToggleSelectAll: handleToggleSelectAll,
|
|
184
|
+
onSortByColumn: handleSortByColumn,
|
|
185
|
+
onColumnViewChange: handleColumnViewChange,
|
|
186
|
+
themeConfig: themeConfig
|
|
187
|
+
}));
|
|
188
|
+
};
|
|
189
|
+
var _default = PaginatedTable;
|
|
190
|
+
exports.default = _default;
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
# PAGINATED TABLE COMPONENT DESIGN
|
|
2
|
+
|
|
3
|
+
### Bento core paginated table design:
|
|
4
|
+
|
|
5
|
+
* Use of UseReducer to track table state and local state to display dialog component
|
|
6
|
+
* use of useContext to access table state
|
|
7
|
+
* Limit use of props drilling
|
|
8
|
+
* Core layout defined by Bento Core table component
|
|
9
|
+
* Build on top of Mui table (demo - https://mui.com/material-ui/react-table/#custom-pagination-actions)
|
|
10
|
+
* Apply SOLID principles in react (https://konstantinlebedev.com/solid-in-react/)
|
|
11
|
+
|
|
12
|
+
## 1 UseReducer configuration
|
|
13
|
+
|
|
14
|
+
### Generate and integrate redux dispatch actions
|
|
15
|
+
```
|
|
16
|
+
const initTblState = (initailState) => ({
|
|
17
|
+
...initailState,
|
|
18
|
+
title: config.name,
|
|
19
|
+
query: config.api,
|
|
20
|
+
dataKey: config.dataKey,
|
|
21
|
+
columns: configColumn(config.columns),
|
|
22
|
+
count: dashboardStats[config.count],
|
|
23
|
+
selectedRows: [],
|
|
24
|
+
tableMsg: config.tableMsg,
|
|
25
|
+
paginationAPIField: config.paginationAPIField,
|
|
26
|
+
sortBy: config.defaultSortField,
|
|
27
|
+
sortOrder: config.defaultSortDirection,
|
|
28
|
+
rowsPerPage: 10,
|
|
29
|
+
page: 0,
|
|
30
|
+
});
|
|
31
|
+
```
|
|
32
|
+
**Paginated Table Init State TABLE-1**
|
|
33
|
+
| Table State | Required | description | Configuration |
|
|
34
|
+
| :--- | :----:| :----: | ----: |
|
|
35
|
+
| title | TRUE | table name (Case, Sample, Files), required for class name | |
|
|
36
|
+
| query | TRUE | GraphQL Query for paginated Table (e.g. GET_CASES_OVERVIEW_QUERY) | api |
|
|
37
|
+
| dataKey | TRUE | Tracking selected rows (case - dataKey: 'subject_id') | dashboardTabData/tabContainers |
|
|
38
|
+
| columns | TRUE | columns defined by dashboardTabData (tabContainers) | add fucntion attribut customCellRender/customColHeaderRender to configure custom cell (see bento frontend) |
|
|
39
|
+
| count | TRUE | Total row cound for (Cases, Samples, Files), update based on filter event | |
|
|
40
|
+
| selectedRows | TRUE | Tracks selected Rows | |
|
|
41
|
+
| tableMsg | TRUE | Display noMatch Msg | dashboardTabData/tabContainers/tableMsg |
|
|
42
|
+
| theme | FALSE | override style with themeprovider use ClassName provided by bento-core table to apply style (refer to class name table) | |
|
|
43
|
+
| paginationAPIField | TRUE | Access http response data - defined by dashboardTabData (tabContainers) | ```paginationAPIField: 'subjectOverview'```|
|
|
44
|
+
| sortBy | TRUE | default sort column | defaultSortField: 'subject_id',|
|
|
45
|
+
| sortOrder | FALSE | default sort column 'ASC' | ```defaultSortDirection: 'asc',```|
|
|
46
|
+
| rowsPerPage | FALSE | default 10 | |
|
|
47
|
+
| page | FALSE | 0 | |
|
|
48
|
+
| extendedViewConfig | FALSE | extended view of table header component | refer bento-frontend tabContainers, dashboardTabData.js |
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
### 2 Importing Component and Configuration
|
|
52
|
+
```
|
|
53
|
+
import TableView from 'bento-core/PaginationTable/PaginatedTable';
|
|
54
|
+
// active filter json structure
|
|
55
|
+
<TableView
|
|
56
|
+
initState={initTblState}
|
|
57
|
+
themeConfig={themeConfig}
|
|
58
|
+
activeFilters={activeFilters}
|
|
59
|
+
totalRowCount={dashboardStats[config.count]}
|
|
60
|
+
activeTab={activeTab}
|
|
61
|
+
/>
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
**Paginated Table Props Config TABLE-2**
|
|
65
|
+
| Table | Required | description | Configuration |
|
|
66
|
+
| :--- | :----:| :----: | ----: |
|
|
67
|
+
| table state | TRUE | as describe on TABLE-1 | |
|
|
68
|
+
| viewConfig | FALSE | (Optional) table view config, set hide/diaply pagination above table header | |
|
|
69
|
+
| themeConfig | FALSE | override style with themeprovider use ClassName provided by bento-core table to apply style (refer to class name table) | |
|
|
70
|
+
| totalRowCount | TRUE | Total row cound for (Cases, Samples, Files), update based on filter event | |
|
|
71
|
+
| activeTab | TRUE | prevents http call for inactive tabs (dashboard) /set true to myFile cart | |
|
|
72
|
+
|
|
73
|
+
## 3 Table component themeConfig Configuration
|
|
74
|
+
```
|
|
75
|
+
export const tblHeader = {
|
|
76
|
+
MuiTableSortLabel: {
|
|
77
|
+
root: {
|
|
78
|
+
...define style
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
export const tblPgn = {
|
|
84
|
+
MuiTablePagination: {
|
|
85
|
+
root: {
|
|
86
|
+
paddingRight: '50px',
|
|
87
|
+
borderTop: '5px solid #e7e5e5',
|
|
88
|
+
borderBottom: '3px solid #e7e5e5',
|
|
89
|
+
},
|
|
90
|
+
toolbar: {
|
|
91
|
+
minHeight: '45px',
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
// define mui styles for table component
|
|
96
|
+
export const themeConfig = {
|
|
97
|
+
tblHeader,
|
|
98
|
+
tblTopPgn,
|
|
99
|
+
tblPgn,
|
|
100
|
+
tblBody,
|
|
101
|
+
};
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## 3 Table state Context provider Configuration
|
|
105
|
+
```
|
|
106
|
+
Reference - TabPanel.js (bento-frontend)
|
|
107
|
+
|
|
108
|
+
import {
|
|
109
|
+
TableContextProvider,
|
|
110
|
+
TableView,
|
|
111
|
+
Wrapper,
|
|
112
|
+
} from '@bento-core/paginated-table';
|
|
113
|
+
|
|
114
|
+
const initTblState = (initailState) => ({
|
|
115
|
+
...initailState,
|
|
116
|
+
title: config.name,
|
|
117
|
+
query: config.api,
|
|
118
|
+
paginationAPIField: config.paginationAPIField,
|
|
119
|
+
dataKey: config.dataKey,
|
|
120
|
+
columns: configColumn(config.columns),
|
|
121
|
+
count: dashboardStats[config.count],
|
|
122
|
+
selectedRows: [],
|
|
123
|
+
enableRowSelection: config.enableRowSelection,
|
|
124
|
+
tableMsg: config.tableMsg,
|
|
125
|
+
sortBy: config.defaultSortField,
|
|
126
|
+
sortOrder: config.defaultSortDirection,
|
|
127
|
+
extendedViewConfig: config.extendedViewConfig,
|
|
128
|
+
rowsPerPage: 10,
|
|
129
|
+
page: 0,
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
<TableContextProvider>
|
|
133
|
+
<Wrapper
|
|
134
|
+
wrapConfig={configWrapper(config, wrapperConfig)}
|
|
135
|
+
customTheme={customTheme}
|
|
136
|
+
classes={classes}
|
|
137
|
+
section={config.name}
|
|
138
|
+
>
|
|
139
|
+
<Grid container>
|
|
140
|
+
<Grid item xs={12} id={config.tableID}>
|
|
141
|
+
<TableView
|
|
142
|
+
initState={initTblState}
|
|
143
|
+
themeConfig={themeConfig}
|
|
144
|
+
queryVariables={activeFilters}
|
|
145
|
+
totalRowCount={dashboardStats[config.count]}
|
|
146
|
+
activeTab={activeTab}
|
|
147
|
+
/>
|
|
148
|
+
</Grid>
|
|
149
|
+
</Grid>
|
|
150
|
+
</Wrapper>
|
|
151
|
+
</TableContextProvider>
|
|
152
|
+
|
|
153
|
+
//child component
|
|
154
|
+
|
|
155
|
+
import { TableContext } from 'bento-core';
|
|
156
|
+
|
|
157
|
+
const tableContext = useContext(TableContext);
|
|
158
|
+
|
|
159
|
+
```
|
|
160
|
+
TableContextProvider provides table state to Wrapper Component or it can be used in higher parent component as needed.
|
|
161
|
+
|
|
162
|
+
####
|
|
163
|
+
|
|
164
|
+
## 4 Wrapper Configuration:
|
|
165
|
+
Wrapper component around table compnent.
|
|
166
|
+
1. ADD ALL FILES button
|
|
167
|
+
2. ADD SELECTED ROWS button
|
|
168
|
+
3. Go to My File link
|
|
169
|
+
|
|
170
|
+
```
|
|
171
|
+
/**
|
|
172
|
+
* Configuration display component based on index
|
|
173
|
+
* CAUTION: If table is in wrapper component provide position of table component
|
|
174
|
+
*/
|
|
175
|
+
export const wrapperConfig = [{
|
|
176
|
+
container: 'buttons',
|
|
177
|
+
size: 'xl',
|
|
178
|
+
clsName: 'container_header',
|
|
179
|
+
items: [
|
|
180
|
+
{
|
|
181
|
+
title: 'ADD ALL FILES',
|
|
182
|
+
clsName: 'add_all_button',
|
|
183
|
+
type: types.BUTTON,
|
|
184
|
+
role: btnTypes.ADD_ALL_FILES,
|
|
185
|
+
btnType: btnTypes.ADD_ALL_FILES,
|
|
186
|
+
conditional: false,
|
|
187
|
+
alertMessage,
|
|
188
|
+
},
|
|
189
|
+
{
|
|
190
|
+
title: 'ADD SELECTED FILES',
|
|
191
|
+
clsName: 'add_selected_button',
|
|
192
|
+
type: types.BUTTON,
|
|
193
|
+
role: btnTypes.ADD_SELECTED_FILES,
|
|
194
|
+
btnType: btnTypes.ADD_SELECTED_FILES,
|
|
195
|
+
tooltipCofig: tooltipContent,
|
|
196
|
+
conditional: true,
|
|
197
|
+
}],
|
|
198
|
+
},
|
|
199
|
+
{
|
|
200
|
+
container: 'paginatedTable',
|
|
201
|
+
paginatedTable: true,
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
container: 'buttons',
|
|
205
|
+
size: 'xl',
|
|
206
|
+
clsName: 'container_footer',
|
|
207
|
+
items: [
|
|
208
|
+
{
|
|
209
|
+
title: 'ADD SELECTED FILES',
|
|
210
|
+
clsName: 'add_selected_button',
|
|
211
|
+
type: types.BUTTON,
|
|
212
|
+
role: btnTypes.ADD_SELECTED_FILES,
|
|
213
|
+
btnType: btnTypes.ADD_SELECTED_FILES,
|
|
214
|
+
tooltipCofig: tooltipContent,
|
|
215
|
+
conditional: true,
|
|
216
|
+
}],
|
|
217
|
+
},
|
|
218
|
+
{
|
|
219
|
+
container: 'buttons',
|
|
220
|
+
size: 'xl',
|
|
221
|
+
clsName: 'container_footer_link',
|
|
222
|
+
items: [
|
|
223
|
+
{
|
|
224
|
+
title: 'Go to Cart >',
|
|
225
|
+
clsName: 'go_to_cart',
|
|
226
|
+
url: '#/fileCentricCart',
|
|
227
|
+
type: types.LINK,
|
|
228
|
+
}],
|
|
229
|
+
},
|
|
230
|
+
];
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
Each item in headerConfig and footerConfig represent container
|
|
234
|
+
**container Config TABLE-3**
|
|
235
|
+
headerConfig - upper component on the table
|
|
236
|
+
footerConfig - button component on the table
|
|
237
|
+
| Attris | Required | description | Configuration |
|
|
238
|
+
| :--- | :----:| :----: | ----: |
|
|
239
|
+
| container | TRUE | describe container | |
|
|
240
|
+
| size | TRUE | container size | xl, md, sm |
|
|
241
|
+
| clsName | TRUE | class name to apply style using themeprovider | |
|
|
242
|
+
| item | TRUE | number of button component ***(refer to table 4)*** | |
|
|
243
|
+
|
|
244
|
+
**Button component Config TABLE-4**
|
|
245
|
+
headerConfig - upper component on the table
|
|
246
|
+
| Attris | Required | description | Configuration |
|
|
247
|
+
| :--- | :----:| :----: | ----: |
|
|
248
|
+
| title | TRUE | button label | 'ADD SELECTED FILES' |
|
|
249
|
+
| clsName | TRUE | class name to apply style using themeprovider | |
|
|
250
|
+
| type | TRUE | add all files or add selected files| btnTypes.ADD_SELECTED_FILES |
|
|
251
|
+
| tooltipCofig | FALSE | appears on side of the refers button | dashboardTabData/ tooltipContent |
|
|
252
|
+
|
|
253
|
+
|