Skip to content

[EuiDataGrid] Add renderCustomToolbar render prop #7147

Closed

Description

@kertal

Is your feature request related to a problem? Please describe.
We're giving Discover a visual refresh, and part of this is redesigning the toolbar of EuiDataGrid in a significant way. It should allow the rendering on the number of documents on the left side of the toolbar, move all other elements on the right side, change the appearance, change at least 1 icon, make one popover extensible.

Describe the solution you'd like
Chatting about this use case @cee-chen suggested to use render props for that, and drafted:

// custom consumer toolbar
const renderCustomToolbar: ({
  columnsControlButton,
  sortControlButton,
  keyboardShortcutsButton,
  fullScreenButton,
  displayOptionsControls,
}) => (
  <EuiFlexGroup justifyContent="spaceBetween">
    <EuiFlexItem grow={false} data-test-subj="leftAlignedContent">
      1,112 documents
    </EuiFlexItem>
    <EuiFlexItem grow={false} data-test-subj="rightAlignedContent">
      {columnsControlButton}
      {sortControlButton}

      {keyboardShortcutsButton}
      <EuiPopover
        button={<EuiButtonIcon iconType="controlsHorizontal" aria-label="Custom grid controls" />}
      >
        {displayOptionsControls}
        Your own extra controls go here
      </EuiPopover>
      {fullScreenButton}
    </EuiFlexItem>
  <EuiFlexGroup>
);

<EuiDataGrid
  renderCustomToolbar={renderCustomToolbar}
  // ...
/>

A solution like this would be very flexible and we could implement all desired changes in Discover.

Describe alternatives you've considered
@kertal first thought to solve it via adding more configuration properties, but the render props solution is much much better.

Desired timeline
Kibana 8.11 would be great 🙈 , In Kibana 8.12 we would need to apply these changes, so early 8.12 would also work ❤️

Additional context
This is how it how should look like in Discover:
Bildschirmfoto 2023-08-31 um 08 38 33

Activity

  1. cee-chen commented on Sep 7, 2023

    @cee-chen
    Contributor

    Architecturally I think the biggest thing to explore with the snippet in the PR is passing back React nodes or React components, i.e. <ColumnsControlButton /> as opposed to {columnsControlButton}.

    I'd like to investigate how feasible passing back configurable components instead of raw nodes would be, as that would allow extra consumer configuration (e.g. allowing consumers to pass CSS/styles props directly to buttons as opposed to needing a wrapper, that kind of thing). I'm planning on spiking that out today/tomorrow as part of my support week.

  2. cee-chen commented on Sep 11, 2023

    @cee-chen
    Contributor

    I poked around a bit re: returning a React component from our various hooks and eventually decided against it - let's stick to returning React nodes/JSX for now (since it's significantly simpler as that's already the current architecture).


    [The below is mostly some long rambling thoughts on my research around the topic and why I eventually decided against it, feel free to skip until after the next break]

    When I did a bit of googling around the interwebs, there is one helpful article on returning components from hooks that mentions "you can do it, but the component ends up fully unmounting/remounting whenever dependent props change" and eventually just kinda concludes with "so in the end it's better to define the component statically and use context instead" 😅 which is totally valid, and context is great, but EuiDataGrid kind of already has a lot of context (3 providers at the top level of the grid already). TBH, on that subject, I've often wondered if we should redo the entire top-level data_grid.tsx and have it just be like 10 or so providers, so we can avoid the current painful waterfall of a million passed props down to every child/grandchild component. It's an interesting thought, but probably not a refactor worth doing just for this one feature request.

    In summary, I think we'd need a really compelling reason to make the architectural changes necessary to pass back components for every toolbar control. Right now I'm not seeing a compelling enough reason to overhaul our architecture to do so, but if there is a strong enough reason in the future, it might be worth re-investigating then.


    I took a quick peek at the merged PR and a quick comment I have there is I'd like the conditional if renderCustomToolbar exists, use the render prop logic to live within the data_grid_toolbar.tsx file instead of being called in the top level data_grid.tsx. We can just pass renderCustomToolbar as a prop down to the <EuiDataGridToolbar> component instead (will be much easier to unit test that way tbh).

  3. kertal commented on Sep 11, 2023

    @kertal
    MemberAuthor

    @cee-chen thx for your feedback 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions