-
Notifications
You must be signed in to change notification settings - Fork 568
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
Search: Add tag suggestions to notes list #1648
Conversation
71c2dc2
to
c2f843e
Compare
c2f843e
to
fd65592
Compare
b48bfac
to
64478d3
Compare
76a75af
to
dc3390e
Compare
This has a couple bugs still but I think it's ready to not be a draft anymore! Would love opinions on the open questions above, thoughts on how the code looks, and testing. I'll try to mop up the known issues tomorrow (assuming we even want to keep the keyboard stuff, it's kinda janky). |
This comment has been minimized.
This comment has been minimized.
lib/icons/tag.jsx
Outdated
@@ -0,0 +1,16 @@ | |||
import React from 'react'; |
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.
Is this from the new Icon pack? Can this be added as a separate PR?
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.
Which new Icon pack? It's the tag icon shown next to a tag name (differentiates tag suggestions from search suggestions). Tyler shared the SVG with me in Slack.
d479da6
to
a3609e7
Compare
This comment has been minimized.
This comment has been minimized.
lib/search-suggestions/index.jsx
Outdated
? 'search-suggestion-row search-suggestion-row-selected' | ||
: 'search-suggestion-row' | ||
} | ||
onClick={() => onSearch(`tag:${tag.id}`)} |
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.
fun fact, not too important here, but can be useful especially since this event originates on a div
- we can pass data through custom attributes and access them in the callback…
<div
key={tag.id}
id={tag.id}
data-tag-id={tag.id}
onClick={this.doSearch}
>
doSearch = ( { target: { dataset: { tagId } } } ) => this.props.onSearch( `tag:${ tagId }` ));
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.
Ooh this is something I have needed in attempting to translate my jQuery brain into React.
lib/search-suggestions/index.jsx
Outdated
|
||
const mapStateToProps = ({ appState: state }, ownProps) => ({ | ||
filteredTags: state.tags.filter(function(tag) { | ||
return tag.id.startsWith(encodeURIComponent(ownProps.query)); |
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.
if we have encodeURIComponent
here in this component it probably means we're neglecting to convert it on entry into the application. did you come across this incidentally or did you anticipate the need for this?
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 found the need for it in testing... you're saying the query should get encoded upstream somewhere?
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 think I got it here, is that what you had in mind? Any thoughts on the fact that this input was not formerly encoded? 8a7493c
Some things that were discussed away from GitHub:
Feedback:
|
Done:
|
lib/search-field/index.jsx
Outdated
this.clearQuery(); | ||
doSearch = query => { | ||
this.setState({ query, searchSelected: true }); | ||
this.debouncedSearch(query); |
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.
let's remove the query
from the debounce to prevent the parallel-universes effect when we have multiple calls to doSearch
in a row. granted, we shouldn't have the same problems as with the note content (which could be updated by remote calls) but this keeps a single source of data instead of two
debouncedSearch()
also has to change but not in a big way
debouncedSearch = debounce(() => this.props.onSearch(this.state.query), SEARCH_DELAY);
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.
is debounce
the appropriate idiom for search? if we keep on typing then it won't search until we stop. a throttle
might be more appropriate so that we can see search results as we continue to type but it will still make sure we don't send a new search on every keystroke
debounce
will prevent the search from interfering with our typing but won't update until we have finished typing
throttle
will allow a slow search to interfere with our typing but provide us partial results as we type
…as input tag: or a subset thereof
6c2f569
to
4ffe286
Compare
Since we introduced tag suggestions in #1648 we have been recalculating the list of tag suggestions on every render, at least twice (once to get the count of tag suggestions in note-list and once in tag-suggestions). In order to prevent needless re-rendering we implemented custom memoization in the tag-suggestions component. In this patch we're moving the tag suggestions logic into our search module where the tag suggestions can update with the rest of the search results. By doing this we'll leave one place to update them, couple them with the filtered notes, and be able to remove our custom memoizatoin without losing the benefits it brought us.
Since we introduced tag suggestions in #1648 we have been recalculating the list of tag suggestions on every render, at least twice (once to get the count of tag suggestions in note-list and once in tag-suggestions). In order to prevent needless re-rendering we implemented custom memoization in the tag-suggestions component. In this patch we're moving the tag suggestions logic into our search module where the tag suggestions can update with the rest of the search results. By doing this we'll leave one place to update them, couple them with the filtered notes, and be able to remove our custom memoizatoin without losing the benefits it brought us.
initial version of search suggestions dropdown, removed from #1648
Fix
This PR adds matching tag results to the notes list.
It shows a maximum of five and hides the section if there are no matches.
Clicking a suggested tag fills in the search field with the
tag:
syntax.Fixes #1624, #895
Test
Screenshots
More here.
Release