Skip to content

Commit eb904e3

Browse files
committed
Add latestVersionLabel parameter for VesionSelect component
1 parent 50a7e5b commit eb904e3

File tree

3 files changed

+26
-7
lines changed

3 files changed

+26
-7
lines changed

layouts/DocsLayout.re

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,21 @@ module Toc = {
3535

3636
module VersionSelect = {
3737
[@react.component]
38-
let make = (~onChange, ~version: string, ~availableVersions: array(string)) => {
38+
let make =
39+
(
40+
~onChange,
41+
~version: string,
42+
~latestVersionLabel: string,
43+
~availableVersions: array(string),
44+
) => {
3945
let children =
40-
Belt.Array.map(availableVersions, ver => {
41-
<option className="py-4" key=ver value=ver> ver->s </option>
42-
});
46+
Belt.Array.map(
47+
availableVersions,
48+
ver => {
49+
let label = ver === "latest" ? latestVersionLabel : ver;
50+
<option className="py-4" key=ver value=ver> label->s </option>;
51+
},
52+
);
4353
<select
4454
className="text-14 border border-fire inline-block rounded px-4 py-1 font-semibold "
4555
name="versionSelection"
@@ -329,6 +339,7 @@ let make =
329339
~frontmatter: option(Js.Json.t)=?,
330340
~version: option(string)=?,
331341
~availableVersions: option(array(string))=?,
342+
~latestVersionLabel: string="latest",
332343
~activeToc: option(Toc.t)=?,
333344
~categories: array(Category.t),
334345
~components=Markdown.default,
@@ -375,10 +386,8 @@ let make =
375386
open Url;
376387
ReactEvent.Form.preventDefault(evt);
377388
let version = evt->ReactEvent.Form.target##value;
378-
Js.log2("selected version", version);
379389
let url = Url.parse(route);
380390

381-
Js.log2("url", url);
382391
let targetUrl =
383392
"/"
384393
++ Js.Array2.joinWith(url.base, "/")
@@ -389,7 +398,12 @@ let make =
389398
Js.log2("targetUrl", targetUrl);
390399
router->Next.Router.push(targetUrl);
391400
};
392-
<VersionSelect onChange version availableVersions />;
401+
<VersionSelect
402+
latestVersionLabel
403+
onChange
404+
version
405+
availableVersions
406+
/>;
393407
| None => <span className="font-mono text-sm"> version->s </span>
394408
}
395409
| None => React.null

layouts/ManualDocsLayout.re

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ module Link = Next.Link;
33
// This is used for the version dropdown in the manual layouts
44
let allManualVersions = [|"latest", "v8.0.0"|];
55

6+
// Used for replacing "latest" with "vX.X.X" in the version dropdown
7+
let latestVersionLabel = "v8.2.0";
8+
69
// Structure defined by `scripts/extract-tocs.js`
710
let tocData:
811
Js.Dict.t({
@@ -184,6 +187,7 @@ module Docs = {
184187
version
185188
title
186189
availableVersions=allManualVersions
190+
latestVersionLabel
187191
?activeToc
188192
?breadcrumbs>
189193
children

layouts/ManualDocsLayout8_0_0.re

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ module Docs = {
207207
categories
208208
version
209209
availableVersions=ManualDocsLayout.allManualVersions
210+
latestVersionLabel=ManualDocsLayout.latestVersionLabel
210211
?frontmatter
211212
title
212213
?activeToc

0 commit comments

Comments
 (0)