All files / modules/85-cv/pages/monitored-service/CVMonitoredService/components/MonitoredServiceGraphView/views SummaryCard.tsx

88.89% Statements 24/27
83.33% Branches 20/24
75% Functions 3/4
88% Lines 22/25

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              14x 14x 14x 14x 14x 14x   14x 14x   14x   14x 6x   6x                 6x 1x             5x 1x     4x       4x     14x 4x 4x                                     14x  
/*
 * 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 { createPortal } from 'react-dom'
import { Container, Icon, PageError } from '@wings-software/uicore'
import { Color } from '@harness/design-system'
import { useGetMonitoredServiceDetailsWithServiceId } from 'services/cv'
import type { ProjectPathProps } from '@common/interfaces/RouteInterfaces'
import { getErrorMessage } from '@cv/utils/CommonUtils'
import SummaryCardContent from '../../GraphSummaryCard/GraphSummaryCard'
import type { SummaryCardProps } from '../ServiceDependencyGraph.types'
import css from '../ServiceDependencyGraph.module.scss'
 
export const SummaryCard: React.FC<SummaryCardProps> = ({ point, ...rest }) => {
  const { accountId, orgIdentifier, projectIdentifier } = useParams<ProjectPathProps>()
 
  const { data, loading, refetch, error } = useGetMonitoredServiceDetailsWithServiceId({
    monitoredServiceIdentifier: point?.monitoredServiceIdentifier ?? '',
    queryParams: {
      accountId,
      orgIdentifier,
      projectIdentifier
    }
  })
 
  if (loading) {
    return (
      <Container flex={{ justifyContent: 'center' }} height="100%">
        <Icon name="steps-spinner" color={Color.GREY_400} size={30} />
      </Container>
    )
  }
 
  if (error) {
    return <PageError message={getErrorMessage(error)} onClick={() => refetch()} width={300} />
  }
 
  Iif (!data) {
    return null
  }
 
  return <SummaryCardContent {...rest} monitoredService={data} />
}
 
const SummaryCardWrapper: React.FC<SummaryCardProps> = ({ point, ...rest }) => {
  Eif (!point?.sticky?.element) {
    return null
  }
 
  return createPortal(
    <foreignObject className="node" width="360px" height="485px">
      <Container
        height="100%"
        padding="large"
        background={Color.GREY_700}
        onClick={e => e.stopPropagation()}
        className={css.graphSummaryCard}
      >
        <SummaryCard {...rest} point={point} />
      </Container>
    </foreignObject>,
    point.sticky.element
  )
}
 
export default SummaryCardWrapper