Skip to content

Commit

Permalink
Fix scrolling to relevant records in search, filter all that doesnt m…
Browse files Browse the repository at this point in the history
…atch required amout of letters
  • Loading branch information
MarcinAman authored and Kordyjan committed Sep 17, 2020
1 parent af9f246 commit 32a9cb0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import {Select} from "@jetbrains/ring-ui";
import {Option, OptionWithHighlightComponent, OptionWithSearchResult, SearchRank} from "./types";
import fuzzyHighlight from '@jetbrains/ring-ui/components/global/fuzzy-highlight.js'
import React from "react";
import {SearchResultRow} from "./searchResultRow";
import {SearchResultRow, signatureFromSearchResult} from "./searchResultRow";
import _ from "lodash";

const orderRecords = (records: OptionWithSearchResult[], searchPhrase: string): OptionWithSearchResult[] => {
return records.sort((a: OptionWithSearchResult, b: OptionWithSearchResult) => {
Expand Down Expand Up @@ -38,6 +39,11 @@ const highlightMatchedPhrases = (records: OptionWithSearchResult[]): OptionWithH
})
}

const hasAnyMatchedPhraseLongerThan = (searchResult: OptionWithSearchResult, length: number): boolean => {
const values = _.chunk(signatureFromSearchResult(searchResult).split("**"), 2).map(([txt, matched]) => matched ? matched.length >= length : null)
return values.reduce((acc, element) => acc || element)
}

export class DokkaFuzzyFilterComponent extends Select {
componentDidUpdate(prevProps, prevState) {
super.componentDidUpdate(prevProps, prevState)
Expand Down Expand Up @@ -66,7 +72,7 @@ export class DokkaFuzzyFilterComponent extends Select {
rank: SearchRank.NameMatch
}
})
.filter((record: OptionWithSearchResult) => record.matched)
.filter((record: OptionWithSearchResult) => record.matched && (hasAnyMatchedPhraseLongerThan(record, 3) || filterPhrase.length < 3))

this.props.onFilter(filterPhrase)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const WithFuzzySearchFilterComponent: React.FC<Props> = ({data}: Props) => {
type={Select.Type.CUSTOM}
clear
renderOptimization
disableScrollToActive
selected={selected}
data={data}
popupClassName={"popup-wrapper"}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ const Highlighter: React.FC<HighlighterProps> = ({label}: HighlighterProps) => {
return <strong>{label}</strong>
}

export const SearchResultRow: React.FC<SearchProps> = ({searchResult}: SearchProps) => {
const signatureFromSearchResult = (searchResult: OptionWithSearchResult): string => {
if(searchResult.rank == SearchRank.SearchKeyMatch){
return searchResult.name.replace(searchResult.searchKey, searchResult.highlight)
}
return searchResult.highlight
export const signatureFromSearchResult = (searchResult: OptionWithSearchResult): string => {
if(searchResult.rank == SearchRank.SearchKeyMatch){
return searchResult.name.replace(searchResult.searchKey, searchResult.highlight)
}
return searchResult.highlight
}

export const SearchResultRow: React.FC<SearchProps> = ({searchResult}: SearchProps) => {
/*
This is a work-around for an issue: https://youtrack.jetbrains.com/issue/RG-2108
*/
Expand Down

0 comments on commit 32a9cb0

Please sign in to comment.