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

feat(DatePicker, DatePickerInput): refactors to functional component #10224

Merged
merged 27 commits into from
Jan 14, 2022

Conversation

jnm2377
Copy link
Contributor

@jnm2377 jnm2377 commented Dec 3, 2021

Closes #10010

Copied over from this draft: #10156

Changelog

  • Refactors DatePickerInput to functional component
  • Adds separate component for calendar icon (in same file)

Testing / Reviewing

@jnm2377 jnm2377 requested a review from a team as a code owner December 3, 2021 22:55
@netlify
Copy link

netlify bot commented Dec 3, 2021

✔️ Deploy Preview for carbon-react-next ready!

🔨 Explore the source changes: fa9429a

🔍 Inspect the deploy log: https://app.netlify.com/sites/carbon-react-next/deploys/61e1f598e650020007e1bd89

😎 Browse the preview: https://deploy-preview-10224--carbon-react-next.netlify.app

@netlify
Copy link

netlify bot commented Dec 3, 2021

✔️ Deploy Preview for carbon-components-react ready!
Built without sensitive environment variables

🔨 Explore the source changes: fa9429a

🔍 Inspect the deploy log: https://app.netlify.com/sites/carbon-components-react/deploys/61e1f5989de68300078177e6

😎 Browse the preview: https://deploy-preview-10224--carbon-components-react.netlify.app/

@netlify
Copy link

netlify bot commented Dec 3, 2021

✔️ Deploy Preview for carbon-elements ready!

🔨 Explore the source changes: fa9429a

🔍 Inspect the deploy log: https://app.netlify.com/sites/carbon-elements/deploys/61e1f598eb25010008cdbb26

😎 Browse the preview: https://deploy-preview-10224--carbon-elements.netlify.app

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.

Just a couple minor things

Copy link
Contributor

@joshblack joshblack left a comment

Choose a reason for hiding this comment

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

I think we'll need to make an update in DatePicker to make sure the openCalendar functionality works.

If I remember correctly from our work @jnm2377, the difference is in the assign* helpers in the class that assign the refs for inputField and inputToField. Let me know if I'm misremembering 🤔

@jnm2377 jnm2377 requested a review from tay1orjones December 6, 2021 21:47
@jnm2377
Copy link
Contributor Author

jnm2377 commented Dec 6, 2021

I think we'll need to make an update in DatePicker to make sure the openCalendar functionality works.

If I remember correctly from our work @jnm2377, the difference is in the assign* helpers in the class that assign the refs for inputField and inputToField. Let me know if I'm misremembering 🤔

@joshblack I opened the PR based on your suggestion to try to get DatePickerInput in while continuing work on DatePicker, but should I just close this then? I know there’s still work to be done on DatePicker but seems like you're saying separating into different PRs won’t work?

@jnm2377 jnm2377 requested a review from joshblack December 11, 2021 04:11
@jnm2377 jnm2377 changed the title feat(DatePickerInput): refactors input to function feat(DatePicker, DatePickerInput): refactors to functional component Dec 11, 2021
Copy link
Contributor

@abbeyhrt abbeyhrt 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!! 🎉

@jnm2377 jnm2377 requested a review from tay1orjones December 14, 2021 19:31
@jnm2377 jnm2377 marked this pull request as draft January 4, 2022 17:53
@jnm2377 jnm2377 marked this pull request as ready for review January 11, 2022 19:03
@jnm2377
Copy link
Contributor Author

jnm2377 commented Jan 11, 2022

@joshblack this is ready for re-review. I updated as best I could some of the tests we went over yesterday, but ended up simplifying a bit just for the sake of getting this in. 😅

@jnm2377 jnm2377 requested a review from joshblack January 11, 2022 19:04
Copy link
Contributor

@joshblack joshblack left a comment

Choose a reason for hiding this comment

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

Looking great! Left a couple comments/questions

useEffect(() => {
if (calendarRef.current) {
calendarRef.current.set({ value });
updateClassNames(calendarRef.current);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is updateClassNames something that can be pulled out of the component or does it change based on data?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@joshblack If I understand correctly, it changes based on data. It's used when the component mounts and also here.

Copy link
Contributor

Choose a reason for hiding this comment

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

@jnm2377 to avoid the react-hooks/exhaustive-deps warnings (and prevent future bugs) we should pull out updateClassNames of the component and add any additional arguments that it needs / depends on in the scope.

This should remove the need to get rid of the react-hooks/exhaustive-deps warnings (at least in cases where it's because of updateClassNames

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@joshblack Is this a blocker for this PR? I looked into it yesterday afternoon, but was running into some issues bc it's used in the useEffect that creates the flatpickr calendar, and then it's used to actually create the flatpickr calendar instance, so I'm not sure how that would work w/ pulling out the function. If it's working as expected, was wondering if this is ok as is?

Copy link
Contributor

Choose a reason for hiding this comment

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

@jnm2377 the bug that we can run into is that if updateClassNames in the future is updated to use some kind of state then that state value would be stale (since the useEffect is only seeing the first "version" of this function).

What error were you seeing when you moved updateClassNames into the outermost scope of the page?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@joshblack when I pull it out, it no longer creates the flatpickr calendar instance (from the initial useEffect), so then there are a bunch of additional errors from other parts of the code that reference the instance. I think I understand the potential issue you're describing. I guess, I feel like that's more of an enhancement to support a state.

Copy link
Contributor

Choose a reason for hiding this comment

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

@jnm2377 I think what might be happening is that updateClassNames requires prefix (it's using it from the parent scope) and so when it's moved to the top-level scope things are erroring out, included the calendar creation that you're talking about.

If it is updated to include prefix as an argument I think you won't see that issue anymore, let me know!


For background on why this is something I noticed, in general, we do not want to disable the eslint rule for the rules of hooks. There are specific moments where that is okay (if we can prove the dependencies will always be up-to-date or missing deps are stable) but they should be isolated since ignoring the rules of hooks will lead to hard-to-find bugs later down the line (in my opinion)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@joshblack I had included prefix differently (had also pulled it out to be used in the function), but hadn't tried including it as an argument. 👍🏽

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@joshblack pushed the changes, ready for review

@jnm2377 jnm2377 requested a review from joshblack January 11, 2022 21:26
@kodiakhq kodiakhq bot merged commit ce4edc3 into carbon-design-system:main Jan 14, 2022
@abbeyhrt abbeyhrt mentioned this pull request Jan 27, 2022
22 tasks
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.

[DatePickerInput]: upgrade to functional component
4 participants