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

fix(EuiBasicTable): fixed EuiBasicTable proptypes of itemId #3133

Merged
merged 5 commits into from
Mar 26, 2020

Conversation

pranshuchittora
Copy link
Contributor

@pranshuchittora pranshuchittora commented Mar 20, 2020

Summary

Closes #3130
Summarize your PR. If it includes design elements include a screenshot or gif.
As of now, I have added a type the propTypes of ItemId (number).
Another approach is that I can convert the given input to String.

Checklist

  • Check against all themes for compatibility in both light and dark modes
  • Checked in mobile
  • Checked in IE11 and Firefox
  • Props have proper autodocs
  • Added documentation 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?

@cchaos
Copy link
Contributor

cchaos commented Mar 20, 2020

Jenkins test this

@kibanamachine
Copy link

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

@cchaos
Copy link
Contributor

cchaos commented Mar 20, 2020

@pranshuchittora Can you describe how you found the issue to be that number was not supported?

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.

The root case here is the re-use of ItemId<T> type for both EuiBasicTable's itemId and CollapsedItemActions's itemId. This was an oversight during these components' translation to TypeScript.

EuiBasicTable uses its itemId to know what field on an object is its ID, thus the string | ((item: T) => string) definition. However, CollapsedItemActions's itemId is the resolved value (either a string or a number are valid, thus the change).

The proper way to fix this is to re-define CollapsedItemAction's itemId as string | number, not ItemId<T>. expanded_item_actions.tsx should be updated similarly.

@pranshuchittora
Copy link
Contributor Author

pranshuchittora commented Mar 20, 2020

Why the ItemId has a generic type?
Why it can't just be a string or a number?

export type ItemId<T> = string | ((item: T) => string);

@chandlerprall
Copy link
Contributor

It needs the generic type because, when it is a function, it is passed the item as its argument. For the tables, the item type is represented by the generic. The code using itemId as a function is at

export function getItemId<T>(item: T, itemId?: ItemId<T>) {

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.

Looks good, but needs to make the same changes to src/components/basic_table/expanded_item_actions.tsx

@pranshuchittora
Copy link
Contributor Author

@chandlerprall please review the new changes :)

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 locally. I also merged in master to correct the changelog entry placement (releases often screw up open PR changelogs)

@chandlerprall chandlerprall merged commit a4eecae into elastic:master Mar 26, 2020
@chandlerprall
Copy link
Contributor

Thanks for the bugfix @pranshuchittora !

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

Successfully merging this pull request may close these issues.

EuiBasicTable actions example throws proptype warning
5 participants