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 grids that set a defaultHeight with lineCount and rowHeights overrides with lineCount #5376

Merged
merged 11 commits into from
Nov 17, 2021

Conversation

cee-chen
Copy link
Contributor

@cee-chen cee-chen commented Nov 11, 2021

Summary

I found this bug while QAing my row height switcher work 🐛

Problem

The bug was caused by #5354: the switch to using minRowHeight state for lineCount assumed that every single row in the grid would be the same height, and did not account for the rowHeights object which allows overriding specific rows with custom lineCounts, e.g.:

{
  defaultHeight: { lineCount: 3 },
  rowHeights: {
    1: { lineCount: 5 },
    4: { lineCount: 1 },
    5: { lineCount: 10 },
  }
}

The bug results in the before gif you can see below, where multiple rows are all fighting to set different minRowHeights 😬 (EDIT: The gif actually doesn't have the FPS to capture the extent of the brokenness, there's way more flashing stuff going on if you test the REVERT commit against prod).

Solution

The solution I came up with was to bogart the existing heightsCache that auto heights use, but for lineCount overrides only. This is probably a little over-engineered for lineCount heights, but since I doubt many consumers are setting custom rowHeights.lineCounts, I don't think it'll have a significant performance impact, and from a developer readability standpoint I think it's not adding too much spaghetti (and said spaghetti at least has comments + unit tests added for context).

Before

before.mp4

After

after.mp4

Extra

This PR also simplifies the auto height example, as that example does not need rowHeights overrides and it was always really confusing to me while debugging/testing 🙈

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

Leaving out a changelog as this bug is in

  • Revert [REVERT ME] commits

- Remove line overrides from auto example (causes confusion during testing, isn't necessary)
…cache instead of setting the minRowHeight

- the lineCount overrides are causing incorrect minRowHeight calculations for other rows, so they need their own specific map, and the auto one is right there 🤷
@kibanamachine
Copy link

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

@cee-chen cee-chen force-pushed the datagrid-fix-line-height-overrides branch from 45d6824 to e7c6ed1 Compare November 16, 2021 19:46
@kibanamachine
Copy link

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

@@ -218,6 +218,9 @@ describe('EuiDataGridCell', () => {
});

callMethod(component);
expect(
mockRowHeightUtils.calculateHeightForLineCount
).toHaveBeenCalledWith(expect.any(HTMLElement), 3, false);
Copy link
Contributor

@chandlerprall chandlerprall Nov 16, 2021

Choose a reason for hiding this comment

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

TIL expect.any

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 the PR's preview docs.

@cee-chen cee-chen enabled auto-merge (squash) November 16, 2021 23:52
@kibanamachine
Copy link

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

@cee-chen cee-chen merged commit a648149 into elastic:main Nov 17, 2021
@cee-chen cee-chen deleted the datagrid-fix-line-height-overrides branch November 17, 2021 00:37
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