All files / modules/85-cv/pages/ChangeSource/ChangeSourceDrawer/components/HarnessCDCurrentGenChangeSource HarnessCDCurrentGenChangeSource.utils.ts

86.36% Statements 19/22
75% Branches 57/76
90% Functions 9/10
83.33% Lines 15/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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69                  18x                   18x 3x               18x 2x 2x             18x 2x 1x             18x         6x           18x 5x     18x         5x    
/*
 * 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 { SelectOption } from '@wings-software/uicore'
import type { GetDataError } from 'restful-react'
import { getErrorMessage } from '@cv/utils/CommonUtils'
import type {
  Application,
  Environment,
  RestResponsePageResponseApplication,
  RestResponsePageResponseEnvironment,
  RestResponsePageResponseService,
  Service
} from 'services/portal'
 
export const getApplicationsData = (applicationsData: RestResponsePageResponseApplication | null): SelectOption[] => {
  return (
    ((applicationsData?.resource as any)?.response?.map((el: Application) => ({
      label: el?.name,
      value: el?.appId
    })) as SelectOption[]) || []
  )
}
 
export const getServicesData = (servicesData: RestResponsePageResponseService | null): SelectOption[] => {
  return (
    ((servicesData?.resource as any)?.response?.map((el: Service) => ({
      label: el?.name,
      value: el?.uuid
    })) as SelectOption[]) || []
  )
}
 
export const getEnvironmentsData = (environmentsData: RestResponsePageResponseEnvironment | null): SelectOption[] => {
  return (
    ((environmentsData?.resource as any)?.response?.map((el: Environment) => ({
      label: el?.name,
      value: el?.uuid
    })) as SelectOption[]) || []
  )
}
 
export function showToasterError(
  error: GetDataError<unknown> | null,
  clear: () => void,
  showError: (message: React.ReactNode, timeout?: number | undefined, key?: string | undefined) => void
): void {
  Iif (error) {
    clear()
    showError(getErrorMessage(error))
  }
}
 
export function getPlaceHolder(loadingFlag: boolean, placeholderText: string, loadingText: string): string {
  return loadingFlag ? loadingText : placeholderText
}
 
export function getHarnessCDFieldValue(
  currentApplicationId: string,
  options: SelectOption[],
  fieldToGet: SelectOption | string
): SelectOption {
  return (!currentApplicationId ? options?.find(el => el.value === fieldToGet) : fieldToGet) as SelectOption
}