All files / modules/10-common/components/ResourceCenter MenuItems.tsx

92.86% Statements 39/42
100% Branches 6/6
85.71% Functions 6/7
92.86% Lines 39/42

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              14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x   14x 4x     4x                                                 4x                                                                               14x   14x     14x 18x 18x 18x 18x 18x 1x 1x 1x   18x 1x 1x 1x         1x 1x     18x                         1x                 1x               14x  
/*
 * Copyright 2022 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 moment from 'moment'
import cx from 'classnames'
import { capitalize } from 'lodash-es'
import { Button, ButtonVariation, Layout, Text, Popover, Icon } from '@wings-software/uicore'
import { Color, FontVariation } from '@harness/design-system'
import { PopoverInteractionKind, Classes, Position } from '@blueprintjs/core'
import { useFeatureFlags } from '@common/hooks/useFeatureFlag'
import { useCommunity } from 'framework/LicenseStore/useCommunity'
import { useAppStore } from 'framework/AppStore/AppStoreContext'
import { useStrings } from 'framework/strings'
import Feedback from './Feedback'
import { getMenuItems } from './ResourceCenterUtil'
import css from './ResourceCenter.module.scss'
 
const CommunitySubmitTicket: React.FC = () => {
  const { getString } = useStrings()
 
  const tooltip = (
    <Layout.Vertical className={css.communityTooltip} spacing={'medium'} padding={'medium'}>
      <Text
        icon="flash"
        color={Color.ORANGE_800}
        font={{ variation: FontVariation.FORM_MESSAGE_WARNING, weight: 'bold' }}
        iconProps={{ color: Color.ORANGE_800, size: 25 }}
        padding={{ bottom: 'xsmall' }}
      >
        {getString('common.levelUp')}
      </Text>
      <Text color={Color.WHITE}>{getString('common.resourceCenter.communityLevelUp')}</Text>
      <Button
        variation={ButtonVariation.PRIMARY}
        width={'fit-content'}
        onClick={e => {
          e.preventDefault()
          e.stopPropagation()
          window.open('https://harness.io/pricing/?module=cd', '_blank')
        }}
      >
        {getString('common.explorePlans')}
      </Button>
    </Layout.Vertical>
  )
 
  return (
    <Popover
      openOnTargetFocus={false}
      fill
      usePortal
      hoverCloseDelay={50}
      interactionKind={PopoverInteractionKind.HOVER}
      content={tooltip}
      position={Position.RIGHT}
      className={Classes.DARK}
    >
      <Layout.Horizontal
        padding={'xlarge'}
        className={cx(css.middleregion, css.onHover)}
        flex={{ justifyContent: 'space-between' }}
      >
        <Layout.Vertical>
          <Text
            font={{ variation: FontVariation.H4 }}
            padding={{ bottom: 'xsmall' }}
            color={Color.GREY_300}
            icon="flash"
            iconProps={{ padding: { right: 'medium' }, size: 25 }}
          >
            {capitalize(getString('common.contactSupport'))}
          </Text>
          <Text font={{ variation: FontVariation.BODY2 }} padding={{ bottom: 'xsmall' }} color={Color.GREY_300}>
            {getString('common.resourceCenter.ticketmenu.submitDesc')}
          </Text>
        </Layout.Vertical>
        <Icon name="chevron-right" color={Color.GREY_300} />
      </Layout.Horizontal>
    </Popover>
  )
}
 
interface MenuItemsProps {
  closeResourceCenter: () => void
}
 
const timestamp = moment.now()
const HARNESS_SUPPORT_LINK =
  '/sso.html?action=login&brand_id=114095000394&locale_id=1&return_to=https%3A%2F%2Fsupport.harness.io%2Fhc%2Fen-us%2Frequests&src=zendesk&timestamp=' +
  timestamp
 
const MenuItems: React.FC<MenuItemsProps> = ({ closeResourceCenter }: MenuItemsProps) => {
  const { getString } = useStrings()
  const isCommunity = useCommunity()
  const { SHOW_NG_REFINER_FEEDBACK } = useFeatureFlags()
  const { currentUserInfo } = useAppStore()
  const openZendeskSupport = (e: React.MouseEvent<Element, MouseEvent>): void => {
    e.stopPropagation()
    e.preventDefault()
    window.open(HARNESS_SUPPORT_LINK)
  }
  const openFileATicket = (e: React.MouseEvent<Element, MouseEvent>): void => {
    e.stopPropagation()
    e.preventDefault()
    window.Saber.do('set_options', {
      feedback_values: {
        Email: currentUserInfo.email // set default value for email field
      }
    })
    closeResourceCenter()
    window.Saber.do('open')
  }
 
  return isCommunity ? (
    <CommunitySubmitTicket />
  ) : (
    <Layout.Vertical padding={'xlarge'} className={css.middleregion}>
      {SHOW_NG_REFINER_FEEDBACK && <Feedback label={getString('common.resourceCenter.feedback.submit')} />}
      <Layout.Horizontal
        padding={SHOW_NG_REFINER_FEEDBACK ? { top: 'medium' } : {}}
        flex={{ justifyContent: 'space-between' }}
      >
        {getMenuItems({
          title: capitalize(getString('common.contactSupport')),
          description: getString('common.resourceCenter.ticketmenu.submitDesc'),
          onClick: e => {
            openFileATicket(e)
          }
        })}
      </Layout.Horizontal>
      <Layout.Horizontal padding={{ top: 'medium' }} flex={{ justifyContent: 'space-between' }}>
        {getMenuItems({
          title: getString('common.resourceCenter.ticketmenu.tickets'),
          description: getString('common.resourceCenter.ticketmenu.ticketsDesc'),
          onClick: e => {
            openZendeskSupport(e)
          }
        })}
      </Layout.Horizontal>
    </Layout.Vertical>
  )
}
 
export default MenuItems