All files / modules/85-cv/hooks/useLogContentHook/views/LogContentHeader LogContentHeader.tsx

100% Statements 23/23
81.08% Branches 30/37
100% Functions 4/4
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 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148              17x 17x 17x 17x 17x   17x 17x     17x                         63x   63x 63x   63x           63x                             63x               63x 39x 20x         63x 39x 12x         63x                                                                                                                     2x                 17x  
/*
 * 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 from 'react'
import { useParams } from 'react-router-dom'
import { FontVariation, Heading, Layout, Container, Text, Color, Select, Checkbox } from '@harness/uicore'
import { useStrings } from 'framework/strings'
import { useGetAllHealthSourcesForServiceAndEnvironment, useGetVerifyStepHealthSources } from 'services/cv'
import type { ProjectPathProps } from '@common/interfaces/RouteInterfaces'
import { getHealthSourceOptions, getTimeRangeOptions } from '../../useLogContentHook.utils'
import { LogTypes } from '../../useLogContentHook.types'
import type { LogContentHeaderProps } from './LogContentHeader.types'
 
const LogContentHeader: React.FC<LogContentHeaderProps> = ({
  logType,
  verifyStepExecutionId = '',
  serviceName = '',
  envName = '',
  healthSource,
  handleHealthSource,
  monitoredServiceIdentifier,
  timeRange,
  handleTimeRange,
  errorLogsOnly,
  handleDisplayOnlyErrors
}) => {
  const { getString } = useStrings()
 
  const isVerifyStep = Boolean(verifyStepExecutionId)
  const isMonitoredDetailsStep = Boolean(monitoredServiceIdentifier)
 
  const { orgIdentifier, projectIdentifier, accountId } = useParams<ProjectPathProps & { identifier: string }>()
 
  const {
    data: monitoredService,
    loading: monitoredServiceLoading,
    refetch: refetchMonitoredHealthScore
  } = useGetAllHealthSourcesForServiceAndEnvironment({
    queryParams: {
      orgIdentifier,
      projectIdentifier,
      accountId,
      serviceIdentifier: serviceName,
      environmentIdentifier: envName
    },
    lazy: true
  })
 
  const {
    data: verifyStep,
    loading,
    refetch
  } = useGetVerifyStepHealthSources({
    verifyStepExecutionId,
    queryParams: {
      accountId
    },
    lazy: true
  })
 
  React.useEffect(() => {
    if (isVerifyStep) {
      refetch()
    }
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, [isVerifyStep])
 
  React.useEffect(() => {
    if (isMonitoredDetailsStep) {
      refetchMonitoredHealthScore()
    }
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, [isMonitoredDetailsStep])
 
  return (
    <div>
      <Heading
        level={2}
        font={{ variation: FontVariation.FORM_TITLE }}
        border={{ bottom: true }}
        padding={{ top: 'xlarge', right: 'xlarge', bottom: 'small', left: 'xlarge' }}
      >
        {logType === LogTypes.ExecutionLog ? getString('cv.executionLogs') : getString('cv.externalAPICalls')}
      </Heading>
      <Layout.Horizontal spacing="medium" padding={{ top: 'medium', right: 'xlarge', bottom: 'large', left: 'xlarge' }}>
        <Container>
          <Text font={{ variation: FontVariation.TINY_SEMI }} color={Color.GREY_400}>
            {getString('connectors.cdng.monitoredService.label')}
          </Text>
          <Layout.Horizontal spacing="small">
            <Text
              color={Color.BLACK}
              font={{ variation: FontVariation.TINY, weight: 'bold' }}
              padding={{ right: 'xsmall' }}
              style={{ maxWidth: '100px' }}
              lineClamp={1}
            >
              {serviceName}
            </Text>
            <Text color={Color.BLACK} font={{ variation: FontVariation.TINY_SEMI }}>
              /
            </Text>
            <Text
              font={{ variation: FontVariation.TINY_SEMI }}
              color={Color.GREY_700}
              style={{ maxWidth: '100px' }}
              lineClamp={1}
            >
              {envName}
            </Text>
          </Layout.Horizontal>
        </Container>
        <Container border={{ left: true }} />
        <Container width={230}>
          {isVerifyStep || isMonitoredDetailsStep ? (
            <Select
              value={{
                label: `${getString('pipeline.verification.healthSourceLabel')}: ${healthSource?.label}`,
                value: healthSource?.value ?? ''
              }}
              items={getHealthSourceOptions(
                getString,
                isVerifyStep ? verifyStep?.resource : monitoredService?.resource
              )}
              onChange={handleHealthSource}
              disabled={loading || monitoredServiceLoading}
            />
          ) : (
            <Select value={timeRange} items={getTimeRangeOptions(getString)} onChange={handleTimeRange} />
          )}
        </Container>
        <Checkbox
          checked={errorLogsOnly}
          onChange={e => handleDisplayOnlyErrors(e.currentTarget.checked)}
          label={getString('cv.displayOnlyErrors')}
          flex={{ align: 'center-center' }}
        />
      </Layout.Horizontal>
    </div>
  )
}
 
export default LogContentHeader