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] Fix row height not updating dynamically when set to auto #5281

Merged
merged 19 commits into from
Oct 28, 2021

Conversation

cee-chen
Copy link
Contributor

@cee-chen cee-chen commented Oct 18, 2021

Summary

This PR fixes an issue reported by the Discover team when any props (they tested with columns, I ran into this when changing rowHeightOptions dynamically) change on EuiDataGridCell.

It essentially removes several performance APIs in favor of updating the heights cache more aggressively/frequently to get behavior working as expected:

  • isHeightSame
  • clearHeightsCache

Before

before.mp4

After

fix.mp4

QA

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

- [ ] 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_5281/

@cee-chen cee-chen force-pushed the datagrid-auto-height-props-update branch from 07ea516 to 8214083 Compare October 18, 2021 22:19
@cee-chen cee-chen changed the title [EuiDataGrid] Fix incorrect content height check when row height is set to auto [EuiDataGrid] Fix row height not updating dynamically when set to auto Oct 18, 2021
@kibanamachine
Copy link

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

- if we're not checking for sameHeight in componentDidUpdate, we also likely don't need this anymore, and all dynamic user changes appear to work without this code
- Rename `recalculateRowHeight` to `setAutoRowHeight`

- DRY out setAutoRowHeight to be reusable by both the resize observer and during props update (NB: This leads to some repetition with the height being obtained twice, but will not be an issue shortly as I'll be refactoring/removing the cell wrapper observer in a future PR)

- Refactor rowHeightUtils.isAutoHeight to accept an undefined rowHeightsOptions
@cee-chen cee-chen force-pushed the datagrid-auto-height-props-update branch from 9e7feb2 to c91cad5 Compare October 21, 2021 17:12
@cee-chen cee-chen force-pushed the datagrid-auto-height-props-update branch from c91cad5 to 9eb6651 Compare October 21, 2021 17:15
Comment on lines -289 to -304
// check if we should update cell because height was changed
if (
this.cellRef.current &&
nextProps.getRowHeight &&
nextProps.rowHeightUtils
) {
if (
!nextProps.rowHeightUtils?.compareHeights(
this.cellRef.current.offsetHeight,
nextProps.getRowHeight(nextProps.rowIndex)
)
) {
return true;
}
}

Copy link
Contributor Author

@cee-chen cee-chen Oct 21, 2021

Choose a reason for hiding this comment

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

Quick walkthrough of changes:

  1. 0eab3ab is the primary workaround @chandlerprall proposed and @VladLasitsa had in his draft PR

  2. (this code diff) a553005 removes height check logic from shouldComponentUpdate as well. I figured if we aren't checking for same height, it makes sense to remove this code also to reduce extra updates. When I tested with auto height I did not see any issues or problems with height not updating when it should (I tested sorting, density, and hiding/reordering columns).

  3. Some optional proposed refactors: 6b870fd

    • I DRY'd it out so that both the ResizeObserver and props change could call the same method. This leads to some repetition with the height being obtained twice in the observer, but it will not be an issue for long as I'll be refactoring/removing the cell wrapper observer in the row height switcher PR (it does not appear to be doing anything)
    • I refactored rowHeightUtils.isAutoHeight to accept an undefined rowHeightsOptions

@kibanamachine
Copy link

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

Copy link
Contributor

@chandlerprall chandlerprall left a comment

Choose a reason for hiding this comment

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

Found one logic issue and another change to revert, but all of the examples are working great!

- occurs if the `defaultHeight` is auto but a specific `rowHeights` line override is not auto

TODO: Write a unit test for this in the future
@kibanamachine
Copy link

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

@chandlerprall
Copy link
Contributor

Weird unit test outcome, jenkins test this

Copy link
Contributor

@chandlerprall chandlerprall left a comment

Choose a reason for hiding this comment

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

Changes LGTM! Let's see if @VladLasitsa finds anything with the Kibana usage 🤞

@kibanamachine
Copy link

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

@kibanamachine
Copy link

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

@cee-chen cee-chen force-pushed the datagrid-auto-height-props-update branch from 970e4b9 to 67d27af Compare October 26, 2021 19:20
@kibanamachine
Copy link

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

@cee-chen
Copy link
Contributor Author

I think the last commit (which removes clearHeightCache completely) did the trick - @VladLasitsa can you test again and let us know what you see?

@VladLasitsa
Copy link
Contributor

I think the last commit (which removes clearHeightCache completely) did the trick - @VladLasitsa can you test again and let us know what you see?

I see problem: when we hide column cell heights are not recalculating.

@chandlerprall
Copy link
Contributor

Created a PR (cee-chen#3) against this branch with a proposed fix to update row height on column removal.

@cee-chen
Copy link
Contributor Author

@chandlerprall Ha, you read my mind - that was almost exactly the approach I was going to try :)

Copy link
Contributor

@chandlerprall chandlerprall left a comment

Choose a reason for hiding this comment

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

Changes LGTM, tested in many ways and locations

Copy link
Contributor

@VladLasitsa VladLasitsa left a comment

Choose a reason for hiding this comment

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

LGTM

@cee-chen cee-chen enabled auto-merge (squash) October 27, 2021 16:26
@kibanamachine
Copy link

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

@cee-chen cee-chen disabled auto-merge October 27, 2021 16:54
@kibanamachine
Copy link

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

@cee-chen
Copy link
Contributor Author

cee-chen commented Oct 27, 2021

OK, this time with feeling: one last QA round and if we haven't found anything, I think this should be good to go :)

I tested with sorting, reordering, hiding, density on EUI docs, and with auto on/off on the Kibana deployed instance, and everything was working for me 🤞

@cee-chen cee-chen requested a review from VladLasitsa October 27, 2021 18:46
Copy link
Contributor

@VladLasitsa VladLasitsa left a comment

Choose a reason for hiding this comment

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

LGTM! Good job)

@cee-chen cee-chen merged commit 8563fbe into elastic:master Oct 28, 2021
@cee-chen cee-chen deleted the datagrid-auto-height-props-update branch October 28, 2021 15:23
ym pushed a commit to ym/eui that referenced this pull request Oct 29, 2021
…to` (elastic#5281)

* Remove isHeightSame check

* Remove same height check from shouldComponentUpdate

- if we're not checking for sameHeight in componentDidUpdate, we also likely don't need this anymore, and all dynamic user changes appear to work without this code

* [Proposed refactors]

- Rename `recalculateRowHeight` to `setAutoRowHeight`

- DRY out setAutoRowHeight to be reusable by both the resize observer and during props update (NB: This leads to some repetition with the height being obtained twice, but will not be an issue shortly as I'll be refactoring/removing the cell wrapper observer in a future PR)

- Refactor rowHeightUtils.isAutoHeight to accept an undefined rowHeightsOptions

* Improve unit tests

* Add changelog entry

* [PR feedback] Fix `isAutoHeight` false positive
- occurs if the `defaultHeight` is auto but a specific `rowHeights` line override is not auto

TODO: Write a unit test for this in the future

* [PR feedback/Discover testing] Trigger component update when rowHeightsOptions changes

* [cleanup] Remove now-unused compareHeights util

+ clean up mock rowHeightUtils as well

* [revert] rename setAutoRowHeight back to recalculateRowHeight

- lineCount in elastic#5284 will shortly be using the row height cache in addition to auto, so I'm making the fn name less specific again

* Add enqueue/timeout to recalculateRowHeight updates

- to avoid race conditions with cache being cleared

* Remove clearHeightsCache completely

* Unset row+column height values on unmount (elastic#3)

* Add unit test for new unsetRowHeight

+ add optional isAutoHeight check

* Remove hidden columns from row height cache

* Early return in getRowHeight

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
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants