Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 | 101x 101x 101x 101x 101x 101x 101x 101x 101x 101x 101x 101x 101x 4x 4x 4x 4x 4x 4x 4x 1x 1x 1x 1x 4x 1x 14x | /* * Copyright 2022 Harness Inc. All rights reserved. * Use of this source code is governed by the PolyForm Shield 1.0.0 license * that can be found in the licenses directory at the root of this repository, also available at * https://polyformproject.org/wp-content/uploads/2020/06/PolyForm-Shield-1.0.0.txt. */ import React from 'react' import { Formik, Layout, Button, StepProps, Text, ButtonVariation, FormInput, getMultiTypeFromValue, MultiTypeInputType } from '@harness/uicore' import { Form } from 'formik' import * as Yup from 'yup' import { FontVariation } from '@harness/design-system' import { merge } from 'lodash-es' import { useStrings } from 'framework/strings' import type { ArtifactType, ImagePathProps, CustomArtifactSource } from '@pipeline/components/ArtifactsSelection/ArtifactInterface' import type { ConnectorConfigDTO } from 'services/cd-ng' import { ConfigureOptions } from '@common/components/ConfigureOptions/ConfigureOptions' import { getArtifactFormData } from '@pipeline/components/ArtifactsSelection/ArtifactUtils' import { ArtifactIdentifierValidation, ModalViewFor } from '../../../ArtifactHelper' import SideCarArtifactIdentifier from '../SideCarArtifactIdentifier' import css from '../../ArtifactConnector.module.scss' export function CustomArtifact({ context, handleSubmit, expressions, allowableTypes, prevStepData, initialValues, previousStep, artifactIdentifiers, isReadonly = false, selectedArtifact }: StepProps<ConnectorConfigDTO> & ImagePathProps): React.ReactElement { const { getString } = useStrings() const schemaObject = { version: Yup.string().trim().required(getString('validation.nexusVersion')) } const primarySchema = Yup.object().shape(schemaObject) const sidecarSchema = Yup.object().shape({ ...schemaObject, ...ArtifactIdentifierValidation( artifactIdentifiers, initialValues?.identifier, getString('pipeline.uniqueIdentifier') ) }) const getInitialValues = (): CustomArtifactSource => { return getArtifactFormData( initialValues, selectedArtifact as ArtifactType, context === ModalViewFor.SIDECAR ) as CustomArtifactSource } const submitFormData = (formData: CustomArtifactSource & { connectorId?: string }): void => { const artifactObj = { spec: { version: formData?.version } } Eif (context === ModalViewFor.SIDECAR) { merge(artifactObj, { identifier: formData?.identifier }) } handleSubmit(artifactObj) } return ( <Layout.Vertical spacing="medium" className={css.firstep}> <Text font={{ variation: FontVariation.H3 }} margin={{ bottom: 'medium' }}> {getString('pipeline.artifactsSelection.artifactDetails')} </Text> <Formik initialValues={getInitialValues()} formName="imagePath" validationSchema={context === ModalViewFor.SIDECAR ? sidecarSchema : primarySchema} onSubmit={formData => { submitFormData({ ...prevStepData, ...formData }) }} > {formik => ( <Form> <div className={css.connectorForm}> {context === ModalViewFor.SIDECAR && <SideCarArtifactIdentifier />} <div className={css.imagePathContainer}> <FormInput.MultiTextInput label={getString('version')} name="version" placeholder={getString('pipeline.artifactsSelection.versionPlaceholder')} multiTextInputProps={{ expressions, allowableTypes }} /> {getMultiTypeFromValue(formik.values.version) === MultiTypeInputType.RUNTIME && ( <div className={css.configureOptions}> <ConfigureOptions style={{ alignSelf: 'center' }} value={formik.values?.version as string} type={getString('string')} variableName="version" showRequiredField={false} showDefaultField={false} showAdvanced={true} onChange={value => { formik.setFieldValue('version', value) }} isReadonly={isReadonly} /> </div> )} </div> </div> <Layout.Horizontal spacing="medium"> <Button variation={ButtonVariation.SECONDARY} text={getString('back')} icon="chevron-left" onClick={() => previousStep?.(prevStepData)} /> <Button variation={ButtonVariation.PRIMARY} type="submit" text={getString('submit')} rightIcon="chevron-right" /> </Layout.Horizontal> </Form> )} </Formik> </Layout.Vertical> ) } |