Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure current site is always displayed in Sidebar List #24277

Merged

Conversation

pmusolino
Copy link
Member

Fixes #23569

This PR modifies the sidebar site display logic to ensure the currently selected site is always visible, regardless of its position in the recent sites list or alphabetical order.

Changes Made

  • Modified BlogListViewModel.topSites to prioritize displaying the currently selected site
  • Implemented three-tier priority system for site display:
  1. Current site (always shown)
  2. Recent sites (up to display limit)
  3. Other sites (alphabetically sorted)
  • Added some unit tests

Testing Instructions

On iPad/simulator

  1. Change SidebarView.displayedSiteLimit to a number smaller than RecentSitesService.maxSiteCount
  2. Log into an account with more sites than the display limit
  3. Select a site that would normally be pushed out of view (e.g., alphabetically last, you can create a site named "Zoo")
  4. Verify that the selected site remains visible in the sidebar

Screenshot

Simulator Screenshot - iPad Pro 13-inch (M4) - 2025-03-20 at 17 39 04

Regression Notes

  1. Potential unintended areas of impact

  2. What I did to test those areas of impact (or what existing automated tests I relied on)

  3. What automated tests I added (or what prevented me from doing so)

PR submission checklist:

  • I have completed the Regression Notes.
  • I have considered adding unit tests for my changes.
  • I have considered adding accessibility improvements for my changes.
  • I have considered if this change warrants user-facing release notes and have added them to RELEASE-NOTES.txt if necessary.

Testing checklist:

  • WordPress.com sites and self-hosted Jetpack sites.
  • Portrait and landscape orientations.
  • Light and dark modes.
  • Fonts: Larger, smaller and bold text.
  • High contrast.
  • VoiceOver.
  • Languages with large words or with letters/accents not frequently used in English.
  • Right-to-left languages. (Even if translation isn’t complete, formatting should still respect the right-to-left layout)
  • iPhone and iPad.
  • Multi-tasking: Split view and Slide over. (iPad)

Sorry, something went wrong.

- Update `BlogListViewModel.swift` to link `sidebarViewModel` and add logic for `currentSite`.
- Modify `SidebarViewController.swift` to set `blogListViewModel.sidebarViewModel` during initialization.
- Refactor `topSites` logic to ensure the current site is included, recent sites are prioritized, and all sites are sorted alphabetically.
…569-ensure-current-site-is-always-displayed-in-sidebar-list
@pmusolino pmusolino added iPad UI User interface bugs Tech Debt labels Mar 20, 2025
@pmusolino pmusolino added this to the 25.9 milestone Mar 20, 2025
@pmusolino pmusolino requested review from crazytonyli and kean March 20, 2025 17:12
@dangermattic
Copy link
Collaborator

1 Warning
⚠️ This PR is assigned to the milestone 25.9. The due date for this milestone has already passed.
Please assign it to a milestone with a later deadline or check whether the release for this milestone has already been finished.

Generated by 🚫 Danger

var encounteredIDs = Set(topSites.map(\.id))
for site in allSites where !encounteredIDs.contains(site.id) {
if topSites.count >= SidebarView.displayedSiteLimit {
var displaySites = [BlogListSiteViewModel]()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you tried the steps from #23569? I vaguely remember this code, but I think we opened it just in case. I doubt it's a real issue. recentSites always has your most recently selected site as the first item of the array. It's impossible for it to not get displayed. I might be wrong – not entirely sure about this code.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I followed the steps from the original issue, and I confirm I was able to replicate the issue, especially if you have multiple sites and you create or select a new one that starts with W or Z.

Screenshot:
Simulator Screenshot - iPad Pro 13-inch (M4) - 2025-03-21 at 14 13 18

@wpmobilebot
Copy link
Contributor

wpmobilebot commented Mar 20, 2025

WordPress Alpha📲 You can test the changes from this Pull Request in WordPress Alpha by scanning the QR code below to install the corresponding build.
App NameWordPress Alpha WordPress Alpha
ConfigurationRelease-Alpha
Build Numberpr24277-8aeec84
Version25.8
Bundle IDorg.wordpress.alpha
Commit8aeec84
App Center BuildWPiOS - One-Offs #11793
Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.

@wpmobilebot
Copy link
Contributor

wpmobilebot commented Mar 20, 2025

Jetpack Alpha📲 You can test the changes from this Pull Request in Jetpack Alpha by scanning the QR code below to install the corresponding build.
App NameJetpack Alpha Jetpack Alpha
ConfigurationRelease-Alpha
Build Numberpr24277-8aeec84
Version25.8
Bundle IDcom.jetpack.alpha
Commit8aeec84
App Center Buildjetpack-installable-builds #10818
Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.

}

// Add recent sites up to the limit
for site in recentSites {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(nit) you should be able to merge these two loops in one: for site in recentSites + allSites

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good suggestion f802776

return nil
}

return allSites.first { $0.id == selectedBlogID }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(nit) I'd probably suggest using try mainContext.existingObject(with: objectID) instead of iterating over allSites.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 implemented here 5bcfca3

@@ -70,4 +70,120 @@ final class BlogListViewModelTests: CoreDataTestCase {
let displayedNames = viewModel.allSites.map(\.title)
XCTAssertEqual(displayedNames, [".Org", "51 Zone", "A", "C"])
}

func test_topSites_includes_current_site() throws {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(nit) please use camel case. Btw, for new tests (new suites), feel free to use Swift Testing.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated here 8aeec84 👍

…t` for improved error handling
@pmusolino pmusolino added this pull request to the merge queue Mar 21, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Mar 21, 2025
@kean kean added this pull request to the merge queue Mar 21, 2025
Merged via the queue into trunk with commit 52dd231 Mar 21, 2025
25 checks passed
@kean kean deleted the issue/23569-ensure-current-site-is-always-displayed-in-sidebar-list branch March 21, 2025 16:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
iPad Tech Debt UI User interface bugs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The current site may not be displayed in the sidebar
4 participants