Skip to content

Commit

Permalink
Merge branch 'main' into kh-enable_jsx_a11y_linter
Browse files Browse the repository at this point in the history
  • Loading branch information
khiga8 authored Jun 10, 2021
2 parents 982b8bf + 346b38d commit a28fb1a
Show file tree
Hide file tree
Showing 40 changed files with 1,841 additions and 1,063 deletions.
2 changes: 1 addition & 1 deletion components/DefaultLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const DefaultLayout = (props: Props) => {
</Head>
<SidebarNav />

<main className="width-full">
<main className="flex-1 min-width-0">
<Header />
<DeprecationBanner />

Expand Down
3 changes: 2 additions & 1 deletion components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ export const Header = () => {
const showVersionPicker =
relativePath === 'index.md' ||
currentLayoutName === 'product-landing' ||
currentLayoutName === 'product-sublanding'
currentLayoutName === 'product-sublanding' ||
currentLayoutName === 'release-notes'

return (
<div className="border-bottom color-border-secondary no-print">
Expand Down
1 change: 1 addition & 0 deletions components/HeaderNotifications.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export const HeaderNotifications = () => {
const isLast = i === allNotifications.length - 1
return (
<div
key={content}
className={cx(
'header-notifications text-center f5 color-text-primary py-4 px-6',
type === NotificationType.TRANSLATION && 'translation_notice color-bg-info',
Expand Down
2 changes: 2 additions & 0 deletions components/context/MainContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ type EnterpriseServerReleases = {
isOldestReleaseDeprecated: boolean
oldestSupported: string
nextDeprecationDate: string
supported: Array<string>
}
export type MainContextT = {
breadcrumbs: {
Expand Down Expand Up @@ -154,6 +155,7 @@ export const getMainContextFromRequest = (req: any): MainContextT => {
'isOldestReleaseDeprecated',
'oldestSupported',
'nextDeprecationDate',
'supported',
]),
enterpriseServerVersions: req.context.enterpriseServerVersions,
currentLanguage: req.context.currentLanguage,
Expand Down
7 changes: 7 additions & 0 deletions components/context/ProductLandingContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ export type ProductLandingContextT = {
changelogUrl?: string
whatsNewChangelog?: Array<{ href: string; title: string; date: string }>
tocItems: Array<TocItem>
releases: Array<{
version: string
firstPreviousRelease: string
secondPreviousRelease: string
patches: Array<{ date: string; version: string }>
}>
}

export const ProductLandingContext = createContext<ProductLandingContextT | null>(null)
Expand Down Expand Up @@ -89,6 +95,7 @@ export const getProductLandingContextFromRequest = (req: any): ProductLandingCon
changelogUrl: req.context.changelogUrl || [],
productCodeExamples: req.context.productCodeExamples || [],
productCommunityExamples: req.context.productCommunityExamples || [],
releases: req.context.releases || [],

productUserExamples: (req.context.productUserExamples || []).map(
({ user, description }: any) => ({
Expand Down
25 changes: 25 additions & 0 deletions components/hooks/useOnScreen.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { useState, useEffect, MutableRefObject, RefObject } from 'react'

export function useOnScreen<T extends Element>(
ref: MutableRefObject<T | undefined> | RefObject<T>,
rootMargin: string = '0px'
): boolean {
const [isIntersecting, setIntersecting] = useState(false)
useEffect(() => {
const observer = new IntersectionObserver(
([entry]) => {
setIntersecting(entry.isIntersecting)
},
{
rootMargin,
}
)
if (ref.current) {
observer.observe(ref.current)
}
return () => {
ref.current && observer.unobserve(ref.current)
}
}, [])
return isIntersecting
}
7 changes: 6 additions & 1 deletion components/hooks/useVersion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@ import { useRouter } from 'next/router'
type VersionInfo = {
currentVersion: string
isEnterprise: boolean
isEnterpriseServer: boolean
}
const DEFAULT_VERSION = 'free-pro-team@latest'
export const useVersion = (): VersionInfo => {
const router = useRouter()
const currentVersion = (router.query.versionId as string) || DEFAULT_VERSION
return { currentVersion, isEnterprise: currentVersion.includes('enterprise') }
return {
currentVersion,
isEnterprise: currentVersion.includes('enterprise'),
isEnterpriseServer: currentVersion.includes('enterprise-server'),
}
}
13 changes: 10 additions & 3 deletions components/landing/ProductLanding.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,13 @@ import { CodeExamples } from 'components/landing/CodeExamples'
import { LandingSection } from 'components/landing/LandingSection'
import { useTranslation } from 'components/hooks/useTranslation'
import { ProductArticlesList } from 'components/landing/ProductArticlesList'
import { ProductReleases } from 'components/landing/ProductReleases'
import { useRouter } from 'next/router'
import { useVersion } from 'components/hooks/useVersion'

export const ProductLanding = () => {
const router = useRouter()
const { isEnterpriseServer } = useVersion()
const {
shortTitle,
guideCards,
Expand Down Expand Up @@ -49,9 +54,11 @@ export const ProductLanding = () => {
</LandingSection>
)}

{/* {% if currentVersion contains 'enterprise-server' and currentProduct == 'admin' %}
{% include product-releases %}
{% endif %} */}
{router.query.productId === 'admin' && isEnterpriseServer && (
<LandingSection title={t('supported_releases')} className="my-6">
<ProductReleases />
</LandingSection>
)}

{guideCards.length > 0 && (
<div className="color-bg-tertiary py-6 my-8">
Expand Down
68 changes: 68 additions & 0 deletions components/landing/ProductReleases.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { ArrowRightIcon, ArrowUpIcon, FileIcon, ListUnorderedIcon } from '@primer/octicons-react'
import { useMainContext } from 'components/context/MainContext'
import { useProductLandingContext } from 'components/context/ProductLandingContext'
import { useTranslation } from 'components/hooks/useTranslation'
import { Link } from 'components/Link'
import { useRouter } from 'next/router'

export function ProductReleases() {
const { t } = useTranslation('product_landing')
const router = useRouter()
const { enterpriseServerReleases, allVersions } = useMainContext()
const { releases } = useProductLandingContext()
const currentPath = router.asPath.split('?')[0]
return (
<div>
<div className="d-lg-flex gutter-lg flex-items-stretch">
{releases.map((release) => {
const releaseNumber = release.version
if (!enterpriseServerReleases.supported.includes(releaseNumber)) {
return null
}
const releaseVersion = `enterprise-server@${releaseNumber}`
const latestPatch = release.patches[0]
const firstPreviousVersion = `enterprise-server@${release.firstPreviousRelease}`
const secondPreviousVersion = `enterprise-server@${release.secondPreviousRelease}`
return (
<div key={releaseNumber} className="col-lg-4 col-12 mb-3">
<div className="Box color-shadow-medium height-full d-block hover-shadow-large no-underline color-text-primary p-5">
<h2>{allVersions[releaseVersion].versionTitle}</h2>
<p className="mt-2 mb-4 color-text-tertiary">
<ListUnorderedIcon />{' '}
<Link
href={`/${router.locale}/${releaseVersion}/admin/release-notes#${latestPatch.version}`}
>
{t('release_notes_for')} {latestPatch.version}
</Link>{' '}
({latestPatch.date})
</p>
<p className="mt-2 mb-4 color-text-tertiary">
<ArrowUpIcon /> {t('upgrade_from')}{' '}
<Link
href={`/${router.locale}/${firstPreviousVersion}/admin/enterprise-management/upgrading-github-enterprise-server`}
>
{release.firstPreviousRelease}
</Link>{' '}
or{' '}
<Link
href={`/${router.locale}/${secondPreviousVersion}/admin/enterprise-management/upgrading-github-enterprise-server`}
>
{release.secondPreviousRelease}
</Link>
</p>
<p className="mt-2 mb-4 color-text-tertiary">
<FileIcon />{' '}
<Link href={`/${router.locale}/${releaseVersion}`}>{t('browse_all_docs')}</Link>
</p>
</div>
</div>
)
})}
</div>

<Link href={`${currentPath}/release-notes}`} className="btn btn-outline float-right">
{t('explore_release_notes')} <ArrowRightIcon />
</Link>
</div>
)
}
59 changes: 59 additions & 0 deletions components/release-notes/GHAEReleaseNotePatch.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { useRef, useEffect } from 'react'

import { useTranslation } from 'components/hooks/useTranslation'
import { useOnScreen } from 'components/hooks/useOnScreen'
import { PatchNotes } from './PatchNotes'
import { ReleaseNotePatch } from './types'

type Props = { patch: ReleaseNotePatch; didEnterView: () => void }
export function GHAEReleaseNotePatch({ patch, didEnterView }: Props) {
const { t } = useTranslation('release_notes')
const containerRef = useRef<HTMLDivElement>(null)
const onScreen = useOnScreen(containerRef, '-40% 0px -50%')
useEffect(() => {
if (onScreen) {
didEnterView()
}
}, [onScreen])

const bannerText = patch.currentWeek
? t('banner_text_current')
: `${t('banner_text_past')} ${patch.friendlyDate}.`

return (
<div
ref={containerRef}
className="mb-10 color-bg-secondary pb-6 border-bottom border-top"
id={patch.date}
>
<header
style={{ zIndex: 1 }}
className="container-xl position-sticky top-0 color-bg-secondary border-bottom px-3 pt-4 pb-2"
>
<div className="d-flex flex-items-center">
<h2 className="border-bottom-0 m-0 p-0">{patch.title}</h2>

{patch.release_candidate && (
<span
className="IssueLabel color-bg-warning-inverse color-text-inverse ml-3"
style={{ whiteSpace: 'pre' }}
>
Release Candidate
</span>
)}

<button className="js-print btn-link ml-3 text-small text-bold">Print</button>
</div>
<p className="color-text-secondary mt-1">
{patch.friendlyDate} - {bannerText}
</p>
</header>

<div className="container-xl px-3">
<div className="mt-3" dangerouslySetInnerHTML={{ __html: patch.intro }} />

<PatchNotes patch={patch} />
</div>
</div>
)
}
89 changes: 89 additions & 0 deletions components/release-notes/GHAEReleaseNotes.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import { useState } from 'react'
import cx from 'classnames'
import { ChevronDownIcon } from '@primer/octicons-react'
import { GHAEReleaseNotePatch } from './GHAEReleaseNotePatch'
import { GHAEReleaseNotesContextT } from './types'

type GitHubAEProps = {
context: GHAEReleaseNotesContextT
}
export function GHAEReleaseNotes({ context }: GitHubAEProps) {
const { releaseNotes, releases, currentVersion } = context
const [focusedPatch, setFocusedPatch] = useState('')

return (
<div className="d-flex">
<article className="min-width-0 flex-1">
<div className="d-flex flex-items-center flex-justify-between color-bg-primary px-5 py-2">
<div></div>
<h1 className="f4 py-3 m-0">{currentVersion.planTitle} release notes</h1>
<div></div>
</div>

<div className="markdown-body">
{releaseNotes.map((patch) => {
return (
<GHAEReleaseNotePatch
key={patch.version}
patch={patch}
didEnterView={() => setFocusedPatch(patch.version)}
/>
)
})}
</div>
</article>

<aside
className="markdown-body position-sticky top-0 d-none d-md-block border-left no-print color-bg-primary flex-shrink-0"
style={{ width: 260, height: '100vh' }}
>
<nav className="height-full overflow-auto">
<ul className="list-style-none pl-0 text-bold">
{releases.map((release) => {
return (
<li key={release.version} className="border-bottom">
<details
className="my-0 details-reset release-notes-version-picker"
aria-current="page"
open
>
<summary className="px-3 py-4 my-0 d-flex flex-items-center flex-justify-between">
{release.version}
<div className="d-flex">
<span className="color-text-tertiary text-mono text-small text-normal mr-1">
{release.patches.length} releases
</span>
<ChevronDownIcon />
</div>
</summary>
<ul className="color-bg-tertiary border-top list-style-none py-4 px-0 my-0">
{release.patches.map((patch) => {
const isActive = patch.version === focusedPatch
return (
<li
key={patch.version}
className={cx(
'js-release-notes-patch-link px-3 my-0 py-1',
isActive && 'selected'
)}
>
<a
href={`#${patch.date}`}
className="d-flex flex-items-center flex-justify-between"
>
{patch.friendlyDate}
</a>
</li>
)
})}
</ul>
</details>
</li>
)
})}
</ul>
</nav>
</aside>
</div>
)
}
Loading

0 comments on commit a28fb1a

Please sign in to comment.