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

88.46% Statements 23/26
57.69% Branches 15/26
80% Functions 4/5
88.46% Lines 23/26

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              13x 13x 13x 13x 13x 13x 13x 13x 13x   13x 13x   13x             3x   3x                     3x                     13x 7x   7x   7x   7x           9x                       12x                           13x  
/*
 * 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 { Page, Layout, NoDataCard, FlexExpander } from '@wings-software/uicore'
import { useStrings } from 'framework/strings'
import noServiceAvailableImage from '@cv/assets/noServiceAvailable.png'
import { DependencyGraph } from '@cv/components/DependencyGraph/DependencyGraph'
import FilterCard from '@cv/components/FilterCard/FilterCard'
import ServiceDependenciesLegend from '@cv/components/ServiceDependenciesLegend/ServiceDependenciesLegend'
import { getMonitoredServiceFilterOptions } from '@cv/pages/monitored-service/CVMonitoredService/CVMonitoredService.utils'
import SummaryCard from './SummaryCard'
import type { PageViewProps, PageViewContentProps } from '../ServiceDependencyGraph.types'
import { getDependencyGraphOptions } from '../MonitoredServiceGraphView.utils'
import css from '../ServiceDependencyGraph.module.scss'
 
const PageViewContent: React.FC<PageViewContentProps> = ({
  point,
  setPoint,
  monitoredServiceDependencyData,
  onToggleService,
  onDeleteService
}) => {
  const { getString } = useStrings()
 
  Iif (!monitoredServiceDependencyData?.nodes?.length) {
    return (
      <NoDataCard
        image={noServiceAvailableImage}
        message={getString('cv.monitoredServices.youHaveNoMonitoredServices')}
        imageClassName={css.noServiceAvailableImage}
        containerClassName={css.noDataContainer}
      />
    )
  }
 
  return (
    <>
      <DependencyGraph
        dependencyData={monitoredServiceDependencyData}
        options={getDependencyGraphOptions(setPoint, '40%')}
      />
      <SummaryCard isPageView point={point} onToggleService={onToggleService} onDeleteService={onDeleteService} />
    </>
  )
}
 
const PageView: React.FC<PageViewProps> = ({ loading, errorMessage, retryOnError, ...rest }) => {
  const { getString } = useStrings()
 
  const { point, selectedFilter, onFilter, serviceCountData, createButton } = rest
 
  const filterOptions = getMonitoredServiceFilterOptions(getString, serviceCountData ?? null)
 
  return (
    <Page.Body
      loading={loading}
      error={errorMessage}
      retryOnError={retryOnError}
      noData={{
        when: () => !serviceCountData?.allServicesCount,
        image: noServiceAvailableImage,
        imageClassName: css.noServiceAvailableImage,
        message: getString('cv.monitoredServices.youHaveNoMonitoredServices'),
        button: createButton
      }}
      className={css.pageBody}
    >
      <Layout.Vertical height="100%" padding={{ top: 'medium', left: 'xlarge', right: 'xlarge', bottom: 'xlarge' }}>
        <FilterCard
          data={filterOptions}
          cardClassName={css.filterCard}
          selected={filterOptions.find(card => card.type === selectedFilter)}
          onChange={item => {
            onFilter?.(item.type)
            point?.destroySticky()
          }}
        />
        <PageViewContent {...rest} />
        <FlexExpander />
        <ServiceDependenciesLegend margin={{ top: 'medium' }} />
      </Layout.Vertical>
    </Page.Body>
  )
}
 
export default PageView