Skip to content

Commit

Permalink
Several more fixes (#438)
Browse files Browse the repository at this point in the history
  • Loading branch information
naorzr authored Jul 16, 2023
1 parent 342a66b commit 7823d76
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
},
});

Expand All @@ -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;
Expand All @@ -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,
Expand Down Expand Up @@ -324,9 +325,8 @@ export const InstallChartModal = ({
{versions && isNoneEmptyArray(versions) && (
<VersionToInstall
versions={versions}
onSelectVersion={(versionData) => {
setSelectedVersionData(versionData);
}}
initialVersion={selectedVersionData}
onSelectVersion={setSelectedVersionData}
isInstall={isInstall}
/>
)}
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Version>;
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 ? (
Expand All @@ -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<typeof options[number]>();
const initOpt = useMemo(() => options.find(({ value }) => value.version === initialVersion?.version && value.repository === initialVersion?.repository), [options, initialVersion]);
return (
<div className="flex gap-2 text-xl items-center">
{versions?.length ? (
{(versions?.length && (selectedOption || initOpt)) ? (
<>
Version to install:{" "}
<Select
Expand All @@ -53,7 +58,7 @@ export const VersionToInstall: React.FC<{
onSelectVersion(selectedOption.value);
}
}}
value={selectedOption}
value={selectedOption ?? initOpt}
components={{
SingleValue: ({ children, ...props }) => (
<components.SingleValue {...props}>
Expand Down

0 comments on commit 7823d76

Please sign in to comment.