All files / modules/75-ce/components/CESideNav CESideNav.tsx

90.57% Statements 48/53
72.73% Branches 8/11
76.92% Functions 10/13
90.38% Lines 47/52

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 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194              1x 1x 1x 1x 1x 1x 1x   1x 1x 1x 1x 1x 1x 1x 1x 1x 1x   1x             1x 4x 4x   4x 4x   4x 4x                                 1x 8x 8x 8x   8x 1x 1x 1x         1x     8x                             1x                           12x           1x                   1x       1x               1x 4x 4x 4x 4x 4x   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 { useParams } from 'react-router-dom'
import { Button, Checkbox, Layout, Popover, Text } from '@wings-software/uicore'
import { Tabs, Tab } from '@blueprintjs/core'
import { Color } from '@harness/design-system'
import { useTelemetry } from '@common/hooks/useTelemetry'
import routes from '@common/RouteDefinitions'
import type { PipelinePathProps } from '@common/interfaces/RouteInterfaces'
import { SidebarLink } from '@common/navigation/SideNav/SideNav'
import { useAppStore } from 'framework/AppStore/AppStoreContext'
import { useStrings } from 'framework/strings'
import { returnLaunchUrl } from '@common/utils/routeUtils'
import NavExpandable from '@common/navigation/NavExpandable/NavExpandable'
import { LaunchButton } from '@common/components/LaunchButton/LaunchButton'
import { USER_JOURNEY_EVENTS } from '@ce/TrackingEventsConstants'
import { useFeatureFlag } from '@common/hooks/useFeatureFlag'
import { FeatureFlag } from '@common/featureFlags'
import css from './CESideNav.module.scss'
 
const feedbackOptions = [
  'I am a CD/CI user',
  'To organise perspectives better',
  'For access management',
  'Does not matter, account level works for me'
]
 
export default function CESideNav(): React.ReactElement {
  const { currentUserInfo } = useAppStore()
  const { identifyUser } = useTelemetry()
 
  useEffect(() => {
    identifyUser(currentUserInfo.email)
  }, [])
  useTelemetry({ pageName: 'CloudCostPage' })
  return (
    <Layout.Vertical spacing="small">
      <Tabs id="ccmNavTab" selectedTabId={'account'} className={css.sideNavTabs}>
        <Tab id="account" title={'Account'} panel={<SideNavItems />} />
        <Tabs.Expander />
        <Popover interactionKind={'hover'} content={<ProjectLevelFeedback />}>
          <Text>{'Project'}</Text>
        </Popover>
      </Tabs>
    </Layout.Vertical>
  )
}
 
interface ProjectLevelFeedbackProps {
  shouldShowFeedbackCta?: boolean // TODO: temp prop, will remove once data saving API is ready
}
 
export const ProjectLevelFeedback = (props: ProjectLevelFeedbackProps) => {
  const [showFeedbackForm, setShowFeedbackForm] = useState<boolean>(false)
  const [selectedOptions, setSelectedOptions] = useState<string[]>([])
  const [moreInfo, setMoreInfo] = useState<string>('')
 
  const handleOptionChange = (checked: boolean, val: string) => {
    const updatedOptions = [...selectedOptions]
    Eif (checked) {
      updatedOptions.push(val)
    } else {
      const index = updatedOptions.indexOf(val)
      updatedOptions.splice(index, 1)
    }
    setSelectedOptions(updatedOptions)
  }
 
  return (
    <div className={css.projectLevelFeedback}>
      <Text font={{ size: 'small' }} data-testid={'supportText'}>
        We currently only support Cloud Cost Management (CCM) at an Account Level.
      </Text>
      {!showFeedbackForm && props.shouldShowFeedbackCta && (
        <>
          <Text font={{ size: 'small', weight: 'bold' }} className={css.spaceAbove}>
            Would you like us to support CCM at a Project level?
          </Text>
          <Text
            font={{ size: 'small' }}
            color={Color.BLUE_700}
            style={{ cursor: 'pointer' }}
            rightIcon={'chevron-right'}
            onClick={() => setShowFeedbackForm(true)}
            data-testid={'fillFeedbackCta'}
          >
            Fill our feature request form
          </Text>
        </>
      )}
      {showFeedbackForm && (
        <>
          <Text font={{ size: 'small', weight: 'bold' }} className={css.spaceAbove}>
            Tell us why you would like CCM at a Project level?
          </Text>
          <div className={css.spaceAbove}>
            {feedbackOptions.map((option: string) => {
              return (
                <Checkbox
                  key={option.substr(0, 5)}
                  label={option}
                  checked={selectedOptions.indexOf(option) > -1}
                  onChange={(e: React.FormEvent<HTMLInputElement>) =>
                    handleOptionChange(e.currentTarget.checked, option)
                  }
                />
              )
            })}
          </div>
          <textarea
            value={moreInfo}
            placeholder={'Tell us more'}
            className={css.spaceAbove}
            onChange={e => setMoreInfo(e.target.value)}
          ></textarea>
          <Layout.Horizontal className={css.spaceAbove} spacing={'medium'}>
            <Button text="Submit" intent="primary" font={{ size: 'small' }} />
            <Button text="Cancel" font={{ size: 'small' }} onClick={() => setShowFeedbackForm(false)} />
          </Layout.Horizontal>
        </>
      )}
    </div>
  )
}
 
const SideNavItems = () => {
  const { accountId } = useParams<PipelinePathProps>()
  const { getString } = useStrings()
  const { trackEvent } = useTelemetry()
  const isAnomaliesEnabled = useFeatureFlag(FeatureFlag.CCM_ANOMALY_DETECTION_NG)
  const isBusinessMappingEnabled = useFeatureFlag(FeatureFlag.BUSINESS_MAPPING)
 
  return (
    <Layout.Vertical spacing="small">
      <React.Fragment>
        <SidebarLink label={getString('overview')} to={routes.toCEOverview({ accountId })} />
        <SidebarLink
          onClick={() => {
            trackEvent(USER_JOURNEY_EVENTS.PERSPECTIVE_NAV_CLICK, {})
          }}
          label={getString('ce.perspectives.sideNavText')}
          to={routes.toCEPerspectives({ accountId })}
        />
        <SidebarLink label={getString('ce.budgets.sideNavText')} to={routes.toCEBudgets({ accountId })} />
 
        {isAnomaliesEnabled && (
          <SidebarLink
            label={getString('ce.anomalyDetection.sideNavText')}
            to={routes.toCEAnomalyDetection({ accountId })}
          />
        )}
        <SidebarLink
          onClick={() => {
            trackEvent(USER_JOURNEY_EVENTS.RECOMMENDATIONS_NAV_CLICK, {})
          }}
          label={getString('ce.recommendation.sideNavText')}
          to={routes.toCERecommendations({ accountId })}
        />
        <SidebarLink
          onClick={() => {
            trackEvent(USER_JOURNEY_EVENTS.AS_NAV_CLICK, {})
          }}
          label={getString('ce.co.breadCrumb.rules')}
          to={routes.toCECORules({ accountId })}
        />
        <NavExpandable title={getString('common.setup')} route={routes.toCECOAccessPoints({ accountId })}>
          <Layout.Vertical spacing="small">
            <SidebarLink
              label={getString('ce.co.accessPoint.loadbalancers')}
              to={routes.toCECOAccessPoints({ accountId })}
            />
            {isBusinessMappingEnabled ? (
              <SidebarLink
                label={getString('ce.businessMapping.sideNavText')}
                to={routes.toBusinessMapping({ accountId })}
              />
            ) : null}
          </Layout.Vertical>
        </NavExpandable>
      </React.Fragment>
      <LaunchButton
        launchButtonText={getString('common.ce.visibilityLaunchButton')}
        redirectUrl={returnLaunchUrl(`#/account/${accountId}/continuous-efficiency/overview`)}
      />
    </Layout.Vertical>
  )
}