All files / modules/75-ci/components/PipelineSteps/CIStep ArtifactStepCommon.tsx

100% Statements 9/9
100% Branches 88/88
100% Functions 1/1
100% Lines 8/8

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              102x 102x 102x   102x       102x 102x           102x               15x                                                                                            
/*
 * 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 { get } from 'lodash-es'
import { getMultiTypeFromValue, MultiTypeInputType } from '@wings-software/uicore'
import type { ConnectorInfoDTO } from 'services/cd-ng'
import { Connectors } from '@connectors/constants'
import type { ECRStepProps } from '../ECRStep/ECRStep'
import type { GCRStepProps } from '../GCRStep/GCRStep'
import type { DockerHubStepProps } from '../DockerHubStep/DockerHubStep'
import { shouldRenderRunTimeInputView } from './StepUtils'
import { CIStepOptionalConfig } from './CIStepOptionalConfig'
 
interface ArtifactStepCommonProps extends Omit<ECRStepProps | GCRStepProps | DockerHubStepProps, 'initialValues'> {
  artifactConnectorType: ConnectorInfoDTO['type']
}
 
export const ArtifactStepCommon: React.FC<ArtifactStepCommonProps> = ({
  template,
  path,
  readonly,
  stepViewType,
  formik,
  artifactConnectorType
}) => {
  return (
    <CIStepOptionalConfig
      stepViewType={stepViewType}
      readonly={readonly}
      enableFields={{
        ...(shouldRenderRunTimeInputView(template?.spec?.tags) && {
          'spec.tags': {}
        }),
        ...(getMultiTypeFromValue(template?.spec?.optimize) === MultiTypeInputType.RUNTIME && {
          'spec.optimize': {}
        }),
        ...(getMultiTypeFromValue(template?.spec?.dockerfile) === MultiTypeInputType.RUNTIME && {
          'spec.dockerfile': {}
        }),
        ...(getMultiTypeFromValue(template?.spec?.context) === MultiTypeInputType.RUNTIME && {
          'spec.context': {}
        }),
        ...(shouldRenderRunTimeInputView(template?.spec?.labels) && {
          'spec.labels': {}
        }),
        ...(shouldRenderRunTimeInputView(template?.spec?.buildArgs) && {
          'spec.buildArgs': {}
        }),
        ...(getMultiTypeFromValue(template?.spec?.target) === MultiTypeInputType.RUNTIME && {
          'spec.target': {}
        }),
        ...(getMultiTypeFromValue(
          get(
            template?.spec,
            [Connectors.AWS, Connectors.GCP].includes(artifactConnectorType) ? 'remoteCacheImage' : ''
          )
        ) === MultiTypeInputType.RUNTIME && {
          'spec.remoteCacheImage': {}
        }),
        ...(getMultiTypeFromValue(
          get(template?.spec, artifactConnectorType === Connectors.DOCKER ? 'remoteCacheRepo' : '')
        ) === MultiTypeInputType.RUNTIME && {
          'spec.remoteCacheRepo': {}
        })
      }}
      path={path || ''}
      formik={formik}
      isInputSetView={true}
    />
  )
}