Skip to content

Commit 0f9e977

Browse files
tjleingThomas Leing
and
Thomas Leing
authored
Misc. docs engineering improvements (#5495)
* Misc. docs engineering improvements * Add comment to explain QSP logic --------- Co-authored-by: Thomas Leing <[email protected]>
1 parent 896e793 commit 0f9e977

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

src/components/Card/styles.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from "react";
22
import styled from "@emotion/styled";
3-
import Link from "next/link";
3+
import InternalLink from "../InternalLink";
44

55
import {MQFablet, MQDesktop} from "../media";
66

@@ -30,7 +30,7 @@ const docsCard: React.FC<CardProps> = ({
3030
}) => {
3131
if (!href) return <div className={className}>{children}</div>;
3232
return (
33-
<Link href={href} passHref={true} legacyBehavior>
33+
<InternalLink href={href} passHref={true} legacyBehavior>
3434
<Anchor>
3535
{external && (
3636
<ExternalLinkGraphic
@@ -40,7 +40,7 @@ const docsCard: React.FC<CardProps> = ({
4040
)}
4141
<div className={className}>{children}</div>
4242
</Anchor>
43-
</Link>
43+
</InternalLink>
4444
);
4545
};
4646

src/components/Menu/Directory/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ class DirectoryGroup extends React.Component<
7272
if (this.itemsToDisplay.length === 0) {
7373
return <></>;
7474
}
75+
7576
return (
7677
<div>
7778
<DirectoryGroupHeaderStyle onClick={this.toggleOpen}>
@@ -82,7 +83,7 @@ class DirectoryGroup extends React.Component<
8283
<DirectoryLinksStyle>
8384
{this.itemsToDisplay.map((item) => (
8485
<DirectoryGroupItemStyle
85-
isActive={this.currentRoute.startsWith(item.route)}
86+
isActive={this.currentRoute === item.route}
8687
key={item.title}
8788
>
8889
<InternalLink href={`${item.route}`}>

src/components/Menu/VersionSwitcher/index.tsx

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ export function VersionSwitcher({url}) {
8585

8686
const lib = directory["lib"].items;
8787
const libLegacy = directory["lib-v1"].items;
88-
const libLegacyPaths = [];
89-
const libPaths = [];
88+
const libLegacyPaths: string[] = [];
89+
const libPaths: string[] = [];
9090
const libItemsAndPaths: [object, string[]][] = [
9191
[lib, libPaths],
9292
[libLegacy, libLegacyPaths],
@@ -130,18 +130,28 @@ export function LibVersionSwitcher({
130130
urlEnd = url.split("/lib")[1];
131131
}
132132

133+
// Function to remove query string parameters before checking if href is included in the list of possibilities.
134+
// This is so we are only comparing the paths without the query string parameters to avoid false negatives.
135+
function isHrefIncluded(href: string, paths: string[]) {
136+
href = href.split("#")[0];
137+
if (href.endsWith("/")) {
138+
href = href.substring(0, href.length-1);
139+
}
140+
return paths.includes(href);
141+
}
142+
133143
const leftHref = "/lib-v1" + urlEnd;
134144
const leftOption = {
135145
title: legacyVersion,
136-
href: libLegacyPaths.includes(leftHref)
146+
href: isHrefIncluded(leftHref, libLegacyPaths)
137147
? leftHref
138148
: "/lib-v1/" + filter,
139149
};
140150

141151
const rightHref = "/lib" + urlEnd;
142152
const rightOption = {
143153
title: `${latestVersion} (latest)`,
144-
href: libPaths.includes(rightHref) ? rightHref : "/lib/" + filter,
154+
href: isHrefIncluded(rightHref, libPaths) ? rightHref : "/lib/" + filter,
145155
};
146156

147157
return (

0 commit comments

Comments
 (0)