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): Indictment description #17501

Merged
merged 4 commits into from
Jan 15, 2025
Merged

fix(j-s): Indictment description #17501

merged 4 commits into from
Jan 15, 2025

Conversation

oddsson
Copy link
Member

@oddsson oddsson commented Jan 15, 2025

Fix indictment description

Asana

What

This PR fixes several issues in generating the IndictmentDescription in combo-indictments. When adding/removing subtypes in indictment counts, the indictment description would not always update accordingly. To fix this, we now remove the indictment description when a subtype is removed, so the user needs to "start over".

Why

This PR fixes the issues above.

Screenshots / Gifs

Screen.Recording.2025-01-15.at.10.19.26.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

    • Enhanced indictment count management with improved subtype handling
    • Updated legal arguments placeholder text
  • Bug Fixes

    • Refined incident description generation logic for edge cases with subtypes
  • Documentation

    • Updated placeholder text for legal arguments section

The changes improve the precision of indictment count tracking and provide more contextual guidance for legal argument input in the judicial system web application.

@oddsson oddsson requested a review from a team as a code owner January 15, 2025 10:20
Copy link
Contributor

coderabbitai bot commented Jan 15, 2025

Walkthrough

The pull request introduces modifications to the indictment count handling in the Judicial System web application. The changes primarily focus on refining how subtypes are processed and integrated into the indictment count logic across multiple components. The modifications affect the way incident descriptions are generated, how subtypes are managed, and how the legal arguments placeholder is defined, with subtle adjustments to the control flow and data processing related to indictment counts.

Changes

File Change Summary
apps/judicial-system/web/src/routes/Prosecutor/Indictments/Defendant/Defendant.tsx Modified handleUpdateIndictmentCount to create updatedIndictmentCount with spread operator and new indictmentCountSubtypes
apps/judicial-system/web/src/routes/Prosecutor/Indictments/Defendant/PoliceCaseInfo/PoliceCaseInfo.tsx Enhanced subtype handling logic for updating indictment counts when selecting or removing subtypes
apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.strings.ts Updated legalArgumentsPlaceholder with new ID and default message
apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx Modified getIncidentDescription function's conditional logic for handling subtypes

Possibly related PRs

Suggested labels

automerge

Suggested reviewers

  • unakb

Finishing Touches

  • 📝 Generate Docstrings (Beta)

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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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.

@datadog-island-is
Copy link

datadog-island-is bot commented Jan 15, 2025

Datadog Report

Branch report: j-s/fix-indictment-descr
Commit report: ba902f3
Test service: judicial-system-web

✅ 0 Failed, 343 Passed, 0 Skipped, 55.97s Total Time
➡️ Test Sessions change in coverage: 1 no change

Copy link

codecov bot commented Jan 15, 2025

Codecov Report

Attention: Patch coverage is 36.36364% with 7 lines in your changes missing coverage. Please review.

Project coverage is 35.61%. Comparing base (49e2b3a) to head (c11fafc).
Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
...tments/Defendant/PoliceCaseInfo/PoliceCaseInfo.tsx 0.00% 6 Missing ⚠️
...tes/Prosecutor/Indictments/Defendant/Defendant.tsx 0.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main   #17501   +/-   ##
=======================================
  Coverage   35.61%   35.61%           
=======================================
  Files        7015     7015           
  Lines      150339   150344    +5     
  Branches    42981    42983    +2     
=======================================
+ Hits        53541    53543    +2     
- Misses      96798    96801    +3     
Flag Coverage Δ
judicial-system-web 27.85% <36.36%> (+<0.01%) ⬆️

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

Files with missing lines Coverage Δ
.../Indictments/Indictment/IndictmentCount.strings.ts 100.00% <ø> (ø)
...secutor/Indictments/Indictment/IndictmentCount.tsx 37.54% <100.00%> (+0.46%) ⬆️
...tes/Prosecutor/Indictments/Defendant/Defendant.tsx 0.00% <0.00%> (ø)
...tments/Defendant/PoliceCaseInfo/PoliceCaseInfo.tsx 0.00% <0.00%> (ø)

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 8fbbf6b...c11fafc. Read the comment docs.

Copy link
Contributor

@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 (4)
apps/judicial-system/web/src/routes/Prosecutor/Indictments/Defendant/Defendant.tsx (1)

296-301: LGTM! Consider adding type annotation for better type safety.

The changes correctly address the indictment description update issue by ensuring subtypes are properly included. The implementation maintains immutability and follows React best practices.

Consider adding a type annotation to updatedIndictmentCount for better type safety:

-          const updatedIndictmentCount = {
+          const updatedIndictmentCount: typeof indictmentCount = {
             ...indictmentCount,
             indictmentCountSubtypes: subtypes?.[policeCaseNumber],
           }
apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx (1)

315-318: Consider improving readability of the condition.

The logic is correct and aligns with the requirement to reset the description when subtypes are removed. However, the condition could be more readable.

Consider this more readable version:

-    subtypes.length === 0 ||
-    (subtypes.length > 1 &&
-      (!indictmentCountSubtypes?.length ||
-        indictmentCountSubtypes.length === 0))
+    subtypes.length === 0 ||
+    (subtypes.length > 1 && !indictmentCountSubtypes?.length)

The second part of the OR condition can be simplified since both checks (!indictmentCountSubtypes?.length and indictmentCountSubtypes.length === 0) are effectively checking the same thing.

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

Line range hint 254-269: Optimize subtype removal logic and improve error handling.

The current implementation:

  1. Duplicates the filter operation unnecessarily
  2. Could be simplified for better maintainability

Consider this optimization:

-                  const remainingSubtypes = subtypes.filter(
-                    (s) => s !== subtype,
-                  )
-
+                  const remainingSubtypes = subtypes.filter((s) => s !== subtype)
                   updatePoliceCase(index, {
                     policeCaseNumber: policeCaseNumbers[index],
-                    subtypes: subtypes.filter((s) => s !== subtype),
+                    subtypes: remainingSubtypes,
                   })

                   updateIndictmentCount(
                     policeCaseNumbers[index],
                     crimeScene || {},
                     {
-                      [policeCaseNumbers[index]]:
-                        remainingSubtypes.length === 1 ? remainingSubtypes : [],
+                      [policeCaseNumbers[index]]: remainingSubtypes,
                     },
                   )

The suggested changes:

  1. Remove duplicate filter operation
  2. Simplify the logic by always passing remainingSubtypes
  3. Reuse the remainingSubtypes variable for both updates

Line range hint 226-269: Overall implementation feedback.

The changes effectively handle the indictment description update requirements from the PR objectives. The implementation follows React and TypeScript patterns well, but could benefit from:

  1. Consistent error handling for undefined values
  2. Simplified logic for subtype management
  3. Better type safety for the crimeScene object

Consider extracting the subtype management logic into a custom hook to improve reusability and testability. This would also make it easier to maintain consistent behavior across different components.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 49e2b3a and ee32370.

📒 Files selected for processing (4)
  • apps/judicial-system/web/src/routes/Prosecutor/Indictments/Defendant/Defendant.tsx (1 hunks)
  • apps/judicial-system/web/src/routes/Prosecutor/Indictments/Defendant/PoliceCaseInfo/PoliceCaseInfo.tsx (3 hunks)
  • apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.strings.ts (1 hunks)
  • apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx (1 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.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."
apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.strings.ts (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/PoliceCaseInfo/PoliceCaseInfo.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 (4)
apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx (6)
Learnt from: oddsson
PR: island-is/island.is#17192
File: apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx:579-587
Timestamp: 2024-12-17T20:28:47.549Z
Learning: In the `IndictmentCount.tsx` file of the `apps/judicial-system/web` project, constraints on the vehicle registration number are planned to be removed. Avoid suggesting changes related to vehicle registration number validation for now.
Learnt from: oddsson
PR: island-is/island.is#17192
File: apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx:700-758
Timestamp: 2024-12-17T14:33:50.960Z
Learning: In the file `apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx`, the user prefers not to add range validation for the blood alcohol content input.
Learnt from: gudjong
PR: island-is/island.is#16863
File: apps/judicial-system/web/src/routes/Prosecutor/Indictments/Overview/Overview.tsx:194-200
Timestamp: 2024-11-27T14:34:38.028Z
Learning: In `Overview.tsx`, the `defendant.subpoenas` array never contains null or undefined `subpoena` objects, so additional null checks are not needed.
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.
Learnt from: thorhildurt
PR: island-is/island.is#17198
File: apps/judicial-system/web/src/routes/Prison/IndictmentOverview/IndictmentOverview.tsx:42-50
Timestamp: 2024-12-11T14:25:44.741Z
Learning: In `IndictmentOverview.tsx`, when updating the punishment type, update the UI state before making the API call to immediately reflect the change.
Learnt from: unakb
PR: island-is/island.is#15378
File: apps/judicial-system/web/src/routes/Court/Indictments/Summary/Summary.tsx:86-100
Timestamp: 2024-11-12T15:15:11.835Z
Learning: User unakb prefers explicit case handling in switch statements for key functionalities like `getRulingDecisionTagColor` to ensure clarity and avoid assumptions that a case was overlooked.
apps/judicial-system/web/src/routes/Prosecutor/Indictments/Defendant/Defendant.tsx (4)
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.
Learnt from: oddsson
PR: island-is/island.is#17192
File: apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx:579-587
Timestamp: 2024-12-17T20:28:47.549Z
Learning: In the `IndictmentCount.tsx` file of the `apps/judicial-system/web` project, constraints on the vehicle registration number are planned to be removed. Avoid suggesting changes related to vehicle registration number validation for now.
Learnt from: thorhildurt
PR: island-is/island.is#17198
File: apps/judicial-system/web/src/routes/Prison/IndictmentOverview/IndictmentOverview.tsx:42-50
Timestamp: 2024-12-11T14:25:44.741Z
Learning: In `IndictmentOverview.tsx`, when updating the punishment type, update the UI state before making the API call to immediately reflect the change.
Learnt from: gudjong
PR: island-is/island.is#16863
File: apps/judicial-system/web/src/routes/Prosecutor/Indictments/Overview/Overview.tsx:194-200
Timestamp: 2024-11-27T14:34:38.028Z
Learning: In `Overview.tsx`, the `defendant.subpoenas` array never contains null or undefined `subpoena` objects, so additional null checks are not needed.
apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.strings.ts (1)
Learnt from: oddsson
PR: island-is/island.is#17192
File: apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx:579-587
Timestamp: 2024-12-17T20:28:47.549Z
Learning: In the `IndictmentCount.tsx` file of the `apps/judicial-system/web` project, constraints on the vehicle registration number are planned to be removed. Avoid suggesting changes related to vehicle registration number validation for now.
apps/judicial-system/web/src/routes/Prosecutor/Indictments/Defendant/PoliceCaseInfo/PoliceCaseInfo.tsx (4)
Learnt from: oddsson
PR: island-is/island.is#17192
File: apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx:579-587
Timestamp: 2024-12-17T20:28:47.549Z
Learning: In the `IndictmentCount.tsx` file of the `apps/judicial-system/web` project, constraints on the vehicle registration number are planned to be removed. Avoid suggesting changes related to vehicle registration number validation for now.
Learnt from: thorhildurt
PR: island-is/island.is#17198
File: apps/judicial-system/web/src/routes/Prison/IndictmentOverview/IndictmentOverview.tsx:42-50
Timestamp: 2024-12-11T14:25:44.741Z
Learning: In `IndictmentOverview.tsx`, when updating the punishment type, update the UI state before making the API call to immediately reflect the change.
Learnt from: unakb
PR: island-is/island.is#15378
File: apps/judicial-system/web/src/routes/Court/Indictments/Summary/Summary.tsx:86-100
Timestamp: 2024-11-12T15:15:11.835Z
Learning: User unakb prefers explicit case handling in switch statements for key functionalities like `getRulingDecisionTagColor` to ensure clarity and avoid assumptions that a case was overlooked.
Learnt from: gudjong
PR: island-is/island.is#16863
File: apps/judicial-system/web/src/routes/Prosecutor/Indictments/Overview/Overview.tsx:194-200
Timestamp: 2024-11-27T14:34:38.028Z
Learning: In `Overview.tsx`, the `defendant.subpoenas` array never contains null or undefined `subpoena` objects, so additional null checks are not needed.
🔇 Additional comments (3)
apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx (1)

315-318: LGTM! The changes effectively handle description resets.

The implementation correctly ensures that indictment descriptions are reset when subtypes are removed, preventing stale or incorrect descriptions from persisting. This aligns well with the PR's objective of improving description management when subtypes change.

apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.strings.ts (1)

180-181: Consider migration impact of versioned translation ID.

The changes improve the placeholder text to be more specific and aligned with legal terminology. However, the versioned ID (_v1 suffix) indicates a breaking change in translations.

Run the following script to check for any unmigrated usages of the old translation ID:

✅ Verification successful

Translation ID change is safely migrated

No instances of the old translation ID were found in the codebase, indicating a complete migration to the new versioned ID. The change is safe to proceed.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any remaining usages of the old translation ID
# to ensure complete migration

rg "judicial\.system\.core:indictments_indictment\.indictment_count\.legal_arguments_placeholder[^_]" \
  --type ts \
  --type tsx

Length of output: 152


Script:

#!/bin/bash
# Search for old translation ID in all TypeScript files
rg "judicial\.system\.core:indictments_indictment\.indictment_count\.legal_arguments_placeholder[^_]" \
  -g "*.{ts,tsx}"

# Find all files that import the strings file
rg "from.*IndictmentCount\.strings" \
  -g "*.{ts,tsx}" \
  -A 5

Length of output: 1934

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

227-235: Improve type safety and error handling for indictment count updates.

The current implementation has potential issues:

  1. Using an empty object as fallback for undefined crimeScene could lead to data loss.
  2. The logic only updates indictment count when the first subtype is added.

Consider verifying if this behavior aligns with the business requirements. Should the indictment count be updated for subsequent subtype additions as well?

-            if (subtypes.length === 1) {
+            // Always update indictment count when subtypes change
             updateIndictmentCount(
               policeCaseNumbers[index],
-              crimeScene || {},
+              crimeScene ?? { place: '', date: null },
               {
                 [policeCaseNumbers[index]]: subtypes,
               },
             )
-            }
✅ Verification successful

The review comment is correct about both type safety and update behavior issues.

  1. The crimeScene fallback should match the expected type structure with place and date fields.
  2. The indictment count should be updated for all subtype changes, not just when subtypes.length === 1, to maintain consistency with other usage patterns in the codebase.

The suggested fix in the review comment is appropriate:

-            if (subtypes.length === 1) {
             updateIndictmentCount(
               policeCaseNumbers[index],
-              crimeScene || {},
+              crimeScene ?? { place: '', date: null },
               {
                 [policeCaseNumbers[index]]: subtypes,
               },
             )
-            }
🏁 Scripts executed

The following scripts were executed for the analysis:

Error: No shell scripts found


Script:

#!/bin/bash
# Find type definitions related to crimeScene
ast-grep --pattern 'interface $_ {
  $$$
  crimeScene
  $$$
}'

# Find type definitions that might contain crimeScene
ast-grep --pattern 'type $_ = {
  $$$
  crimeScene
  $$$
}'

# Find the implementation of updateIndictmentCount
ast-grep --pattern 'function updateIndictmentCount($$$) {
  $$$
}'

# Find other usages of updateIndictmentCount
rg "updateIndictmentCount" -A 3

Length of output: 24225

@oddsson oddsson added the deprecated:automerge (Disabled) Merge this PR as soon as all checks pass label Jan 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deprecated:automerge (Disabled) Merge this PR as soon as all checks pass
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants