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

refactor: add typescript types to TreeNode and TreeView #14775

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

cesardlinx
Copy link
Contributor

Closes #13581

Typescript annotations added to TreeNode and TreeView

Changelog

Changed

  • TreeNode and TreeView components now use Typescript annotations
  • Renamed TreeNode and TreeView file extension to .tsx
  • Renamed index file extension to .ts

Removed

  • n/a

Testing / Reviewing

  • I run the tests for TreeNode and TreeView and it passes, also I checked that the components are still working in Storybook

image

@cesardlinx cesardlinx requested a review from a team as a code owner October 4, 2023 05:53
@github-actions
Copy link
Contributor

github-actions bot commented Oct 4, 2023

DCO Assistant Lite bot All contributors have signed the DCO.

@cesardlinx
Copy link
Contributor Author

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

@netlify
Copy link

netlify bot commented Oct 4, 2023

Deploy Preview for v11-carbon-react ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit dcfafd1
🔍 Latest deploy log https://app.netlify.com/sites/v11-carbon-react/deploys/6608cc945947160008d75404
😎 Deploy Preview https://deploy-preview-14775--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.

@netlify
Copy link

netlify bot commented Oct 4, 2023

Deploy Preview for carbon-elements ready!

Name Link
🔨 Latest commit 23a955f
🔍 Latest deploy log https://app.netlify.com/sites/carbon-elements/deploys/65410e8ce201a100086d1461
😎 Deploy Preview https://deploy-preview-14775--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.

@andreancardona
Copy link
Contributor

@cesardlinx Hey David, do you mind fixing the merge conflicts - we'll re-review and get it merged!

@cesardlinx
Copy link
Contributor Author

cesardlinx commented Nov 17, 2023

Hey @andreancardona sure thing! I'll fix it 🙂

@cesardlinx cesardlinx requested a review from a team as a code owner November 27, 2023 18:16
@cesardlinx
Copy link
Contributor Author

Hey @andreancardona I have fixed the merge conflict, please let me know if you need anything else

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.

Thanks for diving in to this! I have just a few observations below.

packages/react/src/components/TreeView/index.ts Outdated Show resolved Hide resolved
<div className={`${prefix}--tree-node__label`} ref={currentNodeLabel}>
{/* https://github.com/carbon-design-system/carbon/pull/6008#issuecomment-675738670 */}
{/* eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions */}
<span
className={`${prefix}--tree-parent-node__toggle`}
disabled={disabled}
// disabled={disabled}
Copy link
Member

Choose a reason for hiding this comment

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

I think this needs to remain

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If I add it back I get this error
image

Basically what it is trying to say is that span element doesn't have a disabled prop. And it makes sense because only html elements such as button, input, select, textarea have the disabled attribute

Copy link
Member

Choose a reason for hiding this comment

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

Oh my bad, yeah let's just remove it then

packages/react/src/components/TreeView/TreeNode.tsx Outdated Show resolved Hide resolved
@@ -288,7 +464,7 @@ TreeNode.propTypes = {
* Optional prop to allow each node to have an associated icon.
* Can be a React component class
*/
renderIcon: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
Copy link
Member

Choose a reason for hiding this comment

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

Narrowing proptypes is considered a breaking change. We'll need to leave this as is for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The problem was that by leaving it as how it was I get this error:
image

It appears to be a conflict between TypeScript and PropTypes in this section. The closest issue I found resembling this problem is documented here: DefinitelyTyped/DefinitelyTyped#28015

@@ -148,6 +225,7 @@ export default function TreeView({
}
}
}
// @ts-ignore
Copy link
Member

Choose a reason for hiding this comment

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

What error is being suppressed here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here I'm suppressing the same error as before
image

@cesardlinx
Copy link
Contributor Author

Thank you @tay1orjones for the valuable feedback. I've addressed some of the issues you highlighted, and also I've provided responses to your observations.

@tay1orjones
Copy link
Member

Hey there, sorry for the delay in response here. From what I can tell there's two pieces we need to resolve here

  1. Remove the disabled from TreeNode instead of commenting it out
  2. Find a workaround for renderIcon in TreeNode because we can't narrow the Proptypes without a breaking change

@cesardlinx
Copy link
Contributor Author

Hey @tay1orjones. Sorry, work has kept me busy lately and I almost forgot about this PR. I'll check it out during the weekend and I'll keep you posted.

@cesardlinx
Copy link
Contributor Author

Hey @tay1orjones, I've resolved the issues you pointed out. Let me know if there's anything else I can help with.

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.

Add TypeScript types to TreeView, TreeNode
6 participants