Skip to content

Conversation

@nbradbury
Copy link
Contributor

Partially resolves CMM-1136

Prior to this PR, if you're logged into wp.com and add a self-hosted site, the previously selected wp.com site would remain selected. This PR makes the added self-hosted site the selected site after logging into it.

To test:

  • Log into wp.com
  • Add a self-hosted site
  • Verify that the self-hosted site is shown after logging into it

@dangermattic
Copy link
Collaborator

dangermattic commented Jan 14, 2026

1 Warning
⚠️ PR is not assigned to a milestone.

Generated by 🚫 Danger

@nbradbury
Copy link
Contributor Author

@claude

@claude

This comment was marked as outdated.

@wpmobilebot
Copy link
Contributor

wpmobilebot commented Jan 14, 2026

App Icon📲 You can test the changes from this Pull Request in Jetpack by scanning the QR code below to install the corresponding build.
App NameJetpack
FlavorJalapeno
Build TypeDebug
Versionpr22482-2b24166
Commit2b24166
Direct Downloadjetpack-prototype-build-pr22482-2b24166.apk
Note: Google Login is not supported on these builds.

@wpmobilebot
Copy link
Contributor

wpmobilebot commented Jan 14, 2026

App Icon📲 You can test the changes from this Pull Request in WordPress by scanning the QR code below to install the corresponding build.
App NameWordPress
FlavorJalapeno
Build TypeDebug
Versionpr22482-2b24166
Commit2b24166
Direct Downloadwordpress-prototype-build-pr22482-2b24166.apk
Note: Google Login is not supported on these builds.

@codecov
Copy link

codecov bot commented Jan 14, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 38.94%. Comparing base (8cc6df5) to head (2b24166).
⚠️ Report is 2 commits behind head on trunk.

Additional details and impacted files
@@           Coverage Diff           @@
##            trunk   #22482   +/-   ##
=======================================
  Coverage   38.94%   38.94%           
=======================================
  Files        2189     2189           
  Lines      105355   105356    +1     
  Branches    14946    14946           
=======================================
+ Hits        41034    41035    +1     
  Misses      60890    60890           
  Partials     3431     3431           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

When adding a self-hosted site while logged into WordPress.com, the main
activity now correctly switches to show the newly added site instead of
continuing to show the previously selected WordPress.com site.

This fix handles both login flows by tracking site IDs before navigation
and detecting new sites on resume.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@nbradbury nbradbury force-pushed the issue/CMM-1136-show-added-dotorg-site branch from ecf37d1 to 70d8ff5 Compare January 14, 2026 15:50
nbradbury and others added 5 commits January 14, 2026 11:22
When a self-hosted site is added, automatically select it by detecting
non-WP.com sites in the OnSiteChanged event.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Replace the inelegant onSiteChanged approach with explicit site ID passing:
- Username/password login: setSite(data) in ADD_ACCOUNT case
- Application password login: Pass newSiteLocalId via intent to WPMainActivity
- Remove the broad "select any self-hosted site" code from onSiteChanged

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Remove the intent extra after selecting the site to prevent re-selecting
on activity recreation (e.g., rotation).

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Remove sSiteIdsBeforeNavigation and selectNewlyAddedSiteIfNeeded() as
they're no longer needed. Site selection is now handled explicitly via:
- setSite(data) for username/password login
- ARG_SELECTED_SITE intent extra for application password login

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@nbradbury
Copy link
Contributor Author

@claude

@claude
Copy link
Contributor

claude bot commented Jan 14, 2026

Claude finished @nbradbury's task in 1m 13s —— View job


Code Review for PR #22482

I've completed a comprehensive review of the changes to select newly added self-hosted sites after login.

Tasks

  • Read all changed files
  • Analyze code quality and implementation
  • Check security concerns (including nullable annotation warning)
  • Review performance and edge cases
  • Verify test coverage
  • Provide comprehensive feedback

Summary

This PR implements site selection after adding a self-hosted site via application password login. The implementation is clean and well-structured, with proper test coverage. The changes follow good architectural patterns and maintain consistency with the existing codebase.

Key Changes

The PR modifies the application password login flow to pass the newly added site's local ID to WPMainActivity, which then selects it on startup:

  1. ApplicationPasswordLoginViewModel - Added newSiteLocalId to NavigationActionData
  2. ApplicationPasswordLoginActivity - Passes site ID via intent extra to WPMainActivity
  3. WPMainActivity - Checks for and selects the site specified in ARG_SELECTED_SITE
  4. Tests - Updated to verify the new site ID is included in navigation data

Code Quality: ✅ Excellent

Strengths:

  • Clean implementation that follows existing patterns
  • Proper null safety with Kotlin nullable types and Java null checks
  • Good separation of concerns between ViewModel and Activity
  • Intent extra is properly cleaned up after use (getIntent().removeExtra(ARG_SELECTED_SITE))
  • The logic is well-placed in the onCreate flow

Minor Observations:

  • The refactored ApplicationPasswordLoginActivity.openMainActivity() is cleaner - removed the unused showSiteSelector branch
  • Good defensive programming: checks site existence before selecting (if (site != null))

Security: ⚠️ One Issue

GitHub Advanced Security Warning (Medium Priority):

The security scanner flagged a missing nullable annotation in WPMainActivity.java at line 220. While reviewing the code, I can confirm the field declaration on line 220 is:

public static final String ARG_SELECTED_SITE = "SELECTED_SITE_ID";

This is a public static final String constant, which cannot be null in Java. This appears to be a false positive from the security scanner, as:

  • It's a compile-time constant
  • The value is hardcoded as a string literal
  • There's no realistic way for this to be null

Recommendation: You can safely dismiss this security warning as a false positive. If the scanner continues to flag it, you could optionally add @NonNull for clarity, but it's not technically necessary for a static final String literal.

Performance: ✅ No Issues

  • The site lookup (mSiteStore.getSiteByLocalId()) is efficient and happens only once during activity creation
  • The extra is removed immediately after use, preventing unnecessary re-processing
  • No memory leaks or resource issues identified

Edge Cases: ✅ Well Handled

The implementation handles edge cases appropriately:

  1. Invalid site ID: Defaults to SelectedSiteRepository.UNAVAILABLE and falls back to normal site selection
  2. Null site: Checks if (site != null) before selecting
  3. Missing extra: Uses else-if chain to only init selected site if no explicit site ID provided
  4. Intent reuse: Removes the extra after processing to prevent reselection on configuration changes

One small observation: If the site ID is valid but the site doesn't exist in the store, it falls through to initSelectedSite(), which is the correct behavior.

Testing: ✅ Comprehensive

Test coverage is excellent:

  • 8 test cases covering various scenarios
  • All tests updated to include newSiteLocalId in expected results
  • Tests verify the field is properly set to testSite.id
  • Edge cases like empty data, malformed data, and error conditions are tested

Areas covered:

  • ✅ Empty raw data handling
  • ✅ Malformed data handling
  • ✅ Successful site addition with new site ID
  • ✅ Various combinations of site selector and interstitial flows
  • ✅ Error conditions

Documentation: ✅ Good

  • Added inline comment explaining the site selection logic: "Check if a specific site should be selected (e.g., after adding a self-hosted site)"
  • Removed an outdated comment in onSiteChanged() about improvement opportunities
  • Code is self-documenting with clear variable names

Additional Observations

Positive Changes:

  1. Line 1330 in WPMainActivity: Added setSite(data) after successful account addition, which ensures site selection is consistently handled
  2. The refactored control flow in ApplicationPasswordLoginActivity is cleaner and more maintainable

Architectural Fit:

  • The pattern of passing site selection via intent extras is consistent with existing code (see ChooseSiteActivity.KEY_SITE_LOCAL_ID)
  • The solution is minimal and doesn't over-engineer the problem

Recommendations

  1. ✅ Approve and merge - The implementation is solid and ready for production
  2. 📝 Optional: Consider adding a brief comment in ApplicationPasswordLoginActivity explaining why newSiteLocalId is being passed (for future maintainers)
  3. 🔍 Dismiss security warning - The nullable annotation warning is a false positive

Risk Assessment: Low Risk

This is a low-risk change:

  • Focused scope with clear purpose
  • Proper null checking and fallback behavior
  • Comprehensive test coverage
  • Doesn't break existing flows (extra is only used when present)

Verdict:LGTM - Well-implemented, tested, and ready to ship!

--- | Branch: issue/CMM-1136-show-added-dotorg-site

@nbradbury nbradbury marked this pull request as ready for review January 14, 2026 19:31
@nbradbury nbradbury requested a review from adalpari January 14, 2026 19:31
@sonarqubecloud
Copy link

Copy link
Contributor

@adalpari adalpari left a comment

Choose a reason for hiding this comment

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

LGTM and works as expected! 🚢 it!

@nbradbury nbradbury merged commit 7e3abd4 into trunk Jan 15, 2026
25 checks passed
@nbradbury nbradbury deleted the issue/CMM-1136-show-added-dotorg-site branch January 15, 2026 11:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants