From 1896d797b8595ab2c3b38d5d428e38e1afc180d6 Mon Sep 17 00:00:00 2001 From: mmeigs Date: Mon, 4 Nov 2024 17:27:12 -0500 Subject: [PATCH] DOP-4952: Breadcrumb used for "Previous Page" (#1299) --- src/templates/FeatureNotAvailable.js | 12 +++++------- src/utils/get-complete-breadcrumb-data.js | 15 +++++++++------ 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/templates/FeatureNotAvailable.js b/src/templates/FeatureNotAvailable.js index 7658cf923..6cdd0376c 100644 --- a/src/templates/FeatureNotAvailable.js +++ b/src/templates/FeatureNotAvailable.js @@ -8,6 +8,7 @@ import { H2 } from '@leafygreen-ui/typography'; import { theme } from '../theme/docsTheme'; import Breadcrumbs from '../components/Breadcrumbs'; import { isBrowser } from '../utils/is-browser'; +import { getCompleteUrl, getUrl } from '../utils/url-utils'; const StyledMain = styled.main` max-width: 100vw; @@ -79,12 +80,6 @@ const LinkContainer = styled.div` margin-top: ${theme.size.large}; `; -const click = () => { - if (isBrowser) { - window.history.back(); - } -}; - const FeatureNotAvailContainer = styled.div` align-items: center; display: flex; @@ -110,6 +105,9 @@ const FeatureNotAvailable = () => { pageInfo = JSON.parse(sessionStorage.getItem('pageInfo')); } + const { urlSlug, project, siteBasePrefix } = pageInfo || {}; + const selfCrumbPath = getCompleteUrl(getUrl(urlSlug, project, siteBasePrefix, selfBreadcrumb?.slug)); + return (
@@ -128,7 +126,7 @@ const FeatureNotAvailable = () => {

We're sorry, this page isn't available in the version you selected.

- diff --git a/src/utils/get-complete-breadcrumb-data.js b/src/utils/get-complete-breadcrumb-data.js index 427d149ae..74042eeaa 100644 --- a/src/utils/get-complete-breadcrumb-data.js +++ b/src/utils/get-complete-breadcrumb-data.js @@ -35,6 +35,14 @@ export const getFullBreadcrumbPath = (siteUrl, path, needsPrefix) => { return assertTrailingSlash(path); }; +export const getSelfCrumbPath = (selfCrumbContent, urlSlug, project, siteBasePrefix) => { + if (!project || !siteBasePrefix) return baseUrl(); + const isLanding = project === 'landing'; + if (!isLanding && selfCrumbContent) + return getCompleteUrl(getUrl(urlSlug, project, siteBasePrefix, selfCrumbContent.slug)); + return selfCrumbContent?.slug ?? baseUrl(); +}; + export const getCompleteBreadcrumbData = ({ siteUrl, siteTitle, @@ -82,15 +90,10 @@ export const getCompleteBreadcrumbData = ({ }; }); - const selfCrumbPath = - selfCrumbContent && !isLanding - ? getCompleteUrl(getUrl(urlSlug, project, siteBasePrefix, selfCrumbContent.slug)) - : selfCrumbContent?.slug; - const selfCrumb = selfCrumbContent ? { title: selfCrumbContent.title, - path: selfCrumbPath, + path: getSelfCrumbPath(selfCrumbContent, urlSlug, project, siteBasePrefix), } : null;