@natoora-libs/core 0.1.16-dev-doug-6 → 0.1.16-dev-doug-8

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.
@@ -7449,6 +7449,28 @@ var TableDesktopFooter = ({
7449
7449
  );
7450
7450
  };
7451
7451
 
7452
+ // src/components/TableDesktopLoadingState/TableDesktopLoadingState.tsx
7453
+ var import_material63 = require("@mui/material");
7454
+ var import_jsx_runtime115 = require("react/jsx-runtime");
7455
+ var getRange = (n) => Array.from({ length: n }, (_, i) => i + 1);
7456
+ var TableDesktopLoadingState = ({
7457
+ numRows,
7458
+ rowsPerPage,
7459
+ numColumns,
7460
+ rowHeight
7461
+ }) => {
7462
+ return getRange(Math.min(numRows, rowsPerPage)).map((rowNum) => /* @__PURE__ */ (0, import_jsx_runtime115.jsx)(import_material63.TableRow, { children: getRange(numColumns).map((colNum) => /* @__PURE__ */ (0, import_jsx_runtime115.jsx)(import_material63.TableCell, { children: /* @__PURE__ */ (0, import_jsx_runtime115.jsx)(
7463
+ import_material63.Skeleton,
7464
+ {
7465
+ animation: "pulse",
7466
+ variant: "rounded",
7467
+ height: rowHeight - 33,
7468
+ sx: { bgcolor: colors.neutral100 },
7469
+ "data-testid": "loading-skeleton"
7470
+ }
7471
+ ) }, colNum)) }, rowNum));
7472
+ };
7473
+
7452
7474
  // src/components/TableDesktopNoColumnsMessage/TableDesktopNoColumnsMessage.tsx
7453
7475
  var import_TableBody = __toESM(require("@mui/material/TableBody"), 1);
7454
7476
  var import_TableCell = __toESM(require("@mui/material/TableCell"), 1);
@@ -7456,11 +7478,11 @@ var import_TableRow = __toESM(require("@mui/material/TableRow"), 1);
7456
7478
  var import_Typography = __toESM(require("@mui/material/Typography"), 1);
7457
7479
 
7458
7480
  // src/components/Buttons/BaseButton/BaseIconButton.tsx
7459
- var import_material63 = require("@mui/material");
7460
- var import_jsx_runtime115 = require("react/jsx-runtime");
7481
+ var import_material64 = require("@mui/material");
7482
+ var import_jsx_runtime116 = require("react/jsx-runtime");
7461
7483
  var BaseIconButton = ({ icon, sx, ...props }) => {
7462
- return /* @__PURE__ */ (0, import_jsx_runtime115.jsxs)(
7463
- import_material63.Button,
7484
+ return /* @__PURE__ */ (0, import_jsx_runtime116.jsxs)(
7485
+ import_material64.Button,
7464
7486
  {
7465
7487
  sx: {
7466
7488
  display: "flex",
@@ -7480,10 +7502,10 @@ var BaseIconButton = ({ icon, sx, ...props }) => {
7480
7502
  };
7481
7503
 
7482
7504
  // src/components/TableDesktopNoColumnsMessage/TableDesktopNoColumnsMessage.tsx
7483
- var import_jsx_runtime116 = require("react/jsx-runtime");
7505
+ var import_jsx_runtime117 = require("react/jsx-runtime");
7484
7506
  var TableDesktopNoColumnsMessage = ({
7485
7507
  onClickNoColumnsMessageOpenMenu
7486
- }) => /* @__PURE__ */ (0, import_jsx_runtime116.jsx)(import_TableBody.default, { children: /* @__PURE__ */ (0, import_jsx_runtime116.jsx)(import_TableRow.default, { children: /* @__PURE__ */ (0, import_jsx_runtime116.jsxs)(
7508
+ }) => /* @__PURE__ */ (0, import_jsx_runtime117.jsx)(import_TableBody.default, { children: /* @__PURE__ */ (0, import_jsx_runtime117.jsx)(import_TableRow.default, { children: /* @__PURE__ */ (0, import_jsx_runtime117.jsxs)(
7487
7509
  import_TableCell.default,
7488
7510
  {
7489
7511
  sx: {
@@ -7496,9 +7518,9 @@ var TableDesktopNoColumnsMessage = ({
7496
7518
  alignItems: "center"
7497
7519
  },
7498
7520
  children: [
7499
- /* @__PURE__ */ (0, import_jsx_runtime116.jsx)(import_Typography.default, { variant: "subtitle2", fontSize: 16, children: "Customise your view" }),
7500
- /* @__PURE__ */ (0, import_jsx_runtime116.jsx)(import_Typography.default, { variant: "subtitle1", align: "center", color: "textSecondary", children: "Open the menu to customise your table and search." }),
7501
- /* @__PURE__ */ (0, import_jsx_runtime116.jsxs)(
7521
+ /* @__PURE__ */ (0, import_jsx_runtime117.jsx)(import_Typography.default, { variant: "subtitle2", fontSize: 16, children: "Customise your view" }),
7522
+ /* @__PURE__ */ (0, import_jsx_runtime117.jsx)(import_Typography.default, { variant: "subtitle1", align: "center", color: "textSecondary", children: "Open the menu to customise your table and search." }),
7523
+ /* @__PURE__ */ (0, import_jsx_runtime117.jsxs)(
7502
7524
  import_Typography.default,
7503
7525
  {
7504
7526
  variant: "subtitle1",
@@ -7511,18 +7533,18 @@ var TableDesktopNoColumnsMessage = ({
7511
7533
  },
7512
7534
  children: [
7513
7535
  "Tips: ",
7514
- /* @__PURE__ */ (0, import_jsx_runtime116.jsx)(import_Typography.default, { component: "strong", children: "Save as default" }),
7536
+ /* @__PURE__ */ (0, import_jsx_runtime117.jsx)(import_Typography.default, { component: "strong", children: "Save as default" }),
7515
7537
  " to keep these columns for future views"
7516
7538
  ]
7517
7539
  }
7518
7540
  ),
7519
- /* @__PURE__ */ (0, import_jsx_runtime116.jsx)(
7541
+ /* @__PURE__ */ (0, import_jsx_runtime117.jsx)(
7520
7542
  BaseIconButton,
7521
7543
  {
7522
7544
  variant: "contained",
7523
7545
  color: "primary",
7524
7546
  onClick: onClickNoColumnsMessageOpenMenu,
7525
- icon: /* @__PURE__ */ (0, import_jsx_runtime116.jsx)(IconTableEdit_default, { fill: colors.white }),
7547
+ icon: /* @__PURE__ */ (0, import_jsx_runtime117.jsx)(IconTableEdit_default, { fill: colors.white }),
7526
7548
  children: "OPEN MENU"
7527
7549
  }
7528
7550
  )
@@ -7530,28 +7552,6 @@ var TableDesktopNoColumnsMessage = ({
7530
7552
  }
7531
7553
  ) }) });
7532
7554
 
7533
- // src/components/TableDesktopLoadingState/TableDesktopLoadingState.tsx
7534
- var import_material64 = require("@mui/material");
7535
- var import_jsx_runtime117 = require("react/jsx-runtime");
7536
- var getRange = (n) => Array.from({ length: n }, (_, i) => i + 1);
7537
- var TableDesktopLoadingState = ({
7538
- numRows,
7539
- rowsPerPage,
7540
- numColumns,
7541
- rowHeight
7542
- }) => {
7543
- return getRange(Math.min(numRows, rowsPerPage)).map((rowNum) => /* @__PURE__ */ (0, import_jsx_runtime117.jsx)(import_material64.TableRow, { children: getRange(numColumns).map((colNum) => /* @__PURE__ */ (0, import_jsx_runtime117.jsx)(import_material64.TableCell, { children: /* @__PURE__ */ (0, import_jsx_runtime117.jsx)(
7544
- import_material64.Skeleton,
7545
- {
7546
- animation: "pulse",
7547
- variant: "rounded",
7548
- height: rowHeight - 33,
7549
- sx: { bgcolor: colors.neutral100 },
7550
- "data-testid": "loading-skeleton"
7551
- }
7552
- ) }, colNum)) }, rowNum));
7553
- };
7554
-
7555
7555
  // src/components/TableDesktopRows/TableDesktopRows.tsx
7556
7556
  var import_jsx_runtime118 = require("react/jsx-runtime");
7557
7557
  var descendingComparator2 = (a, b, orderBy) => {
@@ -7588,8 +7588,6 @@ var TableDesktopRows = ({
7588
7588
  keyField,
7589
7589
  order,
7590
7590
  orderBy,
7591
- rowsPerPage,
7592
- isLoading,
7593
7591
  disableInternalSort,
7594
7592
  enableCheckboxSelection,
7595
7593
  enableEditMode,
@@ -7599,17 +7597,6 @@ var TableDesktopRows = ({
7599
7597
  deleteItem
7600
7598
  }) => {
7601
7599
  const sortedData = disableInternalSort ? data : stableSort2(data, getComparator(order, orderBy));
7602
- if (isLoading) {
7603
- return /* @__PURE__ */ (0, import_jsx_runtime118.jsx)(
7604
- TableDesktopLoadingState,
7605
- {
7606
- numRows: data.length,
7607
- rowsPerPage,
7608
- numColumns: visibleHeadCells.length + (enableCheckboxSelection ? 1 : 0),
7609
- rowHeight
7610
- }
7611
- );
7612
- }
7613
7600
  return sortedData.map((row, index) => {
7614
7601
  const isItemSelected = selectedRows.has(row[keyField]);
7615
7602
  return /* @__PURE__ */ (0, import_jsx_runtime118.jsx)(
@@ -7730,7 +7717,7 @@ var TableEmptyResult_default = TableEmptyResult;
7730
7717
  // src/components/TableDesktop/TableDesktop.tsx
7731
7718
  var import_jsx_runtime121 = require("react/jsx-runtime");
7732
7719
  var TableDesktop = ({
7733
- data,
7720
+ data = [],
7734
7721
  headCells,
7735
7722
  RenderItem,
7736
7723
  appliedFilters,
@@ -7847,6 +7834,53 @@ var TableDesktop = ({
7847
7834
  );
7848
7835
  }
7849
7836
  }, [data, setSelectedRows, isEveryRowInPageSelected, isRowsFromAllPagesSelected]);
7837
+ const renderBody = (0, import_react35.useMemo)(
7838
+ () => rowsPerPage !== emptyRows ? /* @__PURE__ */ (0, import_jsx_runtime121.jsx)(
7839
+ TableDesktopRows,
7840
+ {
7841
+ data,
7842
+ RenderItem,
7843
+ visibleHeadCells,
7844
+ keyField,
7845
+ order,
7846
+ orderBy,
7847
+ disableInternalSort,
7848
+ enableCheckboxSelection,
7849
+ enableEditMode,
7850
+ selectedRows,
7851
+ handleRowCheckboxChange,
7852
+ rowHeight,
7853
+ deleteItem
7854
+ }
7855
+ ) : /* @__PURE__ */ (0, import_jsx_runtime121.jsx)(
7856
+ TableEmptyResult_default,
7857
+ {
7858
+ colSpan: enableCheckboxSelection ? visibleHeadCells.length + 1 : visibleHeadCells.length,
7859
+ showClearFilterButton,
7860
+ handleClickOnClearFiltersButton
7861
+ }
7862
+ ),
7863
+ [
7864
+ rowsPerPage,
7865
+ emptyRows,
7866
+ data,
7867
+ RenderItem,
7868
+ visibleHeadCells,
7869
+ keyField,
7870
+ order,
7871
+ orderBy,
7872
+ isLoading,
7873
+ disableInternalSort,
7874
+ enableCheckboxSelection,
7875
+ enableEditMode,
7876
+ selectedRows,
7877
+ handleRowCheckboxChange,
7878
+ rowHeight,
7879
+ deleteItem,
7880
+ showClearFilterButton,
7881
+ handleClickOnClearFiltersButton
7882
+ ]
7883
+ );
7850
7884
  return /* @__PURE__ */ (0, import_jsx_runtime121.jsx)(
7851
7885
  import_material67.Box,
7852
7886
  {
@@ -7913,7 +7947,7 @@ var TableDesktop = ({
7913
7947
  stickyHeader: true,
7914
7948
  "aria-label": "sticky-table",
7915
7949
  sx: { tableLayout },
7916
- children: visibleHeadCells.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime121.jsx)(
7950
+ children: visibleHeadCells.length === 0 && !isLoading ? /* @__PURE__ */ (0, import_jsx_runtime121.jsx)(
7917
7951
  TableDesktopNoColumnsMessage,
7918
7952
  {
7919
7953
  onClickNoColumnsMessageOpenMenu: toolbarProps?.onClickToolbarMenuOpen
@@ -7935,31 +7969,13 @@ var TableDesktop = ({
7935
7969
  shouldShowCheckOnFilter
7936
7970
  }
7937
7971
  ),
7938
- /* @__PURE__ */ (0, import_jsx_runtime121.jsx)(import_material67.TableBody, { children: rowsPerPage !== emptyRows ? /* @__PURE__ */ (0, import_jsx_runtime121.jsx)(
7939
- TableDesktopRows,
7972
+ /* @__PURE__ */ (0, import_jsx_runtime121.jsx)(import_material67.TableBody, { children: !isLoading ? renderBody : /* @__PURE__ */ (0, import_jsx_runtime121.jsx)(
7973
+ TableDesktopLoadingState,
7940
7974
  {
7941
- data,
7942
- RenderItem,
7943
- visibleHeadCells,
7944
- keyField,
7945
- order,
7946
- orderBy,
7975
+ numRows: data.length,
7947
7976
  rowsPerPage,
7948
- isLoading,
7949
- disableInternalSort,
7950
- enableCheckboxSelection,
7951
- enableEditMode,
7952
- selectedRows,
7953
- handleRowCheckboxChange,
7954
- rowHeight,
7955
- deleteItem
7956
- }
7957
- ) : /* @__PURE__ */ (0, import_jsx_runtime121.jsx)(
7958
- TableEmptyResult_default,
7959
- {
7960
- colSpan: enableCheckboxSelection ? visibleHeadCells.length + 1 : visibleHeadCells.length,
7961
- showClearFilterButton,
7962
- handleClickOnClearFiltersButton
7977
+ numColumns: visibleHeadCells.length + (enableCheckboxSelection ? 1 : 0),
7978
+ rowHeight
7963
7979
  }
7964
7980
  ) })
7965
7981
  ] })
@@ -7991,14 +8007,18 @@ var TableDesktopNumericField = ({
7991
8007
  field,
7992
8008
  variant = "standard",
7993
8009
  size,
8010
+ validateInput,
7994
8011
  onUpdateEditableCell
7995
8012
  }) => {
7996
8013
  const [input, setInput] = (0, import_react36.useState)(initialValue);
8014
+ const oldValue = (0, import_react36.useRef)(initialValue);
8015
+ const isDirty = (0, import_react36.useMemo)(() => input !== oldValue.current, [input, oldValue.current]);
8016
+ const hasValidationError = (0, import_react36.useMemo)(() => isDirty && !validateInput?.(input), [input, validateInput, isDirty]);
7997
8017
  const commitValue = (value) => {
7998
- const isDirty = value !== initialValue;
7999
- if (!onUpdateEditableCell || !isDirty) {
8018
+ if (hasValidationError || !onUpdateEditableCell || !isDirty) {
8000
8019
  return;
8001
8020
  }
8021
+ oldValue.current = value;
8002
8022
  onUpdateEditableCell(rowId ?? 0, field, value, value);
8003
8023
  };
8004
8024
  const handleKeyDown = (e) => {
@@ -8016,6 +8036,7 @@ var TableDesktopNumericField = ({
8016
8036
  value: input,
8017
8037
  disabled,
8018
8038
  label: inputLabel,
8039
+ error: hasValidationError,
8019
8040
  onKeyDown: handleKeyDown,
8020
8041
  onChange: (e) => {
8021
8042
  e.target.value = e.target.value.replace(/\D/g, "");
@@ -8122,12 +8143,14 @@ var TableDesktopTextField = ({
8122
8143
  onUpdateEditableCell
8123
8144
  }) => {
8124
8145
  const [input, setInput] = (0, import_react38.useState)(initialValue);
8125
- const hasValidationError = (0, import_react38.useMemo)(() => !validateInput?.(input), [input, validateInput]);
8146
+ const oldValue = (0, import_react38.useRef)(initialValue);
8147
+ const isDirty = (0, import_react38.useMemo)(() => input !== oldValue.current, [input, oldValue.current]);
8148
+ const hasValidationError = (0, import_react38.useMemo)(() => isDirty && !validateInput?.(input), [input, validateInput]);
8126
8149
  const commitValue = (value) => {
8127
- const isDirty = value !== initialValue;
8128
8150
  if (hasValidationError || !onUpdateEditableCell || !isDirty) {
8129
8151
  return;
8130
8152
  }
8153
+ oldValue.current = value;
8131
8154
  onUpdateEditableCell(rowId ?? 0, field, value, value);
8132
8155
  };
8133
8156
  const handleKeyDown = (e) => {
@@ -8238,6 +8261,7 @@ var TableDesktopEditableComponent = ({
8238
8261
  field,
8239
8262
  initialValue: editInitialValue ?? "",
8240
8263
  inputLabel: inputLabel ?? "",
8264
+ validateInput,
8241
8265
  onUpdateEditableCell
8242
8266
  }
8243
8267
  )