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(14831): update component and getter function types to match #17135

Merged

Conversation

nevantan
Copy link
Contributor

@nevantan nevantan commented Aug 9, 2024

Update <TableExpandRow />, <TableSelectAll />, <TableSelectRow /> props to make checked and isSelected optional since they already expect undefined or default to a boolean value anyway. This allows the values returned by getSelectionProps and getRowProps to be more consistent. This should resolve typescript errors that occur when using official examples.

Closes #14831

Making the argument for getSelectionProps optional allows the official examples to work without breaking anything with the change; the function already defaults the argument to an empty object. There is perhaps something to be said for refactoring the getSelectionProps function to better differentiate between the contexts in which it is used (<TableSelectRow /> vs <TableSelectAll />), but the presence of an optional argument (as it is now) seems reasonable.

Switching the onClick handlers to use React's MouseEvent interface makes them compatible with MouseEventHandler<HTMLButtonElement>, which resolves a few of the errors on those components.

The checked prop was overly restrictive in the <TableSelectRow /> and <TableSelectAll /> prop definitions; the only places the prop is used within those components expects it to be optional. Relaxing the type on those two components resolves the typescript errors and seems to have been the original intent based on how it is typed in DataTableRow. This shouldn't be a breaking change to the component API since all currently allowed values are still valid after the change. The isExpanded prop on <TableExpandRow /> is the same issue of being overly restrictive.

The radio key being returned from getSelectionProps unnecessarily included a null option - both the actual value and the type. Removing both references to null makes it compatible with <TableSelectRow /> props.

Changelog

New

Changed

  • DataTable onClick handlers now use React's MouseEvent interface instead of the native MouseEvent
  • DataTable getSelectionProps arguments are now optional
  • DataTable getSelectionProps is now accurately typed to return checked as an optional key
  • DataTable getSelectionprops radio key is now boolean | undefined (changed from boolean | undefined | null)
  • <TableSelectRow /> and <TableSelectAll /> checked prop is now optional
  • <TableExpandRow /> isExpanded prop is now optional

Removed

Testing / Reviewing

Run the code examples for DataTable / Selection / Default and DataTable / Expansion / Default in a TypeScript environment; the errors should be resolved.

Update <TableExpandRow />, <TableSelectAll />, <TableSelectRow /> props
to make checked and isSelected nullable since they already expect
undefined or default to a boolean value anyway. This allows the values
returned by getSelectionProps and getRowProps to be more consistent.
This should resolve typescript errors that occur when using official
examples.
@nevantan nevantan requested a review from a team as a code owner August 9, 2024 20:55
@nevantan nevantan requested review from tay1orjones and emyarod August 9, 2024 20:55
Copy link
Contributor

github-actions bot commented Aug 9, 2024

All contributors have signed the DCO.
Posted by the DCO Assistant Lite bot.

@nevantan
Copy link
Contributor Author

nevantan commented Aug 9, 2024

I have read the DCO document and I hereby sign the DCO.

Copy link

netlify bot commented Aug 9, 2024

Deploy Preview for v11-carbon-react ready!

Name Link
🔨 Latest commit 3920859
🔍 Latest deploy log https://app.netlify.com/sites/v11-carbon-react/deploys/671ff2298db3f10008b718bc
😎 Deploy Preview https://deploy-preview-17135--v11-carbon-react.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

netlify bot commented Aug 9, 2024

Deploy Preview for carbon-elements ready!

Name Link
🔨 Latest commit 3920859
🔍 Latest deploy log https://app.netlify.com/sites/carbon-elements/deploys/671ff22901198800086bb4ce
😎 Deploy Preview https://deploy-preview-17135--carbon-elements.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Member

@emyarod emyarod 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 to me!

Copy link
Member

@tay1orjones tay1orjones left a comment

Choose a reason for hiding this comment

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

Hey sorry I missed this one in my notifications. This looks good to me

Copy link

netlify bot commented Oct 28, 2024

Deploy Preview for v11-carbon-web-components ready!

Name Link
🔨 Latest commit 3920859
🔍 Latest deploy log https://app.netlify.com/sites/v11-carbon-web-components/deploys/671ff229d71bd10008f74b21
😎 Deploy Preview https://deploy-preview-17135--v11-carbon-web-components.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@tay1orjones
Copy link
Member

There must've been some overlap with another PR. When I updated this with latest from main the files changed went down to just a handful of changes.

Copy link

codecov bot commented Oct 28, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 80.79%. Comparing base (f351df6) to head (3920859).
Report is 7 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #17135   +/-   ##
=======================================
  Coverage   80.79%   80.79%           
=======================================
  Files         406      406           
  Lines       14041    14041           
  Branches     4367     4395   +28     
=======================================
  Hits        11344    11344           
  Misses       2530     2530           
  Partials      167      167           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@tay1orjones tay1orjones added this pull request to the merge queue Oct 29, 2024
Merged via the queue into carbon-design-system:main with commit 538060f Oct 29, 2024
40 checks passed
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.

[Bug]: Invalid TypeScript definition for multiple components (DataTable, Modal)
3 participants