@onehat/ui 0.3.37 → 0.3.38

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.37",
3
+ "version": "0.3.38",
4
4
  "description": "Base UI for OneHat apps",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -150,7 +150,7 @@ function GridComponent(props) {
150
150
  gridRef = useRef(),
151
151
  gridContainerRef = useRef(),
152
152
  isAddingRef = useRef(),
153
- [isRendered, setIsRendered] = useState(false),
153
+ isRenderedRef = useRef(),
154
154
  [isReady, setIsReady] = useState(false),
155
155
  [isLoading, setIsLoading] = useState(false),
156
156
  [localColumnsConfig, setLocalColumnsConfigRaw] = useState([]),
@@ -622,50 +622,49 @@ function GridComponent(props) {
622
622
  }
623
623
  setDragRowSlot(null);
624
624
  },
625
- onLayout = (e) => {
626
-
625
+ adjustPageSizeToHeight = (e) => {
627
626
  let doLoad = false;
628
- if (!isRendered) {
629
- setIsRendered(true);
627
+ if (!isRenderedRef.current) {
628
+ isRenderedRef.current = true;
630
629
  if (loadOnRender && Repository && !Repository.isLoaded && !Repository.isLoading && !Repository.isAutoLoad) {
631
630
  doLoad = true; // first time in onLayout only!
632
631
  }
633
632
  }
634
633
 
635
- const adjustPageSizeToHeight = !!(disableAdjustingPageSizeToHeight || !Repository || CURRENT_MODE !== UI_MODE_WEB || !gridRef.current || isAddingRef.current);
634
+ let adjustPageSizeToHeight = true;
635
+ if (disableAdjustingPageSizeToHeight || !Repository) {
636
+ adjustPageSizeToHeight = false;
637
+ }
636
638
  if (adjustPageSizeToHeight) {
637
- // this currently only works on web
638
639
  const
639
- gr = gridContainerRef.current,
640
- // scrollableNode = gr.getScrollableNode(),
641
- // scrollableNodeBoundingBox = scrollableNode.getBoundingClientRect(),
642
- // scrollableNodeHeight = scrollableNodeBoundingBox.height,
643
- // firstRow = scrollableNode.children[0].children[showHeaders ? 1: 0];
644
- height = gr.getBoundingClientRect().height;
645
- // IDEALLY, we want the grid to load right away with appropriate limits.
646
- // Currently, it's been loading once, then doing layout then loading again with correct limit.
647
- // How do we get the right limit before it renders??
648
- // Estimate based on (container height -header -footer) / avg height? This won't work for rows that exceed the avg height.
649
- // Maybe we do that avg at first, and if it exceeds, then we do another query to lose the later ones, which are hidden anyway.
650
- // It'll only do that once. Better to hide the offscreen ones, than to show gap at first, and later fill it
651
- // if (firstRow) { // TODO: this assumes there is a row there already, which is wrong!
652
- // const
653
- // rowHeight = firstRow.getBoundingClientRect().height,
654
- // rowsPerContainer = Math.floor(scrollableNodeHeight / rowHeight);
655
- // let pageSize = rowsPerContainer;
656
- // if (showHeaders) {
657
- // pageSize--;
658
- // }
659
- // if (pageSize !== Repository.pageSize) {
660
- // Repository.setPageSize(pageSize);
661
- // }
662
- // }
640
+ containerHeight = e.nativeEvent.layout.height,
641
+ headerHeight = showHeaders ? 50 : 0,
642
+ footerHeight = !disablePagination ? 50 : 0,
643
+ height = containerHeight - headerHeight - footerHeight,
644
+ rowHeight = 48,
645
+ rowsPerContainer = Math.floor(height / rowHeight);
646
+ let pageSize = rowsPerContainer;
647
+ if (showHeaders) {
648
+ pageSize--;
649
+ }
650
+ if (pageSize !== Repository.pageSize) {
651
+ Repository.setPageSize(pageSize);
652
+ }
663
653
  }
664
654
  if (doLoad) {
665
655
  Repository.load();
666
656
  }
667
657
  },
668
- debouncedOnLayout = useCallback(_.debounce(onLayout, 500), []);
658
+ debouncedAdjustPageSizeToHeight = useCallback(_.debounce(adjustPageSizeToHeight, 200), []),
659
+ onLayout = (e) => {
660
+ if (!isRenderedRef.current) {
661
+ // first time, call this immediately
662
+ adjustPageSizeToHeight(e);
663
+ } else {
664
+ // debounce all subsequent calls
665
+ debouncedAdjustPageSizeToHeight(e);
666
+ }
667
+ };
669
668
 
670
669
  useEffect(() => {
671
670
 
@@ -841,7 +840,7 @@ function GridComponent(props) {
841
840
  bg={bg}
842
841
  borderWidth={styles.GRID_BORDER_WIDTH}
843
842
  borderColor={styles.GRID_BORDER_COLOR}
844
- onLayout={debouncedOnLayout}
843
+ onLayout={onLayout}
845
844
  {...sizeProps}
846
845
  >
847
846
  {topToolbar}
@@ -528,7 +528,6 @@ export default function withFilters(WrappedComponent) {
528
528
  editorType={EDITOR_TYPE__PLAIN}
529
529
  flex={1}
530
530
  startingValues={formStartingValues}
531
- minHeight={minHeight}
532
531
  items={[
533
532
  {
534
533
  type: 'Column',