Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Several more fixes #438

Merged
merged 4 commits into from
Jul 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading