import React from "react"; import {OptionWithSearchResult, SearchProps, SearchRank} from "./types"; import _ from "lodash"; type HighlighterProps = { label: string } const Highlighter: React.FC = ({label}: HighlighterProps) => { return {label} } 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 = ({searchResult}: SearchProps) => { /* This is a work-around for an issue: https://youtrack.jetbrains.com/issue/RG-2108 */ const out = _.chunk(signatureFromSearchResult(searchResult).split('**'), 2).flatMap(([txt, label]) => [ txt, label ? : null, ]); return (
{out} {searchResult.description}
) }