All files / modules/45-projects-orgs/components/ModuleListCard ModuleListCard.tsx

69.23% Statements 18/26
28.57% Branches 2/7
33.33% Functions 1/3
68% Lines 17/25

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              17x 17x 17x 17x 17x 17x 17x   17x 17x 17x               17x                                                                 17x 25x 25x   25x   25x                                                     17x  
/*
 * 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 { Card, Container, Icon, Layout, Text } from '@wings-software/uicore'
import { useHistory } from 'react-router-dom'
import { Color } from '@harness/design-system'
import { getModuleIcon } from '@common/utils/utils'
import { getModulePurpose, getModuleTitle } from '@projects-orgs/utils/utils'
import { useStrings } from 'framework/strings'
 
import { ModuleName } from 'framework/types/ModuleName'
import routes from '@common/RouteDefinitions'
import css from './ModuleListCard.module.scss'
 
export interface ModuleListCardProps {
  module: ModuleName
  orgIdentifier: string
  projectIdentifier: string
  accountId: string
}
export const getModuleLink = ({ accountId, orgIdentifier, projectIdentifier, module }: ModuleListCardProps): string => {
  switch (module) {
    case ModuleName.CD:
      return routes.toProjectOverview({
        projectIdentifier,
        orgIdentifier,
        accountId,
        module: 'cd'
      })
    case ModuleName.CI:
      return routes.toProjectOverview({
        projectIdentifier,
        orgIdentifier,
        accountId,
        module: 'ci'
      })
    case ModuleName.CV:
      return routes.toCVMonitoringServices({
        projectIdentifier,
        orgIdentifier,
        accountId
      })
    case ModuleName.CF:
      return routes.toCFFeatureFlags({
        projectIdentifier,
        orgIdentifier,
        accountId
      })
    case ModuleName.CE:
      return routes.toCEOverview({ accountId })
  }
  return ''
}
const ModuleListCard: React.FC<ModuleListCardProps> = ({ module, accountId, orgIdentifier, projectIdentifier }) => {
  const { getString } = useStrings()
  const history = useHistory()
 
  const purpose = getModulePurpose(module)
 
  return (
    <>
      <Card
        className={css.card}
        interactive
        onClick={() => history.push(getModuleLink({ module, accountId, orgIdentifier, projectIdentifier }))}
      >
        <Layout.Horizontal>
          <Container width="100%" flex border={{ right: true, color: Color.WHITE }}>
            <Layout.Horizontal flex spacing="large">
              <Icon name={getModuleIcon(module)} size={70}></Icon>
              <div>
                <Layout.Vertical padding={{ bottom: 'medium' }}>
                  <Text font={{ size: 'small' }}>{getString(getModuleTitle(module)).toUpperCase()}</Text>
                  <Text font={{ size: 'medium' }} color={Color.BLACK}>
                    {purpose && getString(purpose)}
                  </Text>
                </Layout.Vertical>
              </div>
            </Layout.Horizontal>
          </Container>
        </Layout.Horizontal>
      </Card>
    </>
  )
}
 
export default ModuleListCard