All files / modules/75-cf/pages/environment-details EnvironmentDetailsHeader.tsx

100% Statements 17/17
62.5% Branches 10/16
100% Functions 2/2
100% Lines 17/17

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              1x 1x 1x 1x   1x 1x 1x 1x 1x       1x 1x 1x 1x 1x                                     1x               2x                                                                     1x  
/*
 * 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 { Layout, Text } from '@wings-software/uicore'
import { Link, useParams } from 'react-router-dom'
import routes from '@common/RouteDefinitions'
import type { EnvironmentResponseDTO } from 'services/cd-ng'
import { useStrings } from 'framework/strings'
import { useAppStore } from 'framework/AppStore/AppStoreContext'
import { IdentifierText } from '@cf/components/IdentifierText/IdentifierText'
import { EnvironmentType } from '@common/constants/EnvironmentType'
import { TagsViewer } from '@common/components/TagsViewer/TagsViewer'
 
const CFEnvironmentDetailsHeader: React.FC<{
  environment: EnvironmentResponseDTO
}> = ({ environment }) => {
  const { projectIdentifier, orgIdentifier, accountId } = useParams<Record<string, string>>()
  const { selectedProject } = useAppStore()
  const { getString } = useStrings()
  const breadcrumbs = [
    {
      title: selectedProject?.name,
      url: routes.toProjectDetails({
        accountId,
        orgIdentifier,
        projectIdentifier
      })
    },
    {
      title: getString('cf.environments.adminEnvironments'),
      url: routes.toCFEnvironments({
        accountId,
        orgIdentifier,
        projectIdentifier
      })
    }
  ]
 
  return (
    <Layout.Vertical
      height={117}
      padding={{ top: 'large', right: 'xlarge', bottom: 'large', left: 'xlarge' }}
      style={{ backgroundColor: 'rgba(219, 241, 255, .46)', position: 'relative' }}
    >
      <Layout.Horizontal spacing="small">
        {breadcrumbs.map(linkInfo => (
          <React.Fragment key={linkInfo.title + linkInfo.url}>
            <Link style={{ color: '#0092E4', fontSize: '12px' }} to={linkInfo.url}>
              {linkInfo.title}
            </Link>
            <span>/</span>
          </React.Fragment>
        ))}
      </Layout.Horizontal>
 
      <Layout.Horizontal flex={{ align: 'center-center', distribution: 'space-between' }}>
        <Layout.Vertical>
          <Layout.Horizontal spacing="medium" style={{ alignItems: 'center' }}>
            <Text style={{ lineHeight: '40px', color: '#22272D', fontSize: '16px' }}>{environment.name}</Text>
            <IdentifierText identifier={environment.identifier} style={{ margin: 0 }} allowCopy />
          </Layout.Horizontal>
          {environment.description && <Text font={{ size: 'normal' }}>{environment.description}</Text>}
        </Layout.Vertical>
 
        <Layout.Vertical spacing="small">
          <Layout.Horizontal spacing="medium">
            <Text font={{ weight: 'bold', size: 'normal' }}>{getString('typeLabel')}</Text>
            <Text>{getString(environment.type === EnvironmentType.PRODUCTION ? 'production' : 'nonProduction')}</Text>
          </Layout.Horizontal>
          {Object.keys(environment.tags ?? {}).length > 0 && (
            <Layout.Horizontal spacing="medium" style={{ alignItems: 'center' }}>
              <Text font={{ weight: 'bold', size: 'normal' }}>{getString('tagsLabel')}</Text>
              <TagsViewer tags={Object.values(environment.tags || [])} />
            </Layout.Horizontal>
          )}
        </Layout.Vertical>
      </Layout.Horizontal>
    </Layout.Vertical>
  )
}
 
export default CFEnvironmentDetailsHeader