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

fix(j-s): Fix Empty National Id #17149

Merged
merged 2 commits into from
Dec 5, 2024
Merged

fix(j-s): Fix Empty National Id #17149

merged 2 commits into from
Dec 5, 2024

Conversation

gudjong
Copy link
Member

@gudjong gudjong commented Dec 5, 2024

Fix Empty National Id

Ákærða óskar ekki eftir að sér sé skipaður verjandi böggur

What

  • The court was not able to allow defendant to wafe right to defender. This is fixed in this PR.

Why

  • Verified bug.

Screenshots / Gifs

Screen.Recording.2024-12-05.at.14.51.03.mov

Checklist:

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • Formatting passes locally with my changes
  • I have rebased against main before asking for a review

Summary by CodeRabbit

  • New Features

    • Simplified the defendant creation process by reducing the number of parameters required.
    • Updated the handling of defendant properties when waiving the right to counsel to set fields to null instead of empty strings.
  • Bug Fixes

    • Improved the initialization of new defendant objects to streamline state updates.
  • Documentation

    • Clarified the functionality around creating and managing defendants within the system.

@gudjong gudjong requested a review from a team as a code owner December 5, 2024 14:52
Copy link
Contributor

coderabbitai bot commented Dec 5, 2024

Walkthrough

The pull request introduces changes to the SelectDefender and Defendant components across different files. In the SelectDefender component, the handling of properties related to the defender's information is modified to set them to null instead of an empty string when the defendant waives the right to counsel. The Defendant components are simplified by removing unnecessary parameters during the creation of defendant objects, focusing solely on the caseId. This results in a more streamlined process for managing defendants within the application.

Changes

File Change Summary
apps/judicial-system/web/src/routes/Court/Indictments/Advocates/SelectDefender.tsx Updated toggleDefendantWaivesRightToCounsel to set defenderNationalId, defenderName, defenderEmail, and defenderPhoneNumber to null instead of an empty string when the defendant waives the right to counsel.
apps/judicial-system/web/src/routes/Prosecutor/Indictments/Defendant/Defendant.tsx Simplified createDefendant function call by removing unnecessary parameters; updated createEmptyDefendant to only include the id field.
apps/judicial-system/web/src/routes/Prosecutor/InvestigationCase/Defendant/Defendant.tsx Similar simplifications as above, focusing on passing only caseId to createDefendant and updating createEmptyDefendant to include only the id.

Possibly related PRs

Suggested labels

automerge

Suggested reviewers

  • oddsson

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 5a1b1a6 and 15d5e0e.

📒 Files selected for processing (3)
  • apps/judicial-system/web/src/routes/Court/Indictments/Advocates/SelectDefender.tsx (1 hunks)
  • apps/judicial-system/web/src/routes/Prosecutor/Indictments/Defendant/Defendant.tsx (2 hunks)
  • apps/judicial-system/web/src/routes/Prosecutor/InvestigationCase/Defendant/Defendant.tsx (2 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
apps/judicial-system/web/src/routes/Prosecutor/InvestigationCase/Defendant/Defendant.tsx (1)

Pattern apps/**/*: "Confirm that the code adheres to the following:

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
apps/judicial-system/web/src/routes/Court/Indictments/Advocates/SelectDefender.tsx (1)

Pattern apps/**/*: "Confirm that the code adheres to the following:

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
apps/judicial-system/web/src/routes/Prosecutor/Indictments/Defendant/Defendant.tsx (1)

Pattern apps/**/*: "Confirm that the code adheres to the following:

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
📓 Learnings (3)
apps/judicial-system/web/src/routes/Prosecutor/InvestigationCase/Defendant/Defendant.tsx (1)
Learnt from: oddsson
PR: island-is/island.is#16831
File: apps/judicial-system/backend/src/app/modules/defendant/models/defendant.model.ts:0-0
Timestamp: 2024-11-19T09:04:44.520Z
Learning: Additional documentation is not required when the code is clear and self-explanatory.
apps/judicial-system/web/src/routes/Court/Indictments/Advocates/SelectDefender.tsx (1)
Learnt from: unakb
PR: island-is/island.is#16393
File: apps/judicial-system/web/src/routes/Court/Indictments/Advocates/Advocates.tsx:62-79
Timestamp: 2024-11-12T15:15:11.835Z
Learning: When optional chaining is already used on `workingCase.defendants` in the `Advocates.tsx` component, avoid suggesting additional null checks as it's already handled.
apps/judicial-system/web/src/routes/Prosecutor/Indictments/Defendant/Defendant.tsx (1)
Learnt from: oddsson
PR: island-is/island.is#16731
File: apps/judicial-system/web/src/routes/Shared/IndictmentOverview/IndictmentOverview.tsx:172-186
Timestamp: 2024-11-12T15:15:20.157Z
Learning: In `IndictmentOverview.tsx`, since the defendants data does not change, using `useMemo` to memoize the filtering logic is unnecessary.
🔇 Additional comments (5)
apps/judicial-system/web/src/routes/Court/Indictments/Advocates/SelectDefender.tsx (1)

46-57: LGTM! The fix properly handles empty defender fields.

The change from empty strings to null values when a defendant waives their right to counsel is semantically correct and should resolve the empty National Id issue.

Let's verify that this change fixes the issue with empty National Id:

✅ Verification successful

LGTM! The change to use null values is consistent with the codebase patterns

Based on the codebase analysis, the change from empty strings to null for defender fields when rights are waived is correct and consistent with:

  • Type definitions showing defenderNationalId is typed as string | null
  • Other components like InputAdvocate using null for unset defender fields
  • Backend services handling null values for defender fields appropriately
  • Notification services checking for presence of defender fields using truthiness checks that work with null
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any remaining empty string assignments to defenderNationalId
# Expect: No matches, as all should now use null

# Check for empty string assignments to defender fields
rg -A 2 "defenderNationalId: ''" 

# Check for proper null handling in defender-related code
ast-grep --pattern 'defenderNationalId: $_'

Length of output: 86


Script:

#!/bin/bash
# Let's try a broader search pattern to catch any assignments to defenderNationalId
# and examine the context around defender-related fields

# Search for defenderNationalId assignments with context
rg -A 5 "defenderNationalId" 

# Search for defender-related state handling
rg -A 5 "defender.*Id.*=|defenderNationalId.*=" 

# Look for defender-related type definitions to understand the data model
ast-grep --pattern 'interface $_ {
  $$$
  defenderNationalId
  $$$
}'

Length of output: 71013

apps/judicial-system/web/src/routes/Prosecutor/InvestigationCase/Defendant/Defendant.tsx (2)

195-195: LGTM! Simplified defendant creation.

The simplified createDefendant call, passing only the caseId, is a good improvement that lets the backend handle field initialization.


210-210: LGTM! Simplified empty defendant initialization.

Initializing a new defendant with only an id is cleaner and prevents potential issues with empty fields.

apps/judicial-system/web/src/routes/Prosecutor/Indictments/Defendant/Defendant.tsx (2)

418-418: LGTM! Consistent with investigation case changes.

The simplified createDefendant call maintains consistency with the investigation case component.


433-433: LGTM! Consistent empty defendant initialization.

The simplified empty defendant initialization maintains consistency with the investigation case component.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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 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.

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

codecov bot commented Dec 5, 2024

Codecov Report

Attention: Patch coverage is 0% with 9 lines in your changes missing coverage. Please review.

Project coverage is 35.71%. Comparing base (090c75d) to head (12f9d3c).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...tes/Court/Indictments/Advocates/SelectDefender.tsx 0.00% 5 Missing ⚠️
...tes/Prosecutor/Indictments/Defendant/Defendant.tsx 0.00% 2 Missing ⚠️
...osecutor/InvestigationCase/Defendant/Defendant.tsx 0.00% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #17149      +/-   ##
==========================================
- Coverage   35.74%   35.71%   -0.04%     
==========================================
  Files        6925     6925              
  Lines      147648   147874     +226     
  Branches    42050    42123      +73     
==========================================
+ Hits        52779    52807      +28     
- Misses      94869    95067     +198     
Flag Coverage Δ
judicial-system-api 19.98% <ø> (ø)
judicial-system-backend 55.72% <ø> (ø)
judicial-system-formatters 78.09% <ø> (ø)
judicial-system-web 27.92% <0.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...tes/Prosecutor/Indictments/Defendant/Defendant.tsx 0.00% <0.00%> (ø)
...osecutor/InvestigationCase/Defendant/Defendant.tsx 0.00% <0.00%> (ø)
...tes/Court/Indictments/Advocates/SelectDefender.tsx 0.00% <0.00%> (ø)

... and 11 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 090c75d...12f9d3c. Read the comment docs.

@datadog-island-is
Copy link

Datadog Report

All test runs 294bec7 🔗

18 Total Test Services: 0 Failed, 15 Passed
⬆️ Test Sessions change in coverage: 3 increased, 43 no change

Test Services
This report shows up to 10 services
Service Name Failed Known Flaky New Flaky Passed Skipped Total Time Code Coverage Change Test Service View
api 0 0 0 4 0 2.98s 1 no change Link
api-domains-auth-admin 0 0 0 18 0 13.88s 1 no change Link
application-system-api 0 0 0 46 0 2m 41.34s 1 no change Link
application-template-api-modules 0 0 0 118 0 2m 34.95s 1 no change Link
application-ui-shell 0 0 0 74 0 37.64s 1 no change Link
auth-api-lib 0 0 0 20 0 26.78s 1 no change Link
judicial-system-web 0 0 0 332 0 1m 18.93s 1 increased (+0.01%) Link
services-auth-admin-api 0 0 0 130 0 4m 28.17s 1 no change Link
services-auth-delegation-api 0 0 0 270 0 3m 46.15s 1 increased (+0.01%) Link
services-auth-ids-api 0 0 0 262 0 1m 37.83s 1 no change Link

@oddsson oddsson added the automerge Merge this PR as soon as all checks pass label Dec 5, 2024
@kodiakhq kodiakhq bot merged commit ab80585 into main Dec 5, 2024
37 checks passed
@kodiakhq kodiakhq bot deleted the j-s/fix-empty-national-id branch December 5, 2024 22:43
thorhildurt pushed a commit that referenced this pull request Dec 11, 2024
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge Merge this PR as soon as all checks pass
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants