'use client'; import { PathHeader } from "@/app/[domain]/components/pathHeader"; import { Separator } from "@/components/ui/separator"; import { DoubleArrowDownIcon, DoubleArrowUpIcon } from "@radix-ui/react-icons"; import { useMemo } from "react"; import { FileMatch } from "./fileMatch"; import { RepositoryInfo, SearchResultFile } from "@/features/search"; import { Button } from "@/components/ui/button"; export const MAX_MATCHES_TO_PREVIEW = 3; interface FileMatchContainerProps { file: SearchResultFile; onOpenFilePreview: (matchIndex?: number) => void; showAllMatches: boolean; onShowAllMatchesButtonClicked: () => void; isBranchFilteringEnabled: boolean; repoInfo: Record; yOffset: number; } export const FileMatchContainer = ({ file, onOpenFilePreview, showAllMatches, onShowAllMatchesButtonClicked, isBranchFilteringEnabled, repoInfo, yOffset, }: FileMatchContainerProps) => { const matchCount = useMemo(() => { return file.chunks.length; }, [file]); const matches = useMemo(() => { const sortedMatches = file.chunks.sort((a, b) => { return a.contentStart.lineNumber - b.contentStart.lineNumber; }); if (!showAllMatches) { return sortedMatches.slice(0, MAX_MATCHES_TO_PREVIEW); } return sortedMatches; }, [file, showAllMatches]); const fileNameRange = useMemo(() => { if (file.fileName.matchRanges.length > 0) { const range = file.fileName.matchRanges[0]; return { from: range.start.column - 1, to: range.end.column - 1, } } return undefined; }, [file.fileName.matchRanges]); const isMoreContentButtonVisible = useMemo(() => { return matchCount > MAX_MATCHES_TO_PREVIEW; }, [matchCount]); const branches = useMemo(() => { if (!file.branches) { return []; } return file.branches; }, [file.branches]); const branchDisplayName = useMemo(() => { if (!isBranchFilteringEnabled || branches.length === 0) { return undefined; } return `${branches[0]}${branches.length > 1 ? ` +${branches.length - 1}` : ''}`; }, [branches, isBranchFilteringEnabled]); const repo = useMemo(() => { return repoInfo[file.repositoryId]; }, [repoInfo, file.repositoryId]); return (
{/* Title */}
{/* Matches */} {matches.map((match, index) => (
{(index !== matches.length - 1 || isMoreContentButtonVisible) && ( )}
))} {/* Show more button */} {isMoreContentButtonVisible && (
{ if (e.key !== "Enter") { return; } onShowAllMatchesButtonClicked(); }} onClick={onShowAllMatchesButtonClicked} >

{showAllMatches ? : } {showAllMatches ? `Show fewer matches` : `Show ${matchCount - MAX_MATCHES_TO_PREVIEW} more matches`}

)}
); }