Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hds 2352 fix missing component urls #1437

Merged
merged 2 commits into from
Nov 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 39 additions & 5 deletions site/src/components/layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,47 @@ import versions from '../data/versions.json';

const classNames = (...args) => args.filter((e) => e).join(' ');

const fixUrlExceptions = (href, version) => {
const versionNumber = version ? version.replace('release-', '')?.split('.')[0] : 1000;

// /components/buttons has changed to /components/button after version 3.11.
if (versionNumber > 3 && href.indexOf('/components/buttons') >= 0) {
return href.replace('/components/buttons', '/components/button');
}
else if (versionNumber <= 3 && href.indexOf('/components/button') >= 0 && href.indexOf('/components/buttons') < 0) {
return href.replace('/components/button', '/components/buttons');
}

// /components/dropdown is not available after version 3.11.
if (versionNumber > 3 && href.indexOf('/components/dropdown') >= 0) {
return href.replace('/components/dropdown', '/components');
}

// /components/errorsummary is not available before version 3.11.
if (versionNumber < 3 && href.indexOf('/components/error-summary') >= 0) {
return href.replace('/components/error-summary', '/components');
}

// /components/header is not available before version 3.11.
if (versionNumber < 3 && href.indexOf('/components/header') >= 0) {
return href.replace('/components/header', '/components');
}

return href;
}

const hrefWithVersion = (href, version, withoutPrefix = false) => {
if (!version || version === '' || href === ''
|| href.startsWith('mailto:') || href.startsWith('#') || href.startsWith('http'))
return href;
const hrefWithFixedExceptions = fixUrlExceptions(href, version);

if (!version || hrefWithFixedExceptions === ''
|| hrefWithFixedExceptions.startsWith('mailto:')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to make the long list shorter, !version includes version === ''

|| hrefWithFixedExceptions.startsWith('#')
|| hrefWithFixedExceptions.startsWith('http'))
return hrefWithFixedExceptions;

let withVersion = '';
let versionAdded = false;
const pathParts = href.split('/');
const pathParts = hrefWithFixedExceptions.split('/');

pathParts.forEach((part, index) => {
if (index > 0) {
Expand All @@ -48,6 +81,7 @@ const hrefWithVersion = (href, version, withoutPrefix = false) => {

return ret;
};

const hrefWithoutVersion = (href, version) => {
return href.replace(`/${version}`, '');
};
Expand Down Expand Up @@ -291,7 +325,7 @@ const Layout = ({ location, children, pageContext }) => {
selected={itemVersion === versionNumber}
href={index > 0
? hrefWithVersion(locationWithoutVersion, `release-${itemVersion}`)
: withPrefix(locationWithoutVersion)}
: hrefWithVersion(locationWithoutVersion)}
/>
))}
</Header.ActionBarItem>
Expand Down
Loading