Fix the issue in Linking Care Context for V3#51
Conversation
📝 WalkthroughWalkthroughThe PR removes the OTP-based care-context mapping flow ( ChangesCare-Context V3 Linking Flow
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/registrar/abha-components/health-id-display-modal/health-id-display-modal.component.ts (1)
182-299: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winRefactor
linkCareContextV3below the cognitive-complexity threshold.SonarCloud flags this method at 17 where 15 is allowed. Extract token/link request building and response/error handling into helpers, or flatten the nested subscriptions so this PR does not fail the quality gate.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/registrar/abha-components/health-id-display-modal/health-id-display-modal.component.ts` around lines 182 - 299, The linkCareContextV3 method is too complex and needs to be split up to meet the cognitive-complexity limit. Extract the token request creation, link request creation, and the success/error handling for generateLinkTokenForCareContext and linkCareContextV3 into separate helper methods, or flatten the nested subscribe flow in health-id-display-modal.component.ts while keeping the same behavior and alerts. Use the existing linkCareContextV3 and related request/response symbols to locate the logic and reduce branching in the main method.Source: Linters/SAST tools
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In
`@src/registrar/abha-components/health-id-display-modal/health-id-display-modal.component.html`:
- Around line 292-295: The link action in health-id-display-modal.component.html
remains clickable while linkCareContextV3() is already running, which can
trigger duplicate token generation and repeated care-context link requests.
Update the button’s disabled condition to also reflect the in-flight state
tracked by showProgressBar (or the equivalent loading flag used by
linkCareContextV3), so it stays disabled until the request completes. Keep the
existing selectedHealthID checks and use the linkCareContextV3 method and
showProgressBar state as the key references when wiring the guard.
---
Nitpick comments:
In
`@src/registrar/abha-components/health-id-display-modal/health-id-display-modal.component.ts`:
- Around line 182-299: The linkCareContextV3 method is too complex and needs to
be split up to meet the cognitive-complexity limit. Extract the token request
creation, link request creation, and the success/error handling for
generateLinkTokenForCareContext and linkCareContextV3 into separate helper
methods, or flatten the nested subscribe flow in
health-id-display-modal.component.ts while keeping the same behavior and alerts.
Use the existing linkCareContextV3 and related request/response symbols to
locate the logic and reduce branching in the main method.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: f59fa767-624d-453f-92ea-1316adafb61e
📒 Files selected for processing (3)
src/registrar/abha-components/health-id-display-modal/health-id-display-modal.component.htmlsrc/registrar/abha-components/health-id-display-modal/health-id-display-modal.component.tssrc/registrar/services/registrar.service.ts
| (click)="linkCareContextV3()" | ||
| [disabled]=" | ||
| selectedHealthID === undefined || selectedHealthID === null | ||
| " |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
Disable linking while the request is already in flight.
linkCareContextV3() sets showProgressBar, but this button stays enabled, so double-clicks can generate multiple tokens and send duplicate care-context link POSTs.
Proposed fix
- (click)="linkCareContextV3()"
+ (click)="!showProgressBar && linkCareContextV3()"
[disabled]="
- selectedHealthID === undefined || selectedHealthID === null
+ selectedHealthID === undefined || selectedHealthID === null || showProgressBar
"📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| (click)="linkCareContextV3()" | |
| [disabled]=" | |
| selectedHealthID === undefined || selectedHealthID === null | |
| " | |
| (click)="!showProgressBar && linkCareContextV3()" | |
| [disabled]=" | |
| selectedHealthID === undefined || selectedHealthID === null || showProgressBar | |
| " |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In
`@src/registrar/abha-components/health-id-display-modal/health-id-display-modal.component.html`
around lines 292 - 295, The link action in
health-id-display-modal.component.html remains clickable while
linkCareContextV3() is already running, which can trigger duplicate token
generation and repeated care-context link requests. Update the button’s disabled
condition to also reflect the in-flight state tracked by showProgressBar (or the
equivalent loading flag used by linkCareContextV3), so it stays disabled until
the request completes. Keep the existing selectedHealthID checks and use the
linkCareContextV3 method and showProgressBar state as the key references when
wiring the guard.
|



📋 Description
JIRA ID:
AMM-2290
✅ Type of Change
Summary by CodeRabbit
New Features
Bug Fixes