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] Error appears in console related to prop sorting.sort.direction #4138

Merged
merged 5 commits into from
Nov 4, 2020

Conversation

DianaDerevyankina
Copy link
Contributor

Closes #4137

Summary

The error is caused by setting a value to sortName when columnField is compared to sortName. So when both are undefined, sortName is set to the last column name value, that is why check for columnField presence is needed.

Checklist

  • Check against all themes for compatibility in both light and dark modes
  • Checked in mobile
  • Checked in Chrome, Safari, Edge, and Firefox
  • Props have proper autodocs
  • Added documentation
  • Checked Code Sandbox works for the any docs examples
  • Added or updated jest tests
  • Checked for breaking changes and labeled appropriately
  • Checked for accessibility including keyboard-only and screenreader modes
  • A changelog entry exists and is marked appropriately

@kibanamachine
Copy link

Since this is a community submitted pull request, a Jenkins build has not been kicked off automatically. Can an Elastic organization member please verify the contents of this patch and then kick off a build manually?

@DianaDerevyankina
Copy link
Contributor Author

@chandlerprall Could you review it, please?

@chandlerprall chandlerprall self-requested a review October 15, 2020 16:52
@@ -410,7 +410,8 @@ export class EuiInMemoryTable<T> extends Component<
// map back to `name` if this is the case
for (let i = 0; i < this.props.columns.length; i++) {
const column = this.props.columns[i];
if ((column as EuiTableFieldDataColumnType<T>).field === sortName) {
const columnField = (column as EuiTableFieldDataColumnType<T>).field;
Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you for the PR submission! This does solve the problem, but I'm a little worried about future changes to this code accidentally undoing the fix. Please include two modifications to help future-proof this code:

  1. Instead of always pulling columnField, please use a type guard instead. A quick test if the column contains the field value would suffice to determine if a field is EuiTableFieldDataColumnType. Using a type guard here helps the code self-document what it is doing.

  2. Add a unit test to in_memory_table.test.tsx under the behavior section. There's an existing pagination test that you can copy the format of, but if you're unsure how to set it up please ask! The test need only change the number of displayed rows, we have a utility that automatically fails a test if a proptype check fails.

@chandlerprall chandlerprall marked this pull request as ready for review November 4, 2020 15:59
Copy link
Contributor

@chandlerprall chandlerprall left a comment

Choose a reason for hiding this comment

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

Changes LGTM; Pulled & tested this change locally, including verifying the unit test properly covers a future regression.

I also merged master into this branch to update the changelog placement, as it had been affected by a couple EUI releases.

@chandlerprall
Copy link
Contributor

jenkins test this

@kibanamachine
Copy link

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

@chandlerprall chandlerprall merged commit 018cb98 into elastic:master Nov 4, 2020
cchaos pushed a commit to andreadelrio/eui that referenced this pull request Nov 4, 2020
…sort.direction` (elastic#4138)

* [EuiInMemoryTable] Error appears in console related to prop `sorting.sort.direction`

Closes elastic#4137

* Add descrition to CHANGELOG

* Replace columnField with type guard for field and create a unit test for that case

Co-authored-by: Chandler Prall <chandler.prall@gmail.com>
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] Error appears in console related to prop sorting.sort.direction
3 participants