All files / modules/35-user-profile/components/UserSummary MyProjectsList.tsx

93.33% Statements 14/15
53.85% Branches 28/52
66.67% Functions 2/3
93.33% Lines 14/15

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              1x 1x 1x 1x   1x 1x 1x   1x 14x 14x             14x               14x                         24x                                                                               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 React from 'react'
import { useParams } from 'react-router-dom'
import { Text, Layout, Card, Icon, Container, Tag, PageError } from '@wings-software/uicore'
import { Color } from '@harness/design-system'
import type { AccountPathProps } from '@common/interfaces/RouteInterfaces'
import { useStrings } from 'framework/strings'
import { useGetUserProjectInfo } from 'services/cd-ng'
import css from './UserSummary.module.scss'
 
const MyProjectsList: React.FC = () => {
  const { getString } = useStrings()
  const { accountId } = useParams<AccountPathProps>()
 
  const {
    data: projects,
    loading,
    error,
    refetch
  } = useGetUserProjectInfo({
    queryParams: {
      accountId,
      pageIndex: 0,
      pageSize: 6
    }
  })
 
  return (
    <Layout.Vertical spacing="large" margin={{ bottom: 'medium' }}>
      <Layout.Horizontal flex={{ alignItems: 'center', justifyContent: 'start' }} spacing="medium">
        <Text font={{ size: 'medium', weight: 'semi-bold' }} color={Color.GREY_900}>
          {getString('userProfile.myProjects')}
        </Text>
        {projects?.data?.totalItems ? <Tag className={css.tagClassName}>{projects.data.totalItems}</Tag> : null}
      </Layout.Horizontal>
      {loading ? (
        <Text color={Color.GREY_600}>{getString('common.loading')}</Text>
      ) : projects?.data?.content?.length ? (
        <Container className={css.cardContainer}>
          {projects.data.content.map(project => {
            return (
              <Card key={`${project.identifier}-${project.orgIdentifier}`} className={css.card}>
                <Layout.Vertical flex={{ align: 'center-center' }}>
                  <Icon
                    name="nav-project"
                    size={32}
                    style={{ color: project.color }}
                    color={project.color}
                    margin={{ top: 'xsmall', bottom: 'medium' }}
                  />
                  <Text
                    width={100}
                    lineClamp={3}
                    color={Color.GREY_800}
                    font={{ size: 'small', align: 'center', weight: 'semi-bold' }}
                    className={css.name}
                  >
                    {project.name}
                  </Text>
                </Layout.Vertical>
              </Card>
            )
          })}
          {Number(projects.data.totalItems) > Number(projects.data.content.length) && (
            <Text flex={{ alignItems: 'center' }}>
              {getString('more', {
                number: Number(projects.data.totalItems) - Number(projects.data.content.length)
              })}
            </Text>
          )}
        </Container>
      ) : projects?.data?.content ? (
        <Text color={Color.GREY_700}>{getString('noProjects')}</Text>
      ) : (
        <PageError message={(error?.data as Error)?.message || error?.message} onClick={() => refetch()} />
      )}
    </Layout.Vertical>
  )
}
 
export default MyProjectsList