All files / modules/70-pipeline/pages/execution/ExecutionPipelineView/ExecutionGraphView/ExecutionStageDetails/components/ResourceConstraints ResourceConstraints.tsx

95.45% Statements 21/22
69.35% Branches 43/62
100% Functions 3/3
95.24% Lines 20/21

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              3x 3x 3x 3x 3x 3x 3x   3x                     3x       1x 1x 1x     1x   1x   3x 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 { toLower } from 'lodash-es'
import { useParams, Link } from 'react-router-dom'
import { Spinner } from '@blueprintjs/core'
import { Container, Layout, Text } from '@wings-software/uicore'
import { Color } from '@harness/design-system'
import { useStrings } from 'framework/strings'
import type { ResourceConstraintDetail } from 'services/pipeline-ng'
import routes from '@common/RouteDefinitions'
import type { PipelineType, ProjectPathProps } from '@common/interfaces/RouteInterfaces'
 
export interface ResourceConstraintTooltipProps {
  loading: boolean
  data?: {
    executionList?: ResourceConstraintDetail[]
    executionId: string
  }
}
 
const getnoOfExecutionsBeforePipeline = (
  executionList: ResourceConstraintDetail[] = [],
  executionId?: string
): number => {
  let noOfExecutionsBeforePipeline = 0
  for (let index = 0; index < executionList.length; index++) {
    Iif (executionList[index].planExecutionId === executionId) {
      break
    }
    noOfExecutionsBeforePipeline++
  }
  return noOfExecutionsBeforePipeline
}
export default function ResourceConstraintTooltip(props: ResourceConstraintTooltipProps): React.ReactElement {
  const { projectIdentifier, orgIdentifier, accountId, module } = useParams<PipelineType<ProjectPathProps>>()
  const { getString } = useStrings()
  const noOfExecutionsBeforePipeline = getnoOfExecutionsBeforePipeline(
    props?.data?.executionList,
    props.data?.executionId
  )
 
  return props.loading ? (
    <Container border={{ top: true, width: 1, color: Color.GREY_100 }} padding={'medium'}>
      <Spinner size={24} />
    </Container>
  ) : (
    <Container padding={'medium'} border={{ top: true, width: 1, color: Color.GREY_100 }}>
      {props?.data?.executionList?.length && (
        <Layout.Vertical spacing={'small'}>
          <Text font={{ size: 'small' }}>
            {getString('pipeline.resourceConstraints.infoText', {
              executioncount: noOfExecutionsBeforePipeline,
              executiontext:
                noOfExecutionsBeforePipeline > 1
                  ? toLower(getString('executionsText'))
                  : toLower(getString('executionText'))
            })}
          </Text>
          {props?.data?.executionList?.map((pipeline: ResourceConstraintDetail, index: number) => (
            <Container key={`${pipeline.pipelineIdentifier}-${index}`}>
              <Link
                to={routes.toExecutionPipelineView({
                  pipelineIdentifier: pipeline.pipelineIdentifier || '',
                  projectIdentifier,
                  orgIdentifier,
                  module,
                  accountId,
                  executionIdentifier: pipeline?.planExecutionId || ''
                })}
              >
                <Layout.Horizontal>
                  <Text
                    title={pipeline.pipelineIdentifier}
                    width={200}
                    lineClamp={1}
                    inline={true}
                    font={{ size: 'small' }}
                    color={Color.BLUE_500}
                  >
                    {pipeline.pipelineIdentifier}
                  </Text>
                  <Text inline={true} color={Color.BLUE_500} font={{ size: 'small' }}>
                    {pipeline.planExecutionId === props.data?.executionId &&
                      pipeline.state !== 'ACTIVE' &&
                      getString('pipeline.resourceConstraints.yourPipeline')}
                    {pipeline.state === 'ACTIVE' && getString('pipeline.resourceConstraints.currentlyExecuting')}
                  </Text>
                </Layout.Horizontal>
              </Link>
            </Container>
          ))}
        </Layout.Vertical>
      )}
    </Container>
  )
}