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 to indictment overview #17198

Merged
merged 35 commits into from
Dec 16, 2024

Conversation

thorhildurt
Copy link
Member

@thorhildurt thorhildurt commented Dec 11, 2024

References

Fmst - Stöður hjá fangelsismálastofnun, málalisti og yfirlit máls

What

  • Add the option to select punishment type to indictment overview as a FMST user
    • Migration to add the new optional field punishment_type
    • New limited access controller for defendant which to follow the same pattern as we have for case, subpoena
    • Added role rules to only allow a given role to update a specific field
    • Added new radio buttons in indictment overview to add a relevant punishment type

Why

  • Enables FMST secretaries to sort completed cases in the table according to the punishment type

Screen

Screen.Recording.2024-12-11.at.11.00.05.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 functionality for updating defendant information under limited access scenarios.
    • Added new GraphQL fields for punishment types in case queries.
    • Enhanced the Indictment Overview component with a selection interface for punishment types.
    • Added a new enum for punishment types to represent various legal punishments.
    • Implemented a new controller and resolver for handling limited access updates.
    • Introduced a new mutation for limited access updates to defendant records.
    • Added new message definitions for punishment types in localization support.
  • Bug Fixes

    • Improved error handling for updates related to limited access defendants.
  • Documentation

    • Expanded localization support for punishment types in the Indictment Overview.
  • Chores

    • Added new hooks and GraphQL mutations for limited access updates.

Copy link
Contributor

coderabbitai bot commented Dec 11, 2024

Walkthrough

This pull request introduces multiple enhancements to the judicial system's backend, focusing on limited access functionality. Key additions include new methods in the BackendService for managing defendants and cases under limited access, a new LimitedAccessDefendantResolver, and updates to the UpdateDefendantInput class to include a punishmentType. A new controller, LimitedAccessDefendantController, is also added to handle updates via HTTP requests. Additionally, a PunishmentType enum is introduced, along with corresponding GraphQL schema updates and localization strings for various punishment types.

Changes

File Change Summary
apps/judicial-system/api/src/app/modules/backend/backend.service.ts Added multiple methods for limited access operations: limitedAccessUpdateDefendant, limitedAccessGetCase, limitedAccessUpdateCase, limitedAccessTransitionCase, limitedAccessCreateCasePresignedPost, limitedAccessCreateCaseFile, limitedAccessCreateDefendantCaseFile, limitedAccessCreateCivilClaimantCaseFile, limitedAccessGetCaseFileSignedUrl, limitedAccessDeleteCaseFile.
apps/judicial-system/api/src/app/modules/defendant/defendant.module.ts Introduced LimitedAccessDefendantResolver to the DefendantModule.
apps/judicial-system/api/src/app/modules/defendant/dto/updateDefendant.input.ts Added optional field punishmentType to UpdateDefendantInput.
apps/judicial-system/api/src/app/modules/defendant/limitedAccessDefendant.resolver.ts Created LimitedAccessDefendantResolver with a method limitedAccessUpdateDefendant.
apps/judicial-system/api/src/app/modules/defendant/models/defendant.model.ts Added PunishmentType enum and punishmentType field to Defendant class.
apps/judicial-system/backend/migrations/20241211095654-update-defendant.js Added migration for punishment_type column in defendant table.
apps/judicial-system/backend/src/app/modules/defendant/defendant.module.ts Added LimitedAccessDefendantController.
apps/judicial-system/backend/src/app/modules/defendant/dto/updateDefendant.dto.ts Added optional property punishmentType to UpdateDefendantDto.
apps/judicial-system/backend/src/app/modules/defendant/guards/rolesRules.ts Introduced roles rule for prison staff allowing updates to punishmentType.
apps/judicial-system/backend/src/app/modules/defendant/limitedAccessDefendant.controller.ts Created LimitedAccessDefendantController with updateDefendant method.
apps/judicial-system/web/src/components/FormProvider/case.graphql Added punishmentType field to defendants object in Case query.
apps/judicial-system/web/src/components/FormProvider/limitedAccessCase.graphql Added punishmentType field to defendants object in LimitedAccessCase query.
apps/judicial-system/web/src/routes/Prison/IndictmentOverview/IndictmentOverview.strings.ts Added new message definitions for punishment types.
apps/judicial-system/web/src/routes/Prison/IndictmentOverview/IndictmentOverview.tsx Modified component to include state for selectedPunishmentType and updated rendering logic for punishment selection.
apps/judicial-system/web/src/utils/hooks/useDefendants/index.ts Added limitedAccessUpdateDefendant mutation hook.
apps/judicial-system/web/src/utils/hooks/useDefendants/limitedAccessUpdateDefendant.graphql Introduced LimitedAccessUpdateDefendant mutation.
libs/judicial-system/types/src/index.ts Exported PunishmentType from ./lib/defendant.
libs/judicial-system/types/src/lib/defendant.ts Added PunishmentType enum with various values.

Possibly related PRs

Suggested labels

high priority

Suggested reviewers

  • oddsson

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request.


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.

@thorhildurt thorhildurt changed the title J s/update punishment type prison indictment overview feat(j-s): Add punishment type to indictment overview Dec 11, 2024
Copy link

codecov bot commented Dec 11, 2024

Codecov Report

Attention: Patch coverage is 40.21739% with 55 lines in your changes missing coverage. Please review.

Project coverage is 35.73%. Comparing base (65767dc) to head (67a1220).
Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
...s/Prison/IndictmentOverview/IndictmentOverview.tsx 0.00% 21 Missing ⚠️
...dules/defendant/limitedAccessDefendant.resolver.ts 0.00% 19 Missing ⚠️
...-system/web/src/utils/hooks/useDefendants/index.ts 25.00% 6 Missing ⚠️
...rc/app/modules/defendant/models/defendant.model.ts 0.00% 3 Missing ⚠️
...tem/api/src/app/modules/backend/backend.service.ts 0.00% 2 Missing ⚠️
...app/modules/defendant/dto/updateDefendant.input.ts 0.00% 2 Missing ⚠️
.../api/src/app/modules/defendant/defendant.module.ts 0.00% 1 Missing ⚠️
...kend/src/app/modules/defendant/defendant.module.ts 0.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main   #17198   +/-   ##
=======================================
  Coverage   35.73%   35.73%           
=======================================
  Files        6938     6941    +3     
  Lines      148305   148396   +91     
  Branches    42316    42333   +17     
=======================================
+ Hits        52999    53036   +37     
- Misses      95306    95360   +54     
Flag Coverage Δ
judicial-system-api 20.21% <20.58%> (+<0.01%) ⬆️
judicial-system-backend 55.90% <97.22%> (+0.07%) ⬆️
judicial-system-formatters 78.47% <100.00%> (+0.14%) ⬆️
judicial-system-message 66.48% <ø> (ø)
judicial-system-message-handler 48.16% <ø> (ø)
judicial-system-scheduler 71.08% <100.00%> (+0.16%) ⬆️
judicial-system-types 41.66% <0.00%> (-0.44%) ⬇️
judicial-system-web 27.89% <6.89%> (-0.04%) ⬇️

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

Files with missing lines Coverage Δ
...c/app/modules/defendant/dto/updateDefendant.dto.ts 93.54% <100.00%> (+0.21%) ⬆️
...end/src/app/modules/defendant/guards/rolesRules.ts 100.00% <100.00%> (ø)
...les/defendant/limitedAccessDefendant.controller.ts 100.00% <100.00%> (ø)
...rc/app/modules/defendant/models/defendant.model.ts 87.50% <100.00%> (+0.22%) ⬆️
...les/defendant/test/createTestingDefendantModule.ts 100.00% <100.00%> (ø)
...n/IndictmentOverview/IndictmentOverview.strings.ts 0.00% <ø> (ø)
libs/judicial-system/types/src/index.ts 100.00% <100.00%> (ø)
libs/judicial-system/types/src/lib/defendant.ts 92.10% <100.00%> (+1.48%) ⬆️
.../api/src/app/modules/defendant/defendant.module.ts 0.00% <0.00%> (ø)
...kend/src/app/modules/defendant/defendant.module.ts 0.00% <0.00%> (ø)
... and 6 more

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 c4bc9c4...67a1220. Read the comment docs.

@datadog-island-is
Copy link

datadog-island-is bot commented Dec 11, 2024

Datadog Report

All test runs 654e02c 🔗

14 Total Test Services: 0 Failed, 14 Passed
🔻 Test Sessions change in coverage: 2 decreased, 5 increased, 14 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.32s 1 no change Link
application-system-api 0 0 0 46 0 1m 57.43s 1 no change Link
application-template-api-modules 0 0 0 118 0 2m 37.86s 1 no change Link
application-ui-shell 0 0 0 74 0 35.97s 1 no change Link
judicial-system-api 0 0 0 61 0 6.52s 1 increased (+0.02%) Link
judicial-system-backend 0 0 0 21003 0 22m 36.87s 1 increased (+0.07%) Link
judicial-system-formatters 0 0 0 38 0 5.18s 1 increased (+0.11%) Link
judicial-system-message 0 0 0 39 0 11.06s 1 no change Link
judicial-system-message-handler 0 0 0 4 0 3.41s 1 no change Link
judicial-system-scheduler 0 0 0 4 0 4.13s 1 increased (+0.15%) Link

🔻 Code Coverage Decreases vs Default Branch (2)

  • judicial-system-types - jest 44.32% (-0.49%) - Details
  • judicial-system-web - jest 32.5% (-0.03%) - Details

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

🧹 Outside diff range and nitpick comments (4)
apps/judicial-system/backend/src/app/modules/defendant/limitedAccessDefendant.controller.ts (1)

30-37: LGTM! Consider enhancing API documentation.

The controller setup follows NestJS best practices with proper security guards and dependency injection. The limited access path aligns well with the PR objectives.

Consider adding @ApiParam decorators to document the path parameters:

@ApiParam({ name: 'caseId', description: 'The ID of the case' })
@Controller('api/case/:caseId/limitedAccess/defendant')
apps/judicial-system/backend/src/app/modules/defendant/test/limitedAccessDefendantController/updateDefendant.spec.ts (3)

16-19: Consider using discriminated union for Then interface

The current interface allows both result and error to be present simultaneously, which shouldn't be possible in practice. Consider using a discriminated union type for better type safety:

type Then = 
  | { success: true; result: Defendant; error?: never }
  | { success: false; error: Error; result?: never }

49-50: Remove unnecessary default error mock

The default error mock is immediately overridden in the test case. Consider removing it to avoid confusion.

-    const mockUpdate = mockDefendantModel.update as jest.Mock
-    mockUpdate.mockRejectedValue(new Error('Some error'))

59-70: Refactor promise chain to use async/await

The current promise chain with assignments in expressions has been flagged by static analysis. Consider using async/await for better readability and to avoid assignments in expressions.

try {
  then.result = await limitedAccessDefendantController.updateDefendant(
    caseId,
    defendantId,
    user,
    { id: caseId, courtCaseNumber, type } as Case,
    defendant,
    defendantUpdate,
  )
} catch (error) {
  then.error = error
}
🧰 Tools
🪛 Biome (1.9.4)

[error] 68-68: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)


[error] 69-69: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between ae5dfd5 and 449581e.

📒 Files selected for processing (2)
  • apps/judicial-system/backend/src/app/modules/defendant/limitedAccessDefendant.controller.ts (1 hunks)
  • apps/judicial-system/backend/src/app/modules/defendant/test/limitedAccessDefendantController/updateDefendant.spec.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
apps/judicial-system/backend/src/app/modules/defendant/limitedAccessDefendant.controller.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/defendant/test/limitedAccessDefendantController/updateDefendant.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."
📓 Learnings (1)
apps/judicial-system/backend/src/app/modules/defendant/test/limitedAccessDefendantController/updateDefendant.spec.ts (2)
Learnt from: gudjong
PR: island-is/island.is#16389
File: apps/judicial-system/backend/src/app/modules/case/test/limitedAccessCaseController/getCaseFilesRecordPdfRolesRules.spec.ts:1-1
Timestamp: 2024-11-12T15:15:20.157Z
Learning: The usage of `defenderRule` in the following test files is intentional and should remain unchanged:

- `apps/judicial-system/backend/src/app/modules/file/test/limitedAccessFileController/createPresignedPostRolesRules.spec.ts`
- `apps/judicial-system/backend/src/app/modules/file/test/limitedAccessFileController/deleteCaseFileRolesRules.spec.ts`
- `apps/judicial-system/backend/src/app/modules/file/test/limitedAccessFileController/createCaseFileRolesRules.spec.ts`
- `apps/judicial-system/backend/src/app/modules/file/test/limitedAccessFileController/getCaseFileSignedUrlRolesRules.spec.ts`
- `apps/judicial-system/backend/src/app/modules/case/test/limitedAccessCaseController/getRulingPdfRolesRules.spec.ts`
- `apps/judicial-system/backend/src/app/modules/case/test/limitedAccessCaseController/getRequestPdfRolesRules.spec.ts`
- `apps/judicial-system/backend/src/app/modules/case/test/limitedAccessCaseController/getCourtRecordPdfRolesRules.spec.ts`
- `apps/judicial-system/backend/src/app/modules/case/test/limitedAccessCaseController/getByIdRolesRules.spec.ts`
- `apps/judicial-system/backend/src/app/modules/case/test/limitedAccessCaseController/getAllFilesZipRolesRules.spec.ts`
- `apps/judicial-system/backend/src/app/modules/case/test/caseController/getAllRolesRules.spec.ts`
Learnt from: gudjong
PR: island-is/island.is#16389
File: apps/judicial-system/backend/src/app/modules/file/guards/test/limitedAccessViewCaseFileGuard.spec.ts:175-185
Timestamp: 2024-11-12T15:15:20.157Z
Learning: In the Jest tests for the `LimitedAccessViewCaseFileGuard` in `apps/judicial-system/backend/src/app/modules/file/guards/test/limitedAccessViewCaseFileGuard.spec.ts`, code duplication in the `beforeEach` blocks is acceptable and should remain unchanged.
🪛 Biome (1.9.4)
apps/judicial-system/backend/src/app/modules/defendant/test/limitedAccessDefendantController/updateDefendant.spec.ts

[error] 68-68: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)


[error] 69-69: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)

🔇 Additional comments (1)
apps/judicial-system/backend/src/app/modules/defendant/limitedAccessDefendant.controller.ts (1)

57-62: ⚠️ Potential issue

Add error handling for the service call.

The controller should handle potential errors from the service call and return appropriate HTTP responses.

-    return this.defendantService.updateRequestCaseDefendant(
-      theCase,
-      defendant,
-      updateDto,
-      user,
-    )
+    try {
+      return await this.defendantService.updateRequestCaseDefendant(
+        theCase,
+        defendant,
+        updateDto,
+        user,
+      )
+    } catch (error) {
+      this.logger.error('Failed to update defendant', error)
+      throw new InternalServerErrorException('Failed to update defendant')
+    }

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

♻️ Duplicate comments (1)
apps/judicial-system/backend/src/app/modules/defendant/test/limitedAccessDefendantController/updateDefendant.spec.ts (1)

49-51: 🛠️ Refactor suggestion

Add test cases for error handling

The error mock is set up but there are no test cases verifying error scenarios.

Add test cases for:

  1. Error cases (e.g., invalid punishment type)
  2. Tests for non-INDICTMENT case types
  3. Validation of different punishment type values

Example:

describe('when case type is not INDICTMENT', () => {
  it('should throw an error when updating punishment type', async () => {
    const then = await givenWhenThen(
      { punishmentType: PunishmentType.IMPRISONMENT },
      CaseType.CUSTODY
    );
    expect(then.error).toBeDefined();
  });
});
🧹 Nitpick comments (5)
apps/judicial-system/backend/src/app/modules/defendant/test/limitedAccessDefendantController/updateDefendant.spec.ts (2)

21-26: Remove unused parameter from GivenWhenThen type

The courtCaseNumber parameter is defined but not used in any test case.

 type GivenWhenThen = (
   defendantUpdate: UpdateDefendantDto,
-  type: CaseType,
-  courtCaseNumber?: string,
+  type: CaseType
 ) => Promise<Then>

67-68: Improve readability of promise handling

The assignments in the promise chain can be refactored for better readability and to address the static analysis warnings.

-        .then((result) => (then.result = result))
-        .catch((error) => (then.error = error))
+        .then((result) => {
+          then.result = result;
+        })
+        .catch((error) => {
+          then.error = error;
+        });
🧰 Tools
🪛 Biome (1.9.4)

[error] 67-67: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)


[error] 68-68: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)

apps/judicial-system/web/src/routes/Prison/IndictmentOverview/IndictmentOverview.tsx (3)

42-50: Consider optimistic updates with error handling.

The current implementation updates the UI state before confirming the API call's success. While this provides a better user experience through immediate feedback, it should include error handling.

Consider adding error handling:

   const onChange = (updatedPunishmentType: PunishmentType) => {
     setPunishmentType(updatedPunishmentType)
-    defendant &&
+    if (defendant) {
       limitedAccessUpdateDefendant({
         caseId: workingCase.id,
         defendantId: defendant.id,
         punishmentType: updatedPunishmentType,
-      })
+      }).catch((error) => {
+        console.error('Failed to update punishment type:', error)
+        setPunishmentType(defendant.punishmentType ?? undefined)
+        // TODO: Add user notification for the error
+      })
+    }
   }

52-53: Improve type safety in hasSetPunishmentType function.

The function could be more explicit about its return type and parameter constraints.

Consider this improvement:

-  const hasSetPunishmentType = (punishmentType: PunishmentType) =>
-    !selectedPunishmentType && defendant?.punishmentType === punishmentType
+  const hasSetPunishmentType = (punishmentType: PunishmentType): boolean => {
+    return !selectedPunishmentType && defendant?.punishmentType === punishmentType
+  }

96-186: Consider extracting radio button group into a separate component.

The radio button implementation is repetitive and could benefit from being extracted into a reusable component.

Consider creating a new component like this:

interface PunishmentTypeRadioProps {
  type: PunishmentType;
  selectedType: PunishmentType | undefined;
  onChange: (type: PunishmentType) => void;
  hasSetPunishmentType: (type: PunishmentType) => boolean;
  label: string;
}

const PunishmentTypeRadio: React.FC<PunishmentTypeRadioProps> = ({
  type,
  selectedType,
  onChange,
  hasSetPunishmentType,
  label,
}) => (
  <Box marginBottom={2}>
    <RadioButton
      id={`punishment-type-${type.toLowerCase()}`}
      name={`punishmentType${type}`}
      checked={selectedType === type || hasSetPunishmentType(type)}
      onChange={() => onChange(type)}
      large
      backgroundColor="white"
      label={label}
    />
  </Box>
);

This would simplify the main component and reduce code duplication.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 0b994d0 and d92178c.

📒 Files selected for processing (3)
  • apps/judicial-system/backend/src/app/modules/defendant/test/limitedAccessDefendantController/updateDefendant.spec.ts (1 hunks)
  • apps/judicial-system/web/src/routes/Prison/IndictmentOverview/IndictmentOverview.strings.ts (1 hunks)
  • apps/judicial-system/web/src/routes/Prison/IndictmentOverview/IndictmentOverview.tsx (4 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
apps/judicial-system/web/src/routes/Prison/IndictmentOverview/IndictmentOverview.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/Prison/IndictmentOverview/IndictmentOverview.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/backend/src/app/modules/defendant/test/limitedAccessDefendantController/updateDefendant.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."
📓 Learnings (3)
apps/judicial-system/web/src/routes/Prison/IndictmentOverview/IndictmentOverview.tsx (2)
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.
apps/judicial-system/web/src/routes/Prison/IndictmentOverview/IndictmentOverview.strings.ts (3)
Learnt from: oddsson
PR: island-is/island.is#16495
File: apps/judicial-system/web/src/components/BlueBoxWithIcon/BlueBoxWithDate.strings.ts:3-3
Timestamp: 2024-11-12T15:15:20.157Z
Learning: In `apps/judicial-system/web/src/components/BlueBoxWithIcon/BlueBoxWithDate.strings.ts`, prefer not to add explicit TypeScript type definitions for the messages object.
Learnt from: oddsson
PR: island-is/island.is#16831
File: apps/judicial-system/web/src/components/BlueBoxWithIcon/BlueBoxWithDate.tsx:204-337
Timestamp: 2024-11-19T09:28:36.448Z
Learning: Buttons in this project are considered accessible as is, and adding additional ARIA attributes like `aria-label` and `aria-disabled` is not required unless specifically needed.
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.
apps/judicial-system/backend/src/app/modules/defendant/test/limitedAccessDefendantController/updateDefendant.spec.ts (2)
Learnt from: gudjong
PR: island-is/island.is#16389
File: apps/judicial-system/backend/src/app/modules/case/test/limitedAccessCaseController/getCaseFilesRecordPdfRolesRules.spec.ts:1-1
Timestamp: 2024-11-12T15:15:20.157Z
Learning: The usage of `defenderRule` in the following test files is intentional and should remain unchanged:

- `apps/judicial-system/backend/src/app/modules/file/test/limitedAccessFileController/createPresignedPostRolesRules.spec.ts`
- `apps/judicial-system/backend/src/app/modules/file/test/limitedAccessFileController/deleteCaseFileRolesRules.spec.ts`
- `apps/judicial-system/backend/src/app/modules/file/test/limitedAccessFileController/createCaseFileRolesRules.spec.ts`
- `apps/judicial-system/backend/src/app/modules/file/test/limitedAccessFileController/getCaseFileSignedUrlRolesRules.spec.ts`
- `apps/judicial-system/backend/src/app/modules/case/test/limitedAccessCaseController/getRulingPdfRolesRules.spec.ts`
- `apps/judicial-system/backend/src/app/modules/case/test/limitedAccessCaseController/getRequestPdfRolesRules.spec.ts`
- `apps/judicial-system/backend/src/app/modules/case/test/limitedAccessCaseController/getCourtRecordPdfRolesRules.spec.ts`
- `apps/judicial-system/backend/src/app/modules/case/test/limitedAccessCaseController/getByIdRolesRules.spec.ts`
- `apps/judicial-system/backend/src/app/modules/case/test/limitedAccessCaseController/getAllFilesZipRolesRules.spec.ts`
- `apps/judicial-system/backend/src/app/modules/case/test/caseController/getAllRolesRules.spec.ts`
Learnt from: gudjong
PR: island-is/island.is#16389
File: apps/judicial-system/backend/src/app/modules/file/guards/test/limitedAccessViewCaseFileGuard.spec.ts:175-185
Timestamp: 2024-11-12T15:15:20.157Z
Learning: In the Jest tests for the `LimitedAccessViewCaseFileGuard` in `apps/judicial-system/backend/src/app/modules/file/guards/test/limitedAccessViewCaseFileGuard.spec.ts`, code duplication in the `beforeEach` blocks is acceptable and should remain unchanged.
🪛 Biome (1.9.4)
apps/judicial-system/backend/src/app/modules/defendant/test/limitedAccessDefendantController/updateDefendant.spec.ts

[error] 67-67: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)


[error] 68-68: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)

🔇 Additional comments (1)
apps/judicial-system/web/src/routes/Prison/IndictmentOverview/IndictmentOverview.tsx (1)

37-40: 🛠️ Refactor suggestion

Improve defendant selection robustness.

The current implementation could be more defensive in handling the defendant selection.

Apply this diff to improve type safety and error handling:

   const { defendants } = workingCase
-  const defendant =
-    defendants && defendants?.length > 0 ? defendants[0] : undefined
+  const defendant = defendants?.length > 0 ? defendants[0] : null
+
+  if (!defendant) {
+    console.warn('No defendant found for case:', workingCase.id)
+  }

Likely invalid or redundant comment.

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.

Really nice work! 👏 Going to Approve because all comments were just considerations but feel free to ask for review again if you have any other thoughts or changes you'd like feedback on

@thorhildurt thorhildurt added automerge Merge this PR as soon as all checks pass and removed automerge Merge this PR as soon as all checks pass labels Dec 16, 2024
@thorhildurt thorhildurt added the automerge Merge this PR as soon as all checks pass label Dec 16, 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: 1

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d92178c and 33f5477.

📒 Files selected for processing (2)
  • apps/judicial-system/web/src/routes/Prison/IndictmentOverview/IndictmentOverview.strings.ts (1 hunks)
  • apps/judicial-system/web/src/routes/Prison/IndictmentOverview/IndictmentOverview.tsx (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/judicial-system/web/src/routes/Prison/IndictmentOverview/IndictmentOverview.strings.ts
🧰 Additional context used
📓 Path-based instructions (1)
apps/judicial-system/web/src/routes/Prison/IndictmentOverview/IndictmentOverview.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/Prison/IndictmentOverview/IndictmentOverview.tsx (2)
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.
🔇 Additional comments (5)
apps/judicial-system/web/src/routes/Prison/IndictmentOverview/IndictmentOverview.tsx (5)

4-4: LGTM: Imports are well-organized and follow best practices

The imports are properly categorized and all dependencies are necessary for the implementation.

Also applies to: 7-7, 10-24


29-31: LGTM: Proper state management setup

The component correctly uses context and custom hooks for state management.


37-39: Simplify defendant selection logic

The current implementation has redundant checks. Consider simplifying:

-  const { defendants } = workingCase
-  const defendant =
-    defendants && defendants?.length > 0 ? defendants[0] : undefined
+  const defendant = workingCase.defendants?.length
+    ? workingCase.defendants[0]
+    : null
+
+  if (!defendant) {
+    console.warn('No defendant found for case:', workingCase.id)
+  }

41-51: LGTM: Well-structured update handler

The implementation follows the confirmed pattern of updating UI state before making the API call, with proper error handling.


53-54: LGTM: Clean and type-safe helper function

The helper function is well-implemented with proper null checking using optional chaining.

@kodiakhq kodiakhq bot merged commit e6a12da into main Dec 16, 2024
45 checks passed
@kodiakhq kodiakhq bot deleted the j-s/update-punishment-type-prison-indictment-overview branch December 16, 2024 17:09
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