mui-universal-table 2.1.0 → 2.1.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.
- package/dist/index.cjs +438 -394
- package/dist/index.cjs.map +1 -1
- package/dist/index.esm.js +438 -394
- package/dist/index.esm.js.map +1 -1
- package/package.json +4 -7
package/dist/index.esm.js
CHANGED
|
@@ -2,6 +2,7 @@ import React from 'react';
|
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
3
|
import Paper$1 from '@mui/material/Paper';
|
|
4
4
|
import { Collapse, Box, Typography, LinearProgress, IconButton, Tooltip, Button, Paper, InputBase, Stack, Divider, Toolbar, TableHead, TableRow, TableCell, Checkbox, TableSortLabel, Badge, TableBody, Skeleton, TableContainer, Table, TablePagination } from '@mui/material';
|
|
5
|
+
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
5
6
|
import { alpha } from '@mui/material/styles';
|
|
6
7
|
import { Task, Clear, Search, RemoveCircle, AddCircle } from '@mui/icons-material';
|
|
7
8
|
import RefreshIcon from '@mui/icons-material/Refresh';
|
|
@@ -25,15 +26,6 @@ function _defineProperty(e, r, t) {
|
|
|
25
26
|
writable: true
|
|
26
27
|
}) : e[r] = t, e;
|
|
27
28
|
}
|
|
28
|
-
function _extends() {
|
|
29
|
-
return _extends = Object.assign ? Object.assign.bind() : function (n) {
|
|
30
|
-
for (var e = 1; e < arguments.length; e++) {
|
|
31
|
-
var t = arguments[e];
|
|
32
|
-
for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
|
|
33
|
-
}
|
|
34
|
-
return n;
|
|
35
|
-
}, _extends.apply(null, arguments);
|
|
36
|
-
}
|
|
37
29
|
function _iterableToArray(r) {
|
|
38
30
|
if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
|
|
39
31
|
}
|
|
@@ -120,25 +112,28 @@ var LazyLoadingIndicator = function LazyLoadingIndicator(_ref) {
|
|
|
120
112
|
var show = _ref.show,
|
|
121
113
|
currentPage = _ref.currentPage,
|
|
122
114
|
totalPages = _ref.totalPages;
|
|
123
|
-
return /*#__PURE__*/
|
|
115
|
+
return /*#__PURE__*/jsx(Collapse, {
|
|
124
116
|
"in": show,
|
|
125
117
|
timeout: "auto",
|
|
126
|
-
unmountOnExit: true
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
118
|
+
unmountOnExit: true,
|
|
119
|
+
children: /*#__PURE__*/jsxs(Box, {
|
|
120
|
+
sx: {
|
|
121
|
+
width: "100%",
|
|
122
|
+
p: 2
|
|
123
|
+
},
|
|
124
|
+
children: [/*#__PURE__*/jsxs(Typography, {
|
|
125
|
+
variant: "body2",
|
|
126
|
+
color: "text.secondary",
|
|
127
|
+
sx: {
|
|
128
|
+
mb: 1
|
|
129
|
+
},
|
|
130
|
+
children: ["Loading page ", currentPage, " of ", totalPages, "..."]
|
|
131
|
+
}), /*#__PURE__*/jsx(LinearProgress, {
|
|
132
|
+
variant: "determinate",
|
|
133
|
+
value: currentPage / totalPages * 100
|
|
134
|
+
})]
|
|
135
|
+
})
|
|
136
|
+
});
|
|
142
137
|
};
|
|
143
138
|
LazyLoadingIndicator.propTypes = {
|
|
144
139
|
show: PropTypes.bool.isRequired,
|
|
@@ -356,30 +351,34 @@ function TableSelectionBanner(_ref) {
|
|
|
356
351
|
var selected = _ref.selected,
|
|
357
352
|
onSelection = _ref.onSelection,
|
|
358
353
|
selectIcon = _ref.selectIcon;
|
|
359
|
-
return /*#__PURE__*/
|
|
354
|
+
return /*#__PURE__*/jsx(Collapse, {
|
|
360
355
|
"in": selected.length > 0,
|
|
361
|
-
unmountOnExit: true
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
356
|
+
unmountOnExit: true,
|
|
357
|
+
children: /*#__PURE__*/jsxs(Box, {
|
|
358
|
+
sx: {
|
|
359
|
+
p: 2,
|
|
360
|
+
display: "flex",
|
|
361
|
+
justifyContent: "space-between",
|
|
362
|
+
bgcolor: function bgcolor(theme) {
|
|
363
|
+
return alpha(theme.palette.primary.main, theme.palette.action.activatedOpacity);
|
|
364
|
+
},
|
|
365
|
+
borderRadius: 1,
|
|
366
|
+
borderBottomLeftRadius: 0,
|
|
367
|
+
borderBottomRightRadius: 0
|
|
369
368
|
},
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
}
|
|
382
|
-
}
|
|
369
|
+
children: [/*#__PURE__*/jsxs(Typography, {
|
|
370
|
+
variant: "h6",
|
|
371
|
+
id: "tableTitle",
|
|
372
|
+
component: "div",
|
|
373
|
+
children: [selected.length, " selected"]
|
|
374
|
+
}), /*#__PURE__*/jsx(IconButton, {
|
|
375
|
+
onClick: function onClick() {
|
|
376
|
+
return onSelection(selected);
|
|
377
|
+
},
|
|
378
|
+
children: selectIcon || /*#__PURE__*/jsx(Task, {})
|
|
379
|
+
})]
|
|
380
|
+
})
|
|
381
|
+
});
|
|
383
382
|
}
|
|
384
383
|
TableSelectionBanner.propTypes = {
|
|
385
384
|
selected: PropTypes.array.isRequired,
|
|
@@ -390,13 +389,14 @@ TableSelectionBanner.propTypes = {
|
|
|
390
389
|
function TableTitle(_ref) {
|
|
391
390
|
var name = _ref.name,
|
|
392
391
|
subTable = _ref.subTable;
|
|
393
|
-
return /*#__PURE__*/
|
|
392
|
+
return /*#__PURE__*/jsx(Typography, {
|
|
394
393
|
variant: subTable ? "h6" : "h5",
|
|
395
394
|
color: subTable ? "secondary" : "primary",
|
|
396
395
|
sx: {
|
|
397
396
|
p: 2
|
|
398
|
-
}
|
|
399
|
-
|
|
397
|
+
},
|
|
398
|
+
children: name
|
|
399
|
+
});
|
|
400
400
|
}
|
|
401
401
|
TableTitle.propTypes = {
|
|
402
402
|
name: PropTypes.string,
|
|
@@ -415,14 +415,16 @@ function ReloadBtn(_ref) {
|
|
|
415
415
|
onReload();
|
|
416
416
|
}
|
|
417
417
|
};
|
|
418
|
-
return /*#__PURE__*/
|
|
419
|
-
title: "Reload"
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
418
|
+
return /*#__PURE__*/jsx(Tooltip, {
|
|
419
|
+
title: "Reload",
|
|
420
|
+
children: /*#__PURE__*/jsx(Button, {
|
|
421
|
+
variant: "contained",
|
|
422
|
+
color: "primary",
|
|
423
|
+
onClick: handleClick,
|
|
424
|
+
disabled: loading,
|
|
425
|
+
children: /*#__PURE__*/jsx(RefreshIcon, {})
|
|
426
|
+
})
|
|
427
|
+
});
|
|
426
428
|
}
|
|
427
429
|
ReloadBtn.propTypes = {
|
|
428
430
|
loading: PropTypes.bool,
|
|
@@ -449,69 +451,75 @@ function FancySearch(_ref) {
|
|
|
449
451
|
// Sync internal state when the parent clears/changes the search term.
|
|
450
452
|
// A ref tracks whether this sync came from the user typing or from a parent
|
|
451
453
|
// update, so the debounce only fires for genuine user input.
|
|
452
|
-
var
|
|
453
|
-
return /*#__PURE__*/
|
|
454
|
-
onSubmit: handleSubmit
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
454
|
+
var isUserTypingRef = React.useRef(false);
|
|
455
|
+
return /*#__PURE__*/jsx("form", {
|
|
456
|
+
onSubmit: handleSubmit,
|
|
457
|
+
children: /*#__PURE__*/jsxs(Paper, {
|
|
458
|
+
elevation: 0,
|
|
459
|
+
sx: {
|
|
460
|
+
borderRadius: expanded ? "24px" : "50px",
|
|
461
|
+
display: "flex",
|
|
462
|
+
alignItems: "center",
|
|
463
|
+
transition: "all 0.5s ease-in-out",
|
|
464
|
+
p: expanded ? 1 : 0.5,
|
|
465
|
+
width: "fit-content",
|
|
466
|
+
border: function border(theme) {
|
|
467
|
+
return "1px solid ".concat(theme.palette.divider);
|
|
468
|
+
},
|
|
469
|
+
mb: 1
|
|
466
470
|
},
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
471
|
+
onMouseEnter: function onMouseEnter() {
|
|
472
|
+
return setHover(true);
|
|
473
|
+
},
|
|
474
|
+
onMouseLeave: handleEndHover,
|
|
475
|
+
onKeyDown: function onKeyDown(e) {
|
|
476
|
+
return e.key === "Enter" && handleSubmit(e);
|
|
477
|
+
},
|
|
478
|
+
children: [/*#__PURE__*/jsx(InputBase, {
|
|
479
|
+
placeholder: "Search",
|
|
480
|
+
value: value,
|
|
481
|
+
onChange: function onChange(e) {
|
|
482
|
+
isUserTypingRef.current = true;
|
|
483
|
+
onSubmit(e.target.value);
|
|
484
|
+
},
|
|
485
|
+
sx: _objectSpread2({
|
|
486
|
+
ml: 1,
|
|
487
|
+
width: expanded ? "100%" : 0,
|
|
488
|
+
transition: "width 0.5s ease-in-out"
|
|
489
|
+
}, expanded ? {} : {
|
|
490
|
+
margin: 0
|
|
491
|
+
}),
|
|
492
|
+
onBlur: handleEndHover
|
|
493
|
+
}), /*#__PURE__*/jsx(Collapse, {
|
|
494
|
+
"in": Boolean(value),
|
|
495
|
+
orientation: "horizontal",
|
|
496
|
+
unmountOnExit: true,
|
|
497
|
+
children: /*#__PURE__*/jsxs(Stack, {
|
|
498
|
+
direction: "row",
|
|
499
|
+
spacing: 0,
|
|
500
|
+
sx: {
|
|
501
|
+
mr: 3,
|
|
502
|
+
alignItems: "center"
|
|
503
|
+
},
|
|
504
|
+
children: [/*#__PURE__*/jsx(IconButton, {
|
|
505
|
+
onClick: function onClick() {
|
|
506
|
+
isUserTypingRef.current = false;
|
|
507
|
+
// Immediately clear instead of waiting for the debounce
|
|
508
|
+
onSubmit("");
|
|
509
|
+
},
|
|
510
|
+
children: /*#__PURE__*/jsx(Clear, {})
|
|
511
|
+
}), /*#__PURE__*/jsx(Divider, {
|
|
512
|
+
orientation: "vertical",
|
|
513
|
+
flexItem: true
|
|
514
|
+
})]
|
|
515
|
+
})
|
|
516
|
+
}), /*#__PURE__*/jsx(IconButton, {
|
|
517
|
+
onClick: handleSubmit,
|
|
518
|
+
type: "submit",
|
|
519
|
+
children: /*#__PURE__*/jsx(Search, {})
|
|
520
|
+
})]
|
|
521
|
+
})
|
|
522
|
+
});
|
|
515
523
|
}
|
|
516
524
|
FancySearch.propTypes = {
|
|
517
525
|
value: PropTypes.string,
|
|
@@ -531,12 +539,12 @@ function SearchArea(props) {
|
|
|
531
539
|
}
|
|
532
540
|
return "";
|
|
533
541
|
}, [current, persistSearch, searchName]);
|
|
534
|
-
return /*#__PURE__*/
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
})
|
|
542
|
+
return /*#__PURE__*/jsx("div", {
|
|
543
|
+
children: /*#__PURE__*/jsx(FancySearch, {
|
|
544
|
+
value: searchVal,
|
|
545
|
+
onSubmit: setFinalVal
|
|
546
|
+
})
|
|
547
|
+
}, "SearchArea");
|
|
540
548
|
}
|
|
541
549
|
SearchArea.propTypes = {
|
|
542
550
|
current: PropTypes.string,
|
|
@@ -553,7 +561,7 @@ function TableToolbarContent(_ref) {
|
|
|
553
561
|
onSearchChange = _ref.onSearchChange,
|
|
554
562
|
name = _ref.name,
|
|
555
563
|
persistSearch = _ref.persistSearch;
|
|
556
|
-
return /*#__PURE__*/
|
|
564
|
+
return /*#__PURE__*/jsx(Toolbar, {
|
|
557
565
|
sx: {
|
|
558
566
|
pl: {
|
|
559
567
|
sm: 2
|
|
@@ -563,34 +571,37 @@ function TableToolbarContent(_ref) {
|
|
|
563
571
|
sm: 1
|
|
564
572
|
},
|
|
565
573
|
pt: 2
|
|
566
|
-
}
|
|
567
|
-
}, /*#__PURE__*/React.createElement(Stack, {
|
|
568
|
-
spacing: 2,
|
|
569
|
-
direction: {
|
|
570
|
-
xs: "column",
|
|
571
|
-
md: "row"
|
|
572
|
-
},
|
|
573
|
-
sx: {
|
|
574
|
-
width: "100%",
|
|
575
|
-
alignItems: {
|
|
576
|
-
xs: "flex-start",
|
|
577
|
-
md: "center"
|
|
578
|
-
}
|
|
579
|
-
}
|
|
580
|
-
}, /*#__PURE__*/React.createElement(Box, {
|
|
581
|
-
sx: {
|
|
582
|
-
flex: "1 1 100%"
|
|
583
574
|
},
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
575
|
+
children: /*#__PURE__*/jsxs(Stack, {
|
|
576
|
+
spacing: 2,
|
|
577
|
+
direction: {
|
|
578
|
+
xs: "column",
|
|
579
|
+
md: "row"
|
|
580
|
+
},
|
|
581
|
+
sx: {
|
|
582
|
+
width: "100%",
|
|
583
|
+
alignItems: {
|
|
584
|
+
xs: "flex-start",
|
|
585
|
+
md: "center"
|
|
586
|
+
}
|
|
587
|
+
},
|
|
588
|
+
children: [/*#__PURE__*/jsx(Box, {
|
|
589
|
+
sx: {
|
|
590
|
+
flex: "1 1 100%"
|
|
591
|
+
},
|
|
592
|
+
id: "tableTitle",
|
|
593
|
+
children: /*#__PURE__*/jsx(ReloadBtn, {
|
|
594
|
+
onReload: onReload,
|
|
595
|
+
loading: reloadBtnLoading
|
|
596
|
+
})
|
|
597
|
+
}), /*#__PURE__*/jsx(SearchArea, {
|
|
598
|
+
current: searchTerm,
|
|
599
|
+
setFinalVal: onSearchChange,
|
|
600
|
+
searchName: name,
|
|
601
|
+
persistSearch: persistSearch
|
|
602
|
+
})]
|
|
603
|
+
})
|
|
604
|
+
});
|
|
594
605
|
}
|
|
595
606
|
TableToolbarContent.propTypes = {
|
|
596
607
|
onReload: PropTypes.func,
|
|
@@ -638,7 +649,9 @@ function useEnhancedTableState(_ref2) {
|
|
|
638
649
|
pagination = _React$useState2[0],
|
|
639
650
|
setPagination = _React$useState2[1];
|
|
640
651
|
React.useEffect(function () {
|
|
641
|
-
//
|
|
652
|
+
// Resetting derived pagination state here intentionally preserves the
|
|
653
|
+
// current rows-per-page choice while jumping back to the first page.
|
|
654
|
+
// eslint-disable-next-line @eslint-react/set-state-in-effect
|
|
642
655
|
setPagination(function (previous) {
|
|
643
656
|
if (previous.resetFlag === resetFlag) {
|
|
644
657
|
return previous;
|
|
@@ -706,31 +719,38 @@ function EnhancedTableHead(props) {
|
|
|
706
719
|
rowCount = props.rowCount,
|
|
707
720
|
onSelectAllClick = props.onSelectAllClick,
|
|
708
721
|
async = props.async;
|
|
709
|
-
return /*#__PURE__*/
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
722
|
+
return /*#__PURE__*/jsx(TableHead, {
|
|
723
|
+
children: /*#__PURE__*/jsxs(TableRow, {
|
|
724
|
+
children: [selectRows && /*#__PURE__*/jsx(TableCell, {
|
|
725
|
+
padding: "checkbox",
|
|
726
|
+
children: /*#__PURE__*/jsx(Checkbox, {
|
|
727
|
+
color: "primary",
|
|
728
|
+
indeterminate: numSelected > 0 && numSelected < rowCount,
|
|
729
|
+
checked: rowCount > 0 && numSelected === rowCount,
|
|
730
|
+
onChange: onSelectAllClick
|
|
731
|
+
})
|
|
732
|
+
}), props.headings.map(function (headCell) {
|
|
733
|
+
return /*#__PURE__*/jsx(TableCell, {
|
|
734
|
+
align: headCell.numeric ? "right" : "left",
|
|
735
|
+
padding: "normal",
|
|
736
|
+
sortDirection: orderBy === headCell.id ? order : false,
|
|
737
|
+
children: /*#__PURE__*/jsxs(TableSortLabel, {
|
|
738
|
+
active: orderBy === headCell.id,
|
|
739
|
+
direction: orderBy === headCell.id ? order : "asc",
|
|
740
|
+
onClick: function onClick() {
|
|
741
|
+
return onRequestSort(headCell.id, headCell.sortable && async);
|
|
742
|
+
},
|
|
743
|
+
disabled: headCell.subRow,
|
|
744
|
+
children: [headCell.label, orderBy === headCell.id ? /*#__PURE__*/jsx(Box, {
|
|
745
|
+
component: "span",
|
|
746
|
+
sx: visuallyHidden,
|
|
747
|
+
children: order === "desc" ? "sorted descending" : "sorted ascending"
|
|
748
|
+
}) : undefined]
|
|
749
|
+
})
|
|
750
|
+
}, headCell.id);
|
|
751
|
+
})]
|
|
752
|
+
})
|
|
753
|
+
});
|
|
734
754
|
}
|
|
735
755
|
EnhancedTableHead.propTypes = {
|
|
736
756
|
onRequestSort: PropTypes.func.isRequired,
|
|
@@ -744,11 +764,6 @@ EnhancedTableHead.propTypes = {
|
|
|
744
764
|
async: PropTypes.bool
|
|
745
765
|
};
|
|
746
766
|
|
|
747
|
-
/**
|
|
748
|
-
* Lazily import UniversalTable to statically break the circular dependency:
|
|
749
|
-
* UniversalTable → EnhancedTable → DataRow → SubTableRow → UniversalTable
|
|
750
|
-
* React.lazy resolves the import at render time, so the module graph stays acyclic.
|
|
751
|
-
*/
|
|
752
767
|
var UniversalTable$2 = /*#__PURE__*/React.lazy(function () {
|
|
753
768
|
return Promise.resolve().then(function () { return UniversalTable$1; });
|
|
754
769
|
});
|
|
@@ -763,30 +778,37 @@ function SubRowToggleCell(_ref) {
|
|
|
763
778
|
onToggle = _ref.onToggle,
|
|
764
779
|
rowValues = _ref.rowValues,
|
|
765
780
|
hideBadge = _ref.hideBadge;
|
|
766
|
-
return /*#__PURE__*/
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
781
|
+
return /*#__PURE__*/jsx(TableCell, {
|
|
782
|
+
children: /*#__PURE__*/jsx(Tooltip, {
|
|
783
|
+
title: isOpen ? "Hide ".concat(header.id) : "Show ".concat(header.id),
|
|
784
|
+
children: /*#__PURE__*/jsx(Box, {
|
|
785
|
+
children: /*#__PURE__*/jsx(IconButton, {
|
|
786
|
+
onClick: function onClick(event) {
|
|
787
|
+
event.stopPropagation();
|
|
788
|
+
onToggle();
|
|
789
|
+
},
|
|
790
|
+
disabled: rowValues[header.id].length === 0,
|
|
791
|
+
color: header.iconColor || "secondary",
|
|
792
|
+
children: /*#__PURE__*/jsx(Badge, {
|
|
793
|
+
badgeContent: rowValues[header.id].length,
|
|
794
|
+
invisible: hideBadge,
|
|
795
|
+
anchorOrigin: {
|
|
796
|
+
vertical: "bottom",
|
|
797
|
+
horizontal: "right"
|
|
798
|
+
},
|
|
799
|
+
sx: {
|
|
800
|
+
"& .MuiBadge-badge": {
|
|
801
|
+
color: function color(theme) {
|
|
802
|
+
return theme.palette.text.primary;
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
},
|
|
806
|
+
children: isOpen ? (header === null || header === void 0 ? void 0 : header.closeIcon) || /*#__PURE__*/jsx(RemoveCircle, {}) : (header === null || header === void 0 ? void 0 : header.openIcon) || /*#__PURE__*/jsx(AddCircle, {})
|
|
807
|
+
})
|
|
808
|
+
})
|
|
809
|
+
})
|
|
810
|
+
})
|
|
811
|
+
});
|
|
790
812
|
}
|
|
791
813
|
SubRowToggleCell.propTypes = {
|
|
792
814
|
header: PropTypes.object.isRequired,
|
|
@@ -805,27 +827,32 @@ function SubTableRow(_ref2) {
|
|
|
805
827
|
isOpen = _ref2.isOpen,
|
|
806
828
|
rowValues = _ref2.rowValues,
|
|
807
829
|
colSpan = _ref2.colSpan;
|
|
808
|
-
return /*#__PURE__*/
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
830
|
+
return /*#__PURE__*/jsx(TableRow, {
|
|
831
|
+
children: /*#__PURE__*/jsx(TableCell, {
|
|
832
|
+
colSpan: colSpan,
|
|
833
|
+
style: {
|
|
834
|
+
paddingBottom: 0,
|
|
835
|
+
paddingTop: 0
|
|
836
|
+
},
|
|
837
|
+
children: /*#__PURE__*/jsx(Collapse, {
|
|
838
|
+
"in": isOpen,
|
|
839
|
+
timeout: "auto",
|
|
840
|
+
unmountOnExit: true,
|
|
841
|
+
children: /*#__PURE__*/jsx(React.Suspense, {
|
|
842
|
+
fallback: null,
|
|
843
|
+
children: /*#__PURE__*/jsx(UniversalTable$2, {
|
|
844
|
+
loading: table.loading,
|
|
845
|
+
setLoading: table.setLoading,
|
|
846
|
+
onReload: table.onReload,
|
|
847
|
+
data: rowValues[table.id],
|
|
848
|
+
headers: table.headers,
|
|
849
|
+
name: table.subTitle,
|
|
850
|
+
subTable: true
|
|
851
|
+
})
|
|
852
|
+
})
|
|
853
|
+
})
|
|
854
|
+
})
|
|
855
|
+
});
|
|
829
856
|
}
|
|
830
857
|
SubTableRow.propTypes = {
|
|
831
858
|
table: PropTypes.object.isRequired,
|
|
@@ -835,10 +862,11 @@ SubTableRow.propTypes = {
|
|
|
835
862
|
};
|
|
836
863
|
|
|
837
864
|
function renderDataCells(headers, rowValues) {
|
|
838
|
-
return headers.map(function (header
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
865
|
+
return headers.map(function (header) {
|
|
866
|
+
var _header$id;
|
|
867
|
+
return /*#__PURE__*/jsx(TableCell, _objectSpread2(_objectSpread2({}, header.cellProps), {}, {
|
|
868
|
+
children: header.component ? header.component(rowValues) : formatCellValue(header, rowValues)
|
|
869
|
+
}), (_header$id = header.id) !== null && _header$id !== void 0 ? _header$id : header.label);
|
|
842
870
|
});
|
|
843
871
|
}
|
|
844
872
|
var DataRow = /*#__PURE__*/React.memo(function DataRow(props) {
|
|
@@ -873,41 +901,45 @@ var DataRow = /*#__PURE__*/React.memo(function DataRow(props) {
|
|
|
873
901
|
handleClick(event, props.rowID);
|
|
874
902
|
}
|
|
875
903
|
}, [selectRows, handleClick, props.rowID]);
|
|
876
|
-
return /*#__PURE__*/
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
904
|
+
return /*#__PURE__*/jsxs(Fragment, {
|
|
905
|
+
children: [/*#__PURE__*/jsxs(TableRow, {
|
|
906
|
+
tabIndex: selectRows ? 0 : -1,
|
|
907
|
+
hover: selectRows,
|
|
908
|
+
role: selectRows ? "checkbox" : "row",
|
|
909
|
+
selected: isItemSelected,
|
|
910
|
+
"aria-checked": isItemSelected,
|
|
911
|
+
onKeyDown: handleRowKeyDown,
|
|
912
|
+
children: [selectRows && /*#__PURE__*/jsx(TableCell, {
|
|
913
|
+
padding: "checkbox",
|
|
914
|
+
children: /*#__PURE__*/jsx(Checkbox, {
|
|
915
|
+
color: "primary",
|
|
916
|
+
checked: isItemSelected,
|
|
917
|
+
onClick: function onClick(event) {
|
|
918
|
+
return handleClick(event, props.rowID);
|
|
919
|
+
}
|
|
920
|
+
})
|
|
921
|
+
}), subTables.map(function (header, index) {
|
|
922
|
+
var _header$id2;
|
|
923
|
+
return /*#__PURE__*/jsx(SubRowToggleCell, {
|
|
924
|
+
header: header,
|
|
925
|
+
isOpen: reveal[index],
|
|
926
|
+
onToggle: function onToggle() {
|
|
927
|
+
return toggleSubRow(index);
|
|
928
|
+
},
|
|
929
|
+
rowValues: rowValues,
|
|
930
|
+
hideBadge: hideBadge
|
|
931
|
+
}, (_header$id2 = header.id) !== null && _header$id2 !== void 0 ? _header$id2 : header.label);
|
|
932
|
+
}), renderDataCells(columns, rowValues)]
|
|
933
|
+
}), subTables.map(function (table, index) {
|
|
934
|
+
var _table$id;
|
|
935
|
+
return /*#__PURE__*/jsx(SubTableRow, {
|
|
936
|
+
table: table,
|
|
937
|
+
isOpen: reveal[index],
|
|
938
|
+
rowValues: rowValues,
|
|
939
|
+
colSpan: props.headers.length + 1
|
|
940
|
+
}, (_table$id = table.id) !== null && _table$id !== void 0 ? _table$id : table.label);
|
|
941
|
+
})]
|
|
942
|
+
});
|
|
911
943
|
});
|
|
912
944
|
DataRow.propTypes = {
|
|
913
945
|
rowValues: PropTypes.object.isRequired,
|
|
@@ -919,22 +951,24 @@ DataRow.propTypes = {
|
|
|
919
951
|
rowID: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired
|
|
920
952
|
};
|
|
921
953
|
|
|
954
|
+
var skeletonRows = ["row-1", "row-2", "row-3", "row-4", "row-5"];
|
|
955
|
+
var skeletonCells = ["cell-1", "cell-2", "cell-3", "cell-4"];
|
|
922
956
|
var TableLoader = function TableLoader() {
|
|
923
|
-
return /*#__PURE__*/
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
})
|
|
936
|
-
})
|
|
937
|
-
})
|
|
957
|
+
return /*#__PURE__*/jsxs(Fragment, {
|
|
958
|
+
children: [/*#__PURE__*/jsx(TableHead, {}), /*#__PURE__*/jsx(TableBody, {
|
|
959
|
+
children: skeletonRows.map(function (rowKey) {
|
|
960
|
+
return /*#__PURE__*/jsx(TableRow, {
|
|
961
|
+
children: skeletonCells.map(function (cellKey) {
|
|
962
|
+
return /*#__PURE__*/jsx(TableCell, {
|
|
963
|
+
children: /*#__PURE__*/jsx(Skeleton, {
|
|
964
|
+
height: 30
|
|
965
|
+
})
|
|
966
|
+
}, cellKey);
|
|
967
|
+
})
|
|
968
|
+
}, rowKey);
|
|
969
|
+
})
|
|
970
|
+
})]
|
|
971
|
+
});
|
|
938
972
|
};
|
|
939
973
|
|
|
940
974
|
function EnhancedTable(props) {
|
|
@@ -977,59 +1011,66 @@ function EnhancedTable(props) {
|
|
|
977
1011
|
var visibleRows = React.useMemo(function () {
|
|
978
1012
|
return stableSort(rows, getComparator(order, orderBy), headers, orderBy).slice(page * effectiveRowsPerPage, page * effectiveRowsPerPage + effectiveRowsPerPage);
|
|
979
1013
|
}, [effectiveRowsPerPage, headers, order, orderBy, page, rows]);
|
|
980
|
-
return /*#__PURE__*/
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1014
|
+
return /*#__PURE__*/jsxs(TableContainer, {
|
|
1015
|
+
children: [/*#__PURE__*/jsx(Table, {
|
|
1016
|
+
sx: {
|
|
1017
|
+
minWidth: 750
|
|
1018
|
+
},
|
|
1019
|
+
size: "small" ,
|
|
1020
|
+
"aria-label": props.name || "data table",
|
|
1021
|
+
children: props.loading ? /*#__PURE__*/jsx(TableLoader, {}) : /*#__PURE__*/jsxs(Fragment, {
|
|
1022
|
+
children: [/*#__PURE__*/jsx(EnhancedTableHead, {
|
|
1023
|
+
order: order,
|
|
1024
|
+
orderBy: orderBy,
|
|
1025
|
+
onRequestSort: handleSort,
|
|
1026
|
+
headings: headers,
|
|
1027
|
+
selectRows: props.selectRows,
|
|
1028
|
+
numSelected: selected.length,
|
|
1029
|
+
rowCount: rows.length,
|
|
1030
|
+
onSelectAllClick: props.handleSelectAllClick,
|
|
1031
|
+
async: async
|
|
1032
|
+
}), /*#__PURE__*/jsxs(TableBody, {
|
|
1033
|
+
children: [visibleRows.map(function (row, index) {
|
|
1034
|
+
var rowKey = selectID ? row[selectID] : "row-".concat(page * effectiveRowsPerPage + index);
|
|
1035
|
+
var rowID = getSelectableRowId(row, index, selectID);
|
|
1036
|
+
return /*#__PURE__*/jsx(DataRow, {
|
|
1037
|
+
rowID: rowID,
|
|
1038
|
+
headers: headers,
|
|
1039
|
+
rowValues: row,
|
|
1040
|
+
hideBadge: props.hideBadge,
|
|
1041
|
+
selectRows: props.selectRows,
|
|
1042
|
+
handleClick: props.handleClick,
|
|
1043
|
+
isSelected: isSelected
|
|
1044
|
+
}, rowKey);
|
|
1045
|
+
}), !subTable && emptyRows > 0 && /*#__PURE__*/jsx(TableRow, {
|
|
1046
|
+
style: {
|
|
1047
|
+
height: (33 ) * emptyRows
|
|
1048
|
+
},
|
|
1049
|
+
children: /*#__PURE__*/jsx(TableCell, {
|
|
1050
|
+
colSpan: headers.length
|
|
1051
|
+
})
|
|
1052
|
+
})]
|
|
1053
|
+
})]
|
|
1054
|
+
})
|
|
1055
|
+
}), subTable ? /*#__PURE__*/jsx(Box, {
|
|
1056
|
+
sx: {
|
|
1057
|
+
mb: 3
|
|
1058
|
+
}
|
|
1059
|
+
}) : /*#__PURE__*/jsx(TablePagination, {
|
|
1060
|
+
rowsPerPageOptions: props.pageSizeOptions || getPageOptions(rows.length),
|
|
1061
|
+
component: "div",
|
|
1062
|
+
count: rows.length,
|
|
1063
|
+
rowsPerPage: rowsPerPage,
|
|
1064
|
+
page: page,
|
|
1065
|
+
onPageChange: handleChangePage,
|
|
1066
|
+
onRowsPerPageChange: handleChangeRowsPerPage,
|
|
1067
|
+
sx: {
|
|
1068
|
+
overflow: "visible"
|
|
1069
|
+
},
|
|
1070
|
+
showFirstButton: true,
|
|
1071
|
+
showLastButton: true
|
|
1072
|
+
})]
|
|
1073
|
+
});
|
|
1033
1074
|
}
|
|
1034
1075
|
EnhancedTable.propTypes = {
|
|
1035
1076
|
headers: PropTypes.array.isRequired,
|
|
@@ -1080,6 +1121,7 @@ function UniversalTable(_ref) {
|
|
|
1080
1121
|
persistSearch = _ref.persistSearch,
|
|
1081
1122
|
asyncPages = _ref.asyncPages;
|
|
1082
1123
|
var debounceRef = React.useRef(null);
|
|
1124
|
+
var hasLoadedInitialAsyncPageRef = React.useRef(false);
|
|
1083
1125
|
var async = typeof asyncPages === "number" && asyncPages > 0;
|
|
1084
1126
|
var head = headers || [];
|
|
1085
1127
|
var _useSearchableRows = useSearchableRows(data, head, async),
|
|
@@ -1129,18 +1171,17 @@ function UniversalTable(_ref) {
|
|
|
1129
1171
|
};
|
|
1130
1172
|
}, []);
|
|
1131
1173
|
React.useEffect(function () {
|
|
1132
|
-
if (async) {
|
|
1133
|
-
|
|
1134
|
-
searchTerm: searchTerm,
|
|
1135
|
-
direction: order,
|
|
1136
|
-
column: orderBy,
|
|
1137
|
-
pages: asyncPages
|
|
1138
|
-
});
|
|
1174
|
+
if (!async || hasLoadedInitialAsyncPageRef.current) {
|
|
1175
|
+
return;
|
|
1139
1176
|
}
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1177
|
+
hasLoadedInitialAsyncPageRef.current = true;
|
|
1178
|
+
setLoading({
|
|
1179
|
+
searchTerm: searchTerm,
|
|
1180
|
+
direction: order,
|
|
1181
|
+
column: orderBy,
|
|
1182
|
+
pages: asyncPages
|
|
1183
|
+
});
|
|
1184
|
+
}, [async, asyncPages, order, orderBy, searchTerm, setLoading]);
|
|
1144
1185
|
var handleReload = React.useCallback(function () {
|
|
1145
1186
|
if (typeof onReload === "function") {
|
|
1146
1187
|
onReload();
|
|
@@ -1155,51 +1196,54 @@ function UniversalTable(_ref) {
|
|
|
1155
1196
|
} : true);
|
|
1156
1197
|
}
|
|
1157
1198
|
}, [async, onReload, setLoading, searchTerm, order, orderBy, asyncPages]);
|
|
1158
|
-
return /*#__PURE__*/
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1199
|
+
return /*#__PURE__*/jsxs(Fragment, {
|
|
1200
|
+
children: [/*#__PURE__*/jsx(LazyLoadingIndicator, {
|
|
1201
|
+
show: lazyloading,
|
|
1202
|
+
currentPage: currentPage,
|
|
1203
|
+
totalPages: totalPages
|
|
1204
|
+
}), /*#__PURE__*/jsxs(Paper$1, {
|
|
1205
|
+
sx: _objectSpread2({}, subTable && {
|
|
1206
|
+
boxShadow: "none"
|
|
1207
|
+
}),
|
|
1208
|
+
children: [/*#__PURE__*/jsx(TableSelectionBanner, {
|
|
1209
|
+
selected: selected,
|
|
1210
|
+
onSelection: onSelection,
|
|
1211
|
+
selectIcon: selectIcon
|
|
1212
|
+
}), /*#__PURE__*/jsx(TableTitle, {
|
|
1213
|
+
name: name,
|
|
1214
|
+
subTable: subTable
|
|
1215
|
+
}), !subTable && /*#__PURE__*/jsx(TableToolbarContent, {
|
|
1216
|
+
onReload: typeof onReload === "function" || typeof setLoading === "function" ? handleReload : undefined,
|
|
1217
|
+
reloadBtnLoading: reloadBtnLoading,
|
|
1218
|
+
searchTerm: searchTerm,
|
|
1219
|
+
onSearchChange: handleSearch,
|
|
1220
|
+
name: name,
|
|
1221
|
+
persistSearch: persistSearch
|
|
1222
|
+
}), /*#__PURE__*/jsx(EnhancedTable, {
|
|
1223
|
+
headers: head,
|
|
1224
|
+
rows: rows,
|
|
1225
|
+
resetFlag: searchTerm,
|
|
1226
|
+
searchTerm: searchTerm,
|
|
1227
|
+
subTable: subTable,
|
|
1228
|
+
hideBadge: hideBadge,
|
|
1229
|
+
loading: loading,
|
|
1230
|
+
selectRows: selectRows,
|
|
1231
|
+
handleSelectAllClick: handleSelectAllClick,
|
|
1232
|
+
handleClick: handleClick,
|
|
1233
|
+
selected: selected,
|
|
1234
|
+
selectID: selectID,
|
|
1235
|
+
pageSizeOptions: pageSizeOptions,
|
|
1236
|
+
name: name,
|
|
1237
|
+
setLoading: setLoading,
|
|
1238
|
+
order: order,
|
|
1239
|
+
orderBy: orderBy,
|
|
1240
|
+
setOrder: setOrder,
|
|
1241
|
+
setOrderBy: setOrderBy,
|
|
1242
|
+
asyncPages: asyncPages,
|
|
1243
|
+
async: async
|
|
1244
|
+
})]
|
|
1245
|
+
})]
|
|
1246
|
+
});
|
|
1203
1247
|
}
|
|
1204
1248
|
UniversalTable.propTypes = {
|
|
1205
1249
|
loading: PropTypes.bool,
|