All files / modules/75-cd/components/CDExecutionSummary CDExecutionSummary.tsx

100% Statements 21/21
84.21% Branches 16/19
100% Functions 4/4
100% Lines 20/20

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              1x 1x 1x       1x 1x 1x   1x   1x 1x   1x   1x   1x   1x 7x   7x 6x       7x 6x       6x     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 { Icon } from '@wings-software/uicore'
import { identity, uniqBy } from 'lodash-es'
import type { CDPipelineModuleInfo, CDStageModuleInfo, ServiceExecutionSummary } from 'services/cd-ng'
import type { ExecutionSummaryProps } from '@pipeline/factories/ExecutionFactory/types'
 
import { ServicesList } from './ServicesList'
import { EnvironmentsList } from './EnvironmentsList'
import css from './CDExecutionSummary.module.scss'
 
const LIMIT = 2
 
export function CDExecutionSummary(props: ExecutionSummaryProps<CDPipelineModuleInfo>): React.ReactElement {
  const { nodeMap } = props
 
  const { services, environments } = React.useMemo(() => {
    // eslint-disable-next-line @typescript-eslint/no-shadow
    const services: ServiceExecutionSummary[] = []
    // eslint-disable-next-line @typescript-eslint/no-shadow
    const environments: string[] = []
 
    nodeMap.forEach(stage => {
      const stageInfo = stage.moduleInfo?.cd || /* istanbul ignore next */ ({} as CDStageModuleInfo)
      // istanbul ignore else
      if (stageInfo.serviceInfo) {
        services.push(stageInfo.serviceInfo)
      }
 
      // istanbul ignore else
      if (stageInfo.infraExecutionSummary?.name || stageInfo.infraExecutionSummary?.identifier) {
        environments.push(stageInfo.infraExecutionSummary.name || stageInfo.infraExecutionSummary.identifier)
      }
    })
 
    return { services: uniqBy(services, s => s.identifier), environments: uniqBy(environments, identity) }
  }, [nodeMap])
 
  return (
    <div className={css.main}>
      <Icon name="cd-main" size={18} />
      <ServicesList services={services} limit={LIMIT} />
      <EnvironmentsList environments={environments} limit={LIMIT} />
    </div>
  )
}