All files / modules/40-gitsync/pages/entities EntityHelper.tsx

83.33% Statements 25/30
56.25% Branches 9/16
100% Functions 6/6
81.48% Lines 22/27

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              3x 3x   3x   3x   3x 8x       1x           1x   6x               3x 4x 4x                   3x 4x 4x     3x 4x   4x                 3x 4x                                     3x 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 React from 'react'
import { IconName, Text, Icon, Layout } from '@wings-software/uicore'
import type { CellProps, Renderer, Column } from 'react-table'
import { Color } from '@harness/design-system'
import type { GitSyncEntityListDTO, GitSyncEntityDTO } from 'services/cd-ng'
import { Entities } from '@common/interfaces/GitSyncInterface'
 
export const getEntityIconName = (entityType: string | undefined): IconName => {
  switch (entityType) {
    case Entities.PROJECTS:
      return 'nav-project-selected'
    case Entities.PIPELINES:
      return 'pipeline-ng'
    case Entities.INPUT_SETS:
      return 'yaml-builder-input-sets'
    case Entities.TEMPLATE:
      return 'templates-icon'
    case Entities.FEATURE_FLAGS:
      return 'cf-main'
    case Entities.CONNECTORS:
      return 'connectors-icon'
    case Entities.SECRETS:
      return 'secret-manager'
    default:
      return 'placeholder'
  }
}
 
const RenderEntity: Renderer<CellProps<GitSyncEntityDTO>> = ({ row }) => {
  const data = row.original
  return (
    <Layout.Horizontal>
      <Icon inline name={getEntityIconName(data.entityType)}></Icon>
      <Text padding={{ left: 'small' }} inline lineClamp={1}>
        {data.entityName}
      </Text>
    </Layout.Horizontal>
  )
}
 
const RenderEntityId: Renderer<CellProps<GitSyncEntityDTO>> = ({ row }) => {
  const data = row.original
  return <Text lineClamp={1}>{data.entityIdentifier}</Text>
}
 
const RenderYamlPath: Renderer<CellProps<GitSyncEntityDTO>> = ({ row }) => {
  const data = row.original
 
  return (
    <a href={data?.entityUrl} target="_blank" rel="noopener noreferrer">
      <Text color={Color.PRIMARY_7} lineClamp={1}>
        {data?.entityUrl}
      </Text>
    </a>
  )
}
 
export const getEntityHeaderText = (data: GitSyncEntityListDTO): JSX.Element => {
  return (
    <Layout.Horizontal>
      <Text margin="small" font={{ size: 'medium', weight: 'semi-bold' }} color={Color.GREY_600}>
        {data.entityType}
      </Text>
      <Text
        margin="small"
        padding={{ left: 'small', right: 'small' }}
        border={false}
        font={{ size: 'medium', weight: 'semi-bold' }}
        color={Color.PRIMARY_6}
        background={Color.PRIMARY_1}
      >
        {data.count}
      </Text>
    </Layout.Horizontal>
  )
}
 
export const getTableColumns = (): Column<GitSyncEntityDTO>[] => {
  return [
    {
      Header: 'NAME',
      accessor: 'entityName',
      width: '25%',
      Cell: RenderEntity,
      disableSortBy: false
    },
    {
      Header: 'IDENTIFIER',
      accessor: 'entityIdentifier',
      width: '25%',
      Cell: RenderEntityId,
      disableSortBy: false
    },
    {
      Header: 'PATH',
      accessor: 'entityGitPath',
      width: '50%',
      Cell: RenderYamlPath,
      disableSortBy: false
    }
  ]
}