Skip to content

Commit a4a03e7

Browse files
fix: hide irrelevant download install options
Signed-off-by: abhijeet nardele <234410808+abhijeetnardele24-hash@users.noreply.github.com>
1 parent c52de6f commit a4a03e7

File tree

3 files changed

+38
-16
lines changed

3 files changed

+38
-16
lines changed

apps/site/components/Downloads/Release/InstallationMethodDropdown.tsx

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,30 @@ const InstallationMethodDropdown: FC = () => {
2222
[release.os, release.version]
2323
);
2424

25+
const enabledInstallMethods = useMemo(
26+
() => parsedInstallMethods.filter(({ disabled }) => !disabled),
27+
[parsedInstallMethods]
28+
);
29+
2530
// We group Platforms on the Platform Dropdown to provide the User
2631
// understanding of what is recommended/official and what is not.
2732
const grouppedMethods = useMemo(
28-
() => [
29-
{
30-
label: t('layouts.download.dropdown.platformGroups.official'),
31-
items: parsedInstallMethods.filter(({ recommended }) => recommended),
32-
},
33-
{
34-
label: t('layouts.download.dropdown.platformGroups.unofficial'),
35-
items: parsedInstallMethods.filter(({ recommended }) => !recommended),
36-
},
37-
],
33+
() =>
34+
[
35+
{
36+
label: t('layouts.download.dropdown.platformGroups.official'),
37+
items: enabledInstallMethods.filter(({ recommended }) => recommended),
38+
},
39+
{
40+
label: t('layouts.download.dropdown.platformGroups.unofficial'),
41+
items: enabledInstallMethods.filter(
42+
({ recommended }) => !recommended
43+
),
44+
},
45+
].filter(({ items }) => items.length > 0),
3846
// We only want to react on the change of the parsedPlatforms
3947
// eslint-disable-next-line react-hooks/exhaustive-deps
40-
[parsedInstallMethods]
48+
[enabledInstallMethods]
4149
);
4250

4351
useEffect(() => {
@@ -49,28 +57,28 @@ const InstallationMethodDropdown: FC = () => {
4957
// Sets either the utmost recommended platform or the first non-disabled one
5058
// Note that the first item of groupped platforms is always the recommended one
5159
nextItem<InstallationMethod | ''>('', grouppedMethods[0].items) ||
52-
nextItem<InstallationMethod | ''>('', parsedInstallMethods);
60+
nextItem<InstallationMethod | ''>('', enabledInstallMethods);
5361

5462
// This will never return an empty string as there should always be an item
5563
// when the OS has finished loading for a given installation method
5664
release.setInstallMethod(installationMethod as InstallationMethod);
5765
}
5866
// eslint-disable-next-line react-hooks/exhaustive-deps
59-
}, [parsedInstallMethods, release.installMethod, release.os]);
67+
}, [enabledInstallMethods, release.installMethod, release.os]);
6068

6169
// We set the Platform to the next available platform when the current
6270
// one is not valid anymore due to OS or Version changes
6371
useEffect(
6472
() => {
6573
if (release.os !== 'LOADING' && release.installMethod !== '') {
6674
release.setInstallMethod(
67-
nextItem(release.installMethod, parsedInstallMethods)
75+
nextItem(release.installMethod, enabledInstallMethods)
6876
);
6977
}
7078
},
7179
// We only want to react on the change of the OS and Version
7280
// eslint-disable-next-line react-hooks/exhaustive-deps
73-
[release.os, release.version]
81+
[enabledInstallMethods, release.os, release.version]
7482
);
7583

7684
return (

apps/site/util/__tests__/download.test.mjs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,20 @@ describe('parseCompat', () => {
4747
});
4848

4949
describe('extended tests', () => {
50+
it('should keep nvm available for AIX', () => {
51+
const nvm = INSTALL_METHODS.find(({ value }) => value === 'NVM');
52+
53+
const [result] = parseCompat([nvm], {
54+
os: 'AIX',
55+
installMethod: 'NVM',
56+
platform: 'ppc64',
57+
version: 'v24.14.0',
58+
release: { status: 'Current' },
59+
});
60+
61+
assert.equal(result.disabled, false);
62+
});
63+
5064
it('should disable items if OS is not supported', () => {
5165
const items = [
5266
{

apps/site/util/download/constants.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@
129129
"icon": "NVM",
130130
"name": "nvm",
131131
"compatibility": {
132-
"os": ["MAC", "LINUX", "OTHER"]
132+
"os": ["MAC", "LINUX", "AIX", "OTHER"]
133133
},
134134
"recommended": true,
135135
"url": "https://github.com/nvm-sh/nvm",

0 commit comments

Comments
 (0)