import { useRef } from 'react'; import { X } from 'lucide-react'; import { Form, Formik, FormikProps } from 'formik'; import { useRouter } from '@uirouter/react'; import { notifySuccess } from '@/portainer/services/notifications'; import { useAnalytics } from '@/react/hooks/useAnalytics'; import { useCanExit } from '@/react/hooks/useCanExit'; import { Widget } from '@@/Widget'; import { Button } from '@@/buttons/Button'; import { FallbackImage } from '@@/FallbackImage'; import Svg from '@@/Svg'; import { Icon } from '@@/Icon'; import { WebEditorForm } from '@@/WebEditorForm'; import { confirmGenericDiscard } from '@@/modals/confirm'; import { FormSection } from '@@/form-components/FormSection'; import { InlineLoader } from '@@/InlineLoader'; import { FormActions } from '@@/form-components/FormActions'; import { Chart } from '../types'; import { useHelmChartValues } from './queries/useHelmChartValues'; import { HelmIcon } from './HelmIcon'; import { useHelmChartInstall } from './queries/useHelmChartInstall'; type Props = { selectedChart: Chart; clearHelmChart: () => void; namespace?: string; name?: string; }; type FormValues = { values: string; }; const emptyValues: FormValues = { values: '', }; export function HelmTemplatesSelectedItem({ selectedChart, clearHelmChart, namespace, name, }: Props) { const router = useRouter(); const analytics = useAnalytics(); const { mutate: installHelmChart, isLoading: isInstalling } = useHelmChartInstall(); const { data: initialValues, isLoading: loadingValues } = useHelmChartValues(selectedChart); const formikRef = useRef>(null); useCanExit(() => !formikRef.current?.dirty || confirmGenericDiscard()); function handleSubmit(values: FormValues) { if (!name || !namespace) { // Theoretically this should never happen and is mainly to keep typescript happy return; } installHelmChart( { Name: name, Repo: selectedChart.repo, Chart: selectedChart.name, Values: values.values, Namespace: namespace, }, { onSuccess() { analytics.trackEvent('kubernetes-helm-install', { category: 'kubernetes', metadata: { 'chart-name': selectedChart.name, }, }); notifySuccess('Success', 'Helm chart successfully installed'); // Reset the form so page can be navigated away from without getting "Are you sure?" formikRef.current?.resetForm(); router.stateService.go('kubernetes.applications'); }, } ); } return ( <>
{selectedChart.name} {' '} Helm
{selectedChart.description}
handleSubmit(values)} > {({ values, setFieldValue }) => (
{loadingValues && (
Loading values.yaml...
)} {!!initialValues && ( setFieldValue('values', value)} type="yaml" data-cy="helm-app-creation-editor" textTip="Define or paste the content of your values yaml file here" > You can get more information about Helm values file format in the{' '} official documentation . )}
)}
); }