Skip to content

Commit

Permalink
Fix reversed ordering of enum entries (#2469)
Browse files Browse the repository at this point in the history
* Fix reversed ordering of enum entries

Fixes #2466

* Add navigation sideMenu unit tests

* Make enum entries in tests non alphabetical
  • Loading branch information
IgnatBeresnev committed Apr 26, 2022
1 parent 52d066c commit a43f710
Show file tree
Hide file tree
Showing 3 changed files with 241 additions and 49 deletions.
24 changes: 15 additions & 9 deletions plugins/base/src/main/kotlin/renderers/html/htmlPreprocessors.kt
Expand Up @@ -26,15 +26,21 @@ abstract class NavigationDataProvider {
children = page.navigableChildren()
)

private fun ContentPage.navigableChildren(): List<NavigationNode> =
when {
this !is ClasslikePageNode ->
children.filterIsInstance<ContentPage>().map { visit(it) }
documentables.any { it is DEnum } ->
children.filter { it is WithDocumentables && it.documentables.any { it is DEnumEntry } }
.map { visit(it as ContentPage) }
else -> emptyList()
}.sortedBy { it.name.toLowerCase() }
private fun ContentPage.navigableChildren(): List<NavigationNode> {
return if (this !is ClasslikePageNode) {
children
.filterIsInstance<ContentPage>()
.map { visit(it) }
.sortedBy { it.name.toLowerCase() }
} else if (documentables.any { it is DEnum }) {
// no sorting for enum entries, should be the same as in source code
children
.filter { child -> child is WithDocumentables && child.documentables.any { it is DEnumEntry } }
.map { visit(it as ContentPage) }
} else {
emptyList()
}
}

/**
* Parenthesis is applied in 1 case:
Expand Down
Expand Up @@ -216,7 +216,7 @@ class DocumentableVisibilityFilterTransformer(val context: DokkaContext) : PreMe
}

private fun filterEnumEntries(entries: List<DEnumEntry>, filteredPlatforms: Set<DokkaSourceSet>): Pair<Boolean, List<DEnumEntry>> =
entries.foldRight(Pair(false, emptyList())) { entry, acc ->
entries.fold(Pair(false, emptyList())) { acc, entry ->
val intersection = filteredPlatforms.intersect(entry.sourceSets)
if (intersection.isEmpty()) Pair(true, acc.second)
else {
Expand Down

0 comments on commit a43f710

Please sign in to comment.