All files / modules/70-pipeline/components/ManifestSelection/ManifestWizard ManifestWizard.tsx

90.91% Statements 20/22
83.33% Branches 25/30
100% Functions 5/5
90.91% Lines 20/22

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              101x 101x   101x 101x     101x 101x 101x   101x                                                   101x                                 20x 20x 2x           20x 20x 20x 10x                 10x     20x                                 1x           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 { Text, Icon, StepWizard, StepProps, MultiTypeInputType } from '@wings-software/uicore'
import type { IconProps } from '@wings-software/uicore/dist/icons/Icon'
import { Color } from '@harness/design-system'
import { useStrings } from 'framework/strings'
import type { ConnectorConfigDTO } from 'services/cd-ng'
import type { ConnectorRefLabelType } from '@pipeline/components/ArtifactsSelection/ArtifactInterface'
import { ManifestRepoTypes } from '../ManifestWizardSteps/ManifestRepoTypes'
import ManifestStore from '../ManifestWizardSteps/ManifestStore'
import { manifestTypeLabels } from '../Manifesthelper'
import type { ManifestStepInitData, ManifestStores, ManifestTypes } from '../ManifestInterface'
import css from './ManifestWizard.module.scss'
 
interface StepChangeData<SharedObject> {
  prevStep?: number
  nextStep?: number
  prevStepData: SharedObject
}
 
interface ManifestWizardStepsProps {
  handleConnectorViewChange: (isConnectorView: boolean) => void
  handleStoreChange: (store?: ManifestStores) => void
  initialValues: ManifestStepInitData
  types: Array<ManifestTypes>
  manifestStoreTypes: Array<ManifestStores>
  labels: ConnectorRefLabelType
  selectedManifest: ManifestTypes | null
  newConnectorView: boolean
  expressions: string[]
  allowableTypes: MultiTypeInputType[]
  newConnectorSteps?: any
  lastSteps?: Array<React.ReactElement<StepProps<ConnectorConfigDTO>>> | null
  changeManifestType: (data: ManifestTypes | null) => void
  iconsProps: IconProps
  isReadonly: boolean
}
 
export function ManifestWizard({
  handleConnectorViewChange,
  handleStoreChange,
  initialValues,
  types,
  expressions,
  allowableTypes,
  manifestStoreTypes,
  labels,
  selectedManifest,
  newConnectorView,
  newConnectorSteps,
  lastSteps,
  changeManifestType,
  iconsProps,
  isReadonly
}: ManifestWizardStepsProps): React.ReactElement {
  const { getString } = useStrings()
  const onStepChange = (arg: StepChangeData<any>): void => {
    Iif (arg?.prevStep && arg?.nextStep && arg.prevStep > arg.nextStep && arg.nextStep <= 2) {
      handleConnectorViewChange(false)
      handleStoreChange()
    }
  }
 
  const renderSubtitle = (): JSX.Element => {
    const stringId = selectedManifest && getString(manifestTypeLabels[selectedManifest])
    if (selectedManifest) {
      return (
        <div className={css.subtitle} style={{ display: 'flex' }}>
          <Icon {...iconsProps} size={26} />
          <Text style={{ alignSelf: 'center', marginLeft: 'var(--spacing-small)' }} color={Color.WHITE}>
            {stringId}
          </Text>
        </div>
      )
    }
    return <></>
  }
 
  return (
    <StepWizard className={css.manifestWizard} subtitle={renderSubtitle()} onStepChange={onStepChange}>
      <ManifestRepoTypes
        manifestTypes={types}
        name={getString('pipeline.manifestType.manifestRepoType')}
        stepName={labels.firstStepName}
        selectedManifest={selectedManifest}
        changeManifestType={changeManifestType}
        initialValues={initialValues}
      />
      <ManifestStore
        name={getString('pipeline.manifestType.manifestSource')}
        stepName={labels.secondStepName}
        expressions={expressions}
        allowableTypes={allowableTypes}
        isReadonly={isReadonly}
        manifestStoreTypes={manifestStoreTypes}
        handleConnectorViewChange={() => handleConnectorViewChange(true)}
        handleStoreChange={handleStoreChange}
        initialValues={initialValues}
      />
      {newConnectorView ? newConnectorSteps : null}
 
      {lastSteps?.length ? lastSteps?.map(step => step) : null}
    </StepWizard>
  )
}