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] Enhance renderCustomGridBody to better support consumer virtualization #8028

Merged

Conversation

logeekal
Copy link
Contributor

@logeekal logeekal commented Sep 18, 2024

Summary

See #8002

This PR tries to provide more control to the users of DataGrid when they pass renderCustomGridBody prop. Below are the changes done.

Changes

  • headerRow and footerRow are now passed to renderCustomBody component for the user of data grid to render. This was done so that if users are rendering rows in a custom manner, those customization can also be applied to header and footer rows. For example, I was trying to use a virtualized table component where there was option to scroll the table horizontally, since headerRow was already rendered by EUI, I did not have option to contain it within a section same as table and hence scrolling was different in headerRow and the actual table.

  • More memoizations in packages/eui/src/components/datagrid/body/data_grid_body_custom.tsx here

Existing Issues

Below issues exist in custom body render and currently, I do not have a good way to resolve these but these are also low priority.

  1. Width of the grid with static height doesn't/can't take scrollbar width into account when customRenderBody. Currently customRenderBody function does not have any way to recalculate the width of data grid. ( DataGrid width is more than a container with customBodyRender #8038)
  2. Ability to pass maxWidth to the cell content in order to restrict that to the width of the header.

QA

Below is the demo on how virtualization with Event Renderer looks like.

render_custom_body_eui_PR_demo.mp4

General checklist

  • Browser QA - N/A
  • Docs site QA
  • Code quality checklist
  • Release checklist
    • A changelog entry exists and is marked appropriately.
    • If applicable, added the breaking change issue label (and filled out the breaking change checklist)
  • Designer checklist - N/A

@logeekal logeekal force-pushed the fix/render_custom_body_support_virtualiztion branch from 6b4fcdd to 6e9474a Compare September 27, 2024 09:46
@logeekal logeekal marked this pull request as ready for review September 30, 2024 15:51
@logeekal logeekal requested a review from a team as a code owner September 30, 2024 15:51
customGridBodyProps?.className
)}
>
{headerRow}
Copy link
Contributor

Choose a reason for hiding this comment

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

FYI, the fact that we're no longer automatically rendering the header and footer row for custom grid bodies will need to constitute a breaking change. I'm not against it, but there are at least 2 current custom grid usages in Kibana that will need to be updated when this change is made, or production usage will break.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

I should be able to get this into Kibana by 8.16 FF if I merge this in and do a release today. Does that work for you?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Woohoo.. Thanks @cee-chen for merging it.

rowHeightUtils,
});

const headerRowProps = useMemo(() => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Just to check, were the props not correctly getting memoized by these lines? 😬

const headerRow = useMemo(() => {
return <EuiDataGridHeaderRow ref={setHeaderRowRef} {...props} />;
}, [props]);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, this was the strange one. Although props were exactly the same ( same identity ) but when passed into useDataGridHeader as an object, identify to props object recieved in useDataGridHeader was changing. Possibly because I think it was creating a new object everytime to pass as props.

This was causing headerRow to be recreated and renderCustomBody to be completely render again.

Copy link
Contributor

Choose a reason for hiding this comment

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

Gotcha, thanks so much for explaining!

@cee-chen
Copy link
Contributor

cee-chen commented Oct 8, 2024

Hey Jatin, apologies for dropping the ball on this PR! I'll spend tomorrow pushing up some docs changes (probably merging the two examples so there's just one), and then update the changelog to highlight that this PR contains a breaking change. Other than that I think this is good to go.

@cee-chen cee-chen self-assigned this Oct 8, 2024
- which allows conditionally rendering the prop - errors otherwise

+ tweak displayName
- give this example its own folder, it's gotten complex enough at this point

- also give it its own custom toggles and tabs, since codesandbox doesn't generate a link with relative imports
- these are all definitively passed
Copy link

github-actions bot commented Oct 8, 2024

This PR contains breaking changes. The opener of this pull request is asked to perform the following due diligence steps below, to assist EUI in our next Kibana upgrade:

  • If this PR contains prop/API changes:
    • Search through Kibana for <EuiComponent usages (example search)
    • In the PR description or in a PR comment, include a count or list with the number of component usages in Kibana that will need to be updated (if that amount is "none", include that information as well)
  • If this PR contains CSS changes:
    • Search through Kibana for the changed EUI selectors, e.g. .euiComponent (example search)
    • In the PR description or in a PR comment, include a count or list with the number of custom CSS overrides in Kibana that will need to be updated (if that amount is "none", include that information as well)
  • 🔍 Tip: When searching through Kibana, consider excluding **/target, **/*.snap, **/*.storyshot files to reduce noise and only look at source code usages
  • ⚠️ For extremely risky changes, the EUI team should potentially consider the following precautions:
    • Using a pre-release release candidate to test Kibana CI ahead of time
    • Using kibana-a-la-carte for manual QA, and to give other Kibana teams a staging server to quickly test against

@elasticmachine
Copy link
Collaborator

💚 Build Succeeded

History

cc @cee-chen

@cee-chen cee-chen changed the title [Fix] Datagrid Custom Body Render general fixes [EuiDataGrid] Enhance renderCustomGridBody to better support consumer virtualization Oct 8, 2024
@cee-chen
Copy link
Contributor

cee-chen commented Oct 9, 2024

I was going to push up some Storybook VRT screenshots, but my local Docker is running into issues 🥲 to avoid holding up this PR further, I'm going to go ahead and merge it in and follow up with Storybook later. Thanks so much for this PR Jatin!

@cee-chen cee-chen merged commit 9ab356e into elastic:main Oct 9, 2024
5 checks passed
@logeekal
Copy link
Contributor Author

logeekal commented Oct 9, 2024

Thanks @cee-chen for pushing it so quickly and creating a PR in Kibana. I do not see any DataGrid issues in your Kibana PR so please let me know if something pops up.

Additionally, I see couple of minor issues with Try this out in codesandbox

  1. It only appears on Cell Components tab.
  2. It does not export complete code in CodeSandbox but only partial.

Thanks.

@cee-chen
Copy link
Contributor

cee-chen commented Oct 9, 2024

Nice catch on the docs! Unfortunately our CodeSandbox integration is pretty limited in how it allows importing multiple local files - hence the semi-broken behavior here. I believe we'll be switching to a different setup with live code in our new EUI+ docs, so this won't be an issue for much longer.

My preference would be to leave it without a fully working CodeSandbox example for now as I think having discrete examples of custom grid bodies instead of 1 long and hard to read file is going to be easier for devs to follow along and copy into their setups, if needed.

@logeekal
Copy link
Contributor Author

Makes sense. thanks @cee-chen

delanni pushed a commit to elastic/kibana that referenced this pull request Oct 14, 2024
`v96.1.0`⏩`v97.0.0`

_[Questions? Please see our Kibana upgrade
FAQ.](https://github.com/elastic/eui/blob/main/wiki/eui-team-processes/upgrading-kibana.md#faq-for-kibana-teams)_

---

## [`v97.0.0`](https://github.com/elastic/eui/releases/v97.0.0)

**Breaking changes**

- EuiDataGrid's custom grid body (rendered via `renderCustomGridBody`)
no longer automatically renders the column header row or footer rows. It
instead now passes the `headerRow` and `footerRow` React elements, which
require manual rendering.
([#8028](elastic/eui#8028))
- This change was made to allow consumers to sync header/footer rows
with their own custom virtualization libraries.
- To facilitate this, a `gridWidth` prop is now also passed to custom
grid body renderers.

**Bug fixes**

- Fixed inputs not taking the whole width when passing `fullWidth` as
`true` to EuiDatePickerRange component
([#8061](elastic/eui#8061))

**Accessibility**

- Improved accessibility of `EuiExternalLinkIcon` by clarifying text for
Screen Reader users. ([#8065](elastic/eui#8065))

---------

Co-authored-by: Elastic Machine <[email protected]>
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Oct 14, 2024
`v96.1.0`⏩`v97.0.0`

_[Questions? Please see our Kibana upgrade
FAQ.](https://github.com/elastic/eui/blob/main/wiki/eui-team-processes/upgrading-kibana.md#faq-for-kibana-teams)_

---

## [`v97.0.0`](https://github.com/elastic/eui/releases/v97.0.0)

**Breaking changes**

- EuiDataGrid's custom grid body (rendered via `renderCustomGridBody`)
no longer automatically renders the column header row or footer rows. It
instead now passes the `headerRow` and `footerRow` React elements, which
require manual rendering.
([elastic#8028](elastic/eui#8028))
- This change was made to allow consumers to sync header/footer rows
with their own custom virtualization libraries.
- To facilitate this, a `gridWidth` prop is now also passed to custom
grid body renderers.

**Bug fixes**

- Fixed inputs not taking the whole width when passing `fullWidth` as
`true` to EuiDatePickerRange component
([elastic#8061](elastic/eui#8061))

**Accessibility**

- Improved accessibility of `EuiExternalLinkIcon` by clarifying text for
Screen Reader users. ([elastic#8065](elastic/eui#8065))

---------

Co-authored-by: Elastic Machine <[email protected]>
(cherry picked from commit cd60c66)
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