diff --git a/components/context/MainContext.tsx b/components/context/MainContext.tsx index 23131b86a37e..7c965675f211 100644 --- a/components/context/MainContext.tsx +++ b/components/context/MainContext.tsx @@ -15,17 +15,40 @@ type VersionItem = { // free-pro-team@latest, enterprise-cloud@latest, enterprise-server@3.3 ... version: string versionTitle: string - currentRelease: string - latestVersion: string - shortName: string - // api.github.com, ghec, ghes-3.3, github.ae - openApiVersionName: string - // api.github.com, ghec, ghes-, github.ae - openApiBaseName: string + isGHES?: boolean apiVersions: string[] latestApiVersion: string } +// This reflects what gets exported from `all-versions.js` in the +// `allVersions` object. +// It's necessary for TypeScript, but we don't need to write down +// every possible key that might be present because we don't need it +// for rendering. +type FullVersionItem = VersionItem & { + shortName: string +} + +function minimalAllVersions( + allVersions: Record, +): Record { + const all: Record = {} + for (const [plan, info] of Object.entries(allVersions)) { + all[plan] = { + version: info.version, + versionTitle: info.versionTitle, + apiVersions: info.apiVersions, + latestApiVersion: info.latestApiVersion, + } + // Deal with keys that are optional. It's preferred to omit + // booleans if they're false anyway. + if (info.shortName === 'ghes') { + all[plan].isGHES = true + } + } + return all +} + export type ProductTreeNode = { title: string href: string @@ -171,7 +194,7 @@ export const getMainContext = async (req: any, res: any): Promise 'supported', ]), enterpriseServerVersions: req.context.enterpriseServerVersions, - allVersions: req.context.allVersions, + allVersions: minimalAllVersions(req.context.allVersions), currentVersion: req.context.currentVersion, // This is a slimmed down version of `req.context.currentProductTree` // that only has the minimal titles stuff needed for sidebars and diff --git a/src/rest/components/RestBanner.tsx b/src/rest/components/RestBanner.tsx index c01e912253e0..d70d4941f39b 100644 --- a/src/rest/components/RestBanner.tsx +++ b/src/rest/components/RestBanner.tsx @@ -50,13 +50,13 @@ export const RestBanner = () => { bannerText = t('rest.banner.api_versioned') versionWithApiVersion = currentVersion } else { - if (currentVersionObj.shortName === 'ghes') { + if (currentVersionObj.isGHES) { // If this is a GHES release with no REST versions, // find out if any GHES releases contain REST versioning yet. const firstGhesReleaseWithApiVersions = Object.values(allVersions) .reverse() .find((v) => { - return v.shortName === 'ghes' && v.apiVersions.length + return v.isGHES && v.apiVersions.length }) if (firstGhesReleaseWithApiVersions) {