Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EuiDataGrid] improve height calculation #5447

Conversation

chandlerprall
Copy link
Contributor

@chandlerprall chandlerprall commented Dec 6, 2021

Summary

Fixes a bug that was uncovered by adding the row height switcher, where going from single or line heights to auto fit wouldn't trigger a resize of the grid, as it is unable to guess the heights of rows when auto. This expands the unconstrained height calculation to include known heights and continue guessing at unknown rows, as auto-fit cells render their heights become known, causing the container to resize.

Added a cypress test for regression. Not sure if the approach grab the original height and do the rest of the test in a .then() block is the recommended approach, but it works and I couldn't find a way to do the comparison at a single block level.

Checklist

- [ ] Check against all themes for compatibility in both light and dark modes
- [ ] Checked in mobile

  • Checked in Chrome, Safari, Edge, and Firefox
    - [ ] Props have proper autodocs and playground toggles
    - [ ] Added documentation
    - [ ] Checked Code Sandbox works for any docs examples
  • Added or updated jest and cypress tests
  • Checked for breaking changes and labeled appropriately
    - [ ] Checked for accessibility including keyboard-only and screenreader modes
    - [ ] A changelog entry exists and is marked appropriately

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_5447/

@cee-chen
Copy link
Member

cee-chen commented Dec 6, 2021

Tested on Chrome, Edge, and Safari. Looks good except for one scenario:

  • Set the localStorage example (2nd on page) to Auto fit
  • Refresh the page
  • Note that the grid loads in with a scrollbar (which goes away when you click the display selector weirdly enough)

Also for some reason my local Firefox for some reason just has never shown grid heights correctly (see #5313 (review)) so you might want someone else to corroborate that it works there. It's showing a bunch of really bizarre extra height/whitespace for me on FF 🤷‍♀️

@chandlerprall chandlerprall changed the title Bug/datagrid height calculation [EuiDataGrid] improve height calculation Dec 7, 2021
@chandlerprall
Copy link
Contributor Author

Looks good except for one scenario:

Set the localStorage example (2nd on page) to Auto fit
Refresh the page
Note that the grid loads in with a scrollbar (which goes away when you click the display selector weirdly enough)

Pushed a fix, which triggers the grid body to re-render when any rows report a new height. If it looks good, I'll abstract the useState usage out so it's not such a weird block of code in the middle of other logic

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_5447/

@chandlerprall
Copy link
Contributor Author

@constancecchen I've pushed three change sets:

  • cherry-picked your callback simplification (thanks for that btw!)
  • abstracted the force rerender callback into a hook
  • refactored unconstrained height calculation into a hook for organization, added comments

@@ -254,6 +255,67 @@ export function getParentCellContent(_element: Node | HTMLElement) {
return element;
}

// computes the unconstrained (total possible) height of a grid
const useUnconstrainedHeight = ({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This entire commit + set of comments is amazing and really helps me understand what this PR is doing. Thanks for taking the time to do it!! 😍

In the future, I might poke a bit more at splitting up even more of data_grid_body's logic into separate utils/hooks like this for organization - I personally think it's super useful for dev experience and unit testing. Thanks for the awesome headstart!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Breaking out into more hooks would be great; likely a great time to pair as well

Copy link
Member

@cee-chen cee-chen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is seriously super cool. Thanks so much for going the extra mile here, I think it'll really pay off in the future in terms of dev experience and maintainability.

I have one minor non-blocking suggestion, but other than that I've tested this on Chrome, Safari, and Edge and confirm it's all working as expected. My Firefox is sadly still funkytown so if you could test that on my behalf it'd be super appreciated!

Co-authored-by: Constance <constancecchen@users.noreply.github.com>
@chandlerprall
Copy link
Contributor Author

In addition to Constance's 👁️ , I've tested in Chrome, FF, Edge, and Safari

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_5447/

@chandlerprall chandlerprall merged commit 9d816bf into elastic:feat/datagrid/toolbar-reorg-and-row-height-switcher Dec 7, 2021
@chandlerprall chandlerprall deleted the bug/datagrid-height-calculation branch December 7, 2021 19:50
cee-chen pushed a commit that referenced this pull request Dec 7, 2021
…5415)

* [EuiDataGrid] Toolbar UI layout reorganization (#5334)

* [EuiDataGrid] Add extra left prepend position to the `additionalControls` API (#5394)

* [EuiDataGrid] Add rowHeightSwitcher logic + API change (#5372)

* [EuiDataGrid] Add `onChange` callbacks for display selector changes (#5424)

* [EuiDataGrid] Row height switcher should override `rowHeights` + add reset button (#5428)

* [EuiDataGrid] improve height calculation (#5447)

Co-authored-by: Caroline Horn <549577+cchaos@users.noreply.github.com>
Co-authored-by: Chandler Prall <chandler.prall@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants