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.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__*/React.createElement(Collapse, {
115
+ return /*#__PURE__*/jsx(Collapse, {
124
116
  "in": show,
125
117
  timeout: "auto",
126
- unmountOnExit: true
127
- }, /*#__PURE__*/React.createElement(Box, {
128
- sx: {
129
- width: "100%",
130
- p: 2
131
- }
132
- }, /*#__PURE__*/React.createElement(Typography, {
133
- variant: "body2",
134
- color: "text.secondary",
135
- sx: {
136
- mb: 1
137
- }
138
- }, "Loading page ", currentPage, " of ", totalPages, "..."), /*#__PURE__*/React.createElement(LinearProgress, {
139
- variant: "determinate",
140
- value: currentPage / totalPages * 100
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__*/React.createElement(Collapse, {
354
+ return /*#__PURE__*/jsx(Collapse, {
360
355
  "in": selected.length > 0,
361
- unmountOnExit: true
362
- }, /*#__PURE__*/React.createElement(Box, {
363
- sx: {
364
- p: 2,
365
- display: "flex",
366
- justifyContent: "space-between",
367
- bgcolor: function bgcolor(theme) {
368
- return alpha(theme.palette.primary.main, theme.palette.action.activatedOpacity);
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
- borderRadius: 1,
371
- borderBottomLeftRadius: 0,
372
- borderBottomRightRadius: 0
373
- }
374
- }, /*#__PURE__*/React.createElement(Typography, {
375
- variant: "h6",
376
- id: "tableTitle",
377
- component: "div"
378
- }, selected.length, " selected"), /*#__PURE__*/React.createElement(IconButton, {
379
- onClick: function onClick() {
380
- return onSelection(selected);
381
- }
382
- }, selectIcon || /*#__PURE__*/React.createElement(Task, null))));
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__*/React.createElement(Typography, {
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
- }, name);
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__*/React.createElement(Tooltip, {
419
- title: "Reload"
420
- }, /*#__PURE__*/React.createElement(Button, {
421
- variant: "contained",
422
- color: "primary",
423
- onClick: handleClick,
424
- disabled: loading
425
- }, /*#__PURE__*/React.createElement(RefreshIcon, null)));
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 isUserType = React.useRef(false);
453
- return /*#__PURE__*/React.createElement("form", {
454
- onSubmit: handleSubmit
455
- }, /*#__PURE__*/React.createElement(Paper, {
456
- elevation: 0,
457
- sx: {
458
- borderRadius: expanded ? "24px" : "50px",
459
- display: "flex",
460
- alignItems: "center",
461
- transition: "all 0.5s ease-in-out",
462
- p: expanded ? 1 : 0.5,
463
- width: "fit-content",
464
- border: function border(theme) {
465
- return "1px solid ".concat(theme.palette.divider);
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
- mb: 1
468
- },
469
- onMouseEnter: function onMouseEnter() {
470
- return setHover(true);
471
- },
472
- onMouseLeave: handleEndHover,
473
- onKeyDown: function onKeyDown(e) {
474
- return e.key === "Enter" && handleSubmit(e);
475
- }
476
- }, /*#__PURE__*/React.createElement(InputBase, {
477
- placeholder: "Search",
478
- value: value,
479
- onChange: function onChange(e) {
480
- isUserType.current = true;
481
- onSubmit(e.target.value);
482
- },
483
- sx: _objectSpread2({
484
- ml: 1,
485
- width: expanded ? "100%" : 0,
486
- transition: "width 0.5s ease-in-out"
487
- }, expanded ? {} : {
488
- margin: 0
489
- }),
490
- onBlur: handleEndHover
491
- }), /*#__PURE__*/React.createElement(Collapse, {
492
- "in": Boolean(value),
493
- orientation: "horizontal",
494
- unmountOnExit: true
495
- }, /*#__PURE__*/React.createElement(Stack, {
496
- direction: "row",
497
- spacing: 0,
498
- sx: {
499
- mr: 3,
500
- alignItems: "center"
501
- }
502
- }, /*#__PURE__*/React.createElement(IconButton, {
503
- onClick: function onClick() {
504
- isUserType.current = false;
505
- // Immediately clear instead of waiting for the debounce
506
- onSubmit("");
507
- }
508
- }, /*#__PURE__*/React.createElement(Clear, null)), /*#__PURE__*/React.createElement(Divider, {
509
- orientation: "vertical",
510
- flexItem: true
511
- }))), /*#__PURE__*/React.createElement(IconButton, {
512
- onClick: handleSubmit,
513
- type: "submit"
514
- }, /*#__PURE__*/React.createElement(Search, null))));
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__*/React.createElement("div", {
535
- key: "SearchArea"
536
- }, /*#__PURE__*/React.createElement(FancySearch, {
537
- value: searchVal,
538
- onSubmit: setFinalVal
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__*/React.createElement(Toolbar, {
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
- id: "tableTitle"
585
- }, /*#__PURE__*/React.createElement(ReloadBtn, {
586
- onReload: onReload,
587
- loading: reloadBtnLoading
588
- })), /*#__PURE__*/React.createElement(SearchArea, {
589
- current: searchTerm,
590
- setFinalVal: onSearchChange,
591
- searchName: name,
592
- persistSearch: persistSearch
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
- // eslint-disable-next-line react-hooks/set-state-in-effect
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__*/React.createElement(TableHead, null, /*#__PURE__*/React.createElement(TableRow, null, selectRows && /*#__PURE__*/React.createElement(TableCell, {
710
- padding: "checkbox"
711
- }, /*#__PURE__*/React.createElement(Checkbox, {
712
- color: "primary",
713
- indeterminate: numSelected > 0 && numSelected < rowCount,
714
- checked: rowCount > 0 && numSelected === rowCount,
715
- onChange: onSelectAllClick
716
- })), props.headings.map(function (headCell) {
717
- return /*#__PURE__*/React.createElement(TableCell, {
718
- key: headCell.id,
719
- align: headCell.numeric ? "right" : "left",
720
- padding: "normal",
721
- sortDirection: orderBy === headCell.id ? order : false
722
- }, /*#__PURE__*/React.createElement(TableSortLabel, {
723
- active: orderBy === headCell.id,
724
- direction: orderBy === headCell.id ? order : "asc",
725
- onClick: function onClick() {
726
- return onRequestSort(headCell.id, headCell.sortable && async);
727
- },
728
- disabled: headCell.subRow
729
- }, headCell.label, orderBy === headCell.id ? /*#__PURE__*/React.createElement(Box, {
730
- component: "span",
731
- sx: visuallyHidden
732
- }, order === "desc" ? "sorted descending" : "sorted ascending") : undefined));
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__*/React.createElement(TableCell, null, /*#__PURE__*/React.createElement(Tooltip, {
767
- title: isOpen ? "Hide ".concat(header.id) : "Show ".concat(header.id)
768
- }, /*#__PURE__*/React.createElement(Box, null, /*#__PURE__*/React.createElement(IconButton, {
769
- onClick: function onClick(event) {
770
- event.stopPropagation();
771
- onToggle();
772
- },
773
- disabled: rowValues[header.id].length === 0,
774
- color: header.iconColor || "secondary"
775
- }, /*#__PURE__*/React.createElement(Badge, {
776
- badgeContent: rowValues[header.id].length,
777
- invisible: hideBadge,
778
- anchorOrigin: {
779
- vertical: "bottom",
780
- horizontal: "right"
781
- },
782
- sx: {
783
- "& .MuiBadge-badge": {
784
- color: function color(theme) {
785
- return theme.palette.text.primary;
786
- }
787
- }
788
- }
789
- }, isOpen ? (header === null || header === void 0 ? void 0 : header.closeIcon) || /*#__PURE__*/React.createElement(RemoveCircle, null) : (header === null || header === void 0 ? void 0 : header.openIcon) || /*#__PURE__*/React.createElement(AddCircle, null))))));
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__*/React.createElement(TableRow, null, /*#__PURE__*/React.createElement(TableCell, {
809
- colSpan: colSpan,
810
- style: {
811
- paddingBottom: 0,
812
- paddingTop: 0
813
- }
814
- }, /*#__PURE__*/React.createElement(Collapse, {
815
- "in": isOpen,
816
- timeout: "auto",
817
- unmountOnExit: true
818
- }, /*#__PURE__*/React.createElement(React.Suspense, {
819
- fallback: null
820
- }, /*#__PURE__*/React.createElement(UniversalTable$2, {
821
- loading: table.loading,
822
- setLoading: table.setLoading,
823
- onReload: table.onReload,
824
- data: rowValues[table.id],
825
- headers: table.headers,
826
- name: table.subTitle,
827
- subTable: true
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, index) {
839
- return /*#__PURE__*/React.createElement(TableCell, _extends({
840
- key: header.id || index
841
- }, header.cellProps), header.component ? header.component(rowValues) : formatCellValue(header, rowValues));
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__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(TableRow, {
877
- tabIndex: selectRows ? 0 : -1,
878
- hover: selectRows,
879
- role: selectRows ? "checkbox" : "row",
880
- selected: isItemSelected,
881
- "aria-checked": isItemSelected,
882
- onKeyDown: handleRowKeyDown
883
- }, selectRows && /*#__PURE__*/React.createElement(TableCell, {
884
- padding: "checkbox"
885
- }, /*#__PURE__*/React.createElement(Checkbox, {
886
- color: "primary",
887
- checked: isItemSelected,
888
- onClick: function onClick(event) {
889
- return handleClick(event, props.rowID);
890
- }
891
- })), subTables.map(function (header, index) {
892
- return /*#__PURE__*/React.createElement(SubRowToggleCell, {
893
- key: header.id || index,
894
- header: header,
895
- isOpen: reveal[index],
896
- onToggle: function onToggle() {
897
- return toggleSubRow(index);
898
- },
899
- rowValues: rowValues,
900
- hideBadge: hideBadge
901
- });
902
- }), renderDataCells(columns, rowValues)), subTables.map(function (table, index) {
903
- return /*#__PURE__*/React.createElement(SubTableRow, {
904
- key: table.id || index,
905
- table: table,
906
- isOpen: reveal[index],
907
- rowValues: rowValues,
908
- colSpan: props.headers.length + 1
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__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(TableHead, null), /*#__PURE__*/React.createElement(TableBody, null, Array.from({
924
- length: 5
925
- }).map(function (_, index) {
926
- return /*#__PURE__*/React.createElement(TableRow, {
927
- key: index
928
- }, Array.from({
929
- length: 4
930
- }).map(function (_, cellIndex) {
931
- return /*#__PURE__*/React.createElement(TableCell, {
932
- key: cellIndex
933
- }, /*#__PURE__*/React.createElement(Skeleton, {
934
- height: 30
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__*/React.createElement(TableContainer, null, /*#__PURE__*/React.createElement(Table, {
981
- sx: {
982
- minWidth: 750
983
- },
984
- size: "small" ,
985
- "aria-label": props.name || "data table"
986
- }, props.loading ? /*#__PURE__*/React.createElement(TableLoader, null) : /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(EnhancedTableHead, {
987
- order: order,
988
- orderBy: orderBy,
989
- onRequestSort: handleSort,
990
- headings: headers,
991
- selectRows: props.selectRows,
992
- numSelected: selected.length,
993
- rowCount: rows.length,
994
- onSelectAllClick: props.handleSelectAllClick,
995
- async: async
996
- }), /*#__PURE__*/React.createElement(TableBody, null, visibleRows.map(function (row, index) {
997
- var rowKey = selectID ? row[selectID] : "row-".concat(page * effectiveRowsPerPage + index);
998
- var rowID = getSelectableRowId(row, index, selectID);
999
- return /*#__PURE__*/React.createElement(DataRow, {
1000
- key: rowKey,
1001
- rowID: rowID,
1002
- headers: headers,
1003
- rowValues: row,
1004
- hideBadge: props.hideBadge,
1005
- selectRows: props.selectRows,
1006
- handleClick: props.handleClick,
1007
- isSelected: isSelected
1008
- });
1009
- }), !subTable && emptyRows > 0 && /*#__PURE__*/React.createElement(TableRow, {
1010
- style: {
1011
- height: (33 ) * emptyRows
1012
- }
1013
- }, /*#__PURE__*/React.createElement(TableCell, {
1014
- colSpan: headers.length
1015
- }))))), subTable ? /*#__PURE__*/React.createElement(Box, {
1016
- sx: {
1017
- mb: 3
1018
- }
1019
- }) : /*#__PURE__*/React.createElement(TablePagination, {
1020
- rowsPerPageOptions: props.pageSizeOptions || getPageOptions(rows.length),
1021
- component: "div",
1022
- count: rows.length,
1023
- rowsPerPage: rowsPerPage,
1024
- page: page,
1025
- onPageChange: handleChangePage,
1026
- onRowsPerPageChange: handleChangeRowsPerPage,
1027
- sx: {
1028
- overflow: "visible"
1029
- },
1030
- showFirstButton: true,
1031
- showLastButton: true
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
- setLoading({
1134
- searchTerm: searchTerm,
1135
- direction: order,
1136
- column: orderBy,
1137
- pages: asyncPages
1138
- });
1174
+ if (!async || hasLoadedInitialAsyncPageRef.current) {
1175
+ return;
1139
1176
  }
1140
- // Run the initial async load once on mount; search/sort/reload handlers
1141
- // send their own payloads after user interaction.
1142
- // eslint-disable-next-line react-hooks/exhaustive-deps
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__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(LazyLoadingIndicator, {
1159
- show: lazyloading,
1160
- currentPage: currentPage,
1161
- totalPages: totalPages
1162
- }), /*#__PURE__*/React.createElement(Paper$1, {
1163
- sx: _objectSpread2({}, subTable && {
1164
- boxShadow: "none"
1165
- })
1166
- }, /*#__PURE__*/React.createElement(TableSelectionBanner, {
1167
- selected: selected,
1168
- onSelection: onSelection,
1169
- selectIcon: selectIcon
1170
- }), /*#__PURE__*/React.createElement(TableTitle, {
1171
- name: name,
1172
- subTable: subTable
1173
- }), !subTable && /*#__PURE__*/React.createElement(TableToolbarContent, {
1174
- onReload: typeof onReload === "function" || typeof setLoading === "function" ? handleReload : undefined,
1175
- reloadBtnLoading: reloadBtnLoading,
1176
- searchTerm: searchTerm,
1177
- onSearchChange: handleSearch,
1178
- name: name,
1179
- persistSearch: persistSearch
1180
- }), /*#__PURE__*/React.createElement(EnhancedTable, {
1181
- headers: head,
1182
- rows: rows,
1183
- resetFlag: searchTerm,
1184
- searchTerm: searchTerm,
1185
- subTable: subTable,
1186
- hideBadge: hideBadge,
1187
- loading: loading,
1188
- selectRows: selectRows,
1189
- handleSelectAllClick: handleSelectAllClick,
1190
- handleClick: handleClick,
1191
- selected: selected,
1192
- selectID: selectID,
1193
- pageSizeOptions: pageSizeOptions,
1194
- name: name,
1195
- setLoading: setLoading,
1196
- order: order,
1197
- orderBy: orderBy,
1198
- setOrder: setOrder,
1199
- setOrderBy: setOrderBy,
1200
- asyncPages: asyncPages,
1201
- async: async
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,