All files / modules/70-pipeline/components/PipelineStudio/AdvancedOptions AdvancedOptions.tsx

100% Statements 26/26
80% Branches 8/10
100% Functions 5/5
100% Lines 26/26

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 157 158 159 160 161 162 163 164 165 166              24x 24x                       24x 24x 24x 24x 24x   24x 24x       24x 24x 24x               24x                     24x 3x 3x   3x   2x 1x   2x       3x 3x                   10x                         1x                                                                                                     1x 1x                                                
/*
 * 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 from 'react'
import {
  Button,
  ButtonSize,
  ButtonVariation,
  Card,
  Formik,
  FormInput,
  HarnessDocTooltip,
  Icon,
  Layout,
  Text
} from '@wings-software/uicore'
import { FontVariation, Color } from '@harness/design-system'
import * as Yup from 'yup'
import { isEmpty, unset } from 'lodash-es'
import { Page } from '@common/exports'
import { useStrings } from 'framework/strings'
import type { PipelineInfoConfig } from 'services/cd-ng'
import { usePipelineContext } from '@pipeline/components/PipelineStudio/PipelineContext/PipelineContext'
import {
  FormMultiTypeDurationField,
  getDurationValidationSchema
} from '@common/components/MultiTypeDuration/MultiTypeDuration'
import { useVariablesExpression } from '../PiplineHooks/useVariablesExpression'
import DelegateSelectorPanel from '../../PipelineSteps/AdvancedSteps/DelegateSelectorPanel/DelegateSelectorPanel'
import css from './AdvancedOptions.module.scss'
 
interface AdvancedOptionsProps {
  onApplyChanges: (data: PipelineInfoConfig) => void
  onDiscard: () => void
  pipeline: PipelineInfoConfig
}
 
const stageExecutionOptions = [
  {
    label: 'Yes',
    value: true
  },
  {
    label: 'No',
    value: false
  }
]
 
export function AdvancedOptions({ onApplyChanges, onDiscard, pipeline }: AdvancedOptionsProps): React.ReactElement {
  const { getString } = useStrings()
  const { expressions } = useVariablesExpression()
 
  const onSubmit = React.useCallback(
    (data: PipelineInfoConfig) => {
      if (isEmpty(data.timeout)) {
        unset(data, 'timeout')
      }
      onApplyChanges(data)
    },
    [onApplyChanges]
  )
  const { isReadonly } = usePipelineContext()
  return (
    <Formik<PipelineInfoConfig>
      formName="pipelineAdvancedOptions"
      validationSchema={Yup.object().shape({
        timeout: getDurationValidationSchema({ minimum: '10s' })
      })}
      initialValues={pipeline}
      onSubmit={onSubmit}
    >
      {formikProps => (
        <>
          <Page.Header
            title={
              <Layout.Horizontal spacing="small" flex={{ justifyContent: 'center' }}>
                <Icon name="pipeline-advanced" color={Color.PRIMARY_7} size={24} />
                <Text font={{ variation: FontVariation.H4 }}>{getString('pipeline.advancedOptions')}</Text>
              </Layout.Horizontal>
            }
            toolbar={
              <Layout.Horizontal>
                <Button variation={ButtonVariation.SECONDARY} size={ButtonSize.SMALL} onClick={formikProps.submitForm}>
                  {getString('applyChanges')}
                </Button>
                <Button variation={ButtonVariation.LINK} size={ButtonSize.SMALL} onClick={() => onDiscard()}>
                  {getString('common.discard')}
                </Button>
              </Layout.Horizontal>
            }
          />
          <Page.Body className={css.body}>
            <Layout.Vertical spacing="small" margin={{ bottom: 'large' }}>
              <Text font={{ variation: FontVariation.H5 }} data-tooltip-id="pipelineCreate_timeout">
                {getString('pipeline.pipelineTimeoutSettings')}
                <HarnessDocTooltip useStandAlone={true} tooltipId="pipelineCreate_timeout" />
              </Text>
              <Card>
                <Layout.Vertical spacing="small">
                  <Text
                    color={Color.GREY_600}
                    style={{ marginBottom: 4 }}
                    font={{ variation: FontVariation.SMALL_SEMI }}
                  >
                    {getString('pipeline.pipelineTimeoutHelpText')}
                  </Text>
                  <FormMultiTypeDurationField
                    name="timeout"
                    isOptional
                    style={{ width: 320 }}
                    label={getString('pipelineSteps.timeoutLabel')}
                    multiTypeDurationProps={{ enableConfigureOptions: true, expressions }}
                  />
                </Layout.Vertical>
              </Card>
            </Layout.Vertical>
 
            <Layout.Vertical spacing="small">
              <Text font={{ variation: FontVariation.H5 }} data-tooltip-id="stageExecution_settings">
                {getString('pipeline.stageExecutionSettings')}
                <HarnessDocTooltip useStandAlone={true} tooltipId="stageExecution_settings" />
              </Text>
              <Card>
                <Layout.Vertical spacing="small">
                  <Text
                    color={Color.GREY_600}
                    style={{ marginBottom: 4 }}
                    font={{ variation: FontVariation.SMALL_SEMI }}
                  >
                    {getString('pipeline.stageExecutionsHelperText')}
                  </Text>
                  <FormInput.RadioGroup
                    name="allowStageExecutions"
                    radioGroup={{ inline: true }}
                    items={stageExecutionOptions as any}
                    onChange={e => {
                      const currentValue = e.currentTarget?.value === 'true'
                      formikProps?.setFieldValue('allowStageExecutions', currentValue)
                    }}
                  />
                </Layout.Vertical>
              </Card>
            </Layout.Vertical>
 
            <br></br>
            <Layout.Vertical spacing="small">
              <Text font={{ variation: FontVariation.H5 }} data-tooltip-id="delegateSelector">
                {getString('pipeline.delegate.DelegateSelectorOptional')}
              </Text>
              <Card>
                <Layout.Vertical spacing="small">
                  <DelegateSelectorPanel isReadonly={isReadonly} />
                </Layout.Vertical>
              </Card>
            </Layout.Vertical>
          </Page.Body>
        </>
      )}
    </Formik>
  )
}