import React from 'react'; import SearchFileTitle from './search-file-title'; import Replace from '@components/icons/replace'; interface SearchResultProps { searchResults: Array<{ [key: string]: Array<{ code: string }> }>; unExpandedTitles: Record; searchText: string; selectedRow: { titleIndex: number; rowIndex: number }; handleRowSelection: (titleIndex: number, rowIndex: number) => void; toggleExpand: (expanded: boolean, titleIndex: number) => void; replaceRowSelection: ( event: React.MouseEvent ) => void; canReplace: boolean; } const SearchResult: React.FC = ({ searchResults, unExpandedTitles, searchText, selectedRow, handleRowSelection, toggleExpand, replaceRowSelection, canReplace, }) => { const renderStringWithHighlight = (str: string, highlight: string) => { const parts = str.split(highlight); return ( {parts.map((part, index) => ( {part} {index !== parts.length - 1 && ( {highlight} )} ))} ); }; return (
    {searchResults.map((result, titleIndex) => { return Object.keys(result ?? {}).map((title) => (
  • toggleExpand(expanded, titleIndex) } />
      {searchText && result[title].map((row, rowIndex) => (
    • handleRowSelection(titleIndex, rowIndex)} >
      {renderStringWithHighlight(row.code, searchText)}
      {canReplace && titleIndex === selectedRow.titleIndex && rowIndex === selectedRow.rowIndex && (
      )}
    • ))}
  • )); })}
); }; export default SearchResult;