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

Trim input value in navigation search input field #19832

Merged
merged 3 commits into from
Mar 12, 2020

Conversation

sainthkh
Copy link
Contributor

Description

Trim input values in navigation search input field.

How has this been tested?

Added related e2e code.

Screenshots

Before:

Screenshot from 2020-01-23 17-36-30

After:

Screenshot from 2020-01-23 17-35-55

NOTE: It doesn't show url item at the bottom because page is not a valid url.

Types of changes

Bug fix

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.
  • [NA] I've included developer documentation if appropriate.
  • [NA] I've updated all React Native files affected by any refactorings/renamings in this PR. .

I'm sorry @WunderBart. I realized that I intercepted your issue after finished implementing it.

@sainthkh sainthkh changed the title Trim input value in navigation search input field [WIP] Trim input value in navigation search input field Jan 23, 2020
Copy link
Contributor

@getdave getdave left a comment

Choose a reason for hiding this comment

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

Thank you for the PR. A nice fix!

It should be ok to remove whitespace from start/end of string. Would you consider adding a unit test in LinkControl to cover this?

@sainthkh
Copy link
Contributor Author

@getdave

  1. Removed e2e test because it doesn't work on CI.
  2. Added unit test.

@sainthkh sainthkh changed the title [WIP] Trim input value in navigation search input field Trim input value in navigation search input field Jan 24, 2020
Copy link
Contributor

@getdave getdave left a comment

Choose a reason for hiding this comment

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

Thank you so much for submitting this. I'd love to see this get merged.

Currently, however, the implementation doesn't correctly ensure the handler which fetches search results over XHR has its search term trimmed. Moreover, the tests give you a false positive. You probably know this already but I felt it was worth pointing out.

I've left a comment with a suggestion on amending both tests and implementation detail to get this working for you.

I'd recommend:

  • Rebasing against upstream master to bring in the latest changes.
  • Amending the tests as I suggest (assuming you agree).
  • Checking tests correctly confirm the implementation fails (ie: tests fail).
  • Amending the implementation.
  • Checking tests now pass.

I hope this helps.

packages/block-editor/src/components/link-control/index.js Outdated Show resolved Hide resolved
@sainthkh
Copy link
Contributor Author

@getdave thanks for the amazing review.

The goal of submitting PR is to help you save time and do other more valuable things, but I failed to do that. It's a bit embarrassing.

@sainthkh
Copy link
Contributor Author

Fixed merge conflict.

@getdave
Copy link
Contributor

getdave commented Feb 18, 2020

Fixed merge conflict.

Looking better.

I'm afraid I merged a rather large commit yesterday on <LinkControl> so it looks like you have another small merge issue. The component should be stable for a while so now is a good time to do it.

@sainthkh
Copy link
Contributor Author

Conflicts are resolved in my local branch.

I'm waiting for your opinion about adding trim() to TextHighlight.

@sainthkh
Copy link
Contributor Author

sainthkh commented Feb 19, 2020

  • Fixed conflicts.
  • Moved trim to TextHighlight

@getdave
Copy link
Contributor

getdave commented Feb 24, 2020

Thanks for your work on this @sainthkh 👍

@@ -231,7 +231,7 @@ class URLInput extends Component {
! ( suggestions && suggestions.length )
) {
// Ensure the suggestions are updated with the current input value
this.updateSuggestions( value );
this.updateSuggestions( value.trim() );
Copy link
Member

Choose a reason for hiding this comment

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

If the updateSuggestions() func is expected to always be called with trimmed value, it's probably better to do the trimming inside that very function. Not a blocker though, just a suggestion - feel free to 🚢 this one. Nice work!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

IMHO, it's only duplicated once now. When we need trimming once more, it's strikeout and let's refactor.

I cannot think of a case that doesn't need trimming. But we don't know the future.

@getdave
Copy link
Contributor

getdave commented Mar 6, 2020

@sainthkh 👋 Are you still intending to merge this?

@sainthkh
Copy link
Contributor Author

sainthkh commented Mar 6, 2020

@getdave Yes. Or is there any problem?

@noisysocks noisysocks merged commit e8c7e97 into WordPress:master Mar 12, 2020
@github-actions github-actions bot added this to the Gutenberg 7.8 milestone Mar 12, 2020
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.

LinkControl - for search term and suggested URL, input value should be passed trimmed of whitespace.
6 participants