-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Expand file tree
/
Copy pathwithReleaseSelect.tsx
More file actions
59 lines (47 loc) · 1.7 KB
/
withReleaseSelect.tsx
File metadata and controls
59 lines (47 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import StatelessSelect from '@node-core/ui-components/Common/Select/StatelessSelect';
import Link from '#site/components/Link';
import provideReleaseData from '#site/next-data/providers/releaseData';
import { STATUS_ORDER } from '#site/util/download';
import type { NodeRelease } from '#site/types';
import type { ComponentProps, FC } from 'react';
type Navigations = Record<string, Array<{ label: string; value: string }>>;
/**
* Generates the navigation links for the Node.js download archive
* It creates a list of links for each major release, grouped by status,
* formatted with the major version and codename if available.
*/
const groupReleasesByStatus = (releases: Array<NodeRelease>) => {
const groupedByStatus = releases.reduce((acc, release) => {
const { status, major, codename, versionWithPrefix } = release;
if (!acc[status]) {
acc[status] = [];
}
acc[status].push({
label: `Node.js v${major}.x ${codename ? `(${codename})` : ''}`,
value: `/download/archive/${versionWithPrefix}`,
});
return acc;
}, {} as Navigations);
return STATUS_ORDER.filter(status => groupedByStatus[status]).map(status => ({
label: status,
items: groupedByStatus[status],
}));
};
type WithReleaseSelectProps = Omit<
ComponentProps<typeof StatelessSelect>,
'values' | 'as'
>;
const WithReleaseSelect: FC<WithReleaseSelectProps> = async ({ ...props }) => {
const releaseData = await provideReleaseData();
const navigation = groupReleasesByStatus(releaseData);
return (
<StatelessSelect
{...props}
values={navigation}
as={Link}
className="w-full md:w-64"
ariaLabel={props.defaultValue}
/>
);
};
export default WithReleaseSelect;