All files / modules/30-delegates/pages/delegates DelegateDetails.tsx

90.91% Statements 30/33
61.11% Branches 22/36
66.67% Functions 2/3
93.75% Lines 30/32

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              9x 9x 9x 9x 9x 9x             9x 9x 9x 9x 9x 9x 9x 9x   9x 1x     1x 1x         1x                       1x 1x           1x             1x         1x 1x   1x 1x                       1x                               1x       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 { useParams } from 'react-router-dom'
import { Container, Layout, Text, IconName } from '@wings-software/uicore'
import { NGBreadcrumbs } from '@common/components/NGBreadcrumbs/NGBreadcrumbs'
import { Page } from '@common/exports'
import routes from '@common/RouteDefinitions'
import type {
  ProjectPathProps,
  ModulePathParams,
  DelegatePathProps,
  AccountPathProps
} from '@common/interfaces/RouteInterfaces'
import { delegateTypeToIcon } from '@common/utils/delegateUtils'
import { useStrings } from 'framework/strings'
import { useGetDelegateGroupByIdentifier, useGetV2 } from 'services/portal'
import { ContainerSpinner } from '@common/components/ContainerSpinner/ContainerSpinner'
import { getScopeFromDTO } from '@common/components/EntityReference/EntityReference'
import { Scope } from '@common/interfaces/SecretsInterface'
import { DelegateOverview } from './DelegateOverview'
import css from './DelegateDetails.module.scss'
 
export default function DelegateDetails(): JSX.Element {
  const { delegateIdentifier, accountId, orgIdentifier, projectIdentifier, module } = useParams<
    Partial<ProjectPathProps & ModulePathParams> & DelegatePathProps & AccountPathProps
  >()
  const { getString } = useStrings()
  const { data } = useGetDelegateGroupByIdentifier({
    identifier: delegateIdentifier,
    queryParams: { accountId, orgId: orgIdentifier, projectId: projectIdentifier }
  })
 
  const breadcrumbs = [
    {
      label: getString('delegate.delegates'),
      url: routes.toDelegateList({
        accountId,
        orgIdentifier,
        projectIdentifier,
        module
      })
    }
  ]
 
  Eif (getScopeFromDTO({ accountId, orgIdentifier, projectIdentifier }) === Scope.ACCOUNT) {
    breadcrumbs.unshift({
      url: routes.toAccountResources({ accountId }),
      label: getString('common.accountResources')
    })
  }
 
  const delegate = data?.resource
 
  const {
    loading,
    error,
    data: profileResponse,
    refetch
  } = useGetV2({
    delegateProfileId: delegate?.delegateConfigurationId || '',
    queryParams: { accountId }
  })
 
  const delegateProfile = delegate?.delegateConfigurationId ? profileResponse?.resource : undefined
  const icon: IconName = delegateTypeToIcon(delegate?.delegateType as string)
 
  const renderTitle = (): React.ReactNode => {
    return (
      <Layout.Vertical spacing="small">
        <Layout.Horizontal spacing="small">
          <NGBreadcrumbs links={breadcrumbs} />
        </Layout.Horizontal>
        <Text style={{ fontSize: '20px', color: 'var(--black)' }} icon={icon} iconProps={{ size: 21 }}>
          {delegate?.groupName}
        </Text>
      </Layout.Vertical>
    )
  }
 
  Iif (loading) {
    return (
      <Container
        style={{
          position: 'fixed',
          top: '0',
          left: '270px',
          width: 'calc(100% - 270px)',
          height: '100%'
        }}
      >
        <ContainerSpinner />
      </Container>
    )
  }
 
  Iif (error) {
    return <Page.Error message={error.message} onClick={() => refetch()} />
  }
 
  return (
    <>
      <Container
        height={116}
        padding={{ top: 'large', right: 'xlarge', bottom: 'large', left: 'xlarge' }}
        className={css.detailsContainer}
      >
        {renderTitle()}
      </Container>
      <Page.Body className={css.main}>
        <Layout.Vertical>
          <Layout.Horizontal spacing="large">
            <Container className={css.cardContainer}>
              {delegate && (
                <Layout.Vertical spacing="large" width="50%">
                  <DelegateOverview delegate={delegate} delegateProfile={delegateProfile} />
                </Layout.Vertical>
              )}
            </Container>
          </Layout.Horizontal>
        </Layout.Vertical>
      </Page.Body>
    </>
  )
}