import { useMemo, useState } from "react"; import Select, { components } from "react-select"; import { BsCheck2 } from "react-icons/bs"; import { NonEmptyArray } from "../../../data/types"; interface Version { repository: string; version: string; isChartVersion: boolean; urls: string[]; } export const VersionToInstall: React.FC<{ versions: NonEmptyArray; initialVersion?: { repository?: string; version?: string; }; onSelectVersion: (props: { version: string; repository: string; urls: string[]; }) => void; showCurrentVersion: boolean; }> = ({ versions, onSelectVersion, showCurrentVersion, initialVersion }) => { const chartVersion = useMemo( () => versions.find(({ isChartVersion }) => isChartVersion)?.version, [versions] ); const currentVersion = chartVersion && showCurrentVersion ? (

{"(current version is "} {`${chartVersion}`} {")"}

) : null; // Prepare your options for react-select const options = useMemo( () => versions.map(({ repository, version, urls }) => ({ value: { repository, version, urls }, label: `${repository} @ ${version}`, check: chartVersion === version, })) || [], [chartVersion, versions] ); const [selectedOption, setSelectedOption] = useState<(typeof options)[number]>(); const initOpt = useMemo( () => options.find( ({ value }) => value.version === initialVersion?.version && value.repository === initialVersion?.repository ), [options, initialVersion] ); return (
{versions?.length && (selectedOption || initOpt) ? ( <> Version to install:{" "}