Skip to content

Commit

Permalink
refactor: Moving the version support button to the footer (nodejs#7156)
Browse files Browse the repository at this point in the history
refactor: moving the version support button to the footer
  • Loading branch information
canerakdas authored Nov 1, 2024
1 parent 33c6599 commit fcff96f
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 55 deletions.
41 changes: 0 additions & 41 deletions apps/site/components/Common/ActiveLink/__tests__/index.test.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { render, screen } from '@testing-library/react';

import { VERSION_SUPPORT_SHORTCUT } from '@/next.constants.mjs';

import ActiveLink from '..';

// mock usePathname, but retain all the other imports
Expand Down Expand Up @@ -64,43 +62,4 @@ describe('ActiveLink', () => {

expect(screen.findByText('Link')).resolves.toHaveAttribute('class', 'link');
});

it('sets active class when href is other than VERSION_SUPPORT_SHORTCUT', () => {
const { usePathname } = require('@/navigation.mjs');
usePathname.mockReturnValue('/link/sublink');

render(
<ActiveLink
className="link"
activeClassName="active"
allowSubPath={true}
href={'/link/sub-link'}
>
Link
</ActiveLink>
);

expect(screen.findByText('Link')).resolves.toHaveAttribute(
'class',
'link active'
);
});

it('does not set active class when href is VERSION_SUPPORT_SHORTCUT', () => {
const { usePathname } = require('@/navigation.mjs');
usePathname.mockReturnValue(VERSION_SUPPORT_SHORTCUT);

render(
<ActiveLink
className="link"
activeClassName="active"
allowSubPath={true}
href={VERSION_SUPPORT_SHORTCUT}
>
Link
</ActiveLink>
);

expect(screen.findByText('Link')).resolves.toHaveAttribute('class', 'link');
});
});
5 changes: 1 addition & 4 deletions apps/site/components/Common/ActiveLink/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import type { ComponentProps, FC } from 'react';

import Link from '@/components/Link';
import { usePathname } from '@/navigation.mjs';
import { VERSION_SUPPORT_SHORTCUT } from '@/next.constants.mjs';

type ActiveLocalizedLinkProps = ComponentProps<typeof Link> & {
activeClassName?: string;
Expand All @@ -27,9 +26,7 @@ const ActiveLink: FC<ActiveLocalizedLinkProps> = ({
? // When using allowSubPath we want only to check if
// the current pathname starts with the utmost upper level
// of an href (e.g. /docs/...)
pathname.startsWith(`/${href.toString().split('/')[1]}`) &&
// but not when this link is for the deep link shortcut to previous releases
href.toString() !== VERSION_SUPPORT_SHORTCUT
pathname.startsWith(`/${href.toString().split('/')[1]}`)
: href.toString() === pathname,
});

Expand Down
8 changes: 4 additions & 4 deletions apps/site/navigation.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@
"link": "https://nodejs.org/docs/latest/api/",
"label": "components.containers.navBar.links.docs"
},
"support": {
"link": "/about/previous-releases",
"label": "components.containers.navBar.links.support"
},
"certification": {
"link": "https://training.linuxfoundation.org/openjs/",
"label": "components.containers.navBar.links.certification",
Expand All @@ -39,6 +35,10 @@
"link": "https://privacy-policy.openjsf.org/",
"text": "components.containers.footer.links.privacyPolicy"
},
{
"link": "/about/previous-releases",
"text": "components.containers.footer.links.versionSupport"
},
{
"link": "https://github.com/openjs-foundation/cross-project-council/blob/main/CODE_OF_CONDUCT.md",
"text": "components.containers.footer.links.codeOfConduct"
Expand Down
5 changes: 0 additions & 5 deletions apps/site/next.constants.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,3 @@ export const GITHUB_API_KEY = process.env.NEXT_GITHUB_API_KEY || '';
*/
export const ESP_SUPPORT_THRESHOLD_VERSION =
process.env.ESP_SUPPORT_THRESHOLD_VERSION || '18.0.0';

/**
* This deep link into the app is repeated in the top nav, but we want to ignore it for active-link highlighting, since it will be covered by About
*/
export const VERSION_SUPPORT_SHORTCUT = '/about/previous-releases';
2 changes: 1 addition & 1 deletion packages/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"links": {
"trademarkPolicy": "Trademark Policy",
"privacyPolicy": "Privacy Policy",
"versionSupport": "Version Support",
"codeOfConduct": "Code of Conduct",
"security": "Security Policy"
}
Expand All @@ -14,7 +15,6 @@
"about": "About",
"download": "Download",
"docs": "Docs",
"support": "Version Support",
"guides": "Guides",
"learn": "Learn",
"security": "Security",
Expand Down

0 comments on commit fcff96f

Please sign in to comment.