1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-18 21:09:40 +02:00

fix: fetching values from both install and upgrade views - develop [R8S-368] (#820)

This commit is contained in:
Steven Kang 2025-06-24 15:46:10 +12:00 committed by GitHub
parent d51e9205d9
commit c897baad20
7 changed files with 111 additions and 45 deletions

View file

@ -44,7 +44,6 @@ export function UpgradeButton({
useCache
);
const versions = helmRepoVersionsQuery.data;
const repo = versions?.[0]?.Repo;
// Combined loading state
const isLoading =
@ -63,17 +62,28 @@ export function UpgradeButton({
latestVersionQuery?.data &&
semverCompare(latestVersionAvailable, latestVersionQuery?.data) === 1
);
const currentVersion = release?.chart.metadata?.version;
const currentRepo = versions?.find(
(v) =>
v.Chart === release?.chart.metadata?.name &&
v.AppVersion === release?.chart.metadata?.appVersion &&
v.Version === release?.chart.metadata?.version
)?.Repo;
const editableHelmRelease: UpdateHelmReleasePayload = {
name: releaseName,
namespace: namespace || '',
values: release?.values?.userSuppliedValues,
chart: release?.chart.metadata?.name || '',
version: currentVersion,
repo,
appVersion: release?.chart.metadata?.appVersion,
version: release?.chart.metadata?.version,
repo: currentRepo ?? '',
};
const filteredVersions = currentRepo
? versions?.filter((v) => v.Repo === currentRepo) || []
: versions || [];
return (
<div className="relative">
<LoadingButton
@ -151,7 +161,7 @@ export function UpgradeButton({
async function handleUpgrade() {
const submittedUpgradeValues = await openUpgradeHelmModal(
editableHelmRelease,
versions
filteredVersions
);
if (submittedUpgradeValues) {

View file

@ -19,39 +19,48 @@ import { useHelmChartValues } from '../../queries/useHelmChartValues';
interface Props {
onSubmit: OnSubmit<UpdateHelmReleasePayload>;
values: UpdateHelmReleasePayload;
payload: UpdateHelmReleasePayload;
versions: ChartVersion[];
chartName: string;
repo: string;
}
export function UpgradeHelmModal({
values,
payload,
versions,
onSubmit,
chartName,
repo,
}: Props) {
const versionOptions: Option<ChartVersion>[] = versions.map((version) => {
const isCurrentVersion = version.Version === values.version;
const label = `${version.Repo}@${version.Version}${
const repo = payload.repo === version.Repo ? version.Repo : '';
const isCurrentVersion =
version.AppVersion === payload.appVersion &&
version.Version === payload.version;
const label = `${repo}@${version.Version}${
isCurrentVersion ? ' (current)' : ''
}`;
return {
repo,
label,
value: version,
};
});
const defaultVersion =
versionOptions.find((v) => v.value.Version === values.version)?.value ||
versionOptions[0]?.value;
versionOptions.find(
(v) =>
v.value.AppVersion === payload.appVersion &&
v.value.Version === payload.version &&
v.value.Repo === payload.repo
)?.value || versionOptions[0]?.value;
const [version, setVersion] = useState<ChartVersion>(defaultVersion);
const [userValues, setUserValues] = useState<string>(values.values || '');
const [userValues, setUserValues] = useState<string>(payload.values || '');
const [atomic, setAtomic] = useState<boolean>(true);
const chartValuesRefQuery = useHelmChartValues({
chart: chartName,
repo,
repo: version.Repo,
version: version.Version,
});
@ -75,7 +84,7 @@ export function UpgradeHelmModal({
>
<Input
id="release-name-input"
value={values.name}
value={payload.name}
readOnly
disabled
data-cy="helm-release-name-input"
@ -88,7 +97,7 @@ export function UpgradeHelmModal({
>
<Input
id="namespace-input"
value={values.namespace}
value={payload.namespace}
readOnly
disabled
data-cy="helm-namespace-input"
@ -142,10 +151,10 @@ export function UpgradeHelmModal({
<Button
onClick={() =>
onSubmit({
name: values.name,
name: payload.name,
values: userValues,
namespace: values.namespace,
chart: values.chart,
namespace: payload.namespace,
chart: payload.chart,
repo: version.Repo,
version: version.Version,
atomic,
@ -165,13 +174,12 @@ export function UpgradeHelmModal({
}
export async function openUpgradeHelmModal(
values: UpdateHelmReleasePayload,
payload: UpdateHelmReleasePayload,
versions: ChartVersion[]
) {
return openModal(withReactQuery(withCurrentUser(UpgradeHelmModal)), {
values,
payload,
versions,
chartName: values.chart,
repo: values.repo ?? '',
chartName: payload.chart,
});
}

View file

@ -10,12 +10,15 @@ interface HelmSearch {
}
interface Entries {
[key: string]: { version: string }[];
[key: string]: { version: string; appVersion: string }[];
}
export interface ChartVersion {
Chart?: string;
Repo: string;
Label?: string;
Version: string;
AppVersion?: string;
}
/**
@ -77,8 +80,10 @@ async function getSearchHelmRepo(
const versions = data.entries[chart];
return (
versions?.map((v) => ({
Chart: chart,
Repo: repo,
Version: v.version,
AppVersion: v.appVersion,
})) ?? []
);
} catch (err) {

View file

@ -120,9 +120,10 @@ export interface InstallChartPayload {
export interface UpdateHelmReleasePayload {
namespace: string;
values?: string;
repo?: string;
repo: string;
name: string;
chart: string;
appVersion?: string;
version?: string;
atomic?: boolean;
}