2021-08-18 00:07:46 +03:00
|
|
|
import { Fragment } from 'react'
|
2021-06-09 23:44:32 +03:00
|
|
|
import cx from 'classnames'
|
|
|
|
import slugger from 'github-slugger'
|
|
|
|
import { ReleaseNotePatch } from './types'
|
|
|
|
import { Link } from 'components/Link'
|
|
|
|
|
2021-08-16 17:10:58 +03:00
|
|
|
import styles from './PatchNotes.module.scss'
|
|
|
|
|
2021-06-09 23:44:32 +03:00
|
|
|
const SectionToLabelMap: Record<string, string> = {
|
|
|
|
features: 'Features',
|
|
|
|
bugs: 'Bug fixes',
|
|
|
|
known_issues: 'Known issues',
|
|
|
|
security_fixes: 'Security fixes',
|
|
|
|
changes: 'Changes',
|
|
|
|
deprecations: 'Deprecations',
|
|
|
|
backups: 'Backups',
|
|
|
|
}
|
|
|
|
|
2021-08-16 17:10:58 +03:00
|
|
|
const ColorMap = {
|
|
|
|
features: 'var(--color-auto-green-5)',
|
|
|
|
bugs: 'var(--color-auto-yellow-5)',
|
|
|
|
known_issues: 'var(--color-auto-blue-5)',
|
|
|
|
security_fixes: 'var(--color-auto-pink-5)',
|
|
|
|
changes: 'var(--color-auto-green-5)',
|
|
|
|
deprecations: 'var(--color-auto-purple-5)',
|
|
|
|
backups: 'var(--color-auto-orange-5)',
|
|
|
|
}
|
|
|
|
|
2021-06-09 23:44:32 +03:00
|
|
|
type Props = {
|
|
|
|
patch: ReleaseNotePatch
|
|
|
|
withReleaseNoteLabel?: boolean
|
|
|
|
}
|
|
|
|
export function PatchNotes({ patch, withReleaseNoteLabel }: Props) {
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
{Object.entries(patch.sections).map(([key, sectionItems], i, arr) => {
|
|
|
|
const isLast = i === arr.length - 1
|
2021-08-16 17:10:58 +03:00
|
|
|
const primaryColor = ColorMap[key as keyof typeof ColorMap] || ColorMap.features
|
2021-06-09 23:44:32 +03:00
|
|
|
return (
|
|
|
|
<div
|
|
|
|
key={key}
|
|
|
|
className={cx(
|
|
|
|
'py-6 d-block d-xl-flex gutter-xl flex-items-baseline',
|
|
|
|
!withReleaseNoteLabel && 'mx-6',
|
|
|
|
!isLast && 'border-bottom'
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
{withReleaseNoteLabel && (
|
|
|
|
<div className="col-12 col-xl-3 mb-5">
|
2021-08-16 17:10:58 +03:00
|
|
|
<span
|
|
|
|
className="px-3 py-2 text-small text-bold text-uppercase text-mono color-text-inverse"
|
|
|
|
style={{ backgroundColor: primaryColor }}
|
|
|
|
>
|
2021-06-09 23:44:32 +03:00
|
|
|
{SectionToLabelMap[key] || 'INVALID SECTION'}
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
)}
|
2021-08-16 17:10:58 +03:00
|
|
|
<ul className={cx(withReleaseNoteLabel && 'col-xl-9', 'col-12')}>
|
2021-06-09 23:44:32 +03:00
|
|
|
{sectionItems.map((item) => {
|
|
|
|
if (typeof item === 'string') {
|
2021-08-16 17:10:58 +03:00
|
|
|
return <li key={item} className="f4" dangerouslySetInnerHTML={{ __html: item }} />
|
2021-06-09 23:44:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
const slug = item.heading ? slugger.slug(item.heading) : ''
|
|
|
|
return (
|
2021-08-18 00:07:46 +03:00
|
|
|
<Fragment key={slug}>
|
2021-06-09 23:44:32 +03:00
|
|
|
<h4
|
|
|
|
id={slug}
|
2021-08-16 17:10:58 +03:00
|
|
|
className={cx(styles.sectionHeading, 'text-uppercase text-bold f4')}
|
2021-08-18 00:07:46 +03:00
|
|
|
style={{ color: primaryColor }}
|
2021-06-09 23:44:32 +03:00
|
|
|
>
|
|
|
|
<Link href={`#${slug}`} className="text-inherit">
|
|
|
|
{item.heading}
|
|
|
|
</Link>
|
|
|
|
</h4>
|
2021-08-18 00:07:46 +03:00
|
|
|
<li className={!withReleaseNoteLabel ? 'list-style-none' : ''}>
|
|
|
|
<ul className={cx(styles.releaseNotesList, 'pl-0 pb-4 mt-2')}>
|
|
|
|
{item.notes.map((note) => {
|
|
|
|
return (
|
|
|
|
<li
|
|
|
|
key={note}
|
|
|
|
className="list-style-none f4"
|
|
|
|
dangerouslySetInnerHTML={{ __html: note }}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
})}
|
|
|
|
</ul>
|
|
|
|
</li>
|
|
|
|
</Fragment>
|
2021-06-09 23:44:32 +03:00
|
|
|
)
|
|
|
|
})}
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
})}
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|