All files / modules/75-cf/components/ItemBriefInfo ItemBriefInfo.tsx

100% Statements 15/15
57.14% Branches 8/14
100% Functions 1/1
100% Lines 14/14

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              5x 5x 5x 5x 5x 5x 5x 5x 5x 5x                   5x               9x 9x   9x                                                                                        
/*
 * 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 { Avatar, Container, Layout, Text } from '@wings-software/uicore'
import { useStrings } from 'framework/strings'
import { DISABLE_AVATAR_PROPS } from '@cf/utils/CFUtils'
import { ItemContainer, ItemContainerProps } from '@cf/components/ItemContainer/ItemContainer'
import RbacOptionsMenuButton from '@rbac/components/RbacOptionsMenuButton/RbacOptionsMenuButton'
import { PermissionIdentifier } from '@rbac/interfaces/PermissionIdentifier'
import { ResourceType } from '@rbac/interfaces/ResourceType'
import useActiveEnvironment from '@cf/hooks/useActiveEnvironment'
import css from './ItemBriefInfo.module.scss'
 
interface ItemBriefInfoProps extends ItemContainerProps {
  name: string
  description: string
  onRemoveClick?: () => void
  noAvatar?: boolean
  disabled?: boolean
}
 
export const ItemBriefInfo: React.FC<ItemBriefInfoProps> = ({
  name,
  description,
  onRemoveClick,
  noAvatar,
  disabled,
  ...props
}) => {
  const { getString } = useStrings()
  const { activeEnvironment } = useActiveEnvironment()
 
  return (
    <ItemContainer style={{ paddingRight: 'var(--spacing-xsmall)' }} {...props}>
      <Layout.Horizontal spacing="xsmall" style={{ alignItems: 'center' }}>
        {noAvatar !== true && (
          <Avatar
            name={name}
            {...DISABLE_AVATAR_PROPS}
            style={{ transform: 'scale(1.3)', cursor: 'default' }}
            className={css.avatar}
          />
        )}
        <Container style={{ flexGrow: 1 }} padding={{ left: 'xsmall' }}>
          <Text
            margin={{ bottom: description?.length ? 'xsmall' : undefined }}
            style={{
              color: disabled ? 'var(--grey-400)' : '#22222A',
              fontSize: '12px',
              fontWeight: 600,
              lineHeight: '16px'
            }}
          >
            {name}
          </Text>
          <Text style={{ color: disabled ? 'var(--grey-350)' : '#22222ac7', fontSize: '12px' }}>{description}</Text>
        </Container>
        {onRemoveClick && (
          <RbacOptionsMenuButton
            items={[
              {
                text: getString('cf.targetDetail.removeSegment'),
                icon: 'cross',
                onClick: onRemoveClick,
                permission: {
                  resource: { resourceType: ResourceType.ENVIRONMENT, resourceIdentifier: activeEnvironment },
                  permission: PermissionIdentifier.EDIT_FF_TARGETGROUP
                }
              }
            ]}
          />
        )}
      </Layout.Horizontal>
    </ItemContainer>
  )
}