Skip to content

Commit

Permalink
Version the 'All products' link (github#24972)
Browse files Browse the repository at this point in the history
* Don't show link no matter what version you're on

* Maintain current version in link

* No 'All products' link on homepage for all versions
  • Loading branch information
rsese authored Feb 3, 2022
1 parent 1d42bbe commit c5f9788
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
9 changes: 8 additions & 1 deletion components/sidebar/AllProductsLink.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import { useRouter } from 'next/router'
import { ArrowLeftIcon } from '@primer/octicons-react'
import { DEFAULT_VERSION, useVersion } from 'components/hooks/useVersion'

export const AllProductsLink = () => {
const router = useRouter()
const { currentVersion } = useVersion()
const currentVersionPathSegment = currentVersion === DEFAULT_VERSION ? '' : `/${currentVersion}`

return (
<li>
<a href={`/${router.locale}`} className="f6 pl-4 pr-5 ml-n1 pb-1 color-fg-default">
<a
href={`/${router.locale}${currentVersionPathSegment}`}
className="f6 pl-4 pr-5 ml-n1 pb-1 color-fg-default"
>
<ArrowLeftIcon size="small" className="mr-1" />
All products
</a>
Expand Down
3 changes: 0 additions & 3 deletions components/sidebar/SidebarHomepage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import { useVersion } from 'components/hooks/useVersion'
import { useMainContext } from 'components/context/MainContext'
import { Link } from 'components/Link'

import { AllProductsLink } from './AllProductsLink'

export const SidebarHomepage = () => {
const router = useRouter()
const { currentVersion } = useVersion()
Expand Down Expand Up @@ -55,7 +53,6 @@ export const SidebarHomepage = () => {

return (
<ul data-testid="sidebar" className="mt-4">
{!isFPT && <AllProductsLink />}
<li>
<ActionList {...{ as: 'ul' }} items={navItems}></ActionList>
</li>
Expand Down
5 changes: 0 additions & 5 deletions tests/rendering/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,10 @@ describe('server', () => {
const productTitles = productItems.map((el) => $(el).text().trim())
const productHrefs = productItems.map((el) => $(el).attr('href'))

const firstSidebarTitle = sidebarTitles.shift()
const firstSidebarHref = sidebarHrefs.shift()

const titlesInProductsButNotSidebar = lodash.difference(productTitles, sidebarTitles)

const hrefsInProductsButNotSidebar = lodash.difference(productHrefs, sidebarHrefs)

expect(firstSidebarTitle).toBe('All products')
expect(firstSidebarHref).toBe('/en')
expect(
titlesInProductsButNotSidebar.length,
`Found titles missing from sidebar: ${titlesInProductsButNotSidebar.join(', ')}`
Expand Down

0 comments on commit c5f9788

Please sign in to comment.