|
| 1 | +/** |
| 2 | + * <ReleaseFeed/> — release feed for /release-notes/infrahub. |
| 3 | + * Full detail for the newest `detailedLines` release lines, compact rows for |
| 4 | + * earlier ones. Reads global data from plugins/release-notes-data.js. |
| 5 | + */ |
| 6 | +import React from "react"; |
| 7 | +import Link from "@docusaurus/Link"; |
| 8 | +import { usePluginData } from "@docusaurus/useGlobalData"; |
| 9 | +import styles from "./styles.module.css"; |
| 10 | + |
| 11 | +type Release = { |
| 12 | + version: string; |
| 13 | + line: string; |
| 14 | + major: number; |
| 15 | + minor: number; |
| 16 | + patch: number | null; |
| 17 | + date: string | null; |
| 18 | + type: "minor" | "patch" | "security"; |
| 19 | + description: string; |
| 20 | + breaking: boolean; |
| 21 | + permalink: string; |
| 22 | +}; |
| 23 | + |
| 24 | +const fmtDate = (iso: string | null, month: "long" | "short" = "long") => |
| 25 | + iso |
| 26 | + ? new Date(`${iso}T00:00:00`).toLocaleDateString("en-US", { year: "numeric", month, day: "numeric" }) |
| 27 | + : ""; |
| 28 | + |
| 29 | +/** Fully-expanded group: X.Y.0 hero first, then updates in chronological (ascending) order. */ |
| 30 | +function LineGroup({ line, releases }: { line: string; releases: Release[] }) { |
| 31 | + const base = releases.find((r) => r.patch === 0 || r.patch === null) ?? releases[0]; |
| 32 | + const updates = releases.filter((r) => r !== base).sort((a, b) => (a.patch ?? 0) - (b.patch ?? 0)); |
| 33 | + return ( |
| 34 | + <section className={styles.group}> |
| 35 | + <div className={styles.groupHead}> |
| 36 | + <h2>{line}</h2> |
| 37 | + <span className={styles.featureBadge}>Feature release</span> |
| 38 | + </div> |
| 39 | + <Link to={base.permalink} className={styles.heroRow}> |
| 40 | + <div className={styles.rowHead}> |
| 41 | + <span className={styles.heroVersion}>{base.version}</span> |
| 42 | + {base.breaking && <span className={styles.breakingChip}>Breaking changes</span>} |
| 43 | + <span className={styles.date}>{fmtDate(base.date)}</span> |
| 44 | + </div> |
| 45 | + {base.description && <p className={styles.heroSummary}>{base.description}</p>} |
| 46 | + </Link> |
| 47 | + <div className={styles.updates}> |
| 48 | + {updates.map((r) => ( |
| 49 | + <Link key={r.version} to={r.permalink} className={styles.updateRow}> |
| 50 | + <span className={styles.bullet} /> |
| 51 | + <div className={styles.rowHead}> |
| 52 | + <span className={styles.updateVersion}>{r.version}</span> |
| 53 | + {r.breaking && <span className={styles.breakingChip}>Breaking</span>} |
| 54 | + <span className={styles.date}>{fmtDate(r.date)}</span> |
| 55 | + </div> |
| 56 | + {r.description && <p className={styles.summary}>{r.description}</p>} |
| 57 | + </Link> |
| 58 | + ))} |
| 59 | + </div> |
| 60 | + </section> |
| 61 | + ); |
| 62 | +} |
| 63 | + |
| 64 | +/** Compact row for older lines: version · description · date. */ |
| 65 | +function EarlierRow({ base }: { base: Release }) { |
| 66 | + return ( |
| 67 | + <Link to={base.permalink} className={styles.earlierRow}> |
| 68 | + <span className={styles.earlierVersion}>{base.line}</span> |
| 69 | + <span className={styles.earlierSummary}>{base.description}</span> |
| 70 | + <span className={styles.date}>{fmtDate(base.date, "short")}</span> |
| 71 | + </Link> |
| 72 | + ); |
| 73 | +} |
| 74 | + |
| 75 | +/** Newest `detailedLines` version lines fully expanded; the rest as compact rows. */ |
| 76 | +export default function ReleaseFeed({ detailedLines = 2 }: { detailedLines?: number }) { |
| 77 | + const { releases } = usePluginData("release-notes-data") as { releases: Release[] }; |
| 78 | + const lines: string[] = []; |
| 79 | + for (const r of releases) if (!lines.includes(r.line)) lines.push(r.line); // newest line first |
| 80 | + const detailed = lines.slice(0, detailedLines); |
| 81 | + const earlier = lines.slice(detailedLines); |
| 82 | + return ( |
| 83 | + <div className={styles.feed}> |
| 84 | + <h1 className={styles.title}>Infrahub release notes</h1> |
| 85 | + {detailed.map((line) => ( |
| 86 | + <LineGroup key={line} line={line} releases={releases.filter((r) => r.line === line)} /> |
| 87 | + ))} |
| 88 | + <section className={styles.group}> |
| 89 | + <div className={styles.earlierHead}> |
| 90 | + <h2>Earlier releases</h2> |
| 91 | + </div> |
| 92 | + {earlier.map((line) => { |
| 93 | + const rs = releases.filter((r) => r.line === line); |
| 94 | + const base = rs.find((r) => r.patch === 0 || r.patch === null) ?? rs[rs.length - 1]; |
| 95 | + return <EarlierRow key={line} base={base} />; |
| 96 | + })} |
| 97 | + </section> |
| 98 | + </div> |
| 99 | + ); |
| 100 | +} |
0 commit comments