From b1893e433864176375a35e48e3ceca4a6cc5d032 Mon Sep 17 00:00:00 2001 From: Thomas Leing Date: Tue, 23 May 2023 16:43:24 -0700 Subject: [PATCH 1/2] Misc. docs engineering improvements --- src/components/Card/styles.tsx | 6 +++--- src/components/Menu/Directory/index.tsx | 3 ++- src/components/Menu/VersionSwitcher/index.tsx | 16 ++++++++++++---- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/components/Card/styles.tsx b/src/components/Card/styles.tsx index 2a48f6da5af..9bd84131226 100644 --- a/src/components/Card/styles.tsx +++ b/src/components/Card/styles.tsx @@ -1,6 +1,6 @@ import React from "react"; import styled from "@emotion/styled"; -import Link from "next/link"; +import InternalLink from "../InternalLink"; import {MQFablet, MQDesktop} from "../media"; @@ -30,7 +30,7 @@ const docsCard: React.FC = ({ }) => { if (!href) return
{children}
; return ( - + {external && ( = ({ )}
{children}
- +
); }; diff --git a/src/components/Menu/Directory/index.tsx b/src/components/Menu/Directory/index.tsx index 35405e70606..02f2c3934a3 100644 --- a/src/components/Menu/Directory/index.tsx +++ b/src/components/Menu/Directory/index.tsx @@ -72,6 +72,7 @@ class DirectoryGroup extends React.Component< if (this.itemsToDisplay.length === 0) { return <>; } + return (
@@ -82,7 +83,7 @@ class DirectoryGroup extends React.Component< {this.itemsToDisplay.map((item) => ( diff --git a/src/components/Menu/VersionSwitcher/index.tsx b/src/components/Menu/VersionSwitcher/index.tsx index 4aa67a3a123..a3d41b7f2f3 100644 --- a/src/components/Menu/VersionSwitcher/index.tsx +++ b/src/components/Menu/VersionSwitcher/index.tsx @@ -85,8 +85,8 @@ export function VersionSwitcher({url}) { const lib = directory["lib"].items; const libLegacy = directory["lib-v1"].items; -const libLegacyPaths = []; -const libPaths = []; +const libLegacyPaths: string[] = []; +const libPaths: string[] = []; const libItemsAndPaths: [object, string[]][] = [ [lib, libPaths], [libLegacy, libLegacyPaths], @@ -130,10 +130,18 @@ export function LibVersionSwitcher({ urlEnd = url.split("/lib")[1]; } + function isHrefIncluded(href: string, paths: string[]) { + href = href.split("#")[0]; + if (href.endsWith("/")) { + href = href.substring(0, href.length-1); + } + return paths.includes(href); + } + const leftHref = "/lib-v1" + urlEnd; const leftOption = { title: legacyVersion, - href: libLegacyPaths.includes(leftHref) + href: isHrefIncluded(leftHref, libLegacyPaths) ? leftHref : "/lib-v1/" + filter, }; @@ -141,7 +149,7 @@ export function LibVersionSwitcher({ const rightHref = "/lib" + urlEnd; const rightOption = { title: `${latestVersion} (latest)`, - href: libPaths.includes(rightHref) ? rightHref : "/lib/" + filter, + href: isHrefIncluded(rightHref, libPaths) ? rightHref : "/lib/" + filter, }; return ( From c1b4b6ff6bfd005878f1545212e30a7c13ca91e1 Mon Sep 17 00:00:00 2001 From: Thomas Leing Date: Tue, 30 May 2023 15:43:05 -0700 Subject: [PATCH 2/2] Add comment to explain QSP logic --- src/components/Menu/VersionSwitcher/index.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/components/Menu/VersionSwitcher/index.tsx b/src/components/Menu/VersionSwitcher/index.tsx index a3d41b7f2f3..04b1691abdb 100644 --- a/src/components/Menu/VersionSwitcher/index.tsx +++ b/src/components/Menu/VersionSwitcher/index.tsx @@ -130,6 +130,8 @@ export function LibVersionSwitcher({ urlEnd = url.split("/lib")[1]; } + // Function to remove query string parameters before checking if href is included in the list of possibilities. + // This is so we are only comparing the paths without the query string parameters to avoid false negatives. function isHrefIncluded(href: string, paths: string[]) { href = href.split("#")[0]; if (href.endsWith("/")) {