MCPcopy
hub / github.com/github/docs / RestBanner

Function RestBanner

components/page-header/RestBanner.tsx:35–140  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

33}
34
35export const RestBanner = () => {
36 const router = useRouter()
37 const { t } = useTranslation('products')
38 // Having a productId === 'rest' and no router.query.category would mean a product landing page like http://docs.github.com/en/rest?apiVersion=2022-08-09
39 const isRestPage = router.query.productId === 'rest' || router.query.category
40 const restPage = router.query.category as string
41 const { currentVersion } = useVersion()
42 const { allVersions } = useMainContext()
43 const currentVersionObj = allVersions[currentVersion]
44 const apiVersions = currentVersionObj.apiVersions
45
46 let bannerText = ''
47 let versionWithApiVersion = ''
48
49 if (isRestPage && apiVersions.length) {
50 bannerText = t('rest.banner.api_versioned')
51 versionWithApiVersion = currentVersion
52 } else {
53 if (currentVersionObj.shortName === 'ghes') {
54 // If this is a GHES release with no REST versions,
55 // find out if any GHES releases contain REST versioning yet.
56 const firstGhesReleaseWithApiVersions = Object.values(allVersions)
57 .reverse()
58 .find((v) => {
59 return v.shortName === 'ghes' && v.apiVersions.length
60 })
61
62 if (firstGhesReleaseWithApiVersions) {
63 versionWithApiVersion = firstGhesReleaseWithApiVersions.version
64 bannerText = t('rest.banner.ghes_api_versioned')
65 .replace(
66 '{{ firstGhesReleaseWithApiVersions.versionTitle }}',
67 firstGhesReleaseWithApiVersions.versionTitle
68 )
69 .replace(/{{\s*currentVersion\s*}}/, currentVersion)
70 }
71 }
72 }
73 // Temporary banner for REST API Versioning
74 if (isRestPage && bannerText !== '') {
75 return (
76 <div
77 data-testid="rest-api-versioning-temporary-banner"
78 className="container-xl mt-3 mx-auto p-responsive"
79 >
80 <Flash>
81 <span dangerouslySetInnerHTML={{ __html: bannerText }} />{' '}
82 <span
83 dangerouslySetInnerHTML={{
84 __html: t('rest.banner.api_version_info').replace(
85 /{{\s*versionWithApiVersion\s*}}/,
86 versionWithApiVersion === DEFAULT_VERSION ? '' : `/${versionWithApiVersion}`
87 ),
88 }}
89 />
90 </Flash>
91 </div>
92 )

Callers

nothing calls this directly

Calls 3

useTranslationFunction · 0.90
useVersionFunction · 0.90
useMainContextFunction · 0.90

Tested by

no test coverage detected