All files / modules/75-ce/components/RecommendationDetails RecommendationTabs.tsx

58.33% Statements 14/24
50% Branches 3/6
33.33% Functions 1/3
58.33% Lines 14/24

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              3x 3x 3x 3x   3x 3x 3x 3x   3x                             3x             8x 8x   8x                                                                                                                   3x  
/*
 * 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, Layout, Text } from '@wings-software/uicore'
import { Color, FontVariation } from '@harness/design-system'
import cx from 'classnames'
 
import { useStrings } from 'framework/strings'
import { useTelemetry } from '@common/hooks/useTelemetry'
import { USER_JOURNEY_EVENTS } from '@ce/TrackingEventsConstants'
import { RecommendationType } from './constants'
 
import css from './RecommendationDetails.module.scss'
 
interface RecommendationTabsProps {
  selectedRecommendation: RecommendationType
  setSelectedRecommendation: React.Dispatch<React.SetStateAction<RecommendationType>>
  setCPUReqVal: React.Dispatch<React.SetStateAction<number>>
  setMemReqVal: React.Dispatch<React.SetStateAction<number>>
  setMemLimitVal: React.Dispatch<React.SetStateAction<number>>
  costOptimizedSavings: number
  performanceOptimizedSavings: number
  currentSavings: number
  isPerfOptimizedCustomized: boolean
  isCostOptimizedCustomized: boolean
}
 
const RecommendationTabs: React.FC<RecommendationTabsProps> = ({
  selectedRecommendation,
  setSelectedRecommendation,
  setCPUReqVal,
  setMemReqVal,
  setMemLimitVal
}) => {
  const { getString } = useStrings()
  const { trackEvent } = useTelemetry()
 
  return (
    <Container padding="small" className={css.recommendationTypeContainer}>
      <Layout.Horizontal className={css.recommendations}>
        <Layout.Horizontal
          className={cx(css.recommendationTypeText, {
            [css.selectedTab]: selectedRecommendation === RecommendationType.CostOptimized
          })}
          spacing="xsmall"
          onClick={() => {
            trackEvent(USER_JOURNEY_EVENTS.RECOMMENDATION_COST_PERFORMANCE_OPTIMISED_CLICK, {
              type: RecommendationType.CostOptimized
            })
            setCPUReqVal(50)
            setMemReqVal(50)
            setMemLimitVal(95)
            setSelectedRecommendation(RecommendationType.CostOptimized)
          }}
        >
          <Text
            font={{ variation: FontVariation.SMALL_BOLD, align: 'center' }}
            color={selectedRecommendation === RecommendationType.CostOptimized ? Color.WHITE : Color.PRIMARY_9}
            className={cx({ [css.selectedTab]: selectedRecommendation === RecommendationType.CostOptimized })}
            tooltipProps={{ dataTooltipId: 'costOptimized' }}
          >
            {getString('ce.recommendation.detailsPage.costOptimized')}
          </Text>
        </Layout.Horizontal>
 
        <Layout.Horizontal
          className={cx(css.recommendationTypeText, {
            [css.selectedTab]: selectedRecommendation === RecommendationType.PerformanceOptimized
          })}
          color={selectedRecommendation === RecommendationType.PerformanceOptimized ? Color.WHITE : Color.PRIMARY_9}
          spacing="xsmall"
          onClick={() => {
            trackEvent(USER_JOURNEY_EVENTS.RECOMMENDATION_COST_PERFORMANCE_OPTIMISED_CLICK, {
              type: RecommendationType.PerformanceOptimized
            })
            setCPUReqVal(95)
            setMemReqVal(95)
            setMemLimitVal(95)
            setSelectedRecommendation(RecommendationType.PerformanceOptimized)
          }}
        >
          <Text
            font={{ variation: FontVariation.SMALL_BOLD, align: 'center' }}
            color={selectedRecommendation === RecommendationType.PerformanceOptimized ? Color.WHITE : Color.PRIMARY_9}
            className={cx({ [css.selectedTab]: selectedRecommendation === RecommendationType.PerformanceOptimized })}
            tooltipProps={{ dataTooltipId: 'performanceOptimized' }}
          >
            {getString('ce.recommendation.detailsPage.performanceOptimized')}
          </Text>
        </Layout.Horizontal>
      </Layout.Horizontal>
    </Container>
  )
}
 
export default RecommendationTabs