All files / modules/75-cf/pages/feature-flags SelectFlagGitRepoPage.tsx

82.61% Statements 19/23
100% Branches 0/0
20% Functions 1/5
82.61% Lines 19/23

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              1x 1x 1x 1x   1x 1x 1x 1x 1x 1x 1x 1x           1x 2x 2x 2x 2x   2x                                                                                                         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, { ReactElement, useState } from 'react'
import { useParams } from 'react-router-dom'
import { Text, Container, Icon } from '@wings-software/uicore'
import { FontVariation, Color } from '@harness/design-system'
import type { ProjectPathProps, ModulePathParams } from '@common/interfaces/RouteInterfaces'
import RbacButton from '@rbac/components/Button/Button'
import { PermissionIdentifier } from '@rbac/interfaces/PermissionIdentifier'
import { ResourceType } from '@rbac/interfaces/ResourceType'
import { useStrings } from 'framework/strings'
import { GitSyncStoreProvider } from 'framework/GitRepoStore/GitSyncStoreContext'
import SaveFlagRepoDialog from '@cf/components/SaveFlagRepoDialog/SaveFlagRepoDialog'
import CreateNewFlagRepoDialog from '@cf/components/CreateNewFlagRepoDialog/CreateNewFlagRepoDialog'
import css from './SelectFlagGitRepoPage.module.scss'
 
interface SelectFlagGitRepoPageProps {
  gitRepoRefetch: () => void
}
 
const SelectFlagGitRepoPage = ({ gitRepoRefetch }: SelectFlagGitRepoPageProps): ReactElement => {
  const { projectIdentifier } = useParams<ProjectPathProps & ModulePathParams>()
  const [isExistingRepoModalOpen, setIsExistingRepoModalOpen] = useState(false)
  const [isCreateNewRepoModalOpen, setIsCreateNewRepoModalOpen] = useState(false)
  const { getString } = useStrings()
 
  return (
    <GitSyncStoreProvider>
      <Container className={css.pageContainer}>
        <Container className={css.pageContent}>
          <Icon size={120} name="git-landing-page" />
          <Text margin="medium" color={Color.GREY_600} font={{ variation: FontVariation.H2 }}>
            {getString('cf.selectFlagRepo.introText')}
          </Text>
          <RbacButton
            intent="primary"
            margin="large"
            font={{ size: 'medium' }}
            text={getString('cf.selectFlagRepo.useExistingRepo')}
            onClick={() => setIsExistingRepoModalOpen(true)}
            permission={{
              permission: PermissionIdentifier.UPDATE_PROJECT,
              resource: {
                resourceType: ResourceType.PROJECT,
                resourceIdentifier: projectIdentifier
              }
            }}
          />
          <RbacButton
            intent="none"
            margin="large"
            font={{ size: 'medium' }}
            text={getString('cf.selectFlagRepo.newRepo')}
            onClick={() => setIsCreateNewRepoModalOpen(true)}
            permission={{
              permission: PermissionIdentifier.UPDATE_PROJECT,
              resource: {
                resourceType: ResourceType.PROJECT,
                resourceIdentifier: projectIdentifier
              }
            }}
          />
          <CreateNewFlagRepoDialog
            isOpen={isCreateNewRepoModalOpen}
            closeModal={() => setIsCreateNewRepoModalOpen(false)}
            gitRepoRefetch={gitRepoRefetch}
          />
 
          <SaveFlagRepoDialog
            isOpen={isExistingRepoModalOpen}
            closeModal={() => setIsExistingRepoModalOpen(false)}
            gitRepoRefetch={gitRepoRefetch}
          />
        </Container>
      </Container>
    </GitSyncStoreProvider>
  )
}
 
export default SelectFlagGitRepoPage