All files / modules/45-projects-orgs/utils utils.ts

84.48% Statements 49/58
80.56% Branches 29/36
85.71% Functions 6/7
82.35% Lines 42/51

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                20x 20x 20x   20x                       20x 27x   6x   5x   5x       11x       20x 25x   5x   5x   5x   5x   5x     20x 5x   1x   1x   1x   1x   1x     20x                               20x 27x 19x   8x 8x                 20x 54x 38x           16x 16x       20x 5x   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 type { SelectOption } from '@wings-software/uicore'
import { getScopeFromDTO, ScopedObjectDTO } from '@common/components/EntityReference/EntityReference'
import { Scope } from '@common/interfaces/SecretsInterface'
import routes from '@common/RouteDefinitions'
import type { StringKeys, StringsMap } from 'framework/strings/StringsContext'
import { ModuleName } from 'framework/types/ModuleName'
 
interface RoleOption extends SelectOption {
  managed: boolean
}
 
interface ScopedDTO {
  accountId: string
  orgIdentifier?: string
  projectIdentifier?: string
}
 
export const getModuleTitle = (module: ModuleName): keyof StringsMap => {
  switch (module) {
    case ModuleName.CV:
      return 'common.purpose.cv.serviceReliability'
    case ModuleName.CE:
      return 'common.purpose.ce.cloudCost'
    case ModuleName.CF:
      return 'common.purpose.cf.feature'
    case ModuleName.CD:
    case ModuleName.CI:
    default:
      return 'projectsOrgs.purposeList.continuous'
  }
}
 
export const getModulePurpose = (module: ModuleName): keyof StringsMap | undefined => {
  switch (module) {
    case ModuleName.CD:
      return 'common.purpose.cd.delivery'
    case ModuleName.CV:
      return 'common.purpose.ce.management'
    case ModuleName.CI:
      return 'common.purpose.ci.integration'
    case ModuleName.CE:
      return 'common.purpose.ce.management'
    case ModuleName.CF:
      return 'common.purpose.cf.flags'
  }
}
export const getModuleDescriptionsForModuleSelectionDialog = (module: ModuleName): keyof StringsMap | undefined => {
  switch (module) {
    case ModuleName.CD:
      return 'common.selectAVersion.description'
    case ModuleName.CV:
      return 'common.purpose.cv.moduleSelectionSubHeading'
    case ModuleName.CI:
      return 'common.purpose.ci.descriptionOnly'
    case ModuleName.CE:
      return 'common.purpose.ce.moduleSelectionSubHeading'
    case ModuleName.CF:
      return 'common.purpose.cf.moduleSelectionSubHeading'
  }
}
export const getModuleDescription = (module: ModuleName): StringKeys => {
  switch (module) {
    case ModuleName.CD:
      return 'projectsOrgs.purposeList.descriptionCD'
    case ModuleName.CV:
      return 'projectsOrgs.purposeList.descriptionCV'
    case ModuleName.CI:
      return 'projectsOrgs.purposeList.descriptionCI'
    case ModuleName.CE:
      return 'projectsOrgs.purposeList.descriptionCE'
    case ModuleName.CF:
      return 'projectsOrgs.purposeList.descriptionCF'
  }
  return 'projectsOrgs.blank'
}
 
export const getDefaultRole = (scope: ScopedObjectDTO, getString: (key: keyof StringsMap) => string): RoleOption => {
  if (getScopeFromDTO(scope) === Scope.PROJECT) {
    return { label: getString('common.projectViewer'), value: '_project_viewer', managed: true }
  }
  Eif (getScopeFromDTO(scope) === Scope.ORG) {
    return {
      label: getString('common.orgViewer'),
      value: '_organization_viewer',
      managed: true
    }
  }
  return { label: getString('common.accViewer'), value: '_account_viewer', managed: true }
}
 
export const getDetailsUrl = ({ accountId, orgIdentifier, projectIdentifier }: ScopedDTO): string => {
  if (projectIdentifier && orgIdentifier) {
    return `${window.location.href.split('#')[0]}#${routes.toProjectDetails({
      accountId,
      orgIdentifier,
      projectIdentifier
    })}`
  }
  Eif (orgIdentifier) {
    return `${window.location.href.split('#')[0]}#${routes.toOrganizationDetails({ accountId, orgIdentifier })}`
  }
  return ''
}
export const getModuleFullLengthTitle = (module: ModuleName): keyof StringsMap => {
  switch (module) {
    case ModuleName.CV:
      return 'common.purpose.cv.continuous'
    case ModuleName.CE:
      return 'common.purpose.ce.continuous'
    case ModuleName.CF:
      return 'common.purpose.cf.continuous'
    case ModuleName.CI:
      return 'common.purpose.ci.continuous'
    default:
      return 'common.purpose.cd.continuous'
  }
}