|
| 1 | +import { Flash } from '@primer/components' |
| 2 | +import { useRouter } from 'next/router' |
| 3 | +import { Link } from 'components/Link' |
| 4 | +const restDisplayPages = [ |
| 5 | + '/rest/reference/branches', |
| 6 | + '/rest/reference/collaborators', |
| 7 | + '/rest/reference/commits', |
| 8 | + '/rest/reference/deployments', |
| 9 | + '/rest/reference/pages', |
| 10 | + '/rest/reference/repos', |
| 11 | + '/rest/reference/repository-metrics', |
| 12 | + '/rest/reference/webhooks', |
| 13 | +] |
| 14 | +const restRepoCategoryExceptions = [ |
| 15 | + 'Branches', |
| 16 | + 'Collaborators', |
| 17 | + 'Commits', |
| 18 | + 'Deployments', |
| 19 | + 'Github Pages', |
| 20 | + 'Repository metrics', |
| 21 | + 'Webhooks', |
| 22 | +] |
| 23 | + |
| 24 | +export const RestRepoBanner = () => { |
| 25 | + const router = useRouter() |
| 26 | + const asPathRoot = router.asPath.split('?')[0].split('#')[0] |
| 27 | + if (!restDisplayPages.includes(asPathRoot)) { |
| 28 | + return null |
| 29 | + } |
| 30 | + |
| 31 | + const newRestPagesText = restRepoCategoryExceptions.map((page, i) => [ |
| 32 | + <Link href={`/rest/references/${page}`}> |
| 33 | + {page} |
| 34 | + {i < restRepoCategoryExceptions.length - 1 && ', '} |
| 35 | + </Link>, |
| 36 | + ]) |
| 37 | + |
| 38 | + return ( |
| 39 | + <div data-testid="rest-api-repos-banner" className="container-xl mt-3 mx-auto p-responsive"> |
| 40 | + <Flash variant="warning"> |
| 41 | + <p> |
| 42 | + <b className="text-bold"> |
| 43 | + <span> |
| 44 | + We've recently moved some of the REST API documentation. If you can't find what you're |
| 45 | + looking for, you might try the new {newRestPagesText} REST API pages. |
| 46 | + </span> |
| 47 | + </b>{' '} |
| 48 | + </p> |
| 49 | + </Flash> |
| 50 | + </div> |
| 51 | + ) |
| 52 | +} |
0 commit comments