Skip to content

Commit

Permalink
Remove edit button only for terraform enterprise (#2564)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

* 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 <[email protected]>
  • Loading branch information
rmainwork and heatlikeheatwave committed Sep 12, 2024
1 parent f4ef779 commit 1512f68
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
17 changes: 16 additions & 1 deletion src/views/docs-view/loaders/remote-content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/<product>.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}`
}
Expand Down
14 changes: 1 addition & 13 deletions src/views/docs-view/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/<product>.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

Expand Down

0 comments on commit 1512f68

Please sign in to comment.