-
Notifications
You must be signed in to change notification settings - Fork 753
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
Implemented autocomplete functionality in open bot dialog #1510
Conversation
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
|
||
// from https://github.com/bevacqua/fuzzysearch | ||
private fuzzysearch(needle: string, haystack: string) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't know if the above copyright and link to source will be compliant, but we can discuss it.
68a855a
to
de17c0f
Compare
de17c0f
to
f7d0956
Compare
f7d0956
to
c687b33
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some recommendations but looks good overall
return this.props.label ? `auto-complete-textbox-${this.state.id}` : undefined; | ||
} | ||
|
||
private get filteredItems(): string[] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would expect the matches to have some sort of emphasis on the searched value. This can be achieved through using a <strong>
tag for the matched string:
...
return filteredItems.map(item => item.replace(new RegExp(this.value, 'gi'), `<strong>${this.value}</strong>`);
Then use dangerouslySetInnerHtml
on the <li>
tag
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would be a nice visual improvement but it might not work so well with this search algorithm because it just checks for the succession of characters in string and returns true if it exists.
For example:
ir would match on international because there is an i in the string, followed by an r. So the meaningful way to emphasize that would probably be to bold everything between the first "i" and the last "r" so you would be left with international.
The method you suggested would provide some strange results in some words:
er
matches on Herbert
so the end result would be Herbert
o
matches on localhost:3948/api/orders
so the end result would be localhost:3948/api/orders with 3 bolded o
's
In my opinion, bolding every character between the first and last matched characters would be the way to go, but that seems like a QoL improvement that could be added in a later PR and not critical to this first implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Opened an issue to track this work: #1518
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. I did't look closely at the fuzzy search function to see this is what it's doing. Maybe an alternative would be to implement the emphasis for sub strings that are exact sequential matches and then sort them so they are first in the list.
Thoughts?
Also, although very long lists are unlikely, have we considered the performance implications of the loop nesting in the search algo for long lists? How would a user remove items that may have gotten in there from a typo or that are no longer needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That strategy for highlighting sounds good to me!
As for the performance with long lists, there are two trivial solutions I can think of:
- put a limit on the number of saved items we feed into the component (easy to manage in the context of saved bot endpoints, but would have to be managed for each autocomplete placed throughout the app)
- swap out the current search algorithm for a more performant one (very easy fix)
The list of searchable items is provided by the parent of the widget, so any item removal / clear functionality would have to be implemented by the parent. It would be very straight forward in this case and we would just need to add a new action handler to the savedBotUrls
reducer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Opened an issue to track work for list item removal / clearing UI: #1525
c687b33
to
01be45f
Compare
One of #1443
===
Don't worry, I'll squash all of the commits.
@mewa1024 I just used the styling from the Split Button drop down specs