mirror of
https://github.com/Redocly/redoc.git
synced 2025-03-09 20:35:48 +03:00
fix: when building factored SideNav menu, don't drop final children
At the end of the loop, we need to append the remaining new children, if there are any.
This commit is contained in:
parent
b5c5436fac
commit
a86cf3830d
|
@ -8,6 +8,15 @@ import type { ContentItemModel, TagGroup, TagInfo, TagsInfoMap } from './types';
|
||||||
|
|
||||||
export const GROUP_DEPTH = 0;
|
export const GROUP_DEPTH = 0;
|
||||||
|
|
||||||
|
function appendChildren(parent: ContentItemModel, children: ContentItemModel[], prefix: string) {
|
||||||
|
for (const child of MenuBuilder.factorByPrefix(children)) {
|
||||||
|
if (child.sidebarLabel.startsWith(prefix)) {
|
||||||
|
child.sidebarLabel = '…' + child.sidebarLabel.slice(prefix.length - 1);
|
||||||
|
}
|
||||||
|
parent.items.push(child);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export class MenuBuilder {
|
export class MenuBuilder {
|
||||||
/**
|
/**
|
||||||
* Builds page content structure based on tags
|
* Builds page content structure based on tags
|
||||||
|
@ -46,12 +55,7 @@ export class MenuBuilder {
|
||||||
newChildren.push(item);
|
newChildren.push(item);
|
||||||
} else {
|
} else {
|
||||||
if (newChildren.length > 0) {
|
if (newChildren.length > 0) {
|
||||||
for (const child of MenuBuilder.factorByPrefix(newChildren)) {
|
appendChildren(parent!, newChildren, prefix);
|
||||||
if (child.sidebarLabel.startsWith(prefix)) {
|
|
||||||
child.sidebarLabel = '…' + child.sidebarLabel.slice(prefix.length - 1);
|
|
||||||
}
|
|
||||||
parent!.items.push(child);
|
|
||||||
}
|
|
||||||
newChildren = [];
|
newChildren = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,6 +66,7 @@ export class MenuBuilder {
|
||||||
} else parent = null;
|
} else parent = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (newChildren.length > 0) appendChildren(parent!, newChildren, prefix);
|
||||||
return newItems;
|
return newItems;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user