Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modifications to get remote-content to fetch versionless docs #2642

Merged
merged 3 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/views/docs-view/loaders/__tests__/remote-content.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ describe('RemoteContentLoader', () => {
loader = new RemoteContentLoader({
basePath: 'commands',
product: 'waypoint',
latestVersionRef: 'v0.5.x',
})

nock.disableNetConnect()
Expand Down Expand Up @@ -67,6 +68,7 @@ describe('RemoteContentLoader', () => {
basePath: 'plugin/mux',
navDataPrefix: 'plugin-mux',
product: 'terraform-plugin-mux',
latestVersionRef: 'v0.6.x',
})

scope
Expand Down Expand Up @@ -153,7 +155,9 @@ describe('RemoteContentLoader', () => {
.get('/api/content/waypoint/nav-data/v0.5.x/commands')
.reply(200, navData_200)

const props = await loader.loadStaticProps({ params: {} })
const props = await loader.loadStaticProps({
params: { page: ['v0.5.x'] },
})

expect(props).toMatchInlineSnapshot(
{
Expand All @@ -165,7 +169,7 @@ describe('RemoteContentLoader', () => {
},
`
{
"currentPath": "",
"currentPath": "v0.5.x",
"frontMatter": {
"layout": "commands",
"page_title": "Waypoint Commands (CLI)",
Expand Down
22 changes: 4 additions & 18 deletions src/views/docs-view/loaders/remote-content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ interface LoadStaticPropsReturn {
}

const moizeOpts: Options = { isPromise: true, maxSize: Infinity }
const cachedFetchNavData = moize(fetchNavData, moizeOpts)
const cachedFetchVersionMetadataList = moize(
fetchVersionMetadataList,
moizeOpts
Expand Down Expand Up @@ -147,19 +146,10 @@ export default class RemoteContentLoader implements DataLoader {
loadStaticPaths = async (): Promise<
{ params: Record<string, string[]> }[]
> => {
// Fetch version metadata to get "latest"
const versionMetadataList = await cachedFetchVersionMetadataList(
this.opts.product
)

const latest: string =
this.opts.latestVersionRef ??
versionMetadataList.find((e) => e.isLatest).version

const latest: string = this.opts.latestVersionRef ?? 'latest'
// Fetch and parse navigation data
const navDataResponse = await cachedFetchNavData(
const navDataResponse = await fetchNavData(
this.opts.product,
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
this.opts.navDataPrefix!,
latest
)
Expand Down Expand Up @@ -206,10 +196,7 @@ export default class RemoteContentLoader implements DataLoader {
const versionMetadataList: VersionMetadataItem[] =
await cachedFetchVersionMetadataList(this.opts.product)

const latestVersion =
this.opts.latestVersionRef ??
versionMetadataList.find((e) => e.isLatest)?.version

const latestVersion = this.opts.latestVersionRef ?? 'latest'
let versionToFetch = latestVersion

if (this.opts.enabledVersionedDocs) {
Expand All @@ -236,9 +223,8 @@ export default class RemoteContentLoader implements DataLoader {
].join('/')

const documentPromise = fetchDocument(this.opts.product, fullPath)
const navDataPromise = cachedFetchNavData(
const navDataPromise = fetchNavData(
this.opts.product,
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
this.opts.navDataPrefix!,
versionToFetch
)
Expand Down
Loading