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 tag suggestions #1827

Merged
merged 3 commits into from
Jan 13, 2020
Merged

Refactor tag suggestions #1827

merged 3 commits into from
Jan 13, 2020

Conversation

dmsnell
Copy link
Member

@dmsnell dmsnell commented Jan 10, 2020

In this patch we're creating some new tests to verify the expected way that the
search field will filter down available tags. This is to help us make updates
to the tag searching and suggesting interface.

Testing

That's what this is! Check the CI build.

In this patch we're creating some new tests to verify the expected way that the
search field will filter down available tags. This is to help us make updates
to the tag searching and suggesting interface.
@dmsnell dmsnell requested a review from codebykat January 10, 2020 07:23
@dmsnell dmsnell changed the title Add tests to tag suggestions component Refactor tag suggestions Jan 10, 2020
I've removed the RegExp and rewritten the filtering loop. Why?

The RegExp added a step of confusion where we needed to parse and understand
what it was doing. It turns out that in the course of this refactor I found a
case where it wasn't doing what we thought it was doing, skipping a full-text
match for `tag:` given a tag named `tag:`. Without the RegExp we simply have
fewer concepts squished into this function.

The filtering loop also was iterating over every tag in the account and
checking if they matched the search query before it thought about pruning down
the list of matches to the maximum number. With the new loop we're using a
helper function (to keep the looping details out of the logic) which will abort
out of its looping as soon as we find as many results as we'll allow. Otherwise
if it never finds the maximum results it will continue iterating until it has
scanned every tag.

One final bug was fixed: it was previously possible to enter whitespace into
the search field and then it would look for all of the tags as possible
matches. With only whitespace in the search field there should be no tag
suggestions.
@dmsnell dmsnell force-pushed the tests/tag-suggestions branch from 1a270ab to cead920 Compare January 10, 2020 08:06
Copy link
Member

@codebykat codebykat left a comment

Choose a reason for hiding this comment

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

This looks and tests great 👍

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.

2 participants