Updating to check apiVersion is a real apiVersion (#33058)

Co-authored-by: Rachael Sewell <rachmari@github.com>
This commit is contained in:
Grace Park 2022-11-29 11:23:54 -08:00 коммит произвёл GitHub
Родитель 1a77ceb9e2
Коммит 53f54707c5
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
4 изменённых файлов: 28 добавлений и 11 удалений

Просмотреть файл

@ -13,14 +13,21 @@ export function RestRedirect() {
const router = useRouter()
const { currentVersion } = useVersion()
const { allVersions } = useMainContext()
const apiVersions = allVersions[currentVersion].apiVersions
const latestApiVersion = allVersions[currentVersion].latestApiVersion
const validApiVersions = allVersions[currentVersion].apiVersions
const isReleaseVersioned = allVersions[currentVersion].apiVersions.length > 0
const latestValidApiVersion = allVersions[currentVersion].latestApiVersion
const queryApiVersion = router.query.apiVersion
useEffect(() => {
if (allVersions[currentVersion].apiVersions.length > 0 && !router.query.apiVersion) {
if (
isReleaseVersioned &&
(!queryApiVersion || !validApiVersions.includes(queryApiVersion as string))
) {
const versionCookie = Cookies.get(API_VERSION_COOKIE_NAME)
const date =
versionCookie && apiVersions.includes(versionCookie) ? versionCookie : latestApiVersion
versionCookie && validApiVersions.includes(versionCookie)
? versionCookie
: latestValidApiVersion
const hash = router.asPath.split('#')[1]
const [asPathRoot, asPathQuery = ''] = router.asPath.split('#')[0].split('?')
const params = new URLSearchParams(asPathQuery)

Просмотреть файл

@ -43,10 +43,15 @@ export const ApiVersionPicker = ({ variant, width }: Props) => {
const { t } = useTranslation(['products'])
const basePath = router.asPath.split('#')[0].split('?')[0]
// Get current date from cookie, query path, or lastly set it to latest rest version date
const currentDate =
router.query.apiVersion && typeof router.query.apiVersion === 'string'
? router.query.apiVersion
: allVersions[currentVersion].latestApiVersion
const isValidApiVersion =
(router.query.apiVersion &&
typeof router.query.apiVersion === 'string' &&
allVersions[currentVersion].apiVersions.includes(router.query.apiVersion)) ||
false
const currentDate = (
isValidApiVersion ? router.query.apiVersion : allVersions[currentVersion].latestApiVersion
) as string
const currentDateDisplayText =
currentDate === allVersions[currentVersion].latestApiVersion

Просмотреть файл

@ -39,8 +39,10 @@ export const getServerSideProps: GetServerSideProps<Props> = async (context) =>
const currentVersion = context.params!.versionId as string
const currentLanguage = req.context.currentLanguage as string
const allVersions = req.context.allVersions
const apiVersion = context.query.apiVersion || allVersions[currentVersion].latestApiVersion
const queryApiVersion = context.query.apiVersion
const apiVersion = allVersions[currentVersion].apiVersions.includes(queryApiVersion)
? queryApiVersion
: allVersions[currentVersion].latestApiVersion
// For pages with category level only operations like /rest/billing, we set
// the subcategory's value to be the category for the call to getRest()
if (!subCategory) {

Просмотреть файл

@ -66,7 +66,10 @@ export const getServerSideProps: GetServerSideProps<Props> = async (context) =>
const currentVersion = context.params!.versionId as string
const currentLanguage = req.context.currentLanguage as string
const allVersions = req.context.allVersions
const apiVersion = context.query.apiVersion || allVersions[currentVersion].latestApiVersion
const queryApiVersion = context.query.apiVersion
const apiVersion = allVersions[currentVersion].apiVersions.includes(queryApiVersion)
? queryApiVersion
: allVersions[currentVersion].latestApiVersion
// For pages with category level only operations like /rest/billing, we set
// the subcategory's value to be the category for the call to getRest()