All files / modules/75-cf/components/LanguageSelection LanguageSelection.tsx

100% Statements 30/30
100% Branches 12/12
100% Functions 7/7
100% Lines 29/29

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              2x 2x 2x       2x 2x 2x 2x 2x 2x 2x 2x 2x   2x 2x 2x     2x 2x 2x 2x                               2x                                                                                                 30x             2x 4x   4x   32x 32x 32x             1x 1x                              
/*
 * 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 { Button, Layout, Text } from '@wings-software/uicore'
import React, { useState } from 'react'
import cx from 'classnames'
import type { StringsMap } from 'stringTypes'
import type { StringKeys } from 'framework/strings'
 
import android from './icons/android.svg'
import dotnet from './icons/dotnet.svg'
import golang from './icons/golang.svg'
import ios from './icons/ios.svg'
import java from './icons/java.svg'
import javascript from './icons/javascript.svg'
import nodejs from './icons/nodejs.svg'
import python from './icons/python.svg'
import css from './LanguageSelection.module.scss'
 
export enum PlatformEntryType {
  CLIENT = 'client',
  SERVER = 'server'
}
 
export enum CodeSetupStringType {
  HEADER = 'HEADER',
  CODE = 'CODE',
  TEXT = 'TEXT'
}
 
export interface CodeSetupDocEntry {
  stringId: keyof StringsMap
  stringType: CodeSetupStringType
}
 
export interface PlatformEntry {
  name: string
  icon: string
  type: PlatformEntryType
  readmeStringId: StringKeys
  disabled?: boolean
}
 
export const SupportPlatforms = [
  {
    name: 'NodeJS',
    icon: nodejs,
    type: PlatformEntryType.SERVER,
    readmeStringId: 'cf.onboarding.readme.nodejs'
  },
  {
    name: 'Java',
    icon: java,
    type: PlatformEntryType.SERVER,
    readmeStringId: 'cf.onboarding.readme.java'
  },
  {
    name: 'Golang',
    icon: golang,
    type: PlatformEntryType.SERVER,
    readmeStringId: 'cf.onboarding.readme.golang'
  },
  {
    name: '.NET',
    icon: dotnet,
    type: PlatformEntryType.SERVER,
    readmeStringId: 'cf.onboarding.readme.dotnet'
  },
  {
    name: 'Python',
    icon: python,
    type: PlatformEntryType.SERVER,
    readmeStringId: 'cf.onboarding.readme.python'
  },
  {
    name: 'JavaScript',
    icon: javascript,
    type: PlatformEntryType.CLIENT,
    readmeStringId: 'cf.onboarding.readme.javascript'
  },
  {
    name: 'Android',
    icon: android,
    type: PlatformEntryType.CLIENT,
    readmeStringId: 'cf.onboarding.readme.android'
  },
  {
    name: 'iOS',
    icon: ios,
    type: PlatformEntryType.CLIENT,
    readmeStringId: 'cf.onboarding.readme.ios'
  }
].sort((a, b) => (a.name.toLowerCase() > b.name.toLowerCase() ? 1 : -1)) as Array<PlatformEntry>
 
export interface LanguageSelectionProps {
  selected: PlatformEntry | undefined
  onSelect: (entry: PlatformEntry) => void
}
 
export const LanguageSelection: React.FC<LanguageSelectionProps> = ({ selected, onSelect }) => {
  const [selectedEntry, setSelectedEntry] = useState<PlatformEntry | undefined>(selected)
 
  return (
    <ul className={css.list}>
      {SupportPlatforms.filter(entry => !entry.disabled).map(entry => {
        const { name, icon } = entry
        return (
          <li key={name} className={css.item}>
            <Layout.Vertical spacing="small">
              <Button
                noStyling
                className={cx(css.button, selectedEntry?.name === name && css.selected)}
                onClick={() => {
                  setSelectedEntry(entry)
                  onSelect(entry)
                }}
              >
                <img src={icon} alt={name} width={35} height={35} />
              </Button>
              <Text inline style={{ fontWeight: 500, color: '#555770', fontSize: '12px', textAlign: 'center' }}>
                {name}
              </Text>
            </Layout.Vertical>
          </li>
        )
      })}
    </ul>
  )
}