All files / modules/20-rbac/pages/AccessControl AccessControlPage.tsx

100% Statements 19/19
83.33% Branches 5/6
100% Functions 4/4
100% Lines 18/18

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              10x 10x 10x 10x 10x 10x 10x   10x               10x 2x 2x 2x   2x                                                       2x 10x     2x           10x               10x  
/*
 * 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 { TabNavigation } from '@wings-software/uicore'
import { useParams, useLocation, matchPath } from 'react-router-dom'
import { NGBreadcrumbs } from '@common/components/NGBreadcrumbs/NGBreadcrumbs'
import { Page } from '@common/exports'
import { useStrings } from 'framework/strings'
import routes from '@common/RouteDefinitions'
import type { ProjectPathProps, PipelineType } from '@common/interfaces/RouteInterfaces'
import ScopedTitle from '@common/components/Title/ScopedTitle'
 
interface AccessControlLink {
  label: string
  to: string
  title: string
}
 
const AccessControlPage: React.FC = ({ children }) => {
  const { accountId, orgIdentifier, projectIdentifier, module } = useParams<PipelineType<ProjectPathProps>>()
  const { getString } = useStrings()
  const { pathname } = useLocation()
 
  const accessControlLinks: AccessControlLink[] = [
    {
      label: getString('users'),
      to: routes.toUsers({ accountId, orgIdentifier, projectIdentifier, module }),
      title: getString('rbac.accessControlTitle.users')
    },
    {
      label: getString('common.userGroups'),
      to: routes.toUserGroups({ accountId, orgIdentifier, projectIdentifier, module }),
      title: getString('rbac.accessControlTitle.userGroups')
    },
    {
      label: getString('rbac.serviceAccounts.label'),
      to: routes.toServiceAccounts({ accountId, orgIdentifier, projectIdentifier, module }),
      title: getString('rbac.accessControlTitle.serviceAccounts')
    },
    {
      label: getString('resourceGroups'),
      to: routes.toResourceGroups({ accountId, orgIdentifier, projectIdentifier, module }),
      title: getString('rbac.accessControlTitle.resourceGroups')
    },
    {
      label: getString('roles'),
      to: routes.toRoles({ accountId, orgIdentifier, projectIdentifier, module }),
      title: getString('rbac.accessControlTitle.roles')
    }
  ]
 
  const getScopedTitle = (): string => {
    return accessControlLinks.find(nav => matchPath(pathname, nav.to))?.title || getString('accessControl')
  }
 
  return (
    <>
      <Page.Header
        breadcrumbs={<NGBreadcrumbs />}
        title={<ScopedTitle title={getScopedTitle()} />}
        toolbar={
          <TabNavigation size={'small'} links={accessControlLinks.map(link => ({ label: link.label, to: link.to }))} />
        }
      />
      <Page.Body>{children}</Page.Body>
    </>
  )
}
 
export default AccessControlPage