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

Perf: EuiDataGrid don't recreate columns on every change #2676

Merged
merged 4 commits into from
Dec 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
**Bug fixes**

- Reverted removal of `toggleOpen` method from `EuiNavDrawer` ([#2682](https://github.com/elastic/eui/pull/2682))
- Improved `EuiDataGrid` update performance ([#2676](https://github.com/elastic/eui/pull/2676))

## [`17.2.1`](https://github.com/elastic/eui/tree/v17.2.1)

Expand Down
20 changes: 14 additions & 6 deletions src/components/datagrid/column_selector.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, {
Fragment,
useState,
useMemo,
ReactChild,
ReactElement,
ChangeEvent,
Expand Down Expand Up @@ -199,11 +200,18 @@ export const useColumnSelector = (
</EuiPopover>
);

const orderedVisibleColumns = visibleColumns
.map<EuiDataGridColumn>(
columnId =>
availableColumns.find(({ id }) => id === columnId) as EuiDataGridColumn // cast to avoid `undefined`, it filters those out next
)
.filter(column => column != null);
const orderedVisibleColumns = useMemo(
() =>
visibleColumns
.map<EuiDataGridColumn>(
columnId =>
availableColumns.find(
({ id }) => id === columnId
) as EuiDataGridColumn // cast to avoid `undefined`, it filters those out next
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not filter first?

Copy link
Contributor Author

@mbondyra mbondyra Dec 17, 2019

Choose a reason for hiding this comment

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

I think (although I am not sure, I just wrapped it with useMemo but that's how I understand the comment) that the find returns nulls in case it won't find the id === columnId and after that we're getting rid of the nulls with filter 🤔

Copy link
Contributor

Choose a reason for hiding this comment

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

Indeed, this looks like whitespace-only changes with the additional useMemo wrapping. I set originally set it up to filter second. No real reason, didn't occur to me to filter first 🤷‍♀

)
.filter(column => column != null),
[availableColumns, visibleColumns]
);

return [columnSelector, orderedVisibleColumns];
};