Skip to content

Commit

Permalink
fix: version idx 0 is rendering twice
Browse files Browse the repository at this point in the history
  • Loading branch information
abvthecity committed Mar 26, 2024
1 parent 2221a87 commit 0eb140f
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -186,3 +186,47 @@ exports[`getAllUrlsFromDocsConfig > primer > gets all urls from docs config 1`]
"primer.io/docs/api/v2/api-reference/payment-methods-api/set-payment-method-default-payment-methods-token-default-post",
]
`;

exports[`getNavigationRoot > primer > gets navigation root for /docs/api/introduction/getting-started 1`] = `
[
{
"availability": "Stable",
"id": "v2.3",
"index": 0,
"slug": [
"docs",
"api",
],
},
{
"availability": null,
"id": "v2.2",
"index": 1,
"slug": [
"docs",
"api",
"v2.2",
],
},
{
"availability": null,
"id": "v2.1",
"index": 2,
"slug": [
"docs",
"api",
"v2.1",
],
},
{
"availability": null,
"id": "v2",
"index": 3,
"slug": [
"docs",
"api",
"v2",
],
},
]
`;
25 changes: 25 additions & 0 deletions packages/commons/fdr-utils/src/__test__/primer.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
import { DocsV2Read } from "@fern-api/fdr-sdk";
import fs from "fs";
import path from "path";
import { getNavigationRoot } from "../getNavigationRoot";
import { testGetAllUrlsFromDocsConfig } from "./testGetAllUrlsFromDocsConfig";

describe("getAllUrlsFromDocsConfig", () => {
testGetAllUrlsFromDocsConfig("primer");
});

describe("getNavigationRoot", () => {
describe("primer", () => {
it("gets navigation root for /docs/api/introduction/getting-started", async () => {
const fixturePath = path.join(__dirname, "fixtures", "primer.json");

const content = fs.readFileSync(fixturePath, "utf-8");

const fixture = JSON.parse(content) as DocsV2Read.LoadDocsForUrlResponse;

const urls = getNavigationRoot(
"docs/api/introduction/getting-started".split("/"),
fixture.baseUrl.basePath,
fixture.definition.config.navigation,
fixture.definition.apis,
);

expect(urls?.type === "found" ? urls.found.versions : []).toMatchSnapshot();
});
});
});
15 changes: 9 additions & 6 deletions packages/commons/fdr-utils/src/getNavigationRoot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,15 @@ export function getNavigationRoot(
// const sidebarNodes = await Promise.all(rawSidebarNodes.map((node) => serializeSidebarNodeDescriptionMdx(node)));
const found: SidebarNavigationRaw = {
currentVersionIndex: versions.index,
versions: versions.items.map((version) => ({
id: version.id,
slug: version.slug,
index: version.index,
availability: version.availability,
})),
versions: versions.items
.map((version) => ({
id: version.id,
slug: version.slug,
index: version.index,
availability: version.availability,
}))
// get rid of duplicate version
.filter((version, idx) => version.index > 0 || version.index === idx),
currentTabIndex: tabs.index,
tabs: tabs.items.map((tab) => ({
title: tab.title,
Expand Down

0 comments on commit 0eb140f

Please sign in to comment.