All files / modules/70-pipeline/components/PipelineStudio StudioGitPopover.tsx

96.67% Statements 29/30
82.76% Branches 24/29
100% Functions 3/3
96.55% Lines 28/29

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              18x 18x   18x 18x     18x 18x 18x 18x 18x   18x 18x 18x                     18x   18x 9x 9x 9x 9x   9x 3x     9x 9x 9x 9x 9x                                                                                                                                                         18x 28x     18x  
/*
 * 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 from 'react'
import { defaultTo } from 'lodash-es'
 
import { Icon, Layout, Text } from '@wings-software/uicore'
import { FontVariation, Color } from '@harness/design-system'
import type { GitSyncEntityDTO, PipelineInfoConfig } from 'services/cd-ng'
import type { EntityGitDetails, NGTemplateInfoConfig } from 'services/template-ng'
import { useGitSyncStore } from 'framework/GitRepoStore/GitSyncStoreContext'
import { useStrings } from 'framework/strings'
import { getRepoDetailsByIndentifier } from '@common/utils/gitSyncUtils'
import GitFilters, { GitFilterScope } from '@common/components/GitFilters/GitFilters'
import { useQueryParams } from '@common/hooks'
import type { GitQueryParams } from '@common/interfaces/RouteInterfaces'
import { getEntityUrl, getRepoEntityObject } from '@gitsync/common/gitSyncUtils'
import { DefaultNewPipelineId } from './PipelineContext/PipelineActions'
import GitPopover from '../GitPopover/GitPopover'
 
interface StudioGitPopoverProps {
  gitDetails: EntityGitDetails
  identifier: string
  isReadonly: boolean
  entityData: PipelineInfoConfig | NGTemplateInfoConfig
  onGitBranchChange: (selectedFilter: GitFilterScope) => void
  entityType: string
}
 
const breakWord = 'break-word'
 
export const GitDetails = (props: StudioGitPopoverProps): JSX.Element => {
  const { gitDetails, identifier, isReadonly, onGitBranchChange, entityType } = props
  const { repoIdentifier, branch } = useQueryParams<GitQueryParams>()
  const { gitSyncRepos, loadingRepos } = useGitSyncStore()
  const { getString } = useStrings()
 
  const getDisabledOptionTitleText = (): string => {
    return getString('common.gitSync.branchSyncNotAllowed', { entityType })
  }
 
  Eif (gitDetails?.objectId || (identifier === DefaultNewPipelineId && gitDetails.repoIdentifier)) {
    const repo = getRepoDetailsByIndentifier(gitDetails?.repoIdentifier, gitSyncRepos)
    const repoEntity: GitSyncEntityDTO = getRepoEntityObject(repo, gitDetails)
    const repoName: string = defaultTo(repo?.name, '')
    return (
      <>
        <Layout.Vertical spacing="large">
          <Text font={{ size: 'small' }} color={Color.GREY_400}>
            {getString('repository')}
          </Text>
          <Layout.Horizontal spacing="small" style={{ alignItems: 'center' }}>
            <Icon name="repository" size={16} color={Color.GREY_700} />
            <Text
              font={FontVariation.SMALL}
              style={{ wordWrap: breakWord, maxWidth: '200px' }}
              lineClamp={1}
              color={Color.GREY_800}
            >
              {repoName}
            </Text>
          </Layout.Horizontal>
        </Layout.Vertical>
        {identifier === DefaultNewPipelineId && !loadingRepos ? null : (
          <Layout.Vertical spacing="large">
            <Text font={{ size: 'small' }} color={Color.GREY_400}>
              {getString('common.git.filePath')}
            </Text>
            <Layout.Horizontal spacing="small" style={{ alignItems: 'center' }}>
              <Icon name="repository" size={16} color={Color.GREY_700} />
              <Text
                data-testid={`${repoEntity.folderPath}${repoEntity.entityGitPath}`}
                font={FontVariation.SMALL}
                style={{ wordWrap: breakWord, maxWidth: '200px' }}
                lineClamp={1}
                color={Color.GREY_800}
              >
                {getEntityUrl(repoEntity)}
              </Text>
            </Layout.Horizontal>
          </Layout.Vertical>
        )}
 
        <Layout.Vertical spacing="large">
          <Text font={{ size: 'small' }} color={Color.GREY_400}>
            {getString('pipelineSteps.deploy.inputSet.branch')}
          </Text>
          <Layout.Horizontal spacing="small" style={{ alignItems: 'center' }}>
            {identifier === DefaultNewPipelineId || isReadonly ? (
              <>
                <Icon name="git-new-branch" size={14} color={Color.GREY_700} />
                <Text
                  font={FontVariation.SMALL}
                  style={{ wordWrap: breakWord, maxWidth: '200px' }}
                  lineClamp={1}
                  color={Color.GREY_800}
                >
                  {gitDetails?.branch}
                </Text>
              </>
            ) : (
              <>
                <Icon name="git-new-branch" size={14} color={Color.GREY_700} />
                <GitFilters
                  onChange={onGitBranchChange}
                  showRepoSelector={false}
                  defaultValue={{ repo: defaultTo(repoIdentifier, ''), branch, getDefaultFromOtherRepo: true }}
                  showBranchIcon={false}
                  shouldAllowBranchSync={false}
                  getDisabledOptionTitleText={getDisabledOptionTitleText}
                />
              </>
            )}
          </Layout.Horizontal>
        </Layout.Vertical>
      </>
    )
  } else {
    return <></>
  }
}
 
export function StudioGitPopover(props: StudioGitPopoverProps): JSX.Element {
  return <GitPopover data={props.gitDetails} customUI={<GitDetails {...props} />} />
}
 
export default StudioGitPopover