2025-06-05 13:13:45 +12:00
|
|
|
import { Form, useFormikContext } from 'formik';
|
|
|
|
import { useMemo } from 'react';
|
|
|
|
|
|
|
|
import { FormControl } from '@@/form-components/FormControl';
|
|
|
|
import { Option, PortainerSelect } from '@@/form-components/PortainerSelect';
|
|
|
|
import { FormSection } from '@@/form-components/FormSection';
|
2025-07-13 10:37:43 +12:00
|
|
|
import { LoadingButton } from '@@/buttons';
|
2025-06-05 13:13:45 +12:00
|
|
|
|
|
|
|
import { Chart } from '../types';
|
|
|
|
import { useHelmChartValues } from '../queries/useHelmChartValues';
|
|
|
|
import { HelmValuesInput } from '../components/HelmValuesInput';
|
2025-07-13 10:37:43 +12:00
|
|
|
import { ChartVersion } from '../queries/useHelmRepoVersions';
|
2025-06-05 13:13:45 +12:00
|
|
|
|
|
|
|
import { HelmInstallFormValues } from './types';
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
selectedChart: Chart;
|
|
|
|
namespace?: string;
|
|
|
|
name?: string;
|
2025-07-13 10:37:43 +12:00
|
|
|
versionOptions: Option<ChartVersion>[];
|
|
|
|
isVersionsLoading: boolean;
|
|
|
|
isRepoAvailable: boolean;
|
2025-06-05 13:13:45 +12:00
|
|
|
};
|
|
|
|
|
|
|
|
export function HelmInstallInnerForm({
|
|
|
|
selectedChart,
|
|
|
|
namespace,
|
|
|
|
name,
|
|
|
|
versionOptions,
|
2025-07-13 10:37:43 +12:00
|
|
|
isVersionsLoading,
|
|
|
|
isRepoAvailable,
|
2025-06-05 13:13:45 +12:00
|
|
|
}: Props) {
|
|
|
|
const { values, setFieldValue, isSubmitting } =
|
|
|
|
useFormikContext<HelmInstallFormValues>();
|
|
|
|
|
2025-07-13 10:37:43 +12:00
|
|
|
const selectedVersion: ChartVersion | undefined = useMemo(
|
2025-06-05 13:13:45 +12:00
|
|
|
() =>
|
2025-07-13 10:37:43 +12:00
|
|
|
versionOptions.find(
|
|
|
|
(v) =>
|
|
|
|
v.value.Version === values.version &&
|
|
|
|
v.value.Repo === selectedChart.repo
|
|
|
|
)?.value ?? versionOptions[0]?.value,
|
|
|
|
[versionOptions, values.version, selectedChart.repo]
|
|
|
|
);
|
|
|
|
|
|
|
|
const repoParams = {
|
|
|
|
repo: selectedChart.repo,
|
|
|
|
};
|
|
|
|
// use isLatestVersionFetched to cache the latest version, to avoid duplicate fetches
|
|
|
|
const isLatestVersionFetched =
|
|
|
|
// if no version is selected, the latest version gets fetched
|
|
|
|
!versionOptions.length ||
|
|
|
|
// otherwise check if the selected version is the latest version
|
|
|
|
(selectedVersion?.Version === versionOptions[0]?.value.Version &&
|
|
|
|
selectedVersion?.Repo === versionOptions[0]?.value.Repo);
|
|
|
|
const chartValuesRefQuery = useHelmChartValues(
|
|
|
|
{
|
|
|
|
chart: selectedChart.name,
|
|
|
|
version: values?.version,
|
|
|
|
...repoParams,
|
|
|
|
},
|
|
|
|
isLatestVersionFetched
|
2025-06-05 13:13:45 +12:00
|
|
|
);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Form className="form-horizontal">
|
|
|
|
<div className="form-group !m-0">
|
|
|
|
<FormSection title="Configuration" className="mt-4">
|
|
|
|
<FormControl
|
|
|
|
label="Version"
|
|
|
|
inputId="version-input"
|
2025-07-13 10:37:43 +12:00
|
|
|
isLoading={isVersionsLoading}
|
2025-06-05 13:13:45 +12:00
|
|
|
loadingText="Loading versions..."
|
|
|
|
>
|
2025-07-13 10:37:43 +12:00
|
|
|
<PortainerSelect<ChartVersion>
|
2025-06-05 13:13:45 +12:00
|
|
|
value={selectedVersion}
|
|
|
|
options={versionOptions}
|
2025-07-13 10:37:43 +12:00
|
|
|
noOptionsMessage={() => 'No versions found'}
|
|
|
|
placeholder="Select a version"
|
2025-06-05 13:13:45 +12:00
|
|
|
onChange={(version) => {
|
|
|
|
if (version) {
|
2025-07-13 10:37:43 +12:00
|
|
|
setFieldValue('version', version.Version);
|
|
|
|
setFieldValue('repo', version.Repo);
|
2025-06-05 13:13:45 +12:00
|
|
|
}
|
|
|
|
}}
|
|
|
|
data-cy="helm-version-input"
|
|
|
|
/>
|
|
|
|
</FormControl>
|
|
|
|
<HelmValuesInput
|
|
|
|
values={values.values}
|
|
|
|
setValues={(values) => setFieldValue('values', values)}
|
|
|
|
valuesRef={chartValuesRefQuery.data?.values ?? ''}
|
|
|
|
isValuesRefLoading={chartValuesRefQuery.isInitialLoading}
|
|
|
|
/>
|
|
|
|
</FormSection>
|
|
|
|
</div>
|
|
|
|
|
2025-07-13 10:37:43 +12:00
|
|
|
<LoadingButton
|
|
|
|
className="!ml-0"
|
2025-06-05 13:13:45 +12:00
|
|
|
loadingText="Installing Helm chart"
|
|
|
|
isLoading={isSubmitting}
|
2025-07-13 10:37:43 +12:00
|
|
|
disabled={!namespace || !name || !isRepoAvailable}
|
2025-06-05 13:13:45 +12:00
|
|
|
data-cy="helm-install"
|
2025-07-13 10:37:43 +12:00
|
|
|
>
|
|
|
|
Install
|
|
|
|
</LoadingButton>
|
2025-06-05 13:13:45 +12:00
|
|
|
</Form>
|
|
|
|
);
|
|
|
|
}
|