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

feat(j-s): Add punishment type tag column in prison cases overview table #17285

Merged
merged 11 commits into from
Dec 19, 2024

Conversation

thorhildurt
Copy link
Member

@thorhildurt thorhildurt commented Dec 18, 2024

What

  • Asana task
  • Render punishment type tag in the prison case table overview representing the added punishment type per case
  • Add a sorting functionality for the punishment type
    • Note: Due to the current defendants data structure, we by default sort by the punishment type of the first defendant

Why

  • To give a better overview of the case list by enabling prison admin to group prison cases according to punishment type

Screenshots / Gifs

Screen.Recording.2024-12-18.at.16.43.54.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

    • Added new field defendantsPunishmentType to the case list.
    • Introduced new messages for punishment types in the localization system.
    • Enhanced table component to display and sort by punishment type.
    • Added functionality to categorize punishment types with visual tags.
    • Updated GraphQL queries to include punishment type details for defendants.
  • Bug Fixes

    • Improved handling of punishment type data in various components.
  • Tests

    • Added a new test suite for array helper functions to ensure correct functionality.
  • Chores

    • Enhanced utility functions for better type safety with arrays.

Copy link
Contributor

coderabbitai bot commented Dec 18, 2024

Walkthrough

This pull request introduces enhancements to the judicial system application's case management functionality, focusing on adding support for displaying and tracking punishment types for defendants. The changes span multiple files across the application, including model updates, GraphQL schema modifications, UI components, and utility functions. The primary goal is to provide more detailed information about case and defendant punishment types, enabling better visualization and sorting of case information.

Changes

File Change Summary
apps/judicial-system/api/src/app/modules/case-list/models/caseList.model.ts Added defendantsPunishmentType field to CaseListEntry class
apps/judicial-system/web/messages/Core/tables.ts Added new localization message for punishment type column
apps/judicial-system/web/src/components/Table/Table.tsx Updated getColumnValue method to handle punishment type column
apps/judicial-system/web/src/components/Tags/CaseTag.strings.ts Added five new messages for different punishment type tags
apps/judicial-system/web/src/components/Tags/utils.ts Introduced getPunishmentTypeTag utility function
apps/judicial-system/web/src/routes/Shared/Cases/PrisonCases.tsx Updated table rendering to include punishment type column and tags
apps/judicial-system/web/src/routes/Shared/Cases/cases.graphql Added punishmentType and defendantsPunishmentType fields
apps/judicial-system/web/src/routes/Shared/Cases/prisonCases.graphql Added punishmentType to defendants object
apps/judicial-system/web/src/utils/arrayHelpers.ts Added three new array utility functions: isPresentArray, isEmptyArray, isNonEmptyArray

Sequence Diagram

sequenceDiagram
    participant GraphQL as GraphQL Query
    participant Table as Table Component
    participant Tags as Punishment Type Tags
    
    GraphQL->>Table: Fetch cases with punishment type
    Table->>Tags: Generate punishment type tag
    Tags-->>Table: Return tag with color and text
    Table->>Table: Render table with punishment type column
Loading

Possibly related PRs

Suggested reviewers

  • unakb
  • oddsson

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.

@thorhildurt thorhildurt marked this pull request as ready for review December 18, 2024 17:00
@thorhildurt thorhildurt requested a review from a team as a code owner December 18, 2024 17:00
@thorhildurt thorhildurt self-assigned this Dec 18, 2024
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: 7

🧹 Nitpick comments (4)
apps/judicial-system/web/src/utils/arrayHelpers.ts (1)

4-5: Remove unnecessary optional chaining

The isPresentArray check already guarantees that arr is defined and an array, making the optional chaining redundant.

-export const isEmptyArray = <T>(arr: T[] | undefined | null): arr is T[] =>
-  isPresentArray(arr) && arr?.length === 0
+export const isEmptyArray = <T>(arr: T[] | undefined | null): arr is T[] =>
+  isPresentArray(arr) && arr.length === 0
apps/judicial-system/web/src/utils/arrayHelpers.spec.ts (1)

11-15: Improve test descriptions

Consider making test descriptions more descriptive of the specific scenario being tested.

-      it(`should return ${expected} for input ${input}`, () => {
+      it(`should return ${expected} when array is ${input === undefined ? 'undefined' : input === null ? 'null' : Array.isArray(input) ? `[${input}]` : input}`, () => {
apps/judicial-system/web/src/components/Tags/CaseTag.strings.ts (1)

100-124: Consider improving clarity of punishment type abbreviations

While the string definitions are well-structured, the abbreviations in defaultMessage might not be immediately clear to all users:

  • 'Óskb.' for imprisonment
  • 'Skb.' for probation
  • 'VL' for ruling decision fine
  • 'ÁS' for signed fine invitation

Consider:

  1. Adding tooltips to explain abbreviations
  2. Documenting abbreviations in user documentation
  3. Translating descriptions to English for better maintainability
apps/judicial-system/web/src/components/Tags/utils.ts (1)

132-147: Consider moving the helper function outside for reusability.

The getPunishmentTypeLabel helper function is defined inside getPunishmentTypeTag. Consider moving it outside to make it reusable and improve code organization.

+const getPunishmentTypeLabel = (punishmentType?: PunishmentType | null) => {
+  switch (punishmentType) {
+    case PunishmentType.IMPRISONMENT:
+      return strings.punishmentTypeImprisonment
+    case PunishmentType.PROBATION:
+      return strings.punishmentTypeProbation
+    case PunishmentType.FINE:
+      return strings.punishmentTypeFine
+    case PunishmentType.INDICTMENT_RULING_DECISION_FINE:
+      return strings.punishmentTypeIndictmentRulingDecisionFine
+    case PunishmentType.SIGNED_FINE_INVITATION:
+      return strings.punishmentTypeSignedFineInvitation
+    default:
+      return strings.unknown
+  }
+}

 export const getPunishmentTypeTag = (
   punishmentType?: PunishmentType | null,
 ): {
   color: TagVariant
   text: { id: string; defaultMessage: string; description: string }
 } | null => {
   if (!punishmentType) return null
-
-  const getPunishmentTypeLabel = (punishmentType?: PunishmentType | null) => {
-    switch (punishmentType) {
-      case PunishmentType.IMPRISONMENT:
-        return strings.punishmentTypeImprisonment
-      case PunishmentType.PROBATION:
-        return strings.punishmentTypeProbation
-      case PunishmentType.FINE:
-        return strings.punishmentTypeFine
-      case PunishmentType.INDICTMENT_RULING_DECISION_FINE:
-        return strings.punishmentTypeIndictmentRulingDecisionFine
-      case PunishmentType.SIGNED_FINE_INVITATION:
-        return strings.punishmentTypeSignedFineInvitation
-      default:
-        return strings.unknown
-    }
-  }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 7fe9be5 and 5260b98.

📒 Files selected for processing (10)
  • apps/judicial-system/api/src/app/modules/case-list/models/caseList.model.ts (2 hunks)
  • apps/judicial-system/web/messages/Core/tables.ts (1 hunks)
  • apps/judicial-system/web/src/components/Table/Table.tsx (1 hunks)
  • apps/judicial-system/web/src/components/Tags/CaseTag.strings.ts (1 hunks)
  • apps/judicial-system/web/src/components/Tags/utils.ts (2 hunks)
  • apps/judicial-system/web/src/routes/Shared/Cases/PrisonCases.tsx (4 hunks)
  • apps/judicial-system/web/src/routes/Shared/Cases/cases.graphql (1 hunks)
  • apps/judicial-system/web/src/routes/Shared/Cases/prisonCases.graphql (1 hunks)
  • apps/judicial-system/web/src/utils/arrayHelpers.spec.ts (1 hunks)
  • apps/judicial-system/web/src/utils/arrayHelpers.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (10)
apps/judicial-system/api/src/app/modules/case-list/models/caseList.model.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/Shared/Cases/cases.graphql (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/messages/Core/tables.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/Shared/Cases/prisonCases.graphql (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/components/Tags/utils.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/Shared/Cases/PrisonCases.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/utils/arrayHelpers.spec.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/components/Table/Table.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/components/Tags/CaseTag.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/utils/arrayHelpers.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."
📓 Learnings (2)
apps/judicial-system/web/src/routes/Shared/Cases/PrisonCases.tsx (4)
Learnt from: oddsson
PR: island-is/island.is#16939
File: apps/judicial-system/web/src/components/Table/PastCasesTable/PastCasesTable.tsx:126-131
Timestamp: 2024-11-19T21:47:09.093Z
Learning: The `CaseListEntry` interface in `@island.is/judicial-system-web/src/graphql/schema` includes the properties `isValidToDateInThePast`, `indictmentRulingDecision`, and `indictmentDecision`.
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#16760
File: apps/judicial-system/web/src/routes/Shared/Cases/PrisonCases.tsx:112-118
Timestamp: 2024-11-12T15:15:11.835Z
Learning: In `apps/judicial-system/web/src/routes/Prosecutor/components/CasesAwaitingConfirmationTable/CasesAwaitingConfirmationTable.tsx`, `apps/judicial-system/web/src/routes/Court/components/CasesAwaitingAssignmentTable/CasesAwaitingAssignmentTable.tsx`, and one instance in `apps/judicial-system/web/src/routes/Shared/Cases/PrisonCases.tsx`, it's correct to pass only the `type` prop to `ColumnCaseType` without the `decision` and `parentCaseId` props.
Learnt from: oddsson
PR: island-is/island.is#14673
File: apps/judicial-system/web/src/routes/PublicProsecutor/Tables/CasesForReview.tsx:79-79
Timestamp: 2024-11-12T15:15:11.835Z
Learning: The implementation of `mapIndictmentCaseStateToTagVariant` in `TagCaseState.tsx`, which maps only `CaseState.ACCEPTED` to a specific tag and defaults others to an "unknown" status, is intentional as per the application's requirements.
apps/judicial-system/web/src/components/Table/Table.tsx (1)
Learnt from: gudjong
PR: island-is/island.is#16760
File: apps/judicial-system/web/src/routes/Shared/Cases/PrisonCases.tsx:112-118
Timestamp: 2024-11-12T15:15:11.835Z
Learning: In `apps/judicial-system/web/src/routes/Prosecutor/components/CasesAwaitingConfirmationTable/CasesAwaitingConfirmationTable.tsx`, `apps/judicial-system/web/src/routes/Court/components/CasesAwaitingAssignmentTable/CasesAwaitingAssignmentTable.tsx`, and one instance in `apps/judicial-system/web/src/routes/Shared/Cases/PrisonCases.tsx`, it's correct to pass only the `type` prop to `ColumnCaseType` without the `decision` and `parentCaseId` props.
🔇 Additional comments (4)
apps/judicial-system/web/src/routes/Shared/Cases/prisonCases.graphql (1)

29-29: Verify schema compatibility

The addition of punishmentType field looks good. However, we should verify the schema changes across the frontend and backend.

✅ Verification successful

Schema changes are properly implemented and consistent

The verification shows complete and consistent implementation of the punishmentType field across the codebase:

  • Properly defined as an enum in libs/judicial-system/types/src/lib/defendant.ts
  • Correctly implemented in backend models and DTOs
  • Consistently used in frontend components with proper type definitions
  • GraphQL schema changes align with both frontend and backend implementations
  • Comprehensive UI implementation including translations and display logic
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for consistent punishment type field usage across the codebase

# Check backend models and resolvers
echo "Checking backend models and resolvers for punishmentType..."
rg -t ts "punishmentType.*:.*PunishmentType" "apps/judicial-system/api/src"

# Check frontend type definitions and usage
echo "Checking frontend type definitions and usage..."
rg -t ts "punishmentType" "apps/judicial-system/web/src/types"

Length of output: 613


Script:

#!/bin/bash
# Let's verify the PunishmentType definition and its usage more thoroughly

# Check for PunishmentType enum/type definition
echo "Checking PunishmentType definition..."
rg -t ts "enum.*PunishmentType|type.*PunishmentType" -A 5

# Check GraphQL schema definitions for punishment type
echo "Checking GraphQL schema definitions..."
fd -e graphql . -x cat {} \; | grep -A 5 -B 5 "punishmentType"

# Check frontend components using punishmentType
echo "Checking frontend usage..."
rg -t ts "punishmentType" "apps/judicial-system/web/src"

Length of output: 8484

apps/judicial-system/web/src/routes/Shared/Cases/cases.graphql (1)

31-31: Verify query performance with new punishment type fields

While the addition of punishment type fields aligns with the PR objectives, we should verify:

  1. Impact on query performance with additional fields
  2. Handling of null/undefined values
  3. Proper error handling in resolvers

Also applies to: 33-33

apps/judicial-system/web/messages/Core/tables.ts (1)

116-120: LGTM!

The new message for punishment type follows the established pattern and includes all required properties with clear descriptions.

apps/judicial-system/web/src/routes/Shared/Cases/PrisonCases.tsx (1)

187-190: LGTM!

The new column is properly configured with sorting capability using the defendantsPunishmentType field.

…s/add-punishment-type-tag-in-prison-cases-overview
@datadog-island-is
Copy link

datadog-island-is bot commented Dec 18, 2024

Datadog Report

All test runs 912b737 🔗

2 Total Test Services: 0 Failed, 2 Passed
🔻 Test Sessions change in coverage: 1 decreased (-0.02%), 1 no change

Test Services
Service Name Failed Known Flaky New Flaky Passed Skipped Total Time Code Coverage Change Test Service View
judicial-system-api 0 0 0 61 0 5.35s 1 decreased (-0.02%) Link
judicial-system-web 0 0 0 344 0 55.96s 1 no change Link

🔻 Code Coverage Decreases vs Default Branch (1)

  • judicial-system-api - jest 21.4% (-0.02%) - Details

Copy link

codecov bot commented Dec 18, 2024

Codecov Report

Attention: Patch coverage is 19.44444% with 29 lines in your changes missing coverage. Please review.

Project coverage is 35.71%. Comparing base (b3d7757) to head (4a41382).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...s/judicial-system/web/src/components/Tags/utils.ts 5.55% 17 Missing ⚠️
...system/web/src/routes/Shared/Cases/PrisonCases.tsx 0.00% 8 Missing ⚠️
...src/app/modules/case-list/models/caseList.model.ts 0.00% 2 Missing ⚠️
...judicial-system/web/src/components/Table/Table.tsx 0.00% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #17285      +/-   ##
==========================================
+ Coverage   35.70%   35.71%   +0.01%     
==========================================
  Files        6923     6947      +24     
  Lines      148601   148605       +4     
  Branches    42454    42442      -12     
==========================================
+ Hits        53058    53078      +20     
+ Misses      95543    95527      -16     
Flag Coverage Δ
judicial-system-api 20.20% <0.00%> (-0.02%) ⬇️
judicial-system-web 27.72% <20.58%> (-0.02%) ⬇️

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

Files with missing lines Coverage Δ
apps/judicial-system/web/messages/Core/tables.ts 100.00% <ø> (ø)
...-system/web/src/components/Tags/CaseTag.strings.ts 100.00% <ø> (ø)
apps/judicial-system/web/src/utils/arrayHelpers.ts 100.00% <100.00%> (ø)
...src/app/modules/case-list/models/caseList.model.ts 0.00% <0.00%> (ø)
...judicial-system/web/src/components/Table/Table.tsx 62.76% <0.00%> (-1.37%) ⬇️
...system/web/src/routes/Shared/Cases/PrisonCases.tsx 0.00% <0.00%> (ø)
...s/judicial-system/web/src/components/Tags/utils.ts 12.94% <5.55%> (-1.99%) ⬇️

... and 70 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 b3d7757...4a41382. Read the comment docs.

@thorhildurt thorhildurt added the automerge Merge this PR as soon as all checks pass label Dec 19, 2024
@kodiakhq kodiakhq bot removed the automerge Merge this PR as soon as all checks pass label Dec 19, 2024
Copy link
Contributor

kodiakhq bot commented Dec 19, 2024

This PR currently has a merge conflict. Please resolve this and then re-add the automerge label.

@thorhildurt thorhildurt added the automerge Merge this PR as soon as all checks pass label Dec 19, 2024
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 (1)
apps/judicial-system/web/src/components/Tags/utils.ts (1)

132-147: Consider extracting the helper function.

The nested getPunishmentTypeLabel function could be extracted to module scope for better reusability and testability. This would also improve code organization by separating concerns.

+const getPunishmentTypeLabel = (punishmentType?: PunishmentType | null) => {
+  switch (punishmentType) {
+    case PunishmentType.IMPRISONMENT:
+      return strings.punishmentTypeImprisonment
+    case PunishmentType.PROBATION:
+      return strings.punishmentTypeProbation
+    case PunishmentType.FINE:
+      return strings.punishmentTypeFine
+    case PunishmentType.INDICTMENT_RULING_DECISION_FINE:
+      return strings.punishmentTypeIndictmentRulingDecisionFine
+    case PunishmentType.SIGNED_FINE_INVITATION:
+      return strings.punishmentTypeSignedFineInvitation
+    default:
+      return strings.unknown
+  }
+}

 export const getPunishmentTypeTag = (
   punishmentType?: PunishmentType | null,
 ): {
   color: TagVariant
   text: { id: string; defaultMessage: string; description: string }
 } | null => {
   if (!punishmentType) return null

-  const getPunishmentTypeLabel = (punishmentType?: PunishmentType | null) => {
-    switch (punishmentType) {
-      case PunishmentType.IMPRISONMENT:
-        return strings.punishmentTypeImprisonment
-      case PunishmentType.PROBATION:
-        return strings.punishmentTypeProbation
-      case PunishmentType.FINE:
-        return strings.punishmentTypeFine
-      case PunishmentType.INDICTMENT_RULING_DECISION_FINE:
-        return strings.punishmentTypeIndictmentRulingDecisionFine
-      case PunishmentType.SIGNED_FINE_INVITATION:
-        return strings.punishmentTypeSignedFineInvitation
-      default:
-        return strings.unknown
-    }
-  }

   return {
     color: 'red' as TagVariant,
     text: getPunishmentTypeLabel(punishmentType),
   }
 }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 503ed03 and 149a412.

📒 Files selected for processing (4)
  • apps/judicial-system/web/src/components/Tags/utils.ts (2 hunks)
  • apps/judicial-system/web/src/routes/Shared/Cases/PrisonCases.tsx (3 hunks)
  • apps/judicial-system/web/src/routes/Shared/Cases/cases.graphql (1 hunks)
  • apps/judicial-system/web/src/routes/Shared/Cases/prisonCases.graphql (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • apps/judicial-system/web/src/routes/Shared/Cases/cases.graphql
  • apps/judicial-system/web/src/routes/Shared/Cases/prisonCases.graphql
  • apps/judicial-system/web/src/routes/Shared/Cases/PrisonCases.tsx
🧰 Additional context used
📓 Path-based instructions (1)
apps/judicial-system/web/src/components/Tags/utils.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."
🔇 Additional comments (2)
apps/judicial-system/web/src/components/Tags/utils.ts (2)

5-5: LGTM!

The import of PunishmentType is correctly placed and necessary for the new functionality.


124-153: Verify completeness of punishment type handling.

Let's ensure we're handling all possible punishment types from the enum.

✅ Verification successful

All punishment types from the enum are correctly handled in the switch statement

The verification confirms that the getPunishmentTypeTag function handles all possible values from the PunishmentType enum. The enum defined in libs/judicial-system/types/src/lib/defendant.ts contains exactly the same five values that are handled in the switch statement:

  • IMPRISONMENT
  • PROBATION
  • FINE
  • INDICTMENT_RULING_DECISION_FINE
  • SIGNED_FINE_INVITATION

Additionally, the function includes a default case that returns an "unknown" string, making it robust against any future enum additions.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that all PunishmentType enum values are handled in the switch statement

# Search for the PunishmentType enum definition
ast-grep --pattern 'enum PunishmentType {
  $$$
}'

# Compare with current implementation
echo "Current implementation handles:"
echo "- IMPRISONMENT"
echo "- PROBATION"
echo "- FINE"
echo "- INDICTMENT_RULING_DECISION_FINE"
echo "- SIGNED_FINE_INVITATION"

Length of output: 945

@kodiakhq kodiakhq bot merged commit b76b7dd into main Dec 19, 2024
27 checks passed
@kodiakhq kodiakhq bot deleted the j-s/add-punishment-type-tag-in-prison-cases-overview branch December 19, 2024 19:33
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.

3 participants