diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt index d9efb5cf487e..0d92999a6d5a 100644 --- a/RELEASE-NOTES.txt +++ b/RELEASE-NOTES.txt @@ -21,6 +21,7 @@ * [*] Add scroll-to-top button to Reader streams [#23957] * [*] Add a quick way to replace a featured image for a post [#23962] * [*] Fix an issue with posts in Reader sometimes showing incorrect covers [#23914] +* [*] Fix non-stable order in Posts and Pages section in Stats [#23915] 25.6 ----- diff --git a/WordPress/Classes/Stores/StatsPeriodStore.swift b/WordPress/Classes/Stores/StatsPeriodStore.swift index ab7937953065..8686f4740f14 100644 --- a/WordPress/Classes/Stores/StatsPeriodStore.swift +++ b/WordPress/Classes/Stores/StatsPeriodStore.swift @@ -895,12 +895,24 @@ private extension StatsPeriodStore { } } - private func receivedPostsAndPages(_ postsAndPages: StatsTopPostsTimeIntervalData?, _ error: Error?) { + private func receivedPostsAndPages(_ data: StatsTopPostsTimeIntervalData?, _ error: Error?) { transaction { state in state.topPostsAndPagesStatus = error != nil ? .error : .success - if postsAndPages != nil { - state.topPostsAndPages = postsAndPages + if let data { + let sortedTopPosts = data.topPosts.sorted { lhs, rhs in + if lhs.viewsCount == rhs.viewsCount { + return lhs.title.localizedCaseInsensitiveCompare(rhs.title) == .orderedAscending + } + return lhs.viewsCount > rhs.viewsCount + } + state.topPostsAndPages = StatsTopPostsTimeIntervalData( + period: data.period, + periodEndDate: data.periodEndDate, + topPosts: sortedTopPosts, + totalViewsCount: data.totalViewsCount, + otherViewsCount: data.otherViewsCount + ) } } }