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

Search: Add tag suggestions to notes list #1648

Merged
merged 37 commits into from
Nov 21, 2019

Conversation

codebykat
Copy link
Member

@codebykat codebykat commented Oct 18, 2019

Fix

This PR adds matching tag results to the notes list.

Screen Shot 2019-11-13 at 1 57 00 PM

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

  1. Perform some searches and make sure everything works in a way that makes sense! Test with weird tag names, long tag names, tags that aren't added to any notes, etc.
  2. Change note layout (comfy, condensed, expanded) and make sure the left panel is laid out properly (all elements the correct heights, no notes missing, no text overflow).
  3. Test in dark mode as well

Screenshots

More here.

Screen Shot 2019-11-13 at 1 56 46 PM

Screen Shot 2019-11-13 at 1 55 38 PM

Screen Shot 2019-11-13 at 1 55 24 PM

Release

RELEASE-NOTES.txt was updated in 6c2f569 with:

Added matching tags to the notes list on search

@codebykat codebykat added [status] needs code review [feature] search Anything related to searching. labels Oct 18, 2019
@codebykat codebykat added this to the Advanced Search milestone Oct 18, 2019
@codebykat codebykat self-assigned this Oct 18, 2019
@dmsnell dmsnell force-pushed the add/search-suggestions-keep-filter branch from 71c2dc2 to c2f843e Compare October 21, 2019 21:18
@dmsnell dmsnell force-pushed the add/search-suggestions-keep-filter branch from c2f843e to fd65592 Compare October 22, 2019 18:48
@codebykat codebykat force-pushed the add/search-suggestions-keep-filter branch 2 times, most recently from b48bfac to 64478d3 Compare October 29, 2019 01:25
@codebykat codebykat force-pushed the add/search-suggestions-keep-filter branch from 76a75af to dc3390e Compare November 5, 2019 06:02
@codebykat
Copy link
Member Author

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).

@belcherj

This comment has been minimized.

@@ -0,0 +1,16 @@
import React from 'react';
Copy link
Contributor

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?

Copy link
Member Author

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.

@codebykat codebykat force-pushed the add/search-suggestions-keep-filter branch from d479da6 to a3609e7 Compare November 5, 2019 19:39
@codebykat

This comment has been minimized.

? 'search-suggestion-row search-suggestion-row-selected'
: 'search-suggestion-row'
}
onClick={() => onSearch(`tag:${tag.id}`)}
Copy link
Member

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 }` ));

Copy link
Member Author

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.


const mapStateToProps = ({ appState: state }, ownProps) => ({
filteredTags: state.tags.filter(function(tag) {
return tag.id.startsWith(encodeURIComponent(ownProps.query));
Copy link
Member

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?

Copy link
Member Author

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?

Copy link
Member Author

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

@SylvesterWilmott
Copy link
Contributor

Some things that were discussed away from GitHub:

  • The designs show a tag: prefix on the tag items in the list, the designs are based on an updated UI which has a wider search bar. This doesn't work well with the current width of the search bar so this detail will be omitted until the UI changes have been made.
  • Desktop has the advantage of being able to show search results and suggestions simultaneously. The filter as you type behaviour will be retained until we understand if the point scoring system of the default "relevance" search will cause problems with performance.

Feedback:

  • The tag suggestions considers character case where it should not
  • Let's allow matches anywhere in the tag name and matching with 2 characters
  • Regarding the style changes request, here is a pen I whipped up

@codebykat
Copy link
Member Author

Done:

  • Style fixes
  • Case insensitive matching anywhere in the string, starting from 2 characters typed
  • Made some code less terrible

@codebykat
Copy link
Member Author

@dmsnell your advice on the correct way to do this would be very welcome ❤ --> 30e2bf8

this.clearQuery();
doSearch = query => {
this.setState({ query, searchSelected: true });
this.debouncedSearch(query);
Copy link
Member

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);

Copy link
Member

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

@codebykat codebykat force-pushed the add/search-suggestions-keep-filter branch from 6c2f569 to 4ffe286 Compare November 21, 2019 08:34
@codebykat codebykat merged commit f53e032 into develop Nov 21, 2019
@codebykat codebykat deleted the add/search-suggestions-keep-filter branch November 21, 2019 20:07
dmsnell added a commit that referenced this pull request Apr 14, 2020
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.
dmsnell added a commit that referenced this pull request Apr 14, 2020
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.
codebykat added a commit that referenced this pull request Dec 14, 2020
initial version of search suggestions dropdown, removed from #1648
@codebykat codebykat modified the milestones: Advanced Search, 1.13 Dec 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[feature] search Anything related to searching.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Search: Add tag suggestions to search results
4 participants