|
| 1 | +import { useEffect, useRef } from 'react' |
| 2 | +import dayjs from 'dayjs' |
| 3 | + |
| 4 | +import { useTranslation } from 'components/hooks/useTranslation' |
| 5 | +import { PatchNotes } from './PatchNotes' |
| 6 | +import { Link } from 'components/Link' |
| 7 | +import { CurrentVersion, ReleaseNotePatch, GHESMessage } from './types' |
| 8 | +import { useOnScreen } from 'components/hooks/useOnScreen' |
| 9 | + |
| 10 | +type Props = { |
| 11 | + patch: ReleaseNotePatch |
| 12 | + currentVersion: CurrentVersion |
| 13 | + latestPatch: string |
| 14 | + latestRelease: string |
| 15 | + message: GHESMessage |
| 16 | + didEnterView: () => void |
| 17 | +} |
| 18 | +export function GHESReleaseNotePatch({ |
| 19 | + patch, |
| 20 | + currentVersion, |
| 21 | + latestPatch, |
| 22 | + latestRelease, |
| 23 | + message, |
| 24 | + didEnterView, |
| 25 | +}: Props) { |
| 26 | + const { t } = useTranslation('header') |
| 27 | + const containerRef = useRef<HTMLDivElement>(null) |
| 28 | + const onScreen = useOnScreen(containerRef, '-40% 0px -50%') |
| 29 | + useEffect(() => { |
| 30 | + if (onScreen) { |
| 31 | + didEnterView() |
| 32 | + } |
| 33 | + }, [onScreen]) |
| 34 | + |
| 35 | + return ( |
| 36 | + <div |
| 37 | + ref={containerRef} |
| 38 | + className="mb-10 color-bg-secondary pb-6 border-bottom border-top" |
| 39 | + id={patch.version} |
| 40 | + > |
| 41 | + <header |
| 42 | + style={{ zIndex: 1 }} |
| 43 | + className="container-xl position-sticky top-0 color-bg-secondary border-bottom px-3 pt-4 pb-2" |
| 44 | + > |
| 45 | + <div className="d-flex flex-items-center"> |
| 46 | + <h2 className="border-bottom-0 m-0 p-0"> |
| 47 | + {currentVersion.versionTitle}.{patch.patchVersion} |
| 48 | + </h2> |
| 49 | + |
| 50 | + {patch.release_candidate && ( |
| 51 | + <span |
| 52 | + className="IssueLabel color-bg-warning-inverse color-text-inverse ml-3" |
| 53 | + style={{ whiteSpace: 'pre' }} |
| 54 | + > |
| 55 | + Release Candidate |
| 56 | + </span> |
| 57 | + )} |
| 58 | + |
| 59 | + {currentVersion.plan == 'enterprise-server' && ( |
| 60 | + <Link |
| 61 | + href={`https://enterprise.github.com/releases/${patch.downloadVersion}/download`} |
| 62 | + className="ml-3 text-small text-bold" |
| 63 | + > |
| 64 | + Download |
| 65 | + </Link> |
| 66 | + )} |
| 67 | + |
| 68 | + <button className="js-print btn-link ml-3 text-small text-bold">Print</button> |
| 69 | + </div> |
| 70 | + |
| 71 | + <p className="color-text-secondary mt-1">{dayjs(patch.date).format('MMMM, DD, YYYY')}</p> |
| 72 | + |
| 73 | + {patch.version !== latestPatch && currentVersion.currentRelease === latestRelease && ( |
| 74 | + <p className="color-text-secondary mt-1"> |
| 75 | + <span |
| 76 | + dangerouslySetInnerHTML={{ __html: message.ghes_release_notes_upgrade_patch_only }} |
| 77 | + />{' '} |
| 78 | + {t('notices.release_notes_use_latest')} |
| 79 | + </p> |
| 80 | + )} |
| 81 | + |
| 82 | + {patch.version === latestPatch && currentVersion.currentRelease !== latestRelease && ( |
| 83 | + <p className="color-text-secondary mt-1"> |
| 84 | + <span |
| 85 | + dangerouslySetInnerHTML={{ __html: message.ghes_release_notes_upgrade_release_only }} |
| 86 | + />{' '} |
| 87 | + {t('notices.release_notes_use_latest')} |
| 88 | + </p> |
| 89 | + )} |
| 90 | + |
| 91 | + {patch.version !== latestPatch && currentVersion.currentRelease !== latestRelease && ( |
| 92 | + <p className="color-text-secondary mt-1"> |
| 93 | + <span |
| 94 | + dangerouslySetInnerHTML={{ |
| 95 | + __html: message.ghes_release_notes_upgrade_patch_and_release, |
| 96 | + }} |
| 97 | + />{' '} |
| 98 | + {t('notices.release_notes_use_latest')} |
| 99 | + </p> |
| 100 | + )} |
| 101 | + </header> |
| 102 | + |
| 103 | + <div className="container-xl px-3"> |
| 104 | + <div className="mt-3" dangerouslySetInnerHTML={{ __html: patch.intro }} /> |
| 105 | + |
| 106 | + <PatchNotes patch={patch} withReleaseNoteLabel /> |
| 107 | + </div> |
| 108 | + </div> |
| 109 | + ) |
| 110 | +} |
0 commit comments