All files / modules/10-common/modals/DefaultVersion/views DefaultExperienceForm.tsx

100% Statements 21/21
100% Branches 4/4
100% Functions 6/6
100% Lines 21/21

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              2x 2x                       2x 2x 2x   2x                 2x 2x 2x 2x 2x 2x                         2x                                                                                 2x 6x 6x                         12x                                     36x         2x 10x                 2x  
/*
 * 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 {
  Layout,
  Heading,
  Text,
  Container,
  Button,
  Tag,
  Icon,
  CardSelect,
  CardSelectType,
  ButtonVariation
} from '@wings-software/uicore'
import { Color } from '@harness/design-system'
import { Experiences } from '@common/constants/Utils'
import { useStrings } from 'framework/strings'
import type { StringsMap } from 'stringTypes'
import css from '../DefaultExperience.module.scss'
 
interface Props {
  onSubmit?: () => void
  currentExperience: Experiences
  setCurrentExperience: (currentExperience: Experiences) => void
  loading: boolean
}
 
enum Modules {
  CD = 'cd-main',
  CI = 'ci-main',
  CF = 'cf-main',
  CE = 'ce-main',
  CV = 'cv-main'
}
 
interface Data {
  type: Experiences
  title: string
  description: string
  modules: {
    name: Modules
    size: number
  }[]
}
 
const data: Data[] = [
  {
    type: Experiences.CG,
    title: 'common.harnessFirstGeneration',
    description: 'common.harnessFirstGenerationDescription',
    modules: [
      {
        name: Modules.CD,
        size: 25
      },
      {
        name: Modules.CE,
        size: 30
      }
    ]
  },
  {
    type: Experiences.NG,
    title: 'common.harnessNextGeneration',
    description: 'common.harnessNextGenerationDescription',
    modules: [
      {
        name: Modules.CD,
        size: 25
      },
      {
        name: Modules.CI,
        size: 25
      },
      {
        name: Modules.CF,
        size: 25
      },
      {
        name: Modules.CE,
        size: 30
      }
    ]
  }
]
 
const DefaultExperienceForm: React.FC<Props> = ({ onSubmit, currentExperience, setCurrentExperience, loading }) => {
  const { getString } = useStrings()
  return (
    <Layout.Vertical padding={{ left: 'huge', right: 'huge' }}>
      <Text color={Color.GREY_900} font={{ size: 'medium', weight: 'semi-bold' }} margin={{ bottom: 'medium' }}>
        {getString('common.defaultExperience')}
      </Text>
      <Text color={Color.GREY_700} font={{ size: 'normal' }} margin={{ bottom: 'xxxlarge' }}>
        {getString('common.selectDefaultExperience')}
      </Text>
      <CardSelect
        data={data}
        className={css.cardContainer}
        type={CardSelectType.CardView}
        renderItem={item => (
          <Container>
            <Layout.Horizontal spacing="small">
              <Heading level={2} color={Color.GREY_900} font={{ weight: 'semi-bold' }} margin={{ bottom: 'medium' }}>
                {getString(item.title as keyof StringsMap)}
              </Heading>
              {item.type === Experiences.NG && (
                <Tag round className={css.tag}>
                  {getString('common.new')}
                </Tag>
              )}
            </Layout.Horizontal>
            <Text color={Color.GREY_900} font={{ size: 'small' }} className={css.cardText} margin={{ bottom: 'large' }}>
              {getString(item.description as keyof StringsMap)}
            </Text>
            <Text color={Color.GREY_700} font={{ size: 'small', weight: 'bold' }} margin={{ bottom: 'medium' }}>
              {getString('common.supportedModals')}
            </Text>
            <Layout.Horizontal spacing="xlarge" flex={{ alignItems: 'center', justifyContent: 'flex-start' }}>
              {item.modules.map(module => (
                <Icon name={module.name} size={module.size} key={module.name} />
              ))}
            </Layout.Horizontal>
          </Container>
        )}
        onChange={card => setCurrentExperience(card.type)}
        selected={data.find(item => item.type === currentExperience)}
      />
      <Container padding={{ top: 'huge', bottom: 'xxlarge' }}>
        <Button text={getString('save')} variation={ButtonVariation.PRIMARY} onClick={onSubmit} disabled={loading} />
      </Container>
    </Layout.Vertical>
  )
}
 
export default DefaultExperienceForm