All files / modules/75-cf/pages/onboarding/views CreateAFlagView.tsx

83.33% Statements 10/12
50% Branches 2/4
66.67% Functions 2/3
81.82% Lines 9/11

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              1x 1x 1x 1x   1x                 1x 5x   5x                                               1x                                                        
/*
 * 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 { Container, TextInput, Heading, Layout, Text } from '@wings-software/uicore'
import { Color } from '@harness/design-system'
import { String, useStrings } from 'framework/strings'
import type { FeatureFlagRequestRequestBody } from 'services/cf'
import { CreateAFlagInfoView } from './CreateAFlagInfoView'
 
export interface CreateAFlagViewProps {
  setFlagName: React.Dispatch<React.SetStateAction<string>>
  flagInfo: FeatureFlagRequestRequestBody
  isCreated: boolean
  goNext: () => void
}
 
export const CreateAFlagView: React.FC<CreateAFlagViewProps> = ({ flagInfo, setFlagName, isCreated, goNext }) => {
  const { getString } = useStrings()
 
  return (
    <Container height="100%">
      <Container padding="xlarge" width="calc(100% - 765px)" height="calc(100vh - 140px)" style={{ overflow: 'auto' }}>
        <Heading
          level={2}
          style={{
            fontWeight: 600,
            fontSize: '20px',
            lineHeight: '28px',
            color: '#22222A'
          }}
          padding={{ bottom: 'xxlarge' }}
        >
          {getString('cf.onboarding.letsStart')}
        </Heading>
        <Layout.Vertical width={400} spacing="xsmall">
          <Text color={Color.BLACK} font={{ weight: 'semi-bold' }}>
            {getString('cf.onboarding.inputLabel')}
          </Text>
          <TextInput
            value={flagInfo.name}
            autoFocus
            disabled={isCreated}
            onChange={e => {
              setFlagName((e.currentTarget as HTMLInputElement).value.trim())
            }}
            onKeyUp={event => {
              if (event.keyCode === 13) {
                goNext()
              }
            }}
          />
        </Layout.Vertical>
        {isCreated && (
          <Text
            color={Color.BLACK}
            rightIcon="tick"
            margin={{ top: 'xxlarge' }}
            rightIconProps={{ color: Color.GREEN_500 }}
          >
            <String
              stringID="cf.onboarding.successLabel"
              vars={{ name: flagInfo.name, identifier: flagInfo.identifier }}
              useRichText
            />
          </Text>
        )}
      </Container>
      <CreateAFlagInfoView />
    </Container>
  )
}