All files / modules/75-ce/components/COGatewayConfig/steps/AdvancedConfiguration AdvancedConfiguration.tsx

95% Statements 19/20
90% Branches 18/20
66.67% Functions 2/3
95% Lines 19/20

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              4x 4x 4x 4x 4x 4x             4x 4x 4x                     4x 21x   21x           21x 21x 21x   21x 1x               21x                                                                                                             4x  
/*
 * 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, { useState } from 'react'
import { Layout, Toggle, Tabs, Tab } from '@wings-software/uicore'
import { defaultTo as _defaultTo } from 'lodash-es'
import { AdvancedConfigTabs, CONFIG_STEP_IDS, RESOURCES } from '@ce/constants'
import { useStrings } from 'framework/strings'
import { Utils } from '@ce/common/Utils'
import type {
  ASRuleCreationActiveStep,
  FixedScheduleClient,
  GatewayDetails
} from '@ce/components/COCreateGateway/models'
import type { Service } from 'services/lw'
import COGatewayConfigStep from '../../COGatewayConfigStep'
import RuleDependency from './RuleDependency'
import FixedSchedules from './FixedSchedules'
 
interface AdvancedConfigurationProps {
  selectedResource: RESOURCES
  totalStepsCount: number
  gatewayDetails: GatewayDetails
  setGatewayDetails: (details: GatewayDetails) => void
  allServices: Service[]
  activeStepDetails?: ASRuleCreationActiveStep | null
}
 
const AdvancedConfiguration: React.FC<AdvancedConfigurationProps> = props => {
  const { getString } = useStrings()
 
  const [selectedTab, setSelectedTab] = useState<AdvancedConfigTabs>(
    props.activeStepDetails?.count === 4 && props.activeStepDetails?.tabId
      ? (props.activeStepDetails?.tabId as AdvancedConfigTabs)
      : AdvancedConfigTabs.deps
  )
 
  const isK8sSelected = props.selectedResource === RESOURCES.KUBERNETES
  const isEcsSelected = props.selectedResource === RESOURCES.ECS
  const isAwsProvider = Utils.isProviderAws(props.gatewayDetails.provider)
 
  const handleTabChange = (id: string) => {
    setSelectedTab(id as AdvancedConfigTabs)
  }
 
  /* istanbul ignore next */
  const handledFixedSchedulesAddition = (schedules: FixedScheduleClient[]) => {
    props.setGatewayDetails({ ...props.gatewayDetails, schedules })
  }
 
  return (
    <COGatewayConfigStep
      count={props.totalStepsCount}
      title={`${getString('ce.co.autoStoppingRule.configuration.step4.setup')} ${getString(
        'ce.co.autoStoppingRule.configuration.step4.advancedConfiguration'
      )}`}
      subTitle={getString('ce.co.gatewayConfig.advancedConfigDescription')}
      totalStepsCount={props.totalStepsCount}
      id={CONFIG_STEP_IDS[3]}
      dataTooltip={{
        titleId: isAwsProvider ? 'awsSetupAdvancedConfig' : /* istanbul ignore next */ 'azureSetupAdvancedConfig'
      }}
    >
      <Layout.Vertical spacing="medium">
        {(isK8sSelected || isEcsSelected) && (
          <Toggle
            label={'Hide Progress Page'}
            checked={props.gatewayDetails.opts.hide_progress_page}
            onToggle={isToggled => {
              props.setGatewayDetails({
                ...props.gatewayDetails,
                opts: { ...props.gatewayDetails.opts, hide_progress_page: isToggled }
              })
            }}
            data-testid={'progressPageViewToggle'}
          />
        )}
        <Tabs id="advancedConfigTabs" selectedTabId={selectedTab} onChange={handleTabChange}>
          <Tab
            id={AdvancedConfigTabs.deps}
            title={getString('ce.co.autoStoppingRule.configuration.step4.tabs.deps.title')}
            panel={
              <RuleDependency
                gatewayDetails={props.gatewayDetails}
                setGatewayDetails={props.setGatewayDetails}
                allServices={props.allServices}
              />
            }
          />
          <Tab
            id={AdvancedConfigTabs.schedules}
            title={getString('ce.co.autoStoppingRule.configuration.step4.tabs.schedules.title')}
            panel={
              <FixedSchedules
                schedules={_defaultTo(props.gatewayDetails.schedules, [])}
                addSchedules={handledFixedSchedulesAddition}
              />
            }
          />
        </Tabs>
      </Layout.Vertical>
    </COGatewayConfigStep>
  )
}
 
export default AdvancedConfiguration