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

[EuiInMemoryTable] Avoid blocking update for getDerivedStateFromProps #3579

Merged
merged 3 commits into from
Jun 10, 2020
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 @@ -8,6 +8,7 @@
- Fixed `EuiKeyPadMenu` and `EuiKeyPadMenuItem` aria roles ([#3502](https://github.com/elastic/eui/pull/3502))
- Fixed `EuiFieldSearch` input clear button doesn't show when external input is passed([#3497](https://github.com/elastic/eui/pull/3497))
- Fixed `EuiBasicTable` footers to always use a unique `key` ([#3559](https://github.com/elastic/eui/pull/3559))
- Fixed `EuiInMemoryTable` by changing the `getDerivedStateFromProps` to not block the updates as soon as it hits a true if condition ([#3579](https://github.com/elastic/eui/pull/3579))

**Breaking changes**

Expand Down
22 changes: 16 additions & 6 deletions src/components/basic_table/in_memory_table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -246,11 +246,15 @@ export class EuiInMemoryTable<T> extends Component<
nextProps: EuiInMemoryTableProps<T>,
prevState: State<T>
) {
let updatedPrevState = prevState;
let componentShouldUpdate = false;
if (nextProps.items !== prevState.prevProps.items) {
// We have new items because an external search has completed, so reset pagination state.
return {
componentShouldUpdate = true;
updatedPrevState = {
...updatedPrevState,
prevProps: {
...prevState.prevProps,
...updatedPrevState.prevProps,
items: nextProps.items,
},
pageIndex: 0,
Expand All @@ -264,7 +268,9 @@ export class EuiInMemoryTable<T> extends Component<
sortName !== prevState.prevProps.sortName ||
sortDirection !== prevState.prevProps.sortDirection
) {
return {
componentShouldUpdate = true;
updatedPrevState = {
...updatedPrevState,
sortName,
sortDirection,
};
Expand All @@ -278,15 +284,19 @@ export class EuiInMemoryTable<T> extends Component<
: '';

if (nextQuery !== prevQuery) {
return {
componentShouldUpdate = true;
updatedPrevState = {
...updatedPrevState,
prevProps: {
...prevState.prevProps,
...updatedPrevState.prevProps,
search: nextProps.search,
},
query: getQueryFromSearch(nextProps.search, false),
};
}

if (componentShouldUpdate) {
return updatedPrevState;
}
return null;
}

Expand Down