All files / modules/75-ce/components/COGatewayAccess CustomDomainMapping.tsx

100% Statements 25/25
100% Branches 0/0
100% Functions 4/4
100% Lines 25/25

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              6x 6x 6x   6x   6x                     6x               8x   8x                             1x 1x 1x 1x       1x 1x                 1x 1x 1x           1x                 1x 1x 1x 1x       1x 1x                   6x  
/*
 * 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, FormInput, Heading, Layout, SelectOption, Text } from '@wings-software/uicore'
import { Radio } from '@blueprintjs/core'
import type { FormikProps } from 'formik'
import { useStrings } from 'framework/strings'
import type { GatewayDetails } from '../COCreateGateway/models'
import css from './COGatewayAccess.module.scss'
 
interface CustomDomainMappingProps {
  formikProps: FormikProps<any>
  gatewayDetails: GatewayDetails
  setGatewayDetails: (details: GatewayDetails) => void
  hostedZonesList: SelectOption[]
  setDNSProvider: (val: string) => void
  setHelpTextSections: (s: string[]) => void
}
 
const CustomDomainMapping: React.FC<CustomDomainMappingProps> = ({
  formikProps,
  gatewayDetails,
  setGatewayDetails,
  hostedZonesList,
  setDNSProvider,
  setHelpTextSections
}) => {
  const { getString } = useStrings()
 
  return (
    <Container className={css.dnsLinkContainer}>
      <Layout.Vertical spacing="medium">
        <Heading level={3} font={{ weight: 'bold' }}>
          {getString('ce.co.autoStoppingRule.setupAccess.customDomain.mappingHeader')}
        </Heading>
        <Text font={{ weight: 'light' }} color="Color.GREY_500" className={css.mapDomainHelperText}>
          {getString('ce.co.autoStoppingRule.setupAccess.customDomain.mappingSubHeader')}
        </Text>
        <Layout.Vertical>
          <Layout.Horizontal flex={{ alignItems: 'center', justifyContent: 'flex-start' }}>
            <Radio
              value="route53"
              checked={formikProps.values.dnsProvider === 'route53'}
              onChange={e => {
                formikProps.setFieldValue('dnsProvider', e.currentTarget.value)
                setDNSProvider(e.currentTarget.value)
                const updatedGatewayDetails = { ...gatewayDetails }
                updatedGatewayDetails.routing = {
                  ...gatewayDetails.routing,
                  custom_domain_providers: { route53: {} }
                }
                setGatewayDetails(updatedGatewayDetails)
                setHelpTextSections(['usingCustomDomain'])
              }}
              name={'route53RadioBtn'}
            />
            <FormInput.Select
              name="route53Account"
              placeholder={getString('ce.co.accessPoint.select.route53')}
              items={hostedZonesList}
              onChange={e => {
                formikProps.setFieldValue('route53Account', e.value)
                const updatedGatewayDetails = { ...gatewayDetails }
                updatedGatewayDetails.routing = {
                  ...gatewayDetails.routing,
                  custom_domain_providers: {
                    route53: { hosted_zone_id: e.value as string }
                  }
                }
                setGatewayDetails(updatedGatewayDetails)
              }}
            />
          </Layout.Horizontal>
          <Radio
            value="others"
            checked={formikProps.values.dnsProvider === 'others'}
            label="Others"
            onChange={e => {
              formikProps.setFieldValue('dnsProvider', e.currentTarget.value)
              setDNSProvider(e.currentTarget.value)
              const updatedGatewayDetails = { ...gatewayDetails }
              updatedGatewayDetails.routing = {
                ...gatewayDetails.routing,
                custom_domain_providers: { others: {} }
              }
              setGatewayDetails(updatedGatewayDetails)
              setHelpTextSections(['usingCustomDomain', 'dns-others'])
            }}
            data-testid={'otherDnsProvider'}
          />
        </Layout.Vertical>
      </Layout.Vertical>
    </Container>
  )
}
 
export default CustomDomainMapping