Skip to content

Commit

Permalink
fix: support nested FlattenApiSection (#840)
Browse files Browse the repository at this point in the history
  • Loading branch information
abvthecity authored May 9, 2024
1 parent c6cf8fb commit ea48616
Showing 1 changed file with 44 additions and 31 deletions.
75 changes: 44 additions & 31 deletions packages/ui/app/src/sidebar/SidebarApiSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,39 +28,21 @@ export const SidebarApiSection: React.FC<SidebarApiSectionProps> = ({
}) => {
const { selectedSlug } = useCollapseSidebar();

if (apiSection.isSidebarFlattened) {
return (
<li>
<FlattenedApiSection
apiSection={apiSection}
registerScrolledToPathListener={registerScrolledToPathListener}
depth={depth}
/>
</li>
);
}

return depth === 0 ? (
<li>
{apiSection.isSidebarFlattened ? (
<ul className="fern-sidebar-group">
{apiSection.items.map((item) =>
visitDiscriminatedUnion(item, "type")._visit({
apiSection: (item) => (
<SidebarApiSection
key={item.id}
apiSection={item}
registerScrolledToPathListener={registerScrolledToPathListener}
depth={depth}
/>
),
page: (item) => (
<SidebarApiSlugLink
key={joinUrlSlugs(...item.slug)}
item={item}
api={apiSection.api}
registerScrolledToPathListener={registerScrolledToPathListener}
depth={depth}
/>
),
_other: () => (
<FernErrorTag
component="SidebarApiSection"
error="Tried to render unknown api section."
/>
),
}),
)}
</ul>
) : apiSection.summaryPage != null ? (
{apiSection.summaryPage != null ? (
<SidebarSlugLink
className={cn({
"mt-6": depth === 0,
Expand Down Expand Up @@ -306,3 +288,34 @@ export const ExpandableSidebarApiSection: React.FC<ExpandableSidebarApiSectionPr
</SidebarSlugLink>
);
};

function FlattenedApiSection({ apiSection, registerScrolledToPathListener, depth }: SidebarApiSectionProps) {
return (
<ul className="fern-sidebar-group">
{apiSection.items.map((item) =>
visitDiscriminatedUnion(item, "type")._visit({
apiSection: (item) => (
<SidebarApiSection
key={item.id}
apiSection={item}
registerScrolledToPathListener={registerScrolledToPathListener}
depth={depth}
/>
),
page: (item) => (
<SidebarApiSlugLink
key={joinUrlSlugs(...item.slug)}
item={item}
api={apiSection.api}
registerScrolledToPathListener={registerScrolledToPathListener}
depth={depth}
/>
),
_other: () => (
<FernErrorTag component="SidebarApiSection" error="Tried to render unknown api section." />
),
}),
)}
</ul>
);
}

0 comments on commit ea48616

Please sign in to comment.