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] Update state.prevProps.sortName & sortDirection #6228

Conversation

chandlerprall
Copy link
Contributor

@chandlerprall chandlerprall commented Sep 9, 2022

Summary

Fixes #6032 by updating EuiInMemoryTable's getDerivedStateFromProps to update the sort details in prevProps as necessary.

To be honest, I'm not sure how to write a meaningful test for this. @sebelga can you extract your use case to a simple test scenario? (just describing it should be fine, I can put the test together)

Checklist

- [ ] Checked in both light and dark modes
- [ ] Checked in mobile
- [ ] Checked in Chrome, Safari, Edge, and Firefox
- [ ] Props have proper autodocs and playground toggles
- [ ] Added documentation
- [ ] Checked Code Sandbox works for any docs examples

  • Added or updated jest and cypress tests
  • Checked for breaking changes and labeled appropriately
    - [ ] Checked for accessibility including keyboard-only and screenreader modes
    - [ ] Updated the Figma library counterpart
  • A changelog entry exists and is marked appropriately

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_6228/

@sebelga
Copy link
Contributor

sebelga commented Sep 12, 2022

if (
      sortName !== prevState.prevProps.sortName ||
      sortDirection !== prevState.prevProps.sortDirection
    ) {
      updatedPrevState = {
        ...updatedPrevState,
        sortName,
        sortDirection,
      };
    }

In the above code prevState.prevProps never gets updated, meaning that sortName !== prevState.prevProps.sortName is never true for the initial column we sort on.

The issue can be reproduced by control the sort

  • Control the sort state in the consumer component ( passing tableSort={tableSort} to the table)
// Consumer state
const [tableSort] = useState({
    field: 'updatedAt'; // initial column we sort on
    direction: 'desc';
});
  • Change the sort order by clicking the column header. It won't let for the udpatedAt field
  • Change the sort order for any other column (e.g. title): no problem, the sortName is different

@chandlerprall
Copy link
Contributor Author

Perfect, thanks @sebelga! I've pushed up a test for this too

@chandlerprall chandlerprall requested review from cee-chen and removed request for thompsongl September 12, 2022 16:11
@chandlerprall chandlerprall marked this pull request as ready for review September 12, 2022 16:11
Copy link
Contributor

@cee-chen cee-chen left a comment

Choose a reason for hiding this comment

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

LGTM! one very minor nit

upcoming_changelogs/6228.md Outdated Show resolved Hide resolved
@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_6228/

@chandlerprall chandlerprall merged commit 634d341 into elastic:main Sep 12, 2022
@chandlerprall chandlerprall deleted the bug/6032-in-memory-table-sorting-prevprops branch September 12, 2022 20:21
@sebelga
Copy link
Contributor

sebelga commented Sep 20, 2022

@chandlerprall Will we have this fix for 8.5 stack release?

@cee-chen cee-chen mentioned this pull request Sep 20, 2022
5 tasks
@chandlerprall
Copy link
Contributor Author

@chandlerprall Will we have this fix for 8.5 stack release?

Yes, we're including this in a backport release for 8.5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[EuiInMemoryTable] Issue with sorting
4 participants