All files / modules/75-ci/components/PipelineSteps/RunStep RunStepInputSet.tsx

96.43% Statements 27/28
98.89% Branches 89/90
50% Functions 1/2
96.3% Lines 26/27

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 167 168 169              98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x   98x 98x 98x 98x 98x   98x               8x 8x   8x   8x   8x                                                                                                                                                                                                                                                       98x 98x  
/*
 * 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 { connect } from 'formik'
import { Text, getMultiTypeFromValue, MultiTypeInputType, FormikForm, Container } from '@wings-software/uicore'
import { Color } from '@harness/design-system'
import { isEmpty, startCase } from 'lodash-es'
import cx from 'classnames'
import { useStrings } from 'framework/strings'
import { ShellScriptMonacoField } from '@common/components/ShellScriptMonaco/ShellScriptMonaco'
import MultiTypeFieldSelector from '@common/components/MultiTypeFieldSelector/MultiTypeFieldSelector'
import { FormMultiTypeCheckboxField } from '@common/components/MultiTypeCheckbox/MultiTypeCheckbox'
import { useVariablesExpression } from '@pipeline/components/PipelineStudio/PiplineHooks/useVariablesExpression'
import StepCommonFieldsInputSet from '@ci/components/PipelineSteps/StepCommonFields/StepCommonFieldsInputSet'
import { StepViewType } from '@pipeline/components/AbstractSteps/Step'
import type { RunStepProps } from './RunStep'
import { CIStep } from '../CIStep/CIStep'
import { CIStepOptionalConfig, renderMultiTypeListInputSet } from '../CIStep/CIStepOptionalConfig'
import { ConnectorRefWithImage } from '../CIStep/ConnectorRefWithImage'
import { AllMultiTypeInputTypesForInputSet, shouldRenderRunTimeInputView } from '../CIStep/StepUtils'
import css from '@pipeline/components/PipelineSteps/Steps/Steps.module.scss'
 
export const RunStepInputSetBasic: React.FC<RunStepProps> = ({
  template,
  path,
  readonly,
  stepViewType,
  allowableTypes,
  formik
}) => {
  const { getString } = useStrings()
  const prefix = isEmpty(path) ? '' : `${path}.`
 
  const { expressions } = useVariablesExpression()
 
  const stepCss = stepViewType === StepViewType.DeploymentForm ? css.sm : css.lg
 
  return (
    <FormikForm className={css.removeBpPopoverWrapperTopMargin}>
      <CIStep
        readonly={readonly}
        stepViewType={stepViewType}
        enableFields={{
          ...(getMultiTypeFromValue(template?.description) === MultiTypeInputType.RUNTIME && { description: {} })
        }}
        path={path || ''}
      />
      <ConnectorRefWithImage
        readonly={readonly}
        showConnectorRef={getMultiTypeFromValue(template?.spec?.connectorRef) === MultiTypeInputType.RUNTIME}
        showImage={getMultiTypeFromValue(template?.spec?.image) === MultiTypeInputType.RUNTIME}
        stepViewType={stepViewType}
        path={path || ''}
      />
      {getMultiTypeFromValue(template?.spec?.command) === MultiTypeInputType.RUNTIME && (
        <div className={cx(css.fieldsGroup, css.withoutSpacing, css.topPadding3, css.bottomPadding3, stepCss)}>
          <MultiTypeFieldSelector
            name={`${prefix}spec.command`}
            label={
              <Text
                color={Color.GREY_800}
                font={{ size: 'normal', weight: 'bold' }}
                className={css.inpLabel}
                style={{ display: 'flex', alignItems: 'center' }}
                tooltipProps={{ dataTooltipId: 'runCommand' }}
              >
                {getString('commandLabel')}
              </Text>
            }
            defaultValueToReset=""
            skipRenderValueInExpressionLabel
            allowedTypes={allowableTypes}
            expressionRender={() => {
              return (
                <ShellScriptMonacoField
                  title={getString('commandLabel')}
                  name={`${prefix}spec.command`}
                  scriptType="Bash"
                  expressions={expressions}
                  disabled={readonly}
                />
              )
            }}
            style={{ flexGrow: 1, marginBottom: 0 }}
            disableTypeSelection={readonly}
          >
            <ShellScriptMonacoField
              title={getString('commandLabel')}
              name={`${prefix}spec.command`}
              scriptType="Bash"
              disabled={readonly}
              expressions={expressions}
            />
          </MultiTypeFieldSelector>
        </div>
      )}
      {getMultiTypeFromValue(template?.spec?.privileged) === MultiTypeInputType.RUNTIME && (
        <div className={cx(css.formGroup, css.sm, css.topMargin4, css.bottomMargin5)}>
          <FormMultiTypeCheckboxField
            name={`${prefix}spec.privileged`}
            label={getString('pipeline.buildInfra.privileged').concat(
              ` (${startCase(getString('common.optionalLabel'))})`
            )}
            disabled={readonly}
            multiTypeTextbox={{
              expressions,
              allowableTypes
            }}
            tooltipProps={{ dataTooltipId: 'privileged' }}
            setToFalseWhenEmpty={true}
          />
        </div>
      )}
      {shouldRenderRunTimeInputView(template?.spec?.reports?.spec?.paths) && (
        <Container className={cx(css.formGroup, stepCss, css.bottomMargin5)}>
          {renderMultiTypeListInputSet({
            name: `${prefix}spec.reports.spec.paths`,
            tooltipId: 'reportPaths',
            labelKey: 'pipelineSteps.reportPathsLabel',
            allowedTypes: AllMultiTypeInputTypesForInputSet,
            placeholderKey: 'pipelineSteps.reportPathsPlaceholder',
            expressions,
            getString,
            readonly,
            formik
          })}
        </Container>
      )}
      {shouldRenderRunTimeInputView(template?.spec?.outputVariables) && (
        <Container className={cx(css.formGroup, stepCss, css.bottomMargin5)}>
          {renderMultiTypeListInputSet({
            name: `${prefix}spec.outputVariables`,
            tooltipId: 'outputVariables',
            labelKey: 'pipelineSteps.outputVariablesLabel',
            allowedTypes: AllMultiTypeInputTypesForInputSet,
            expressions,
            getString,
            readonly,
            formik,
            withObjectStructure: true,
            keyName: 'name'
          })}
        </Container>
      )}
      <CIStepOptionalConfig
        stepViewType={stepViewType}
        readonly={readonly}
        enableFields={{
          ...(shouldRenderRunTimeInputView(template?.spec?.envVariables) && {
            'spec.envVariables': { tooltipId: 'environmentVariables' }
          })
        }}
        path={path || ''}
        formik={formik}
        isInputSetView={true}
      />
      <StepCommonFieldsInputSet path={path} readonly={readonly} template={template} stepViewType={stepViewType} />
    </FormikForm>
  )
}
 
const RunStepInputSet = connect(RunStepInputSetBasic)
export { RunStepInputSet }