[ENG-882] Gate empty-state Create Encounter button by can_create_encounter permission - #16640
[ENG-882] Gate empty-state Create Encounter button by can_create_encounter permission#16640rithviknishad wants to merge 1 commit into
Conversation
… permission The empty-state "Create Encounter" button in EncounterHistory.tsx was rendered unconditionally, unlike the other 3 encounter creation entry points (Patient home, Appointment "Start Consultation", Appointment "Create Planned Encounter"), which all check can_create_encounter. Fixes #16638 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Entire-Checkpoint: 71011e8096d1
|
WalkthroughEncounterHistory now retrieves ChangesEncounter history permissions
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
📝 Generate docstrings
🧪 Generate unit tests (beta)
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 |
Deploying care-preview with
|
| Latest commit: |
3420df6
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://0cc80d80.care-preview-a7w.pages.dev |
| Branch Preview URL: | https://rithviknishad-fix-encounter.care-preview-a7w.pages.dev |
There was a problem hiding this comment.
Pull request overview
This PR aligns the patient encounter history empty-state UI with the rest of the app’s permission model by hiding the “Create Encounter” call-to-action unless the user has can_create_encounter.
Changes:
- Destructures
canCreateEncounterfromgetPermissions()inEncounterHistory.tsx. - Conditionally renders the empty-state
CreateEncounterFormtrigger only whencanCreateEncounteris true.
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 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/components/Patient/PatientDetailsTab/EncounterHistory.tsx`:
- Around line 82-95: Add regression tests around the EncounterHistory
create-action rendering, covering both canCreateEncounter states: assert the
create button and ShortcutBadge with actionId "create-encounter" are present
when enabled, and both are absent when disabled.
- Around line 82-95: Update the description rendered alongside the
CreateEncounterForm in EncounterHistory so the canCreateEncounter=false branch
does not instruct users to create an encounter; either omit that description or
use a non-actionable localized message. Keep the true and false branches as
separate t() calls so both translation keys remain detectable by the i18n
cleanup script.
🪄 Autofix
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: Repository UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 23ffd60a-e554-4c9d-ad5e-f94728d50131
📒 Files selected for processing (1)
src/components/Patient/PatientDetailsTab/EncounterHistory.tsx
| canCreateEncounter ? ( | ||
| <CreateEncounterForm | ||
| facilityId={facilityId} | ||
| patientId={patientId} | ||
| patientName={patientData.name} | ||
| trigger={ | ||
| <Button> | ||
| <PlusIcon /> | ||
| {t("create_encounter")} | ||
| <ShortcutBadge actionId="create-encounter" /> | ||
| </Button> | ||
| } | ||
| /> | ||
| ) : undefined |
There was a problem hiding this comment.
🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win
Add regression coverage for both permission states.
Test that the create button and create-encounter shortcut render with canCreateEncounter enabled and are absent when it is disabled.
🤖 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/components/Patient/PatientDetailsTab/EncounterHistory.tsx` around lines
82 - 95, Add regression tests around the EncounterHistory create-action
rendering, covering both canCreateEncounter states: assert the create button and
ShortcutBadge with actionId "create-encounter" are present when enabled, and
both are absent when disabled.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Use a non-actionable description when creation is not allowed.
When canCreateEncounter is false, action is undefined, but Line 79 still tells the user to create an encounter. Use a separate localized description for this branch, or omit the description.
Proposed fix
- description={t("create_a_new_encounter_to_get_started")}
+ description={
+ canCreateEncounter
+ ? t("create_a_new_encounter_to_get_started")
+ : t("no_permission_to_create_encounter")
+ }Based on learnings, keep each conditional branch as a separate t() call so the i18n cleanup script can detect both keys.
🤖 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/components/Patient/PatientDetailsTab/EncounterHistory.tsx` around lines
82 - 95, Update the description rendered alongside the CreateEncounterForm in
EncounterHistory so the canCreateEncounter=false branch does not instruct users
to create an encounter; either omit that description or use a non-actionable
localized message. Keep the true and false branches as separate t() calls so
both translation keys remain detectable by the i18n cleanup script.
Source: Learnings
🎭 Playwright Test ResultsStatus: ✅ Passed
📊 Detailed results are available in the playwright-final-report artifact. Run: #10625 |
ENG-882
Problem
The empty-state "Create Encounter" button in
EncounterHistory.tsxrendered unconditionally. The other 3 encounter creation entry points checkcan_create_encounterbefore render:Fix
Destructure
canCreateEncounterfromgetPermissions(same helper the other entry points use) and gate the button render on it.Test
tsc --noEmitshows no new errors for the changed file.patientData.permissionsgrantscan_create_encounter.Closes #16638
Summary by CodeRabbit