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 indictment count subtypes to IndictmentCount #17129

Merged
merged 19 commits into from
Dec 9, 2024

Conversation

oddsson
Copy link
Member

@oddsson oddsson commented Dec 4, 2024

Add indictment count subtypes to IndictmentCount

Asana

What

Add checkboxes to IndictmentCount component so that users can select what subtypes are applicable to each indictment count.

Why

This is one step in making other types, besides traffic violations, work in RVG

Screenshots / Gifs

Screen.Recording.2024-12-04.at.15.02.11.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

    • Introduced a new field indictmentCountSubtypes for managing multiple indictment subtypes in various components and APIs.
    • Enhanced GraphQL queries and mutations to include indictmentCountSubtypes, providing more detailed data.
    • Added a selection interface for users to choose indictment subtypes in the application.
    • Integrated feature-based logic to display traffic violation case files based on user features.
  • Bug Fixes

    • Improved error handling and data management in the Indictment component.
  • Documentation

    • Updated string definitions for better user guidance.
  • Style

    • Added new CSS styles for responsive design related to indictment subtypes.
  • Chores

    • Updated environment configurations to enable the new MULTIPLE_INDICTMENT_SUBTYPES feature flag.

@oddsson oddsson requested a review from a team as a code owner December 4, 2024 14:16
Copy link
Contributor

coderabbitai bot commented Dec 4, 2024

Walkthrough

This pull request introduces significant updates to the judicial system application, primarily adding a new optional property, indictmentCountSubtypes, across various components, including DTOs, models, and GraphQL schemas. It also includes a migration script for updating the database schema to accommodate this new field. Additionally, several configuration files are modified to enable a feature flag for handling multiple indictment subtypes, enhancing the application's capability to manage and display detailed indictment information.

Changes

File Change Summary
apps/judicial-system/api/src/app/modules/indictment-count/dto/updateIndictmentCount.input.ts Added indictmentCountSubtypes field to UpdateIndictmentCountInput class; updated import for IndictmentSubtype.
apps/judicial-system/api/src/app/modules/indictment-count/models/indictmentCount.model.ts Added indictmentCountSubtypes field to IndictmentCount class; registered IndictmentSubtype as a GraphQL enum.
apps/judicial-system/backend/migrations/20241204124025-update-indictment-count.js Created migration script to add indictment_count_subtypes column to the indictment_count table.
apps/judicial-system/backend/src/app/modules/indictment-count/dto/updateIndictmentCount.dto.ts Added indictmentCountSubtypes property to UpdateIndictmentCountDto class; updated import for IndictmentSubtype.
apps/judicial-system/web/src/components/FormProvider/case.graphql Added indictmentCountSubtypes field to indictmentCounts array in the case query.
apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/Indictment.tsx Adjusted component structure and data handling; no significant logic changes.
apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.css.ts Added styles for indictmentSubtypesContainter and indictmentSubtypesItem.
apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.strings.ts Added new message entry selectIndictmentSubtype for labeling selection fields.
apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx Introduced functionality for managing indictment subtypes with a new Checkbox component.
apps/judicial-system/web/src/utils/hooks/useIndictmentCounts/updateIndictmentCount.graphql Modified mutation UpdateIndictmentCount to include indictmentCountSubtypes in the response.
apps/judicial-system/api/infra/judicial-system-api.ts Added MULTIPLE_INDICTMENT_SUBTYPES feature flag to HIDDEN_FEATURES configuration.
charts/judicial-system/values.prod.yaml Updated HIDDEN_FEATURES to include MULTIPLE_INDICTMENT_SUBTYPES; adjusted replica counts and HPA settings.
charts/judicial-system/values.staging.yaml Updated HIDDEN_FEATURES to include MULTIPLE_INDICTMENT_SUBTYPES.
charts/services/judicial-system-api/values.prod.yaml Updated HIDDEN_FEATURES to include MULTIPLE_INDICTMENT_SUBTYPES.
charts/services/judicial-system-api/values.staging.yaml Updated HIDDEN_FEATURES to include MULTIPLE_INDICTMENT_SUBTYPES.
libs/judicial-system/types/src/lib/feature.ts Added MULTIPLE_INDICTMENT_SUBTYPES to Feature enum.

Suggested labels

automerge

Suggested reviewers

  • unakb
  • gudjong

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
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: 2

🧹 Outside diff range and nitpick comments (7)
apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/Indictment.tsx (1)

Line range hint 372-385: Consider removing unnecessary AnimatePresence wrapper.

Based on the code structure, the AnimatePresence component appears to be unnecessary here as it wraps a single static component without any exit animations being utilized. This aligns with NextJS best practices for optimizing component rendering.

Consider this simplified structure:

-              <AnimatePresence>
                <IndictmentCount
                  indictmentCount={indictmentCount}
                  workingCase={workingCase}
                  onDelete={index > 0 ? handleDeleteIndictmentCount : undefined}
                  onChange={handleUpdateIndictmentCount}
                  setWorkingCase={setWorkingCase}
                  updateIndictmentCountState={updateIndictmentCountState}
                />
-              </AnimatePresence>
apps/judicial-system/backend/migrations/20241204124025-update-indictment-count.js (1)

4-17: Consider adding transaction timeout for large tables.

The migration is well-structured with proper transaction handling. However, for large tables, consider adding a transaction timeout to prevent long-running migrations from being stuck.

 async up(queryInterface, Sequelize) {
-    await queryInterface.sequelize.transaction((transaction) =>
+    await queryInterface.sequelize.transaction({
+      timeout: 30000 // 30 seconds
+    }, (transaction) =>
       queryInterface.addColumn(
apps/judicial-system/api/src/app/modules/indictment-count/models/indictmentCount.model.ts (1)

6-9: LGTM! Consider centralizing enum type registrations.

The changes are well-implemented following NestJS and GraphQL best practices. The field addition and enum registration are correct.

Consider moving all enum type registrations to a centralized location (e.g., graphql-types.ts) to maintain better organization as the number of enums grows. This would help prevent scattered enum registrations across different files.

Example structure:

// graphql-types.ts
import { registerEnumType } from '@nestjs/graphql'
import { IndictmentCountOffense, IndictmentSubtype } from '@island.is/judicial-system/types'

export const registerGraphQLEnums = () => {
  registerEnumType(IndictmentCountOffense, { name: 'IndictmentCountOffense' })
  registerEnumType(IndictmentSubtype, { name: 'IndictmentSubtype' })
}

Also applies to: 12-12, 48-50

apps/judicial-system/backend/src/app/modules/indictment-count/dto/updateIndictmentCount.dto.ts (1)

13-16: Consider organizing imports

The imports look good, but consider grouping related imports together. The IndictmentCountOffense and IndictmentSubtype could be imported in a single line since they're from the same module.

-import {
-  IndictmentCountOffense,
-  IndictmentSubtype,
-} from '@island.is/judicial-system/types'
+import { IndictmentCountOffense, IndictmentSubtype } from '@island.is/judicial-system/types'
apps/judicial-system/api/src/app/modules/indictment-count/dto/updateIndictmentCount.input.ts (1)

7-10: Consider organizing imports

Similar to the DTO file, consider consolidating the related type imports.

-import {
-  IndictmentCountOffense,
-  IndictmentSubtype,
-} from '@island.is/judicial-system/types'
+import { IndictmentCountOffense, IndictmentSubtype } from '@island.is/judicial-system/types'
apps/judicial-system/backend/src/app/modules/indictment-count/models/indictmentCount.model.ts (1)

14-17: Consider organizing imports

Similar to other files, consider consolidating the related type imports.

-import {
-  IndictmentCountOffense,
-  IndictmentSubtype,
-} from '@island.is/judicial-system/types'
+import { IndictmentCountOffense, IndictmentSubtype } from '@island.is/judicial-system/types'
apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx (1)

349-351: Consider adding explicit type annotation for better type safety

The implementation is solid, particularly the use of Set for managing unique subtypes. However, the type safety could be enhanced.

Consider adding an explicit type annotation for the Set:

-    const currentSubtypes = new Set(
+    const currentSubtypes = new Set<IndictmentSubtype>(
       indictmentCount.indictmentCountSubtypes ?? [],
     )

Also applies to: 415-428

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between be2291a and e5ea1e2.

📒 Files selected for processing (12)
  • apps/judicial-system/api/src/app/modules/indictment-count/dto/updateIndictmentCount.input.ts (2 hunks)
  • apps/judicial-system/api/src/app/modules/indictment-count/models/indictmentCount.model.ts (2 hunks)
  • apps/judicial-system/backend/migrations/20241204124025-update-indictment-count.js (1 hunks)
  • apps/judicial-system/backend/src/app/modules/indictment-count/dto/updateIndictmentCount.dto.ts (2 hunks)
  • apps/judicial-system/backend/src/app/modules/indictment-count/models/indictmentCount.model.ts (2 hunks)
  • apps/judicial-system/web/src/components/FormProvider/case.graphql (1 hunks)
  • apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/Indictment.tsx (1 hunks)
  • apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.css.ts (1 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 (5 hunks)
  • apps/judicial-system/web/src/utils/hooks/useIndictmentCounts/updateIndictmentCount.graphql (1 hunks)
  • libs/judicial-system/types/src/lib/case.ts (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.css.ts
🧰 Additional context used
📓 Path-based instructions (11)
apps/judicial-system/web/src/utils/hooks/useIndictmentCounts/updateIndictmentCount.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/FormProvider/case.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."
libs/judicial-system/types/src/lib/case.ts (1)

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

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
apps/judicial-system/backend/src/app/modules/indictment-count/dto/updateIndictmentCount.dto.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/backend/migrations/20241204124025-update-indictment-count.js (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/Indictment.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/api/src/app/modules/indictment-count/models/indictmentCount.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/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/api/src/app/modules/indictment-count/dto/updateIndictmentCount.input.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/backend/src/app/modules/indictment-count/models/indictmentCount.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/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."
📓 Learnings (2)
apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/Indictment.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.
apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.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.
🪛 Biome (1.9.4)
apps/judicial-system/backend/migrations/20241204124025-update-indictment-count.js

[error] 1-1: Redundant use strict directive.

The entire contents of JavaScript modules are automatically in strict mode, with no statement needed to initiate it.
Safe fix: Remove the redundant use strict directive.

(lint/suspicious/noRedundantUseStrict)

🔇 Additional comments (9)
apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/Indictment.tsx (1)

383-383: LGTM! The tag format change is consistent.

The change from self-closing to standard closing tag format is valid and maintains functionality.

apps/judicial-system/web/src/utils/hooks/useIndictmentCounts/updateIndictmentCount.graphql (1)

14-14: LGTM! Verify field usage in frontend components.

The addition of indictmentCountSubtypes to the mutation response is correct and aligns with the model changes.

Let's verify the field usage in frontend components:

✅ Verification successful

Field is properly used in frontend components

The indictmentCountSubtypes field is correctly utilized in the relevant components:

  • Used in IndictmentCount.tsx for displaying and updating subtypes
  • Included in the case query schema (case.graphql)
  • Properly integrated with the mutation response
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for components using this mutation response field
rg -t tsx -t ts "indictmentCountSubtypes" apps/judicial-system/web/src/

Length of output: 99


Script:

#!/bin/bash
# Search for components using this mutation response field, using ripgrep without file type restrictions
rg "indictmentCountSubtypes" apps/judicial-system/web/src/

Length of output: 727

apps/judicial-system/backend/src/app/modules/indictment-count/dto/updateIndictmentCount.dto.ts (1)

57-61: LGTM! Property decorators are properly configured

The new indictmentCountSubtypes property is well-defined with appropriate decorators for validation and API documentation.

apps/judicial-system/api/src/app/modules/indictment-count/dto/updateIndictmentCount.input.ts (1)

60-65: LGTM! GraphQL field and validation decorators are properly configured

The new indictmentCountSubtypes property is well-defined with appropriate decorators for GraphQL and validation.

apps/judicial-system/backend/src/app/modules/indictment-count/models/indictmentCount.model.ts (1)

76-82: Verify database migration for the new column

The column definition looks good with proper type configuration. However, let's verify that a corresponding migration exists for adding this column.

✅ Verification successful

Migration exists and is properly configured

The migration file 20241204124025-update-indictment-count.js correctly adds the indictment_count_subtypes column with appropriate configuration:

  • Uses ARRAY(STRING) type which matches the model definition
  • Sets allowNull: true as specified in the model
  • Includes both up and down migrations for proper version control
  • Uses a transaction for data integrity
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for migration file that adds indictmentCountSubtypes column

# Look for migration files that might contain the column addition
rg -l "indictment_count_subtypes" apps/judicial-system/backend/migrations/

Length of output: 156


Script:

#!/bin/bash
# Let's check the content of the migration file to verify it properly adds the column
cat apps/judicial-system/backend/migrations/20241204124025-update-indictment-count.js

Length of output: 618

apps/judicial-system/web/src/components/FormProvider/case.graphql (1)

219-219: LGTM! Verify GraphQL schema definition

The addition of indictmentCountSubtypes field to the Case query is correct and aligns with the PR objective.

Let's verify the GraphQL schema definition:

✅ Verification successful

GraphQL schema is properly defined and integrated

The field indictmentCountSubtypes is correctly defined and integrated across the codebase:

  • Enum IndictmentSubtype is defined in libs/judicial-system/types/src/lib/case.ts
  • The field is properly typed in both API and backend models (IndictmentSubtype[])
  • It's correctly used in the frontend components
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if the IndictmentSubtype enum and field are properly defined in the schema

# Search for IndictmentSubtype enum definition
rg -l "enum IndictmentSubtype" --type graphql

# Search for indictmentCountSubtypes field type definition
rg -l "indictmentCountSubtypes.*IndictmentSubtype" --type graphql

Length of output: 179


Script:

#!/bin/bash
# Let's try searching without file type restriction since GraphQL files might have different extensions
# Search for schema files and enum definitions
fd -e gql -e graphql

# Search for IndictmentSubtype enum definition
rg "enum IndictmentSubtype"

# Search for indictmentCountSubtypes field type definition
rg "indictmentCountSubtypes.*:"

Length of output: 21181

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

144-148: LGTM! Translation strings are well-structured

The new message entry follows the established pattern and naming conventions, with clear description and proper translation.

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

8-8: LGTM! Import statements are well-organized

The new imports are properly structured and align with the feature requirements for adding indictment count subtypes.

Also applies to: 14-18, 21-21, 29-29


479-507: Verify the business logic for subtype visibility

The implementation looks good, but please verify:

  1. Should we hide the subtype selection when there's only one subtype?
  2. Should we display a message when there's only one subtype?

The current implementation only shows the selection when there are multiple subtypes (> 1).

✅ Verification successful

Let me search for more context about how subtypes are handled in the codebase.


Let me try a different search approach to find subtype-related code.


Let me search for indictment-related files to understand the context better.


Let me search for the specific implementation of indictment subtypes to understand how they are handled.


Based on the code analysis, I can now provide a definitive response about the subtype visibility logic.

The current implementation is correct

The condition subtypes.length > 1 for showing the subtype selection is the intended behavior because:

  1. The code shows this is part of a judicial system where indictment subtypes are managed carefully
  2. When there's only one subtype, showing a selection UI would be unnecessary since there's no choice to make
  3. The implementation is consistent with other parts of the codebase where subtypes are handled

The code doesn't show any message display when there's only one subtype, which is also correct as it would add unnecessary UI complexity for a non-choice scenario.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for similar patterns in other components to verify consistency
ast-grep --pattern 'subtypes.length > 1'

Length of output: 168


Script:

#!/bin/bash
# Search for subtype-related patterns and their handling
rg -A 5 "subtype" --type typescript

Length of output: 70


Script:

#!/bin/bash
# Search for subtype-related patterns in all files
rg -A 5 "subtype"

# Also search for any files containing "indictment" in their name
fd "indictment" -i

Length of output: 80343


Script:

#!/bin/bash
# Search for indictment-related files and their content
rg -A 5 "indictmentSubtype" --type ts

# Also search for any files containing indictment in their name
fd "indictment" -i

Length of output: 67326


Script:

#!/bin/bash
# Search for the IndictmentSubtype enum definition
rg -A 10 "enum IndictmentSubtype" --type ts

# Also search for any files that define indictment subtype handling logic
rg -A 5 "subtypes.length" --type ts

Length of output: 2432

@datadog-island-is
Copy link

datadog-island-is bot commented Dec 4, 2024

Datadog Report

All test runs 3e91c0a 🔗

28 Total Test Services: 0 Failed, 27 Passed
🔻 Test Sessions change in coverage: 3 decreased, 3 increased, 105 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 3.04s 1 no change Link
application-system-api 0 0 0 46 0 2m 19.33s 1 no change Link
application-template-api-modules 0 0 0 70 0 0s N/A Link
application-templates-driving-license 0 0 0 13 0 18.14s 1 no change Link
application-templates-financial-aid 0 0 0 11 0 16.99s 1 no change Link
application-templates-general-petition 0 0 0 5 0 13.52s 1 no change Link
application-templates-health-insurance 0 0 0 0 0 605.88ms 1 no change Link
application-templates-mortgage-certificate 0 0 0 3 0 21.76s 1 no change Link
application-templates-parental-leave 0 0 0 163 0 20.69s 1 no change Link
application-templates-public-debt-payment-plan 0 0 0 3 0 10.59s 1 no change Link

🔻 Code Coverage Decreases vs Default Branch (3)

  • judicial-system-types - jest 45.54% (-0.07%) - Details
  • judicial-system-web - jest 32.55% (-0.01%) - Details
  • judicial-system-api - jest 21.13% (-0.01%) - Details

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

🧹 Outside diff range and nitpick comments (1)
apps/judicial-system/backend/migrations/20241204124025-update-indictment-count.js (1)

4-17: Consider adding array validation constraints.

The transaction usage is good for ensuring atomic operations. However, consider adding constraints to prevent potential issues:

  1. Maximum array length to prevent memory issues
  2. String validation for array elements to ensure they match expected subtypes
 {
   type: Sequelize.ARRAY(Sequelize.STRING),
   allowNull: true,
   defaultValue: [],
+  validate: {
+    len: [0, 10], // Adjust max length as needed
+    isValidSubtype(value) {
+      if (value && value.length) {
+        const validSubtypes = ['TYPE1', 'TYPE2']; // Add your valid subtypes
+        if (!value.every(type => validSubtypes.includes(type))) {
+          throw new Error('Invalid subtype detected');
+        }
+      }
+    }
+  }
 }
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between e5ea1e2 and 853dea2.

📒 Files selected for processing (1)
  • apps/judicial-system/backend/migrations/20241204124025-update-indictment-count.js (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
apps/judicial-system/backend/migrations/20241204124025-update-indictment-count.js (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."
🪛 Biome (1.9.4)
apps/judicial-system/backend/migrations/20241204124025-update-indictment-count.js

[error] 1-1: Redundant use strict directive.

The entire contents of JavaScript modules are automatically in strict mode, with no statement needed to initiate it.
Safe fix: Remove the redundant use strict directive.

(lint/suspicious/noRedundantUseStrict)

🔇 Additional comments (2)
apps/judicial-system/backend/migrations/20241204124025-update-indictment-count.js (2)

1-2: Remove redundant 'use strict' directive.

JavaScript modules are automatically in strict mode, making this directive unnecessary.

🧰 Tools
🪛 Biome (1.9.4)

[error] 1-1: Redundant use strict directive.

The entire contents of JavaScript modules are automatically in strict mode, with no statement needed to initiate it.
Safe fix: Remove the redundant use strict directive.

(lint/suspicious/noRedundantUseStrict)


19-24: LGTM! Clean rollback implementation.

The down migration correctly removes the column, providing a clean rollback path.

@oddsson oddsson requested a review from a team as a code owner December 4, 2024 14:51
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: 2

🧹 Outside diff range and nitpick comments (4)
apps/judicial-system/web/src/components/ServiceAnnouncement/ServiceAnnouncement.tsx (2)

Line range hint 15-82: Consider improving string formatting readability.

The helper functions are well-structured and handle all cases properly. However, the string concatenation in mapServiceStatusMessages could be more readable.

Consider refactoring the string concatenation using template literals and optional chaining:

-        `${subpoena.servedBy ? subpoena.servedBy : ''}${
-          subpoena.serviceDate
-            ? ` - ${formatDate(subpoena.serviceDate, 'Pp')}`
-            : ''
-        }`,
+        `${subpoena.servedBy ?? ''}${
+          subpoena.serviceDate ? ` - ${formatDate(subpoena.serviceDate, 'Pp')}` : ''
+        }`,

Line range hint 100-143: Consider improving conditional rendering and key generation.

While the component implementation is solid, there are two areas for improvement:

  1. The AlertMessage type prop condition could be simplified
  2. The key prop in the Text component mapping could be more unique to prevent potential issues with duplicate messages

Consider these improvements:

-        type={
-          !subpoena?.serviceStatus
-            ? 'info'
-            : subpoena?.serviceStatus === ServiceStatus.FAILED ||
-              subpoena?.serviceStatus === ServiceStatus.EXPIRED
-            ? 'warning'
-            : 'success'
-        }
+        type={
+          !subpoena?.serviceStatus ? 'info' :
+          [ServiceStatus.FAILED, ServiceStatus.EXPIRED].includes(subpoena.serviceStatus) ? 'warning' : 'success'
+        }

-              <Text variant="small" key={`${msg}-${subpoena.created}`}>
+              <Text variant="small" key={`${msg}-${subpoena.created}-${messages.indexOf(msg)}`}>
apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx (2)

349-351: Consider memoizing the subtypes calculation.

The subtypes calculation could benefit from memoization to prevent unnecessary recalculations on re-renders.

-  const subtypes = indictmentCount.policeCaseNumber
-    ? workingCase.indictmentSubtypes[indictmentCount.policeCaseNumber]
-    : []
+  const subtypes = useMemo(() => 
+    indictmentCount.policeCaseNumber
+      ? workingCase.indictmentSubtypes[indictmentCount.policeCaseNumber]
+      : [],
+    [indictmentCount.policeCaseNumber, workingCase.indictmentSubtypes]
+  )

479-511: Consider accessibility improvements for the checkboxes.

While the implementation is functional, consider adding ARIA labels and role attributes for better screen reader support.

 <div
   className={styles.indictmentSubtypesContainter}
+  role="group"
+  aria-label={formatMessage(strings.selectIndictmentSubtype)}
 >
   {subtypes.map((subtype: IndictmentSubtype) => (
     <div
       className={styles.indictmentSubtypesItem}
       key={`${subtype}-${indictmentCount.id}`}
     >
       <Checkbox
         name={`${subtype}-${indictmentCount.id}`}
         value={subtype}
         label={capitalize(indictmentSubtypes[subtype])}
+        aria-label={`${formatMessage(strings.selectIndictmentSubtype)} ${capitalize(indictmentSubtypes[subtype])}`}
         checked={indictmentCount.indictmentCountSubtypes?.includes(subtype) ?? false}
         onChange={(evt) => {
           handleSubtypeChange(subtype, evt.target.checked)
         }}
         backgroundColor="white"
         large
         filled
       />
     </div>
   ))}
 </div>
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 853dea2 and 026eaf6.

📒 Files selected for processing (10)
  • apps/judicial-system/api/infra/judicial-system-api.ts (1 hunks)
  • apps/judicial-system/web/src/components/ServiceAnnouncement/ServiceAnnouncement.tsx (1 hunks)
  • apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.css.ts (1 hunks)
  • apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx (5 hunks)
  • apps/judicial-system/web/src/utils/hooks/useSections/index.ts (5 hunks)
  • charts/judicial-system/values.prod.yaml (1 hunks)
  • charts/judicial-system/values.staging.yaml (1 hunks)
  • charts/services/judicial-system-api/values.prod.yaml (1 hunks)
  • charts/services/judicial-system-api/values.staging.yaml (1 hunks)
  • libs/judicial-system/types/src/lib/feature.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.css.ts
🧰 Additional context used
📓 Path-based instructions (5)
libs/judicial-system/types/src/lib/feature.ts (1)

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

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
apps/judicial-system/api/infra/judicial-system-api.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/ServiceAnnouncement/ServiceAnnouncement.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/hooks/useSections/index.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/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."
🔇 Additional comments (13)
apps/judicial-system/web/src/components/ServiceAnnouncement/ServiceAnnouncement.tsx (3)

Line range hint 1-13: LGTM! Well-organized imports following best practices.

The imports are properly organized, with clear separation between external dependencies and internal modules. Type imports are correctly used.


Line range hint 84-90: LGTM! Clean error handling implementation.

The error rendering function is concise and properly handles internationalization.


Line range hint 92-98: LGTM! Well-defined TypeScript interface.

The props interface is properly typed and follows TypeScript best practices.

apps/judicial-system/web/src/utils/hooks/useSections/index.ts (3)

11-11: Imports are correctly updated

The addition of Feature to the imports ensures that feature flags are properly utilized within the hook.


23-23: Importing FeatureContext for feature flag access

Importing FeatureContext enables the hook to access the application's feature flags, allowing for conditional logic based on enabled features.


66-66: Using useContext to access features

Accessing features from FeatureContext via useContext is appropriate and aligns with React best practices for context usage.

libs/judicial-system/types/src/lib/feature.ts (1)

3-3: Adding MULTIPLE_INDICTMENT_SUBTYPES to the Feature enum

The new enum member MULTIPLE_INDICTMENT_SUBTYPES correctly extends the Feature enum, supporting the introduction of the new feature flag within the system.

charts/services/judicial-system-api/values.prod.yaml (1)

33-33: Verify the enablement of MULTIPLE_INDICTMENT_SUBTYPES in production

The HIDDEN_FEATURES environment variable now includes 'MULTIPLE_INDICTMENT_SUBTYPES', which activates this feature in the production environment. Please confirm that this feature is fully tested and intended to be released to production users.

charts/services/judicial-system-api/values.staging.yaml (1)

33-33: Enabling MULTIPLE_INDICTMENT_SUBTYPES feature in staging

The environment variable HIDDEN_FEATURES is updated to include 'MULTIPLE_INDICTMENT_SUBTYPES', correctly enabling the new feature in the staging environment for further testing.

apps/judicial-system/api/infra/judicial-system-api.ts (1)

50-51: Confirm activation of MULTIPLE_INDICTMENT_SUBTYPES feature flag in production

The HIDDEN_FEATURES configuration now includes 'MULTIPLE_INDICTMENT_SUBTYPES' for both staging and production environments:

HIDDEN_FEATURES: {
  dev: '',
  staging: 'MULTIPLE_INDICTMENT_SUBTYPES',
  prod: 'MULTIPLE_INDICTMENT_SUBTYPES',
},

Ensure that the feature is fully vetted and that enabling it in the production environment is intentional.

charts/judicial-system/values.prod.yaml (1)

33-33: LGTM! Feature flag consistently applied in production.

The feature flag configuration matches the staging environment, ensuring consistent behavior across environments.

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

8-8: LGTM! Dependencies properly imported.

The imports are well-organized and include all necessary components and utilities for the new subtype functionality.

Also applies to: 14-18, 21-21, 29-29


415-428: LGTM! Event handler implementation is clean and efficient.

The handleSubtypeChange function effectively manages the state updates using Set operations for uniqueness.

Copy link

codecov bot commented Dec 4, 2024

Codecov Report

Attention: Patch coverage is 27.90698% with 31 lines in your changes missing coverage. Please review.

Project coverage is 35.71%. Comparing base (24c792b) to head (5236885).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...secutor/Indictments/Indictment/IndictmentCount.tsx 0.00% 16 Missing ⚠️
...s/indictment-count/models/indictmentCount.model.ts 0.00% 4 Missing ⚠️
...ndictment-count/dto/updateIndictmentCount.input.ts 0.00% 3 Missing ⚠️
...tes/Prosecutor/Indictments/CaseFiles/CaseFiles.tsx 0.00% 3 Missing ⚠️
...s/Prosecutor/Indictments/Processing/Processing.tsx 0.00% 3 Missing ⚠️
...l-system/web/src/utils/hooks/useCaseList/index.tsx 33.33% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #17129      +/-   ##
==========================================
- Coverage   35.72%   35.71%   -0.02%     
==========================================
  Files        6926     6926              
  Lines      147734   147739       +5     
  Branches    42092    42096       +4     
==========================================
- Hits        52779    52762      -17     
- Misses      94955    94977      +22     
Flag Coverage Δ
judicial-system-api 19.97% <12.50%> (-0.01%) ⬇️
judicial-system-backend 55.72% <100.00%> (+<0.01%) ⬆️
judicial-system-formatters 78.11% <100.00%> (+0.02%) ⬆️
judicial-system-message 66.66% <ø> (ø)
judicial-system-message-handler 48.21% <ø> (ø)
judicial-system-scheduler 70.88% <100.00%> (+0.02%) ⬆️
judicial-system-types 42.72% <0.00%> (-0.07%) ⬇️
judicial-system-web 27.90% <22.58%> (-0.02%) ⬇️

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

Files with missing lines Coverage Δ
.../indictment-count/dto/updateIndictmentCount.dto.ts 100.00% <100.00%> (ø)
...s/indictment-count/models/indictmentCount.model.ts 94.44% <100.00%> (+0.32%) ⬆️
...ndictmentCaseFilesList/IndictmentCaseFilesList.tsx 68.60% <100.00%> (+0.74%) ⬆️
...onents/ServiceAnnouncement/ServiceAnnouncement.tsx 6.77% <ø> (ø)
...s/Prosecutor/Indictments/Indictment/Indictment.tsx 0.00% <ø> (ø)
.../Indictments/Indictment/IndictmentCount.strings.ts 100.00% <ø> (ø)
...al-system/web/src/utils/hooks/useSections/index.ts 32.14% <100.00%> (+0.32%) ⬆️
libs/judicial-system/types/src/lib/feature.ts 100.00% <100.00%> (ø)
...l-system/web/src/utils/hooks/useCaseList/index.tsx 14.77% <33.33%> (+0.81%) ⬆️
...ndictment-count/dto/updateIndictmentCount.input.ts 0.00% <0.00%> (ø)
... and 4 more

... and 10 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 24c792b...5236885. 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: 1

🧹 Outside diff range and nitpick comments (7)
apps/judicial-system/web/src/components/IndictmentCaseFilesList/IndictmentCaseFilesList.tsx (2)

76-76: Consider memoizing feature checks

While the current implementation is correct, consider memoizing feature checks to prevent unnecessary rerenders when other context values change.

- const { features } = useContext(FeatureContext)
+ const { features } = useContext(FeatureContext)
+ const memoizedFeatures = useMemo(
+   () => ({
+     hasMultipleIndictmentSubtypes: features.includes(Feature.MULTIPLE_INDICTMENT_SUBTYPES)
+   }),
+   [features]
+ )

Line range hint 1-300: Consider breaking down the component for better maintainability

The component handles multiple responsibilities and contains several conditional rendering blocks. Consider extracting these sections into separate components for better maintainability and reusability:

  1. Create separate components for each file type section (indictments, criminal records, etc.)
  2. Create a common FileSection component to reduce duplication

Example refactor for a file section:

interface FileSectionProps {
  title: string;
  files: CaseFile[];
  onOpenFile: (fileId: string) => void;
}

const FileSection: FC<FileSectionProps> = ({ title, files, onOpenFile }) => {
  if (!files?.length) return null;
  
  return (
    <Box marginBottom={5}>
      <Text variant="h4" as="h4" marginBottom={1}>
        {title}
      </Text>
      <RenderFiles caseFiles={files} onOpenFile={onOpenFile} />
    </Box>
  );
};
apps/judicial-system/web/src/utils/hooks/useCaseList/index.tsx (2)

53-55: Consider extracting traffic violation check to a separate function

The traffic violation check combines feature flag and business logic. Consider extracting this into a separate function for better maintainability and reusability.

+const isTrafficViolationEnabled = (
+  features: Feature[],
+  caseData: Case
+): boolean => {
+  return (
+    features.includes(Feature.MULTIPLE_INDICTMENT_SUBTYPES) ||
+    isTrafficViolationCase(caseData)
+  )
+}

 const openCase = useCallback(
   (caseToOpen: Case, openCaseInNewTab?: boolean) => {
     let routeTo = null
-    const isTrafficViolation =
-      features.includes(Feature.MULTIPLE_INDICTMENT_SUBTYPES) ||
-      isTrafficViolationCase(caseToOpen)
+    const isTrafficViolation = isTrafficViolationEnabled(features, caseToOpen)

Line range hint 134-137: Add missing 'features' dependency to useCallback

The openCase callback uses features from context but doesn't include it in the dependency array. This could lead to stale closures where the callback uses outdated feature flags.

  useCallback(
    (caseToOpen: Case, openCaseInNewTab?: boolean) => {
      // ... callback implementation
    },
-   [router, user],
+   [router, user, features],
  )
apps/judicial-system/web/src/routes/Prosecutor/Indictments/Processing/Processing.tsx (3)

79-81: Consider extracting feature check logic into a custom hook

The feature flag check combined with the traffic violation case check could be moved to a custom hook for better maintainability and reusability.

+const useIsTrafficViolationCase = (workingCase: Case) => {
+  const { features } = useContext(FeatureContext)
+  return features.includes(Feature.MULTIPLE_INDICTMENT_SUBTYPES) ||
+    isTrafficViolationCase(workingCase)
+}

 const Processing: FC = () => {
   // ...
-  const isTrafficViolationCaseCheck =
-    features.includes(Feature.MULTIPLE_INDICTMENT_SUBTYPES) ||
-    isTrafficViolationCase(workingCase)
+  const isTrafficViolationCaseCheck = useIsTrafficViolationCase(workingCase)

Line range hint 116-119: Consider enhancing form validation with a validation schema

The current validation relies on a single function. Consider using a schema validation library like Zod or Yup for more robust form validation.

import { z } from 'zod'

const processingSchema = z.object({
  court: z.string().min(1, 'Court is required'),
  hasCivilClaims: z.boolean(),
  civilClaimants: z.array(
    z.object({
      nationalId: z.string().min(11).nullable(),
      name: z.string().min(1, 'Name is required'),
    })
  ).optional(),
})

const stepIsValid = () => {
  try {
    processingSchema.parse(workingCase)
    return true
  } catch {
    return false
  }
}

Line range hint 95-112: Consider adding type safety to navigation paths

The navigation paths are currently stringly typed. Consider creating a type-safe routing solution.

type RouteConfig = {
  INDICTMENTS_CASE_FILE_ROUTE: string
  INDICTMENTS_TRAFFIC_VIOLATION_ROUTE: string
  INDICTMENTS_CASE_FILES_ROUTE: string
}

const ROUTES: RouteConfig = {
  INDICTMENTS_CASE_FILE_ROUTE: '/indictments/case-file',
  INDICTMENTS_TRAFFIC_VIOLATION_ROUTE: '/indictments/traffic-violation',
  INDICTMENTS_CASE_FILES_ROUTE: '/indictments/case-files',
} as const

const handleNavigationTo = useCallback(
  async (destination: keyof RouteConfig) => {
    // ... existing code
    router.push(`${ROUTES[destination]}/${workingCase.id}`)
  },
  [router, setWorkingCase, transitionCase, workingCase],
)
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 026eaf6 and 9289780.

📒 Files selected for processing (4)
  • apps/judicial-system/web/src/components/IndictmentCaseFilesList/IndictmentCaseFilesList.tsx (3 hunks)
  • apps/judicial-system/web/src/routes/Prosecutor/Indictments/CaseFiles/CaseFiles.tsx (3 hunks)
  • apps/judicial-system/web/src/routes/Prosecutor/Indictments/Processing/Processing.tsx (3 hunks)
  • apps/judicial-system/web/src/utils/hooks/useCaseList/index.tsx (3 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
apps/judicial-system/web/src/routes/Prosecutor/Indictments/CaseFiles/CaseFiles.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/IndictmentCaseFilesList/IndictmentCaseFilesList.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/Processing/Processing.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/hooks/useCaseList/index.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 (1)
apps/judicial-system/web/src/routes/Prosecutor/Indictments/Processing/Processing.tsx (1)
Learnt from: gudjong
PR: island-is/island.is#15421
File: apps/judicial-system/web/src/routes/Prosecutor/Indictments/Processing/Processing.tsx:55-61
Timestamp: 2024-11-12T15:15:11.835Z
Learning: The `updateCase` method in the `apps/judicial-system/web/src/routes/Prosecutor/Indictments/Processing/Processing.tsx` file has its own error handling, and additional error handling in the `initialize` function is not necessary.
🔇 Additional comments (5)
apps/judicial-system/web/src/components/IndictmentCaseFilesList/IndictmentCaseFilesList.tsx (2)

8-8: LGTM: Clean import organization

The new imports follow the project's organization pattern, separating external and internal dependencies appropriately.

Also applies to: 19-19


82-84: Verify feature flag integration across the application

The logic for showing traffic violation case files is well-implemented, combining the new feature flag with existing case type checks for backward compatibility.

Let's verify consistent feature flag usage across related components:

✅ Verification successful

Feature flag integration is consistently implemented

The feature flag MULTIPLE_INDICTMENT_SUBTYPES is consistently used across the application in combination with isTrafficViolationCase checks. The pattern features.includes(Feature.MULTIPLE_INDICTMENT_SUBTYPES) || isTrafficViolationCase(workingCase) is uniformly applied in:

  • IndictmentCaseFilesList component
  • Processing route component
  • CaseFiles route component
  • useSections hook
  • useCaseList hook

The implementation maintains backward compatibility while properly integrating the new feature flag.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for consistent MULTIPLE_INDICTMENT_SUBTYPES feature flag usage

# Search for feature flag usage
rg -A 2 "Feature.MULTIPLE_INDICTMENT_SUBTYPES" --type typescript

# Search for potential traffic violation case handling
ast-grep --pattern 'isTrafficViolationCase($_)'

Length of output: 1454


Script:

#!/bin/bash
# Let's check for the Feature enum definition and other feature flag usages
rg -l "enum Feature" --type ts

# Then check the content of the file containing Feature enum
rg -A 5 "MULTIPLE_INDICTMENT_SUBTYPES" --type ts

Length of output: 4444

apps/judicial-system/web/src/utils/hooks/useCaseList/index.tsx (1)

13-13: LGTM: Feature context integration is well-structured

The Feature import and FeatureContext integration are properly implemented, following React's context best practices.

Also applies to: 27-27, 45-45

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

8-11: LGTM: Consistent feature context implementation

The Feature import and FeatureContext integration follow the same pattern as other files, maintaining consistency across the codebase.

Also applies to: 14-14, 36-36

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

Line range hint 252-282: Consider adding loading state for civil claimant updates

The civil claimant update logic could experience race conditions when multiple updates occur in quick succession. Consider adding a loading state to prevent concurrent updates.

 const [nationalIdNotFound, setNationalIdNotFound] = useState<boolean>(false)
+const [isUpdatingCivilClaimant, setIsUpdatingCivilClaimant] = useState<boolean>(false)

 const handleUpdateCivilClaimant = useCallback(
   async (updatedCivilClaimant: UpdateCivilClaimantInput) => {
+    if (isUpdatingCivilClaimant) return
+    setIsUpdatingCivilClaimant(true)
     try {
       updateCivilClaimantState(updatedCivilClaimant, setWorkingCase)
       await updateCivilClaimant(updatedCivilClaimant)
+    } finally {
+      setIsUpdatingCivilClaimant(false)
+    }
   },
-  [updateCivilClaimant, setWorkingCase, updateCivilClaimantState],
+  [updateCivilClaimant, setWorkingCase, updateCivilClaimantState, isUpdatingCivilClaimant],
 )

Copy link
Member

@robertaandersen robertaandersen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@unakb unakb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@oddsson oddsson added the automerge Merge this PR as soon as all checks pass label Dec 9, 2024
@kodiakhq kodiakhq bot merged commit ea2cdea into main Dec 9, 2024
44 checks passed
@kodiakhq kodiakhq bot deleted the j-s/select-indictment-subtype branch December 9, 2024 18:28
thorhildurt pushed a commit that referenced this pull request Dec 11, 2024
* Add frontend changes for selecting indictment subtypes in indictment count

* Create migration

* Update DB on change

* Refactor

* Refactor

* chore: nx format:write update dirty files

* Add feature flag

* Refactor

* Refactor

* Add featur flag

---------

Co-authored-by: andes-it <[email protected]>
Co-authored-by: unakb <[email protected]>
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.

4 participants