use plain link to link to unsupported GHES versions (#32204)
This commit is contained in:
@@ -11,10 +11,12 @@ import { GHESReleaseNotesContextT } from './types'
|
|||||||
import { GHESReleaseNotePatch } from './GHESReleaseNotePatch'
|
import { GHESReleaseNotePatch } from './GHESReleaseNotePatch'
|
||||||
|
|
||||||
import styles from './PatchNotes.module.scss'
|
import styles from './PatchNotes.module.scss'
|
||||||
|
import { PlainLink } from './PlainLink'
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
context: GHESReleaseNotesContextT
|
context: GHESReleaseNotesContextT
|
||||||
}
|
}
|
||||||
|
|
||||||
export function GHESReleaseNotes({ context }: Props) {
|
export function GHESReleaseNotes({ context }: Props) {
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const { currentProduct } = useMainContext()
|
const { currentProduct } = useMainContext()
|
||||||
@@ -59,16 +61,24 @@ export function GHESReleaseNotes({ context }: Props) {
|
|||||||
{releases.map((release) => {
|
{releases.map((release) => {
|
||||||
const releaseLink = `/${router.locale}/${currentVersion.plan}@${release.version}/${currentProduct?.id}/release-notes`
|
const releaseLink = `/${router.locale}/${currentVersion.plan}@${release.version}/${currentProduct?.id}/release-notes`
|
||||||
|
|
||||||
|
// Use client-side router link component only if it's a supported release.
|
||||||
|
// Otherwise, it will trigger a NextJS data XHR fetch for releases
|
||||||
|
// that are deprecated when in fact you should load it regularly
|
||||||
|
// so it's read as a proxy from the archive.
|
||||||
|
const LinkComponent = currentVersion.releases.includes(release.version)
|
||||||
|
? Link
|
||||||
|
: PlainLink
|
||||||
|
|
||||||
if (!release.patches || release.patches.length === 0) {
|
if (!release.patches || release.patches.length === 0) {
|
||||||
return (
|
return (
|
||||||
<li key={release.version} className="border-bottom">
|
<li key={release.version} className="border-bottom">
|
||||||
<Link
|
<LinkComponent
|
||||||
href={releaseLink}
|
href={releaseLink}
|
||||||
className="Link--primary no-underline px-3 py-4 my-0 d-flex flex-items-center flex-justify-between"
|
className="Link--primary no-underline px-3 py-4 my-0 d-flex flex-items-center flex-justify-between"
|
||||||
>
|
>
|
||||||
{release.version}
|
{release.version}
|
||||||
<LinkExternalIcon />
|
<LinkExternalIcon />
|
||||||
</Link>
|
</LinkComponent>
|
||||||
</li>
|
</li>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -86,7 +96,7 @@ export function GHESReleaseNotes({ context }: Props) {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<li key={release.version} className="border-bottom">
|
<li key={release.version} className="border-bottom">
|
||||||
<Link
|
<LinkComponent
|
||||||
className="px-3 py-4 my-0 d-flex flex-items-center flex-justify-between"
|
className="px-3 py-4 my-0 d-flex flex-items-center flex-justify-between"
|
||||||
href={releaseLink}
|
href={releaseLink}
|
||||||
>
|
>
|
||||||
@@ -95,7 +105,7 @@ export function GHESReleaseNotes({ context }: Props) {
|
|||||||
{release.patches.length}{' '}
|
{release.patches.length}{' '}
|
||||||
{release.patches.length === 1 ? 'release' : 'releases'}
|
{release.patches.length === 1 ? 'release' : 'releases'}
|
||||||
</span>
|
</span>
|
||||||
</Link>
|
</LinkComponent>
|
||||||
</li>
|
</li>
|
||||||
)
|
)
|
||||||
})}
|
})}
|
||||||
|
|||||||
15
components/release-notes/PlainLink.tsx
Normal file
15
components/release-notes/PlainLink.tsx
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
import type { ReactNode } from 'react'
|
||||||
|
|
||||||
|
type PlainLinkProps = {
|
||||||
|
href: string
|
||||||
|
children: ReactNode
|
||||||
|
className?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export function PlainLink({ href, className, children }: PlainLinkProps) {
|
||||||
|
return (
|
||||||
|
<a href={href} className={className}>
|
||||||
|
{children}
|
||||||
|
</a>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -3,6 +3,7 @@ export type CurrentVersion = {
|
|||||||
planTitle: string
|
planTitle: string
|
||||||
versionTitle: string
|
versionTitle: string
|
||||||
currentRelease: string
|
currentRelease: string
|
||||||
|
releases: string[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export type GHESMessage = {
|
export type GHESMessage = {
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
import { GetServerSideProps } from 'next'
|
import { GetServerSideProps } from 'next'
|
||||||
import { Liquid } from 'liquidjs'
|
import { Liquid } from 'liquidjs'
|
||||||
|
import pick from 'lodash/pick'
|
||||||
|
|
||||||
import { MainContextT, MainContext, getMainContext } from 'components/context/MainContext'
|
import { MainContextT, MainContext, getMainContext } from 'components/context/MainContext'
|
||||||
import { DefaultLayout } from 'components/DefaultLayout'
|
import { DefaultLayout } from 'components/DefaultLayout'
|
||||||
import { GHAEReleaseNotes } from 'components/release-notes/GHAEReleaseNotes'
|
import { GHAEReleaseNotes } from 'components/release-notes/GHAEReleaseNotes'
|
||||||
@@ -27,7 +29,18 @@ export default function ReleaseNotes({ mainContext, ghesContext, ghaeContext }:
|
|||||||
export const getServerSideProps: GetServerSideProps<Props> = async (context) => {
|
export const getServerSideProps: GetServerSideProps<Props> = async (context) => {
|
||||||
const req = context.req as any
|
const req = context.req as any
|
||||||
const res = context.res as any
|
const res = context.res as any
|
||||||
const currentVersion = req.context.allVersions[req.context.currentVersion]
|
|
||||||
|
// The `req.context.allVersion[X]` entries contains more keys (and values)
|
||||||
|
// than we need so only pick out the keys that are actually needed
|
||||||
|
// explicitly in the components served from these props.
|
||||||
|
const currentVersion = pick(req.context.allVersions[req.context.currentVersion], [
|
||||||
|
'plan',
|
||||||
|
'planTitle',
|
||||||
|
'versionTitle',
|
||||||
|
'currentRelease',
|
||||||
|
'releases',
|
||||||
|
])
|
||||||
|
|
||||||
const { latestPatch = '', latestRelease = '' } = req.context
|
const { latestPatch = '', latestRelease = '' } = req.context
|
||||||
return {
|
return {
|
||||||
props: {
|
props: {
|
||||||
|
|||||||
Reference in New Issue
Block a user