diff --git a/dashboard/src/components/modal/InstallChartModal/InstallChartModal.tsx b/dashboard/src/components/modal/InstallChartModal/InstallChartModal.tsx index 76aa93af..9ec51f62 100644 --- a/dashboard/src/components/modal/InstallChartModal/InstallChartModal.tsx +++ b/dashboard/src/components/modal/InstallChartModal/InstallChartModal.tsx @@ -49,6 +49,7 @@ export const InstallChartModal = ({ chart: _releaseName, revision, context: selectedCluster, + selectedRepo: currentRepoCtx, } = useParams(); const [namespace, setNamespace] = useState(queryNamespace); const [releaseName, setReleaseName] = useState(isInstall ? chartName : _releaseName); @@ -60,13 +61,12 @@ export const InstallChartModal = ({ ); }, onSuccess: (data) => { - const selectedVersion = (data || []).find( - ({ version }) => - version === - (isUpgrade ? latestVersion : currentlyInstalledChartVersion) - ) || { version: "", repository: "", urls: [] }; - - setSelectedVersionData(selectedVersion); + const empty = { version: "", repository: "", urls: [] } + if (!isInstall) { + return setSelectedVersionData(data[0] ?? empty); + } + const versionsToRepo = data.filter(v => v.repository === currentRepoCtx) + return setSelectedVersionData(versionsToRepo[0] ?? empty); }, }); @@ -82,9 +82,6 @@ export const InstallChartModal = ({ urls: string[]; }>(); - const chart = useMemo(() => { - return selectedVersionData?.urls[0].startsWith('file://') ? selectedVersionData?.urls[0] : `${selectedVersionData?.repository}/${chartName}`; - }, [selectedVersionData, chartName]) const selectedVersion = useMemo(() => { return selectedVersionData?.version; @@ -94,6 +91,10 @@ export const InstallChartModal = ({ return selectedVersionData?.repository; }, [selectedVersionData]); + const chart = useMemo(() => { + return selectedVersionData?.urls?.[0]?.startsWith('file://') ? selectedVersionData?.urls[0] : `${selectedVersionData?.repository}/${chartName}`; + }, [selectedVersionData, chartName]) + const { data: chartValues, isLoading: loadingChartValues, @@ -324,9 +325,8 @@ export const InstallChartModal = ({ {versions && isNoneEmptyArray(versions) && ( { - setSelectedVersionData(versionData); - }} + initialVersion={selectedVersionData} + onSelectVersion={setSelectedVersionData} isInstall={isInstall} /> )} diff --git a/dashboard/src/components/modal/InstallChartModal/VersionToInstall.tsx b/dashboard/src/components/modal/InstallChartModal/VersionToInstall.tsx index eba46bb3..b53bc83a 100644 --- a/dashboard/src/components/modal/InstallChartModal/VersionToInstall.tsx +++ b/dashboard/src/components/modal/InstallChartModal/VersionToInstall.tsx @@ -1,21 +1,26 @@ -import { useState } from "react"; +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<{ - repository: string; - version: string; - isChartVersion: boolean; - urls: string[]; - }>; + versions: NonEmptyArray; + initialVersion?: { + repository?: string; + version?: string; + }; onSelectVersion: (props: { version: string; repository: string; urls: string[] }) => void; isInstall?: boolean; -}> = ({ versions, onSelectVersion, isInstall }) => { - const chartVersion = versions.find( +}> = ({ versions, onSelectVersion, isInstall, initialVersion }) => { + const chartVersion = useMemo(() => versions.find( ({ isChartVersion }) => isChartVersion - )?.version; + )?.version, [versions]); const currentVersion = chartVersion && !isInstall ? ( @@ -33,11 +38,11 @@ export const VersionToInstall: React.FC<{ label: `${repository} @ ${version}`, check: chartVersion === version, })) || []; - const [selectedOption, setSelectedOption] = useState(options[0]); - + const [selectedOption, setSelectedOption] = useState(); + const initOpt = useMemo(() => options.find(({ value }) => value.version === initialVersion?.version && value.repository === initialVersion?.repository), [options, initialVersion]); return (
- {versions?.length ? ( + {(versions?.length && (selectedOption || initOpt)) ? ( <> Version to install:{" "}