Skip to content

Commit

Permalink
fix: bug bashing PR #955 (#957)
Browse files Browse the repository at this point in the history
  • Loading branch information
abvthecity authored Jun 4, 2024
1 parent b35c776 commit d2c3f08
Show file tree
Hide file tree
Showing 16 changed files with 189 additions and 134 deletions.
3 changes: 2 additions & 1 deletion packages/commons/fdr-utils/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ export interface ColorsConfig {
}

export interface SidebarVersionInfo {
id: string;
id: FernNavigation.VersionId;
title: string;
slug: FernNavigation.Slug;
index: number;
availability: FernNavigation.Availability | undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ exports[`getNavigationRoot > yes-version-no-tabs > gets navigation root for /doc
}
`;

exports[`getNavigationRoot > yes-version-no-tabs > gets navigation root for /docs/api/page-5 2`] = `"version-1"`;
exports[`getNavigationRoot > yes-version-no-tabs > gets navigation root for /docs/api/page-5 2`] = `"Version 1"`;

exports[`getNavigationRoot > yes-version-no-tabs > gets navigation root for /docs/api/page-5 3`] = `undefined`;

Expand All @@ -63,7 +63,7 @@ exports[`getNavigationRoot > yes-version-no-tabs > gets navigation root for /doc
}
`;

exports[`getNavigationRoot > yes-version-no-tabs > gets navigation root for /docs/api/version-1 2`] = `"version-1"`;
exports[`getNavigationRoot > yes-version-no-tabs > gets navigation root for /docs/api/version-1 2`] = `"Version 1"`;

exports[`getNavigationRoot > yes-version-no-tabs > gets navigation root for /docs/api/version-1 3`] = `undefined`;

Expand All @@ -79,7 +79,7 @@ exports[`getNavigationRoot > yes-version-no-tabs > gets navigation root for /doc
}
`;

exports[`getNavigationRoot > yes-version-no-tabs > gets navigation root for /docs/api/version-1 5`] = `"version-1"`;
exports[`getNavigationRoot > yes-version-no-tabs > gets navigation root for /docs/api/version-1 5`] = `"Version 1"`;

exports[`getNavigationRoot > yes-version-no-tabs > gets navigation root for /docs/api/version-1 6`] = `undefined`;

Expand All @@ -95,7 +95,7 @@ exports[`getNavigationRoot > yes-version-no-tabs > gets navigation root for /doc
}
`;

exports[`getNavigationRoot > yes-version-no-tabs > gets navigation root for /docs/api/version-1/page-5 2`] = `"version-1"`;
exports[`getNavigationRoot > yes-version-no-tabs > gets navigation root for /docs/api/version-1/page-5 2`] = `"Version 1"`;

exports[`getNavigationRoot > yes-version-no-tabs > gets navigation root for /docs/api/version-1/page-5 3`] = `undefined`;

Expand All @@ -118,7 +118,7 @@ exports[`getNavigationRoot > yes-version-no-tabs > gets navigation root for /doc
}
`;

exports[`getNavigationRoot > yes-version-no-tabs > gets navigation root for /docs/api/version-1/version-1 2`] = `"version-1"`;
exports[`getNavigationRoot > yes-version-no-tabs > gets navigation root for /docs/api/version-1/version-1 2`] = `"Version 1"`;

exports[`getNavigationRoot > yes-version-no-tabs > gets navigation root for /docs/api/version-1/version-1 3`] = `undefined`;

Expand All @@ -141,6 +141,6 @@ exports[`getNavigationRoot > yes-version-no-tabs > gets navigation root for /doc
}
`;

exports[`getNavigationRoot > yes-version-no-tabs > gets navigation root for /docs/api/version-2/version-1 2`] = `"version-2"`;
exports[`getNavigationRoot > yes-version-no-tabs > gets navigation root for /docs/api/version-2/version-1 2`] = `"Version 2"`;

exports[`getNavigationRoot > yes-version-no-tabs > gets navigation root for /docs/api/version-2/version-1 3`] = `undefined`;
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ exports[`getNavigationRoot > yes-version-yes-tabs > gets navigation root for /do
}
`;

exports[`getNavigationRoot > yes-version-yes-tabs > gets navigation root for /docs/api/tab-1 2`] = `"version-1"`;
exports[`getNavigationRoot > yes-version-yes-tabs > gets navigation root for /docs/api/tab-1 2`] = `"Version 1"`;

exports[`getNavigationRoot > yes-version-yes-tabs > gets navigation root for /docs/api/tab-1 3`] = `"docs/api/tab-1"`;

Expand Down Expand Up @@ -81,7 +81,7 @@ exports[`getNavigationRoot > yes-version-yes-tabs > gets navigation root for /do
}
`;

exports[`getNavigationRoot > yes-version-yes-tabs > gets navigation root for /docs/api/version-1/section-2 2`] = `"version-1"`;
exports[`getNavigationRoot > yes-version-yes-tabs > gets navigation root for /docs/api/version-1/section-2 2`] = `"Version 1"`;

exports[`getNavigationRoot > yes-version-yes-tabs > gets navigation root for /docs/api/version-1/section-2 3`] = `"docs/api/version-1/tab-1"`;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"type": "version",
"title": "v4.0",
"default": true,
"versionId": "v4",
"versionId": "v4.0",
"slug": "",
"child": {
"id": "root..*.uv",
Expand Down Expand Up @@ -2071,7 +2071,7 @@
"type": "version",
"title": "v4.0",
"default": false,
"versionId": "v4",
"versionId": "v4.0",
"slug": "v4",
"hidden": true,
"child": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"type": "version",
"title": "v4.0",
"default": true,
"versionId": "v4",
"versionId": "v4.0",
"slug": "",
"child": {
"id": "root..*.uv",
Expand Down Expand Up @@ -2065,7 +2065,7 @@
"type": "version",
"title": "v4.0",
"default": false,
"versionId": "v4",
"versionId": "v4.0",
"slug": "v4",
"hidden": true,
"child": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"type": "version",
"title": "Version 1",
"default": true,
"versionId": "version-1",
"versionId": "Version 1",
"slug": "docs/api",
"child": {
"id": "root..*.uv",
Expand Down Expand Up @@ -97,7 +97,7 @@
"type": "version",
"title": "Version 1",
"default": false,
"versionId": "version-1",
"versionId": "Version 1",
"slug": "docs/api/version-1",
"hidden": true,
"child": {
Expand Down Expand Up @@ -185,7 +185,7 @@
"type": "version",
"title": "Version 2",
"default": false,
"versionId": "version-2",
"versionId": "Version 2",
"slug": "docs/api/version-2",
"hidden": false,
"child": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"type": "version",
"title": "Version 1",
"default": true,
"versionId": "version-1",
"versionId": "Version 1",
"slug": "docs/api",
"child": {
"id": "root..*.uv",
Expand Down Expand Up @@ -91,7 +91,7 @@
"type": "version",
"title": "Version 1",
"default": false,
"versionId": "version-1",
"versionId": "Version 1",
"slug": "docs/api/version-1",
"hidden": true,
"child": {
Expand Down Expand Up @@ -179,7 +179,7 @@
"type": "version",
"title": "Version 2",
"default": false,
"versionId": "version-2",
"versionId": "Version 2",
"slug": "docs/api/version-2",
"hidden": false,
"child": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"type": "version",
"title": "Version 1",
"default": true,
"versionId": "version-1",
"versionId": "Version 1",
"slug": "docs/api",
"child": {
"id": "root..*.uv",
Expand Down Expand Up @@ -175,7 +175,7 @@
"type": "version",
"title": "Version 1",
"default": false,
"versionId": "version-1",
"versionId": "Version 1",
"slug": "docs/api/version-1",
"hidden": true,
"child": {
Expand Down Expand Up @@ -341,7 +341,7 @@
"type": "version",
"title": "Version 2",
"default": false,
"versionId": "version-2",
"versionId": "Version 2",
"slug": "docs/api/version-2",
"hidden": false,
"child": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"type": "version",
"title": "Version 1",
"default": true,
"versionId": "version-1",
"versionId": "Version 1",
"slug": "docs/api",
"child": {
"id": "root..*.uv",
Expand Down Expand Up @@ -169,7 +169,7 @@
"type": "version",
"title": "Version 1",
"default": false,
"versionId": "version-1",
"versionId": "Version 1",
"slug": "docs/api/version-1",
"hidden": true,
"child": {
Expand Down Expand Up @@ -335,7 +335,7 @@
"type": "version",
"title": "Version 2",
"default": false,
"versionId": "version-2",
"versionId": "Version 2",
"slug": "docs/api/version-2",
"hidden": false,
"child": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ export class NavigationConfigConverter {
type: "version",
title: version.version,
default: true,
versionId: FernNavigation.VersionId(version.urlSlug),
// the versionId must match `indexSegmentsByVersionId`
versionId: FernNavigation.VersionId(version.version),
slug: baseSlug,
icon: undefined,
hidden: undefined,
Expand All @@ -95,7 +96,8 @@ export class NavigationConfigConverter {
type: "version",
title: version.version,
default: false,
versionId: FernNavigation.VersionId(version.urlSlug),
// the versionId must match `indexSegmentsByVersionId`
versionId: FernNavigation.VersionId(version.version),
slug,
icon: undefined,
hidden: idx === 0, // hidden from the version selector
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,38 @@ export function flattenApiSection(root: FernNavigation.SidebarRootNode): ApiGrou
return;
}

const breadcrumbs = parents.filter(FernNavigation.isSection).map((parent) => parent);
const breadcrumbs = [...parents, node].filter(FernNavigation.isSection).map((parent) => parent.title);
result.push({
api: node.apiDefinitionId,
id: node.id,
breadcrumbs: breadcrumbs.map((breadcrumb) => breadcrumb.title),
breadcrumbs,
items,
});
}
return;
});
return result;

if (result.length === 0) {
return [];
}

/**
* we want to get the lowest level of breadcrumbs shared by all groups
* for example:
* - [a, b, c]
* - [a, b, d]
*
* the shared breadcrumbs would be [a, b], and the resulting breadcrumbs for each group would be [c] and [d]
*/
const allBreadcrumbs = result.map((group) => group.breadcrumbs);
const sharedBreadcrumbs = allBreadcrumbs.reduce((acc, breadcrumbs) => {
return acc.filter((breadcrumb, idx) => breadcrumb === breadcrumbs[idx]);
}, allBreadcrumbs[0]);

return result.map((group) => ({
...group,
breadcrumbs: group.breadcrumbs.slice(sharedBreadcrumbs.length),
}));
}

function matchesEndpoint(query: string, group: ApiGroup, endpoint: FernNavigation.NavigationNodeApiLeaf): boolean {
Expand Down
Loading

0 comments on commit d2c3f08

Please sign in to comment.