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

75% Statements 12/16
66.67% Branches 4/6
50% Functions 2/4
75% Lines 12/16

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              4x 4x     4x 4x               4x 19x 19x   19x 13x     19x               19x                                                 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, { useEffect, useState } from 'react'
import { Button, Layout, Text } from '@wings-software/uicore'
import type { GatewayDetails } from '@ce/components/COCreateGateway/models'
import type { Service, ServiceDep } from 'services/lw'
import { useStrings } from 'framework/strings'
import CORuleDendencySelector from '../../CORuleDependencySelector'
 
interface RuleDependencyProps {
  gatewayDetails: GatewayDetails
  setGatewayDetails: (details: GatewayDetails) => void
  allServices: Service[]
}
 
const RuleDependency: React.FC<RuleDependencyProps> = props => {
  const { getString } = useStrings()
  const [serviceDependencies, setServiceDependencies] = useState<ServiceDep[]>(props.gatewayDetails.deps || [])
 
  useEffect(() => {
    props.setGatewayDetails({ ...props.gatewayDetails, deps: serviceDependencies })
  }, [serviceDependencies])
 
  const addDependency = () => {
    serviceDependencies.push({
      delay_secs: 5 // eslint-disable-line
    })
    const deps = [...serviceDependencies]
    setServiceDependencies(deps)
  }
 
  return (
    <Layout.Vertical spacing="medium">
      <Text>{getString('ce.co.autoStoppingRule.configuration.step4.tabs.deps.description')}</Text>
      {serviceDependencies && serviceDependencies.length ? (
        <CORuleDendencySelector
          deps={serviceDependencies}
          setDeps={setServiceDependencies}
          service_id={props.gatewayDetails.id}
          allServices={props.allServices}
        ></CORuleDendencySelector>
      ) : null}
      <Button
        intent="none"
        onClick={() => {
          addDependency()
        }}
        icon={'plus'}
        style={{ maxWidth: '180px' }}
      >
        {' Add dependency'}
      </Button>
    </Layout.Vertical>
  )
}
 
export default RuleDependency