* upgrade primer/react * upgrade * using deprecated * remove lib" * Upgrade primer/react: Upgrade Label (#28502) update Label to primer/react 35.2.2 * fix merge conflicts * primer/react v35: update ActionList (#28467) * Update to v35 ActionList for LearningTrack * Update to v35 ActionList for ArticleList * Update to v35 ActionList for ProductArticleList * Update to v35 ActionList for TableOfContents * Update to v35 ActionList for ProductCollapsibleSection * Update to v35 ActionList for RestCollapsibleSection * Update to v35 ActionList for SidebarHomepage * Update to v35 ActionList for MiniTocs * Update to v35 ActionList for Search * Extra div for rendering test * One less div for rendering test * All the style updates for v35 ActionList * Works without setting as an li which is already the default (didn't before for some reason) * Use deprecated ItemInput for now * Picker update for primer/react (#28485) * update picker * inline picker for mobile * set width to auto * Update components/ui/Picker/Picker.tsx Co-authored-by: Kevin Heis <heiskr@users.noreply.github.com> * update * Update Picker.tsx * update onselect * checking language code * move language cookie setting to language picker Co-authored-by: Kevin Heis <heiskr@users.noreply.github.com> * Resolve package merge conflicts * fresh npm install * Primer update UnderlineNav (#28582) * update underlinenav for primer/react update * update tests * update switches test * update one last label * update header test" * remove href in underlinenav * update rendering tests * update cursor * primer/react v35: update DropDownMenu to ActionMenu (#28576) * Update to v35 ActionMenu for ArticleCards * Update to v35 ActionMenu for Search * Set button to inline-block * Put the props on the overlay * Update test for ActionMenu markup * update package * update package lock * primer/react v35: CodeLanguagePicker update from SelectMenu to ActionMenu (#28625) * Use octicon for menu down arrow * Update to v35 ActionMenu for CodeLanguagePicker * update to SubNav Co-authored-by: Grace Park <gracepark@github.com> * update package-lock Co-authored-by: Robert Sese <734194+rsese@users.noreply.github.com> Co-authored-by: Kevin Heis <heiskr@users.noreply.github.com>
62 lines
1.8 KiB
TypeScript
62 lines
1.8 KiB
TypeScript
import { useRouter } from 'next/router'
|
|
|
|
import { useMainContext } from 'components/context/MainContext'
|
|
import { DEFAULT_VERSION, useVersion } from 'components/hooks/useVersion'
|
|
import { useTranslation } from 'components/hooks/useTranslation'
|
|
import { Picker } from 'components/ui/Picker'
|
|
|
|
type Props = {
|
|
variant?: 'inline'
|
|
}
|
|
|
|
export const VersionPicker = ({ variant }: Props) => {
|
|
const router = useRouter()
|
|
const { currentVersion } = useVersion()
|
|
const { allVersions, page, enterpriseServerVersions } = useMainContext()
|
|
const { t } = useTranslation(['pages', 'picker'])
|
|
|
|
if (page.permalinks && page.permalinks.length < 1) {
|
|
return null
|
|
}
|
|
|
|
const allLinks = (page.permalinks || []).map((permalink) => ({
|
|
text: permalink.pageVersionTitle,
|
|
selected: allVersions[currentVersion].versionTitle === permalink.pageVersionTitle,
|
|
href: permalink.href,
|
|
arrow: false,
|
|
info: false,
|
|
}))
|
|
|
|
const hasEnterpriseVersions = (page.permalinks || []).some((permalink) =>
|
|
permalink.pageVersion.startsWith('enterprise-server')
|
|
)
|
|
|
|
if (hasEnterpriseVersions) {
|
|
allLinks.push({
|
|
text: t('all_enterprise_releases'),
|
|
selected: false,
|
|
arrow: true,
|
|
href: `/${router.locale}/${enterpriseServerVersions[0]}/admin/all-releases`,
|
|
info: false,
|
|
})
|
|
}
|
|
|
|
if (allLinks) {
|
|
const currentVersionPathSegment = currentVersion === DEFAULT_VERSION ? '' : `/${currentVersion}`
|
|
|
|
allLinks.push({
|
|
text: t('about_versions'),
|
|
selected: false,
|
|
arrow: false,
|
|
info: true,
|
|
href: `/${router.locale}${currentVersionPathSegment}/get-started/learning-about-github/about-versions-of-github-docs`,
|
|
})
|
|
}
|
|
|
|
return (
|
|
<div data-testid="version-picker">
|
|
<Picker variant={variant} defaultText={t('version_picker_default_text')} options={allLinks} />
|
|
</div>
|
|
)
|
|
}
|