Skip to content

Commit

Permalink
[EuiInMemoryTable] Avoid blocking update for getDerivedStateFromProps (
Browse files Browse the repository at this point in the history
…#3579)

* added single return source in getDerivedStateFromProps

* implemented changes

* Updated changelog
  • Loading branch information
shrey authored Jun 10, 2020
1 parent 0b5d6d2 commit 0b8dd40
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,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

0 comments on commit 0b8dd40

Please sign in to comment.