import * as React from 'react'; import { Button, Form, Grid, GridItem, PageSection, TextInput, TextInputTypes, } from '@patternfly/react-core'; import { PlusCircleIcon } from '@patternfly/react-icons/dist/esm/icons/plus-circle-icon'; import { FormikProps, useField } from 'formik'; import isEmpty from 'lodash-es/isEmpty'; import { FilterContextProvider } from '~/components/Filter/generic/FilterContext'; import { InputField, TextAreaField } from '~/shared/components/formik-base'; import { getErrorState } from '~/shared/utils/error-utils'; import { useReleasePlans } from '../../../../../src/hooks/useReleasePlans'; import PageLayout from '../../../../components/PageLayout/PageLayout'; import { RELEASE_SERVICE_PATH } from '../../../../routes/paths'; import { FormFooter } from '../../../../shared'; import KeyValueField from '../../../../shared/components/formik-fields/key-value-input-field/KeyValueInputField'; import TextColumnField from '../../../../shared/components/formik-fields/text-column-field/TextColumnField'; import { useNamespace } from '../../../../shared/providers/Namespace'; import { Snapshot } from '../../../../types/coreBuildService'; import { IssueType } from './AddIssueSection/AddIssueModal'; import { AddIssueSection } from './AddIssueSection/AddIssueSection'; import { TriggerReleaseFormValues } from './form-utils'; import { ReleasePlanDropdown } from './ReleasePlanDropdown'; import { SnapshotDropdown } from './SnapshotDropdown'; type Props = FormikProps & { snapshotDetails?: Snapshot; }; export const getApplicationNameForReleasePlan = (releasePlans, selectedReleasePlan, loaded) => { if (!loaded || !releasePlans || !releasePlans.length) { return ''; } const currentReleasePlan = releasePlans.find((r) => r.metadata?.name === selectedReleasePlan); return currentReleasePlan?.spec?.application || ''; }; export const TriggerReleaseForm: React.FC = ({ handleSubmit, handleReset, isSubmitting, dirty, errors, status, snapshotDetails, }) => { const namespace = useNamespace(); const [{ value: labels }] = useField('labels'); const [releasePlans, loaded, error] = useReleasePlans(namespace); const [selectedReleasePlanField] = useField('releasePlan'); const [reference, setReference] = React.useState(''); const [references, , { setValue }] = useField('references'); if (error) { return getErrorState(error, loaded, 'release plans'); } const releasePlanApplicationName = getApplicationNameForReleasePlan( releasePlans, selectedReleasePlanField.value, loaded, ); // Use application name from release plan if available, otherwise use from snapshot details const applicationName = releasePlanApplicationName || snapshotDetails?.spec?.application || ''; return ( } >
setValue(references.value.filter?.((r) => v.includes(r)))} > {(props) => { return ( {props.removeButton} ); }} setReference(val)} value={reference} />
); };