All files / modules/85-cv/components/HealthSourceDropDown HealthSourceDropDown.utils.ts

92.86% Statements 13/14
83.33% Branches 30/36
100% Functions 1/1
92.31% Lines 12/13

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                18x         18x         31x 1x   30x       30x 30x 27x 15x               30x 2x     30x    
/*
 * 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 type { IconName } from '@wings-software/uicore'
import { getIconBySourceType } from '@cv/pages/health-source/HealthSourceTable/HealthSourceTable.utils'
import type { SelectOption } from '@pipeline/components/PipelineSteps/Steps/StepsTypes'
import type { UseStringsReturn } from 'framework/strings'
import type { DropdownData } from './HealthSourceDropDown.types'
 
export const getDropdownOptions = (
  { loading, error, data, verificationType }: DropdownData,
  getString: UseStringsReturn['getString'],
  showAllOption = true
): SelectOption[] | [] => {
  if (loading) {
    return [{ value: '', label: getString('loading') }]
  }
  Iif (error) {
    return []
  }
 
  const options = []
  for (const source of data?.resource || []) {
    if (source?.identifier && source?.name && source?.verificationType === verificationType) {
      options.push({
        label: source.name,
        value: source.identifier as string,
        icon: { name: getIconBySourceType(source?.type as string) as IconName }
      })
    }
  }
 
  if (showAllOption && options.length > 1) {
    options.unshift({ label: getString('all'), value: 'all' })
  }
 
  return options
}