All files / modules/75-cf/pages/target-detail TargetDetailPage.tsx

100% Statements 23/23
88.46% Branches 23/26
100% Functions 2/2
100% Lines 23/23

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              1x 1x 1x 1x 1x 1x 1x 1x 1x 1x   1x 8x           8x             8x                             8x                 8x   8x 2x     6x 3x       1x           3x                       1x  
/*
 * 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, { FC } from 'react'
import { useParams } from 'react-router-dom'
import { Target, useGetTarget } from 'services/cf'
import { useGetEnvironment } from 'services/cd-ng'
import useActiveEnvironment from '@cf/hooks/useActiveEnvironment'
import TargetManagementDetailPageTemplate from '@cf/components/TargetManagementDetailPageTemplate/TargetManagementDetailPageTemplate'
import { ContainerSpinner } from '@common/components/ContainerSpinner/ContainerSpinner'
import { Page } from '@common/exports'
import useDeleteTargetDialog from '@cf/pages/target-detail/hooks/useDeleteTargetDialog'
import LeftBar from '@cf/pages/target-detail/components/LeftBar'
 
const TargetDetailPage: FC = () => {
  const { activeEnvironment: environmentIdentifier } = useActiveEnvironment()
  const {
    accountId: accountIdentifier,
    orgIdentifier,
    projectIdentifier,
    targetIdentifier
  } = useParams<Record<string, string>>()
 
  const {
    data: target,
    loading: targetLoading,
    error: targetError,
    refetch: refetchTarget
  } = useGetTarget({
    identifier: targetIdentifier,
    queryParams: {
      accountIdentifier,
      orgIdentifier,
      projectIdentifier,
      environmentIdentifier
    }
  })
 
  const {
    data: envData,
    loading: envLoading,
    error: envError,
    refetch: refetchEnv
  } = useGetEnvironment({
    environmentIdentifier,
    queryParams: {
      accountId: accountIdentifier,
      orgIdentifier,
      projectIdentifier
    }
  })
 
  const deleteTargetDialog = useDeleteTargetDialog(target as Target)
 
  if (targetLoading || envLoading) {
    return <ContainerSpinner flex={{ align: 'center-center' }} />
  }
 
  if (targetError || envError) {
    return (
      <Page.Error
        message={targetError?.message || envError?.message}
        onClick={async () => {
          await Promise.all([refetchTarget(), refetchEnv()])
        }}
      />
    )
  }
 
  return (
    <TargetManagementDetailPageTemplate
      item={target as Target}
      openDeleteDialog={deleteTargetDialog}
      metaData={{ environment: envData?.data?.name as string }}
      leftBar={<LeftBar target={target as Target} />}
    >
      Hello there
    </TargetManagementDetailPageTemplate>
  )
}
 
export default TargetDetailPage