Skip to content

Commit

Permalink
Perf: EuiDataGrid don't recreate columns on every change (#2676)
Browse files Browse the repository at this point in the history
  • Loading branch information
mbondyra committed Dec 17, 2019
1 parent 0363814 commit 1db929c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
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
)
.filter(column => column != null),
[availableColumns, visibleColumns]
);

return [columnSelector, orderedVisibleColumns];
};

0 comments on commit 1db929c

Please sign in to comment.