@onehat/ui 0.3.3 → 0.3.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onehat/ui",
3
- "version": "0.3.3",
3
+ "version": "0.3.4",
4
4
  "description": "Base UI for OneHat apps",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -505,6 +505,8 @@ export function ComboComponent(props) {
505
505
  <WhichGrid
506
506
  showHeaders={false}
507
507
  showHovers={true}
508
+ pageSize={100}
509
+ disableAdjustingPageSizeToHeight={true}
508
510
  shadow={1}
509
511
  getRowProps={() => {
510
512
  return {
@@ -21,6 +21,11 @@ import {
21
21
  DROP_POSITION_BEFORE,
22
22
  DROP_POSITION_AFTER,
23
23
  } from '../../Constants/Grid.js';
24
+ import {
25
+ UI_MODE_WEB,
26
+ UI_MODE_REACT_NATIVE,
27
+ CURRENT_MODE,
28
+ } from '../../Constants/UiModes.js';
24
29
  import * as colourMixer from '@k-renwick/colour-mixer'
25
30
  import UiGlobals from '../../UiGlobals.js';
26
31
  import useForceUpdate from '../../Hooks/useForceUpdate.js';
@@ -70,6 +75,7 @@ function GridComponent(props) {
70
75
  pullToRefresh = true,
71
76
  hideNavColumn = true,
72
77
  noneFoundText,
78
+ disableAdjustingPageSizeToHeight = false,
73
79
  disableLoadingIndicator = false,
74
80
  disableSelectorSelected = false,
75
81
  showRowExpander = false,
@@ -608,6 +614,41 @@ function GridComponent(props) {
608
614
  dragRowSlot.marker.remove();
609
615
  }
610
616
  setDragRowSlot(null);
617
+ },
618
+ onLayout = (e) => {
619
+ if (disableAdjustingPageSizeToHeight || !Repository) {
620
+ return;
621
+ }
622
+ const {
623
+ nativeEvent: {
624
+ layout,
625
+ target,
626
+ },
627
+ } = e;
628
+ let pageSize;
629
+ if (CURRENT_MODE === UI_MODE_WEB) {
630
+ const
631
+ targetBoundingBox = target.getBoundingClientRect(),
632
+ targetHeight = targetBoundingBox.height,
633
+ firstRow = target.children[0]?.children[0]?.children[0]?.children[0]?.children[0];
634
+ if (firstRow) {
635
+ const
636
+ rowBoundingBox = firstRow.getBoundingClientRect(),
637
+ rowHeight = rowBoundingBox.height,
638
+ rowsPerTarget = Math.floor(targetHeight / rowHeight);
639
+ pageSize = rowsPerTarget;
640
+ if (showHeaders) {
641
+ pageSize--;
642
+ }
643
+ if (bottomToolbar) {
644
+ pageSize--;
645
+ }
646
+ }
647
+ }
648
+
649
+ if (pageSize) {
650
+ Repository.setPageSize(pageSize);
651
+ }
611
652
  };
612
653
 
613
654
  useEffect(() => {
@@ -752,7 +793,7 @@ function GridComponent(props) {
752
793
  if (inlineEditor) {
753
794
  rowData.push({ id: 'inlineEditor' }); // make editor the last row so it can scroll with all other rows
754
795
  }
755
- const initialNumToRender = rowData.length || 10;
796
+ const initialNumToRender = rowData?.length || 10;
756
797
 
757
798
  // headers & footers
758
799
  let listFooterComponent = null;
@@ -776,6 +817,7 @@ function GridComponent(props) {
776
817
  bg={bg}
777
818
  borderWidth={styles.GRID_BORDER_WIDTH}
778
819
  borderColor={styles.GRID_BORDER_COLOR}
820
+ onLayout={onLayout}
779
821
  {...sizeProps}
780
822
  >
781
823
  {topToolbar}
@@ -19,6 +19,7 @@ export default function withData(WrappedComponent) {
19
19
  uniqueRepository = false,
20
20
  model,
21
21
  autoLoad = false,
22
+ pageSize,
22
23
 
23
24
  // For plain JS data
24
25
  data,
@@ -51,6 +52,10 @@ export default function withData(WrappedComponent) {
51
52
  Repository = oneHatData.getRepository(model);
52
53
  }
53
54
 
55
+ if (pageSize) {
56
+ Repository.setPageSize(pageSize);
57
+ }
58
+
54
59
  if (Repository && (autoLoad || Repository.autoLoad) && !Repository.isLoaded && Repository.isRemote && !Repository.isAutoLoad && !Repository.isLoading) {
55
60
  await Repository.load();
56
61
  }