All files / modules/85-cv/components/HealthSourceDropDown HealthSourceDropDown.tsx

100% Statements 18/18
84.21% Branches 16/19
100% Functions 3/3
100% Lines 18/18

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              16x 16x 16x 16x 16x   16x   16x 16x 16x   16x 25x 25x 25x   25x         25x 19x       25x                 2x          
/*
 * 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, { useMemo } from 'react'
import { Select, SelectOption } from '@wings-software/uicore'
import { useParams } from 'react-router-dom'
import classNames from 'classnames'
import { useStrings } from 'framework/strings'
import type { ProjectPathProps } from '@common/interfaces/RouteInterfaces'
import { useGetAllHealthSourcesForMonitoredServiceIdentifier } from 'services/cv'
import type { HealthSourceDropDownProps } from './HealthSourceDropDown.types'
import { VerificationType } from './HealthSourceDropDown.constants'
import { getDropdownOptions } from './HealthSourceDropDown.utils'
import css from './HealthSourceDropDown.module.scss'
 
export function HealthSourceDropDown(props: HealthSourceDropDownProps): JSX.Element {
  const { onChange, monitoredServiceIdentifier, className, verificationType = VerificationType.TIME_SERIES } = props
  const { getString } = useStrings()
  const { accountId, projectIdentifier, orgIdentifier } = useParams<ProjectPathProps>()
 
  const { data, error, loading } = useGetAllHealthSourcesForMonitoredServiceIdentifier({
    monitoredServiceIdentifier,
    queryParams: { accountId, projectIdentifier, orgIdentifier }
  })
 
  const healthSources: SelectOption[] = useMemo(() => {
    return getDropdownOptions({ loading, error, data, verificationType }, getString)
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, [data, error, loading, verificationType])
 
  return (
    <Select
      name="healthsources-select"
      items={healthSources}
      className={classNames(css.maxDropDownWidth, className)}
      defaultSelectedItem={healthSources?.[0]}
      key={healthSources?.[0]?.value as string}
      inputProps={{ placeholder: getString('pipeline.verification.healthSourcePlaceholder') }}
      onChange={item => {
        onChange(item?.value === 'all' ? '' : (item.value as string))
      }}
    />
  )
}