All files / modules/70-pipeline/components/PipelineStudio/PipelineVariables/Cards StepCard.tsx

92.59% Statements 25/27
66.67% Branches 4/6
83.33% Functions 5/6
92.59% Lines 25/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 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189              26x 26x 26x 26x 26x   26x   26x 26x     26x   26x 26x                             26x                       49x   49x       49x                                                     26x 49x 49x                                                                               26x                     5x   4x                 8x 8x                                     26x 5x                                          
/*
 * 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 { MultiTypeInputType, NestedAccordionPanel, Text } from '@wings-software/uicore'
import cx from 'classnames'
import { FontVariation, Color } from '@harness/design-system'
import { defaultTo } from 'lodash-es'
import type { StepElementConfig } from 'services/cd-ng'
import { StepWidget } from '@pipeline/components/AbstractSteps/StepWidget'
import type { StepType } from '@pipeline/components/PipelineSteps/PipelineStepInterface'
import { StepViewType } from '@pipeline/components/AbstractSteps/Step'
import { VariablesListTable } from '@pipeline/components/VariablesListTable/VariablesListTable'
import type { TemplateStepNode } from 'services/pipeline-ng'
import type { AbstractStepFactory } from '@pipeline/components/AbstractSteps/AbstractStepFactory'
import { useStrings } from 'framework/strings'
import type { PipelineVariablesData } from '../types'
import VariableAccordionSummary from '../VariableAccordionSummary'
import css from '../PipelineVariables.module.scss'
 
export interface StepCardProps {
  step: StepElementConfig | TemplateStepNode
  originalStep: StepElementConfig | TemplateStepNode
  stageIdentifier: string
  metadataMap: PipelineVariablesData['metadataMap']
  onUpdateStep(data: StepElementConfig, path: string): void
  stepPath: string
  readonly?: boolean
  path?: string
  allowableTypes: MultiTypeInputType[]
  stepsFactory: AbstractStepFactory // REQUIRED (pass to addUpdateGraph)
}
 
export function StepCard(props: StepCardProps): React.ReactElement {
  const {
    step,
    originalStep,
    metadataMap,
    stageIdentifier,
    onUpdateStep,
    stepPath,
    readonly,
    path,
    allowableTypes,
    stepsFactory
  } = props
 
  Iif ((originalStep as TemplateStepNode)?.template) {
    return <></>
  }
 
  return (
    <React.Fragment>
      <VariablesListTable
        className={css.variablePaddingL3}
        data={step}
        originalData={originalStep}
        metadataMap={metadataMap}
      />
      <StepWidget<StepElementConfig | TemplateStepNode>
        factory={stepsFactory}
        initialValues={originalStep}
        allowableTypes={allowableTypes}
        type={(originalStep as StepElementConfig).type as StepType}
        stepViewType={StepViewType.InputVariable}
        onUpdate={(data: StepElementConfig) => onUpdateStep(data, stepPath)}
        readonly={readonly}
        customStepProps={{
          stageIdentifier,
          metadataMap,
          variablesData: step,
          path
        }}
      />
    </React.Fragment>
  )
}
 
export function StepCardPanel(props: StepCardProps): React.ReactElement {
  const { getString } = useStrings()
  return (
    <NestedAccordionPanel
      noAutoScroll
      collapseProps={{
        keepChildrenMounted: true
      }}
      isDefaultOpen
      addDomId
      id={`${props.stepPath}.${props.originalStep.identifier}`}
      summary={
        <VariableAccordionSummary>
          <Text font={{ variation: FontVariation.SMALL_SEMI }} color={Color.BLACK}>
            {defaultTo(props.originalStep.name, getString('step'))}
          </Text>
        </VariableAccordionSummary>
      }
      summaryClassName={cx(css.variableBorderBottom, css.accordianSummaryL3)}
      details={<StepCard {...props} />}
    />
  )
}
 
export interface StepGroupCardProps {
  steps: Array<{
    step: StepElementConfig | TemplateStepNode
    originalStep: StepElementConfig | TemplateStepNode
    path: string
  }>
  stageIdentifier: string
  metadataMap: PipelineVariablesData['metadataMap']
  onUpdateStep(data: StepElementConfig | TemplateStepNode, path: string): void
  stepGroupIdentifier: string
  stepGroupName: string
  stepGroupOriginalName: string
  readonly?: boolean
  path?: string
  allowableTypes: MultiTypeInputType[]
  stepsFactory: AbstractStepFactory
}
 
export function StepGroupCard(props: StepGroupCardProps): React.ReactElement {
  const {
    steps,
    metadataMap,
    onUpdateStep,
    stageIdentifier,
    stepGroupName,
    stepGroupOriginalName,
    readonly,
    allowableTypes,
    stepsFactory
  } = props
 
  return (
    <React.Fragment>
      <VariablesListTable
        data={{ name: stepGroupName }}
        originalData={{ name: stepGroupOriginalName }}
        metadataMap={metadataMap}
        className={css.variablePaddingL3}
      />
      {steps.map(row => {
        const { step, originalStep, path } = row
        return (
          <StepCardPanel
            key={path}
            step={step}
            originalStep={originalStep}
            metadataMap={metadataMap}
            stepPath={path}
            readonly={readonly}
            allowableTypes={allowableTypes}
            stageIdentifier={stageIdentifier}
            onUpdateStep={onUpdateStep}
            stepsFactory={stepsFactory}
          />
        )
      })}
    </React.Fragment>
  )
}
 
export function StepGroupCardPanel(props: StepGroupCardProps): React.ReactElement {
  return (
    <NestedAccordionPanel
      noAutoScroll
      isDefaultOpen
      addDomId
      collapseProps={{
        keepChildrenMounted: true
      }}
      id={`${props.path}.StepGroup.${props.stepGroupIdentifier}`}
      summary={
        <VariableAccordionSummary>
          <Text font={{ variation: FontVariation.SMALL_SEMI }} color={Color.BLACK}>
            {props.stepGroupOriginalName}
          </Text>
        </VariableAccordionSummary>
      }
      summaryClassName={cx(css.variableBorderBottom, css.accordianSummaryL2)}
      details={<StepGroupCard {...props} />}
    />
  )
}