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

Simplify key codes expression in Tags component #4248

Merged
merged 4 commits into from
Oct 9, 2019

Conversation

stesel
Copy link
Contributor

@stesel stesel commented Oct 5, 2019

What type of PR is this? (check all applicable)

  • Refactor

Description

Move combination key codes to separate const in tags.jsx file.
Add test for checking preventDefault in handleKeyDown method.

Suggestions comes form codeclimate.
https://codeclimate.com/github/thepracticaldev/dev.to/app/javascript/shared/components/tags.jsx/source#issue-a087ee1bf368783e621a0b4563a3aaeb

Related Tickets & Documents

https://codeclimate.com/github/thepracticaldev/dev.to/app/javascript/shared/components/tags.jsx/source#issue-a087ee1bf368783e621a0b4563a3aaeb

Mobile & Desktop Screenshots/Recordings (if there are UI changes)

Added to documentation?

  • docs.dev.to
  • readme
  • no documentation needed

[optional] What gif best describes this PR or how it makes you feel?

alt_text

@pr-triage pr-triage bot added the PR: unreviewed bot applied label for PR's with no review label Oct 5, 2019
@CLAassistant
Copy link

CLAassistant commented Oct 5, 2019

CLA assistant check
All committers have signed the CLA.

@stesel stesel changed the title Simplifying this key codes expression in Tags component Simplify key codes expression in Tags component Oct 5, 2019
Copy link
Contributor

@rhymes rhymes left a comment

Choose a reason for hiding this comment

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

Hi @stesel thanks for the code! The PR looks nice.

A question: would you be willing to go a step further and switch from event.keyCode, which is deprecated, to use event.key, see https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key

app/javascript/shared/components/tags.jsx Outdated Show resolved Hide resolved
Copy link
Contributor

@jacobherrington jacobherrington left a comment

Choose a reason for hiding this comment

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

Moving this into a constant and adding a test is a contribution! Thanks @stesel 🎉

I agree with @rhymes and have one small nitpick.

Happy Hacktoberfest! 🎃

e.keyCode != KEYS.RIGHT &&
e.keyCode != KEYS.TAB
) {
} else if ((e.keyCode < 65 || e.keyCode > 90) && !COMBO_KEYS.includes(e.keyCode)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we line wrap this conditional? It's just a bit long for reading on one 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.

Sure, easy :)

@stesel
Copy link
Contributor Author

stesel commented Oct 8, 2019

Hi @stesel thanks for the code! The PR looks nice.

A question: would you be willing to go a step further and switch from event.keyCode, which is deprecated, to use event.key, see https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key

Sure, I've migrated to event.key.

Now I have questions, do we need fallbacks for old browsers witch doesn't support KeyboardEvent.key well?

@rhymes
Copy link
Contributor

rhymes commented Oct 9, 2019

@stesel I don't think so, I'm looking at both https://caniuse.com/#feat=keyboardevent-key and https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent#Browser_compatibility and I think we're fine.

It's obviously open to discussion...

@stesel
Copy link
Contributor Author

stesel commented Oct 9, 2019

@rhymesfor thank you for response!
Then PR can be reviewed again.

@rhymes rhymes requested a review from jacobherrington October 9, 2019 11:18
Copy link
Contributor

@jacobherrington jacobherrington left a comment

Choose a reason for hiding this comment

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

Great work @stesel! Thanks for the PR! 🎉

@pr-triage pr-triage bot added PR: reviewed-approved bot applied label for PR's where reviewer approves changes and removed PR: unreviewed bot applied label for PR's with no review labels Oct 9, 2019
Copy link
Contributor

@rhymes rhymes left a comment

Choose a reason for hiding this comment

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

I agree, great work!

@benhalpern benhalpern merged commit 5e347a6 into forem:master Oct 9, 2019
@pr-triage pr-triage bot added PR: merged bot applied label for PR's that are merged and removed PR: reviewed-approved bot applied label for PR's where reviewer approves changes labels Oct 9, 2019
RakChamp25 pushed a commit to RakChamp25/dev.to that referenced this pull request Oct 15, 2019
* Simplifying this key codes expression in Tags component

* Refactor KeyboardEvent keyCode to key

* Simplify cyrillic letter regexp

* Wrap condition in 2 lines
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: merged bot applied label for PR's that are merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants