All files / modules/70-pipeline/components/SelectOrCreatePipelineForm SelectOrCreatePipelineForm.tsx

82.61% Statements 19/23
0% Branches 0/4
60% Functions 3/5
82.61% Lines 19/23

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              9x 9x 9x 9x 9x 9x 9x 9x 9x               9x 12x 10x 10x 10x   10x 6x           10x                                                                                                       2x 2x                    
/*
 * Copyright 2021 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, { useState, useEffect } from 'react'
import { Text, Layout, Formik, FormikForm as Form, Button, FormInput } from '@wings-software/uicore'
import { Color } from '@harness/design-system'
import * as Yup from 'yup'
import { useStrings } from 'framework/strings'
import PipelineSelect from '@pipeline/components/PipelineSelect/PipelineSelect'
import { useTelemetry } from '@common/hooks/useTelemetry'
import { Category, PipelineActions } from '@common/constants/TrackingConstants'
import css from './SelectOrCreatePipelineForm.module.scss'
 
interface SelectOrCreatePipelineFormProps {
  handleSubmit: (value: string) => void
  closeModal?: () => void
  openCreatPipeLineModal: () => void
}
 
export function SelectOrCreatePipelineForm(props: SelectOrCreatePipelineFormProps): React.ReactElement {
  const { getString } = useStrings()
  const [select, setSelect] = useState('')
  const { openCreatPipeLineModal, handleSubmit, closeModal } = props
  const { trackEvent } = useTelemetry()
 
  useEffect(() => {
    trackEvent(PipelineActions.LoadSelectOrCreatePipeline, {
      category: Category.PIPELINE
    })
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, [])
 
  return (
    <Formik
      initialValues={{
        selectedPipeline: select,
        pipelineRequired: select
      }}
      validationSchema={Yup.object().shape({
        pipelineRequired: Yup.string()
          .trim()
          .required(getString('pipeline.selectOrCreatePipeline.pipelineNameRequired'))
      })}
      enableReinitialize={true}
      onSubmit={() => {
        handleSubmit(select)
        trackEvent(PipelineActions.SelectAPipeline, {
          category: Category.PIPELINE
        })
        closeModal?.()
      }}
      formName="selectCreatePipeline"
    >
      <Form>
        <Text color={Color.BLACK} padding={{ bottom: 8 }} font={{ weight: 'bold', size: 'large' }}>
          {getString('pipeline.selectOrCreatePipeline.setupHeader')}
        </Text>
        <Text font={{ size: 'normal' }} color={Color.BLACK} padding={{ bottom: 40 }}>
          {getString('common.letsGetYouStarted')}
        </Text>
        <Layout.Vertical padding={{ top: 'large', bottom: 'small' }} spacing="small">
          <Text font={{ size: 'normal' }} color={Color.BLACK}>
            {getString('pipeline.selectOrCreatePipeline.selectAPipeline')}
          </Text>
          <PipelineSelect
            onPipelineSelect={value => setSelect(value)}
            selectedPipeline={select}
            defaultSelect={' '}
            className={css.select}
          />
          {/* this FormInput is for Continue button validation use only */}
          <FormInput.Text name="pipelineRequired" className={css.pipelineRequired} />
        </Layout.Vertical>
        <Layout.Horizontal padding={{ top: 'large' }} spacing="medium">
          <Button intent="primary" text={getString('continue')} type="submit" />
          <Button
            text={getString('pipeline.createANewPipeline')}
            alignText={'center'}
            padding={'small'}
            width={200}
            height={33}
            inline
            border={{ width: 1 }}
            onClick={() => {
              openCreatPipeLineModal()
              trackEvent(PipelineActions.CreateAPipeline, {
                category: Category.PIPELINE
              })
            }}
          />
        </Layout.Horizontal>
      </Form>
    </Formik>
  )
}