Skip to content

Conversation

@Jignesh-dimagi
Copy link
Contributor

Product Description

This is fix for bug

Technical Summary

https://dimagi.atlassian.net/browse/CCCT-961

Feature Flag

Bug fix

Safety Assurance

Safety story

Test on staging and prod app for said changes

QA Plan

This PR needs testing the connect ID sign up and recover flow

Labels and Review

  • Do we need to enhance the manual QA test coverage ? If yes, the "QA Note" label is set correctly
  • Does the PR introduce any major changes worth communicating ? If yes, the "Release Note" label is set and a "Release Note" is specified in PR description.
  • Risk label is set correctly
  • The set of people pinged as reviewers is appropriate for the level of risk of the change

@coderabbitai
Copy link

coderabbitai bot commented Apr 22, 2025

📝 Walkthrough

Walkthrough

The changes introduce a new utility class, CommCareNavigationController.kt, which provides a navigateSafely extension function for Android's NavController. This function ensures navigation actions are only performed when the navigation directions and destination are valid, reducing the risk of navigation errors. Existing navigation calls in several Java classes (ConnectIdActivity, ConnectIDSignupFragment, ConnectIdBiometricConfigFragment, and ConnectIdPhoneVerificationFragmnet) are refactored to use this new utility method instead of direct navigation calls. The explicit null checks around navigation are removed in favor of delegating safety checks to the utility function. Additionally, the visibility of the controller field in ConnectIdActivity is changed from public static to private, and necessary imports for the new utility are added where required. No changes are made to the external signatures of public entities except for the visibility modification.

Sequence Diagram(s)

sequenceDiagram
    participant UI_Component as UI Component (Activity/Fragment)
    participant NavController
    participant CommCareNavController

    UI_Component->>CommCareNavController: navigateSafely(navController, navDirections)
    CommCareNavController->>NavController: Validate navDirections and destination
    alt Valid navigation
        CommCareNavController->>NavController: navigate(navDirections)
    else Invalid navigation
        CommCareNavController-->>UI_Component: No navigation performed
    end
Loading

Suggested labels

cross requested, skip-integration-tests

Suggested reviewers

  • pm-dimagi
  • OrangeAndGreen
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
app/src/org/commcare/activities/connect/ConnectIdActivity.java (1)

139-147: Consider updating this navigation call too.

The navigation call in beginSecondaryPhoneVerification still uses the direct approach rather than the new safe navigation utility. Consider updating this for consistency.

-        controller.navigate(navDirections);
+        CommCareNavController.navigateSafely(controller, navDirections);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between aba660f and fad7126.

📒 Files selected for processing (5)
  • app/src/org/commcare/activities/connect/ConnectIdActivity.java (3 hunks)
  • app/src/org/commcare/fragments/connectId/ConnectIDSignupFragment.java (4 hunks)
  • app/src/org/commcare/fragments/connectId/ConnectIdBiometricConfigFragment.java (2 hunks)
  • app/src/org/commcare/fragments/connectId/ConnectIdPhoneVerificationFragmnet.java (2 hunks)
  • app/src/org/commcare/utils/CommCareNavigationController.kt (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (3)
app/src/org/commcare/activities/connect/ConnectIdActivity.java (1)
app/src/org/commcare/utils/CommCareNavigationController.kt (1)
  • navigateSafely (9-21)
app/src/org/commcare/fragments/connectId/ConnectIdPhoneVerificationFragmnet.java (1)
app/src/org/commcare/utils/CommCareNavigationController.kt (1)
  • navigateSafely (9-21)
app/src/org/commcare/fragments/connectId/ConnectIdBiometricConfigFragment.java (1)
app/src/org/commcare/utils/CommCareNavigationController.kt (1)
  • navigateSafely (9-21)
🔇 Additional comments (9)
app/src/org/commcare/utils/CommCareNavigationController.kt (1)

1-25: Well-implemented safe navigation utility

This is a well-designed utility for preventing navigation crashes. The extension function performs comprehensive checks before navigation:

  1. Validates both the NavDirections and current destination
  2. Verifies the navigation action exists
  3. Ensures the destination ID is valid and exists in the navigation graph

The @file:JvmName annotation properly exposes this Kotlin code to Java, and the null-safety checks are thorough.

app/src/org/commcare/fragments/connectId/ConnectIdPhoneVerificationFragmnet.java (2)

41-41: Import added correctly for safe navigation utility.

The CommCareNavController import has been properly added to support the safe navigation implementation.


615-615: Navigation call updated to use safe navigation.

The direct navigation call has been properly replaced with the safer navigateSafely extension function, which will prevent potential crashes when navigation is attempted with invalid directions or destinations.

app/src/org/commcare/activities/connect/ConnectIdActivity.java (3)

22-22: Import added correctly for safe navigation utility.

The CommCareNavController import has been properly added to support the safe navigation implementation.


32-32: Improved encapsulation by making controller private.

Good change - reducing the scope of the NavController from public static to private improves encapsulation and prevents external manipulation.


135-135: Navigation call updated to use safe navigation.

The direct navigation call has been properly replaced with the safer navigateSafely extension function, which will prevent potential crashes when navigation is attempted with invalid directions or destinations.

app/src/org/commcare/fragments/connectId/ConnectIDSignupFragment.java (2)

36-36: Import added correctly for safe navigation utility.

The CommCareNavController import has been properly added to support the safe navigation implementation.


248-248: Navigation calls consistently updated to use safe navigation.

All direct navigation calls in this file have been properly replaced with the safer navigateSafely extension function, which provides consistent protection against navigation crashes throughout the sign-up flow.

Also applies to: 253-253, 306-306, 311-311, 388-388

app/src/org/commcare/fragments/connectId/ConnectIdBiometricConfigFragment.java (1)

32-32: Safe navigation implementation improves stability.

The change adds proper import for the utility class and replaces direct navigation with the safer navigateSafely utility method. This improves the robustness of the navigation by performing comprehensive validation beyond simple null checks, including verifying valid destinations and actions before attempting navigation.

Also applies to: 285-287

Copy link
Contributor

@OrangeAndGreen OrangeAndGreen left a comment

Choose a reason for hiding this comment

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

If we're employing this new safety code in three of the fragments, I wonder if it's worth adding it to the other fragments now as well? I worry that it might take us a while to come back and complete this if we don't do it now... @shubham1g5 Your thoughts?

if (navAction != null) {
val destinationId: Int = navAction.destinationId.orEmpty()
val currentNode: NavGraph? = if (currentDestination is NavGraph) currentDestination else currentDestination.parent
if (destinationId != 0 && currentNode != null && currentNode.findNode(destinationId) != null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Looking at all the conditions that need to be met on the way to finally calling navigate(), I'm wondering in which cases we might want to log a non-fatal exception to Firebase vs. silently do nothing. Is the else-case in each of the three ifs an error situation that we should track?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@OrangeAndGreen We already have crashes in app but still not able to identify the cause as its not giving any useful information to trace the issue. Also, I have feeling that lets not add at other places before seeing the reactions from user so kept at sign up / recovery mode only.

Base automatically changed from connect_qa to dv/connect_initial April 23, 2025 09:19
@Jignesh-dimagi Jignesh-dimagi merged commit fab7395 into dv/connect_initial Apr 24, 2025
1 of 2 checks passed
@shubham1g5 shubham1g5 deleted the jignesh/fix/ccct-961 branch April 24, 2025 13:08
@coderabbitai coderabbitai bot mentioned this pull request Jun 6, 2025
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants