From f4ef779e70768f111db35fac4879539431105fee Mon Sep 17 00:00:00 2001 From: Heat Hamilton <55773810+heatlikeheatwave@users.noreply.github.com> Date: Thu, 12 Sep 2024 13:43:23 -0400 Subject: [PATCH 1/2] chore: Add version selector back to release notes pages (#2570) --- .../__tests__/is-release-notes-page.test.ts | 60 ------------------- src/lib/docs/is-release-notes-page.ts | 11 ---- src/views/docs-view/server.ts | 7 +-- 3 files changed, 1 insertion(+), 77 deletions(-) delete mode 100644 src/lib/__tests__/is-release-notes-page.test.ts delete mode 100644 src/lib/docs/is-release-notes-page.ts diff --git a/src/lib/__tests__/is-release-notes-page.test.ts b/src/lib/__tests__/is-release-notes-page.test.ts deleted file mode 100644 index 15c7a57d7f..0000000000 --- a/src/lib/__tests__/is-release-notes-page.test.ts +++ /dev/null @@ -1,60 +0,0 @@ -/** - * Copyright (c) HashiCorp, Inc. - * SPDX-License-Identifier: MPL-2.0 - */ - -import { isReleaseNotesPage } from 'lib/docs/is-release-notes-page' - -describe('isReleaseNotesPage', () => { - it('returns true for valid release notes page paths', () => { - const validPaths = [ - '/releases/2022/v220601-1', - '/releases/2021/v210601-2', - '/release-notes/1.2.3', - '/release-notes/2.0.x', - '/release-notes/v2.0.x', - '/boundary/docs/release-notes/v0_15_0', - '/vault/docs/release-notes/1.13.0', - ] - - validPaths.forEach((path) => { - expect(isReleaseNotesPage(path)).toBe(true) - }) - }) - - it('returns false for invalid release notes page paths', () => { - const invalidPaths = [ - '/releases/2022/v220601', - '/releases/2021/v210601', - '/release-notes/1.2', - '/release-notes/2.0', - '/release-notes/2.x', - '/releases/2022/v220601-', - '/releases/2021/v210601-', - '/release-notes/1.2.', - '/release-notes/2.0.', - '/release-notes/2.x.', - '/releases/2022/v220601-1234-5678', - '/releases/2021/v210601-5678-1234', - '/release-notes/1.2.3.4', - '/release-notes/2.0.x.y', - ] - invalidPaths.forEach((path) => { - expect(isReleaseNotesPage(path)).toBe(false) - }) - }) - - it('returns false for non-release notes page paths', () => { - const nonReleaseNotesPaths = [ - '/releases', - '/getting-started', - '/enterprise/v202401-1/migrate', - '/enterprise/v202401-1/releases', - '/waypoint/reference/config', - '/vault/install', - ] - nonReleaseNotesPaths.forEach((path) => { - expect(isReleaseNotesPage(path)).toBe(false) - }) - }) -}) diff --git a/src/lib/docs/is-release-notes-page.ts b/src/lib/docs/is-release-notes-page.ts deleted file mode 100644 index e3c50dfab3..0000000000 --- a/src/lib/docs/is-release-notes-page.ts +++ /dev/null @@ -1,11 +0,0 @@ -/** - * Copyright (c) HashiCorp, Inc. - * SPDX-License-Identifier: MPL-2.0 - */ - -// Hide the version selector on TFE release notes page, e.g. /terraform/enterprise// or /vault/docs/release-notes/1.13.0 -export const isReleaseNotesPage = (path: string) => - /(\/releases\/\d{4}\/(v\d{6}-\d{1}))$/i.test(path) || - /\/release-notes\/(v\d+[.|_]|(\d+[.|_]))\d+[.|_]([0-9]|x)$/i.test(path) - ? true - : false diff --git a/src/views/docs-view/server.ts b/src/views/docs-view/server.ts index 84424c41ed..b60f05a9f2 100644 --- a/src/views/docs-view/server.ts +++ b/src/views/docs-view/server.ts @@ -43,7 +43,6 @@ import { getDeployPreviewLoader } from './utils/get-deploy-preview-loader' import { getCustomLayout } from './utils/get-custom-layout' import type { DocsViewPropOptions } from './utils/get-root-docs-path-generation-functions' import { DocsViewProps } from './types' -import { isReleaseNotesPage } from 'lib/docs/is-release-notes-page' /** * Returns static generation functions which can be exported from a page to fetch docs data @@ -453,11 +452,7 @@ export function getStaticGenerationFunctions< }, projectName: projectName || null, versions: - !hideVersionSelector && - !isReleaseNotesPage(currentPathUnderProduct) && // toggle version dropdown - hasMeaningfulVersions - ? validVersions - : null, + !hideVersionSelector && hasMeaningfulVersions ? versions : null, } return { From 1512f68a37593f158cce5c25b6ff65dabcfe6935 Mon Sep 17 00:00:00 2001 From: Robert Main <50675045+rmainwork@users.noreply.github.com> Date: Thu, 12 Sep 2024 14:16:25 -0400 Subject: [PATCH 2/2] Remove edit button only for terraform enterprise (#2564) * Simplify isPublicContentRepo expression Since `isHcp` and `isSentinel` aren't used elsewhere, this expression can be simplified down to a one-liner Co-authored-by: Heat Hamilton <55773810+heatlikeheatwave@users.noreply.github.com> * Use URL to detect terraform enterprise This will hide the "Edit on GitHub" link for terraform enterprise only * Move PTFE detection logic from server.ts to loader * Move private repo logic from server.ts to loader Since logic was implemented in the loader to hide the "Edit this page on GitHub" link for PTFE, it makes sense to move the other (similar) logic there too to keep everything together. Additionally, this also allows the expression to be cleaned up to use `this.opts.product` and `Array.includes()` to detect private repos. --------- Co-authored-by: Heat Hamilton <55773810+heatlikeheatwave@users.noreply.github.com> --- src/views/docs-view/loaders/remote-content.ts | 17 ++++++++++++++++- src/views/docs-view/server.ts | 14 +------------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/views/docs-view/loaders/remote-content.ts b/src/views/docs-view/loaders/remote-content.ts index 36b55e43e2..89d9862ba2 100644 --- a/src/views/docs-view/loaders/remote-content.ts +++ b/src/views/docs-view/loaders/remote-content.ts @@ -264,7 +264,22 @@ export default class RemoteContentLoader implements DataLoader { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion versionMetadataList.find((e) => e.version === document.version)! .isLatest - if (isLatest) { + + /** + * We want to show "Edit on GitHub" links for public content repos only. + * Currently, HCP, PTFE and Sentinel docs are stored in private + * repositories. + * + * Note: If we need more granularity here, we could change this to be + * part of `rootDocsPath` configuration in `src/data/.json`. + */ + const isPrivateContentRepo = [ + 'hcp-docs', + 'sentinel', + 'ptfe-releases', + ].includes(this.opts.product) + + if (isLatest && !isPrivateContentRepo) { // GitHub only allows you to modify a file if you are on a branch, not a commit githubFileUrl = `https://github.com/hashicorp/${this.opts.product}/blob/${this.opts.mainBranch}/${document.githubFile}` } diff --git a/src/views/docs-view/server.ts b/src/views/docs-view/server.ts index b60f05a9f2..18fe0184c7 100644 --- a/src/views/docs-view/server.ts +++ b/src/views/docs-view/server.ts @@ -410,19 +410,7 @@ export function getStaticGenerationFunctions< validVersions.length > 0 && (validVersions.length > 1 || validVersions[0].version !== 'v0.0.x') - /** - * We want to show "Edit on GitHub" links for public content repos only. - * Currently, HCP and Sentinel docs are stored in private repositories. - * - * Note: If we need more granularity here, we could change this to be - * part of `rootDocsPath` configuration in `src/data/.json`. - */ - const isHcp = product.slug == 'hcp' - const isSentinel = product.slug == 'sentinel' - const isPublicContentRepo = !isHcp && !isSentinel - if (isPublicContentRepo) { - layoutProps.githubFileUrl = githubFileUrl - } + layoutProps.githubFileUrl = githubFileUrl const { hideVersionSelector, projectName } = options