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): Allow prosecutor office to change the prosecutor decision #17355

Merged
merged 12 commits into from
Jan 6, 2025

Conversation

thorhildurt
Copy link
Member

@thorhildurt thorhildurt commented Dec 27, 2024

What

  • Asana task
  • Enable the prosecutor office to change the prosecutor result ("Una dómi" or "áfrýja") before sending the case to prison admin

Why

  • It can happen that the prosecutor wants to change the decision, and then it is required to give the office this flexibility to avoid them being blocked by a re-review from the prosecutor before sending the case to the prison admin

Screenshots / Gifs

Screen.Recording.2024-12-27.at.10.30.43.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 component for selecting an indictment reviewer.
    • Added a confirmation button for changing the public prosecutor's decision.
    • Implemented a new modal confirmation mechanism for the review decision process.
  • Bug Fixes

    • Enhanced user permissions for public prosecutor staff by adding a new field.
  • Refactor

    • Updated state management and rendering logic across several components to improve decision handling and modal visibility.
  • Chores

    • Cleaned up unused imports in the Overview component.

@thorhildurt thorhildurt self-assigned this Dec 27, 2024
Copy link
Contributor

coderabbitai bot commented Dec 27, 2024

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 eslint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

warning [email protected]: This version is no longer supported. Please see https://eslint.org/version-support for other options.
warning eslint > @humanwhocodes/[email protected]: Use @eslint/config-array instead
warning eslint > file-entry-cache > flat-cache > [email protected]: Rimraf versions prior to v4 are no longer supported
warning eslint > @humanwhocodes/config-array > @humanwhocodes/[email protected]: Use @eslint/object-schema instead
warning eslint > file-entry-cache > flat-cache > rimraf > [email protected]: Glob versions prior to v9 are no longer supported
warning eslint > file-entry-cache > flat-cache > rimraf > glob > [email protected]: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.
warning jest > @jest/core > jest-config > [email protected]: Glob versions prior to v9 are no longer supported
warning jest > @jest/core > jest-runtime > [email protected]: Glob versions prior to v9 are no longer supported
warning jest > @jest/core > @jest/reporters > [email protected]: Glob versions prior to v9 are no longer supported
warning jest > @jest/core > @jest/transform > babel-plugin-istanbul > test-exclude > [email protected]: Glob versions prior to v9 are no longer supported
warning storybook > @storybook/cli > puppeteer-core > [email protected]: Rimraf versions prior to v4 are no longer supported
warning storybook > @storybook/cli > puppeteer-core > rimraf > [email protected]: Glob versions prior to v9 are no longer supported
warning storybook > @storybook/cli > tempy > del > [email protected]: Rimraf versions prior to v4 are no longer supported
warning storybook > @storybook/cli > jscodeshift > temp > [email protected]: Rimraf versions prior to v4 are no longer supported
warning storybook > @storybook/cli > jscodeshift > temp > rimraf > [email protected]: Glob versions prior to v9 are no longer supported
warning storybook > @storybook/cli > jscodeshift > @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-class-properties instead.
warning storybook > @storybook/cli > jscodeshift > @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-nullish-coalescing-operator instead.
warning storybook > @storybook/cli > jscodeshift > @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-optional-chaining instead.
warning react-native > @react-native/codegen > [email protected]: Glob versions prior to v9 are no longer supported
warning react-native > @react-native/community-cli-plugin > [email protected]: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
warning react-native > @react-native-community/cli > @react-native-community/cli-tools > [email protected]: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning react-native > @react-native/community-cli-plugin > @react-native/dev-middleware > @rnx-kit/chromium-edge-launcher > [email protected]: Rimraf versions prior to v4 are no longer supported
warning react-native > @react-native/community-cli-plugin > @react-native/metro-babel-transformer > @react-native/babel-preset > @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-class-properties instead.
warning react-native > @react-native/community-cli-plugin > @react-native/metro-babel-transformer > @react-native/babel-preset > @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-optional-chaining instead.
warning react-native > @react-native/community-cli-plugin > @react-native/metro-babel-transformer > @react-native/babel-preset > @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-nullish-coalescing-operator instead.
warning react-native > @react-native/community-cli-plugin > @react-native/metro-babel-transformer > @react-native/babel-preset > @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-object-rest-spread instead.
warning react-native > @react-native/community-cli-plugin > @react-native/metro-babel-transformer > @react-native/babel-preset > @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-numeric-separator instead.
warning react-native > @react-native/community-cli-plugin > @react-native/metro-babel-transformer > @react-native/babel-preset > @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-async-generator-functions instead.
warning react-native > @react-native/community-cli-plugin > @react-native/metro-babel-transformer > @react-native/babel-preset > @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-optional-catch-binding instead.
warning react-native > @react-native/community-cli-plugin > @react-native/metro-babel-transformer > @react-native/babel-preset > @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-logical-assignment-operators instead.
warning next-auth > [email protected]: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
warning next-auth > [email protected]: this version is no longer supported
warning next-auth > @next-auth/typeorm-legacy-adapter > typeorm > [email protected]: Glob versions prior to v9 are no longer supported
warning @nx/next > @nx/webpack > stylus > [email protected]: Glob versions prior to v9 are no longer supported
warning @nx/next > @nx/webpack > webpack-dev-server > [email protected]: Rimraf versions prior to v4 are no longer supported
warning @nx/next > @nx/webpack > fork-ts-checker-webpack-plugin > [email protected]: this will be v4
warning @nx/next > @nx/webpack > webpack-dev-server > webpack-dev-middleware > [email protected]: this will be v4
warning workspace-aggregator-b548b43f-6221-4d92-ab2c-87dc42a3537a > [email protected]: This version is no longer supported. Please see https://eslint.org/version-support for other options.

Walkthrough

This pull request introduces changes to the judicial system application, focusing on enhancing the indictment review process. The modifications span multiple files across the backend and frontend, adding a new field for indictment review decisions, creating a new component for reviewer selection, and updating the modal confirmation mechanism. The changes primarily revolve around expanding the capabilities for public prosecutors to manage and review indictment cases.

Changes

File Path Change Summary
apps/judicial-system/backend/src/app/modules/case/guards/rolesRules.ts Added 'indictmentReviewDecision' to publicProsecutorFields
apps/judicial-system/web/src/routes/PublicProsecutor/Indictments/Overview/IndictmentReviewerSelector.tsx New component for selecting indictment reviewers
apps/judicial-system/web/src/routes/PublicProsecutor/Indictments/Overview/Overview.strings.ts Added new message for changing reviewed decision button
apps/judicial-system/web/src/routes/PublicProsecutor/Indictments/Overview/Overview.tsx Refactored component with new reviewer and decision selection logic
apps/judicial-system/web/src/routes/PublicProsecutor/components/ReviewDecision/ReviewDecision.tsx Updated component with enhanced decision handling
apps/judicial-system/web/src/routes/PublicProsecutor/components/utils.ts Added new constants and utility functions for modal management
apps/judicial-system/web/src/routes/Shared/IndictmentOverview/IndictmentOverview.tsx Updated modal confirmation mechanism

Sequence Diagram

sequenceDiagram
    participant User
    participant IndictmentReviewerSelector
    participant ReviewDecision
    participant ConfirmationModal

    User->>IndictmentReviewerSelector: Select Reviewer
    IndictmentReviewerSelector->>User: Confirm Selection
    User->>ReviewDecision: Choose Decision
    ReviewDecision->>ConfirmationModal: Trigger Confirmation
    ConfirmationModal->>User: Confirm Decision
    User->>ReviewDecision: Submit Final Decision
Loading

Possibly related PRs

Suggested labels

automerge

Suggested reviewers

  • unakb

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.

Copy link

codecov bot commented Dec 27, 2024

Codecov Report

Attention: Patch coverage is 1.81818% with 54 lines in your changes missing coverage. Please review.

Project coverage is 35.67%. Comparing base (f643adc) to head (09885de).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...ndictments/Overview/IndictmentReviewerSelector.tsx 0.00% 22 Missing ⚠️
...PublicProsecutor/Indictments/Overview/Overview.tsx 0.00% 19 Missing ⚠️
...eb/src/routes/PublicProsecutor/components/utils.ts 0.00% 6 Missing ⚠️
...cutor/components/ReviewDecision/ReviewDecision.tsx 0.00% 5 Missing ⚠️
...s/Shared/IndictmentOverview/IndictmentOverview.tsx 0.00% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #17355      +/-   ##
==========================================
- Coverage   35.67%   35.67%   -0.01%     
==========================================
  Files        6934     6935       +1     
  Lines      148908   148904       -4     
  Branches    42549    42572      +23     
==========================================
- Hits        53125    53123       -2     
+ Misses      95783    95781       -2     
Flag Coverage Δ
air-discount-scheme-web 0.00% <ø> (ø)
api 3.33% <ø> (ø)
application-api-files 61.97% <ø> (ø)
application-core 75.60% <ø> (ø)
application-system-api 38.73% <ø> (+<0.01%) ⬆️
application-template-api-modules 27.67% <ø> (ø)
application-templates-accident-notification 27.60% <ø> (ø)
application-templates-car-recycling 3.12% <ø> (ø)
application-templates-criminal-record 25.82% <ø> (ø)
application-templates-driving-license 18.17% <ø> (ø)
application-templates-estate 13.67% <ø> (ø)
application-templates-example-payment 24.69% <ø> (ø)
application-templates-financial-aid 14.47% <ø> (ø)
application-templates-general-petition 23.13% <ø> (ø)
application-templates-inheritance-report 6.59% <ø> (ø)
application-templates-marriage-conditions 15.21% <ø> (ø)
application-templates-mortgage-certificate 43.70% <ø> (ø)
application-templates-parental-leave 29.92% <ø> (+0.11%) ⬆️
application-types 6.48% <ø> (ø)
application-ui-components 1.22% <ø> (ø)
application-ui-shell 22.25% <ø> (ø)
clients-charge-fjs-v2 28.88% <ø> (ø)
judicial-system-backend 55.91% <100.00%> (ø)
judicial-system-web 27.77% <0.00%> (-0.04%) ⬇️
web 2.40% <ø> (ø)

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

Files with missing lines Coverage Δ
.../backend/src/app/modules/case/guards/rolesRules.ts 40.84% <100.00%> (ø)
...rosecutor/Indictments/Overview/Overview.strings.ts 0.00% <ø> (ø)
...s/Shared/IndictmentOverview/IndictmentOverview.tsx 0.00% <0.00%> (ø)
...cutor/components/ReviewDecision/ReviewDecision.tsx 0.00% <0.00%> (ø)
...eb/src/routes/PublicProsecutor/components/utils.ts 0.00% <0.00%> (ø)
...PublicProsecutor/Indictments/Overview/Overview.tsx 0.00% <0.00%> (ø)
...ndictments/Overview/IndictmentReviewerSelector.tsx 0.00% <0.00%> (ø)

... and 6 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 f643adc...09885de. Read the comment docs.

@datadog-island-is
Copy link

datadog-island-is bot commented Dec 27, 2024

Datadog Report

All test runs 78964bc 🔗

10 Total Test Services: 0 Failed, 10 Passed
🔻 Test Sessions change in coverage: 1 decreased (-0.06%), 1 increased (+0.09%), 93 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
air-discount-scheme-web 0 0 0 2 0 6.66s 1 no change Link
api 0 0 0 4 0 2.49s 1 no change Link
application-api-files 0 0 0 2 0 4.23s 1 no change Link
application-core 0 0 0 97 0 14.73s 1 no change Link
application-system-api 0 0 0 46 0 2m 11.54s 1 no change Link
application-template-api-modules 0 0 0 118 0 2m 4.9s 1 no change Link
application-templates-accident-notification 0 0 0 140 0 13.01s 1 no change Link
application-templates-criminal-record 0 0 0 2 0 9.44s 1 no change Link
application-templates-driving-license 0 0 0 13 0 12.96s 1 no change Link
application-templates-example-payment 0 0 0 2 0 9.97s 1 no change Link

🔻 Code Coverage Decreases vs Default Branch (1)

  • judicial-system-web - jest 32.4% (-0.06%) - Details

@thorhildurt thorhildurt marked this pull request as ready for review December 27, 2024 14:29
@thorhildurt thorhildurt requested a review from a team as a code owner December 27, 2024 14:29
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (8)
apps/judicial-system/web/src/routes/PublicProsecutor/components/ReviewDecision/ReviewDecision.tsx (1)

112-112: Use optional chaining for safety and clarity.
Replace onSelect && onSelect(item.value) with onSelect?.(item.value) to reduce complexity.

- onSelect && onSelect(item.value)
+ onSelect?.(item.value)
🧰 Tools
🪛 Biome (1.9.4)

[error] 112-112: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

apps/judicial-system/web/src/routes/PublicProsecutor/Indictments/Overview/Overview.tsx (6)

1-3: Remove unused imports if any remain.

Double-check whether all imported hooks and modules are referenced. Keeping imports trimmed helps maintain clarity.


5-5: Adhere to naming conventions and imports grouping.

Make sure that all UI components from @island.is/* libraries are consistently grouped to promote clarity in import statements.


46-48: Ensure variable names clearly reflect their purpose.

isReviewedDecisionChanged is descriptive, but consider clarifying or adding comments where used, confirming that it only tracks changes, not final confirmations.


49-52: Refactor modal state to unify handling logic if possible.

confirmationModal and other modal states might benefit from a central state management approach to keep modal usage consistent across the application.


66-66: Notify user or log result after setting reviewer.

Adding a toast or log message could help confirm that the reviewer has been successfully assigned, improving user transparency.


143-167: Evaluate form labeling and user feedback.

As you toggle between the two sections of the form, consider clarifying button text or disabling conditions so users easily understand why functionality is enabled or disabled.

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

47-50: Centralize modal constants.

The constants CONFIRM_PROSECUTOR_DECISION and ConfirmationModal are helpful. Make sure these remain consistent across all referencing components to avoid confusion.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 56493cc and efd8847.

📒 Files selected for processing (7)
  • apps/judicial-system/backend/src/app/modules/case/guards/rolesRules.ts (1 hunks)
  • apps/judicial-system/web/src/routes/PublicProsecutor/Indictments/Overview/IndictmentReviewerSelector.tsx (1 hunks)
  • apps/judicial-system/web/src/routes/PublicProsecutor/Indictments/Overview/Overview.strings.ts (1 hunks)
  • apps/judicial-system/web/src/routes/PublicProsecutor/Indictments/Overview/Overview.tsx (4 hunks)
  • apps/judicial-system/web/src/routes/PublicProsecutor/components/ReviewDecision/ReviewDecision.tsx (7 hunks)
  • apps/judicial-system/web/src/routes/PublicProsecutor/components/utils.ts (1 hunks)
  • apps/judicial-system/web/src/routes/Shared/IndictmentOverview/IndictmentOverview.tsx (3 hunks)
🧰 Additional context used
📓 Path-based instructions (7)
apps/judicial-system/web/src/routes/PublicProsecutor/Indictments/Overview/Overview.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/case/guards/rolesRules.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/PublicProsecutor/Indictments/Overview/IndictmentReviewerSelector.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/PublicProsecutor/components/utils.ts (1)

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

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
apps/judicial-system/web/src/routes/Shared/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/PublicProsecutor/components/ReviewDecision/ReviewDecision.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/PublicProsecutor/Indictments/Overview/Overview.tsx (1)

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

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
📓 Learnings (3)
apps/judicial-system/web/src/routes/PublicProsecutor/Indictments/Overview/IndictmentReviewerSelector.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/Shared/IndictmentOverview/IndictmentOverview.tsx (3)
Learnt from: thorhildurt
PR: island-is/island.is#17198
File: apps/judicial-system/web/src/routes/Prison/IndictmentOverview/IndictmentOverview.tsx:42-50
Timestamp: 2024-12-11T14:25:44.741Z
Learning: In `IndictmentOverview.tsx`, when updating the punishment type, update the UI state before making the API call to immediately reflect the change.
Learnt from: unakb
PR: island-is/island.is#17112
File: apps/judicial-system/web/src/routes/Court/Indictments/Summary/Summary.tsx:166-178
Timestamp: 2024-12-04T10:10:49.089Z
Learning: In the Judicial System application, error handling for failed case transitions in the `Summary` component (`apps/judicial-system/web/src/routes/Court/Indictments/Summary/Summary.tsx`) is managed externally via a toaster notification. Therefore, additional error handling within the modal is not necessary.
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/PublicProsecutor/Indictments/Overview/Overview.tsx (4)
Learnt from: oddsson
PR: island-is/island.is#16731
File: apps/judicial-system/web/src/routes/Shared/IndictmentOverview/IndictmentOverview.tsx:172-186
Timestamp: 2024-11-12T15:15:20.157Z
Learning: In `IndictmentOverview.tsx`, since the defendants data does not change, using `useMemo` to memoize the filtering logic is unnecessary.
Learnt from: thorhildurt
PR: island-is/island.is#17198
File: apps/judicial-system/web/src/routes/Prison/IndictmentOverview/IndictmentOverview.tsx:42-50
Timestamp: 2024-12-11T14:25:44.741Z
Learning: In `IndictmentOverview.tsx`, when updating the punishment type, update the UI state before making the API call to immediately reflect the change.
Learnt from: unakb
PR: island-is/island.is#17112
File: apps/judicial-system/web/src/routes/Court/Indictments/Summary/Summary.tsx:166-178
Timestamp: 2024-12-04T10:10:49.089Z
Learning: In the Judicial System application, error handling for failed case transitions in the `Summary` component (`apps/judicial-system/web/src/routes/Court/Indictments/Summary/Summary.tsx`) is managed externally via a toaster notification. Therefore, additional error handling within the modal is not necessary.
Learnt from: unakb
PR: island-is/island.is#15378
File: apps/judicial-system/web/src/routes/Court/Indictments/Summary/Summary.tsx:86-100
Timestamp: 2024-11-12T15:15:11.835Z
Learning: User unakb prefers explicit case handling in switch statements for key functionalities like `getRulingDecisionTagColor` to ensure clarity and avoid assumptions that a case was overlooked.
🪛 Biome (1.9.4)
apps/judicial-system/web/src/routes/PublicProsecutor/components/ReviewDecision/ReviewDecision.tsx

[error] 112-112: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

🔇 Additional comments (20)
apps/judicial-system/web/src/routes/PublicProsecutor/components/utils.ts (3)

1-2: Constants look good and follow naming conventions.
These two constants are clearly named and help keep the code explicit.


4-7: Good use of union type for modal identification.
Exporting a union type of string constants is a clear approach that enforces consistent usage of the modal states in the codebase.


8-11: Functions are concise and effective.
These type guards allow for a clean and type-safe check of modal states.

apps/judicial-system/web/src/routes/PublicProsecutor/Indictments/Overview/Overview.strings.ts (1)

41-46: Accurate and descriptive message definition.
The new message key and associated text are properly defined to handle the reviewed decision change scenario.

apps/judicial-system/web/src/routes/PublicProsecutor/Indictments/Overview/IndictmentReviewerSelector.tsx (3)

32-35: Ensure correct error handling or fallback.
The component uses errorPolicy: 'all' and no-cache. Confirm that errors are caught in upstream code or handled gracefully, so the UI doesn't silently fail.


37-53: Memoization is well-placed.
Using useMemo to transform user data ensures that the list is recalculated only when necessary, preventing unnecessary rendering.


75-95: Select component is effectively integrated.
Properly setting the default value and updating state for the selected reviewer aligns with standard React patterns.

apps/judicial-system/web/src/routes/PublicProsecutor/components/ReviewDecision/ReviewDecision.tsx (5)

8-11: Expanded checks for prosecutor roles are correct.
Including isPublicProsecutorUser ensures broader role coverage.


21-21: Well-structured import for the new ConfirmationModal logic.
This clarifies the type usage for modalVisible and unifies modal management.


27-33: Interface updates align with the new modal design.
Shifting from boolean to a union type is an excellent choice for making the state more explicit and ensuring correct usage throughout.


Line range hint 39-54: Initialization with currentDecision keeps the component consistent.
Using state to hold the initially selected decision ensures a smooth user experience.


Line range hint 123-136: Modal usage with typed states is correctly implemented.
By checking isConfirmProsecutorDecisionModal(modalVisible), the code avoids confusion on open/close states.

apps/judicial-system/web/src/routes/PublicProsecutor/Indictments/Overview/Overview.tsx (5)

7-10: Verify usage of newly imported judicial-system types.

Ensure that CaseIndictmentRulingDecision and IndictmentCaseReviewDecision are effectively used in the code to avoid any redundancy.


28-34: Check cross-component dependencies for these new imports.

When managing decisions, confirm that ReviewDecision and the related utilities from utils seamlessly integrate with other parts of the system (e.g., state management, error handling).


110-116: Clarify display logic for reviewer selector.

Ensure that the condition !workingCase.indictmentReviewDecision is correct for controlling when the selector is shown, avoiding potential confusion if future decisions are introduced.


117-139: Check the flow for updating the review decision.

  1. Confirm the onSelect callback effectively synchronizes new decisions with backend logic.
  2. Ensure the state's isReviewedDecisionChanged is reset (if necessary) after successful updates.

169-169: Confirm the side effect of isReviewerAssignedModal.

Validate that the correct modal text is displayed for the assigned reviewer and that the user can successfully proceed after acknowledging.

apps/judicial-system/web/src/routes/Shared/IndictmentOverview/IndictmentOverview.tsx (2)

112-114: Validate type safety for modalVisible.

Converting modalVisible from a boolean to ConfirmationModal | undefined is a good approach. Double-check that all related logic properly accounts for this type change.


312-312: Assess next-button click handler.

Tying onNextButtonClick directly to setModalVisible(CONFIRM_PROSECUTOR_DECISION) is straightforward. Ensure there's no unintended side effect on other modals, if any.

apps/judicial-system/backend/src/app/modules/case/guards/rolesRules.ts (1)

60-63: Confirm new field's permission logic.

The addition of 'indictmentReviewDecision' to publicProsecutorFields fits the PR objective. Verify all necessary security checks are in place and that only authorized roles can update this field.

Copy link
Member

@oddsson oddsson left a comment

Choose a reason for hiding this comment

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

Nice, just a few comments 👀

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (3)
apps/judicial-system/web/src/routes/PublicProsecutor/components/ReviewDecision/ReviewDecision.tsx (1)

83-83: Use optional chaining for better code style.

Replace the logical AND operator with optional chaining for better readability.

-                  onSelect && onSelect(item.value)
+                  onSelect?.(item.value)

Also applies to: 112-112

apps/judicial-system/web/src/routes/PublicProsecutor/Indictments/Overview/Overview.tsx (2)

119-142: Use null coalescing for cleaner default values.

Consider using null coalescing operator for cleaner default value handling.

-            indictmentAppealDeadline={
-              workingCase.indictmentAppealDeadline ?? ''
-            }
-            indictmentAppealDeadlineIsInThePast={
-              workingCase.indictmentVerdictAppealDeadlineExpired ?? false
-            }
+            indictmentAppealDeadline={workingCase.indictmentAppealDeadline ?? ''}
+            indictmentAppealDeadlineIsInThePast={workingCase.indictmentVerdictAppealDeadlineExpired ?? false}

146-170: Extract complex condition for better readability.

Consider extracting the complex nextIsDisabled condition into a separate variable for better readability.

+  const isReviewerSelectionDisabled =
+    !selectedIndictmentReviewer ||
+    selectedIndictmentReviewer.value === workingCase.indictmentReviewer?.id ||
+    isLoadingWorkingCase

   return (
     // ...
     <FormFooter
       nextButtonIcon="arrowForward"
       previousUrl={constants.CASES_ROUTE}
       nextIsLoading={isLoadingWorkingCase}
-      nextIsDisabled={
-        !selectedIndictmentReviewer ||
-        selectedIndictmentReviewer.value === workingCase.indictmentReviewer?.id ||
-        isLoadingWorkingCase
-      }
+      nextIsDisabled={isReviewerSelectionDisabled}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between efd8847 and 1fd78a1.

📒 Files selected for processing (3)
  • apps/judicial-system/web/src/routes/PublicProsecutor/Indictments/Overview/Overview.strings.ts (1 hunks)
  • apps/judicial-system/web/src/routes/PublicProsecutor/Indictments/Overview/Overview.tsx (4 hunks)
  • apps/judicial-system/web/src/routes/PublicProsecutor/components/ReviewDecision/ReviewDecision.tsx (7 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/judicial-system/web/src/routes/PublicProsecutor/Indictments/Overview/Overview.strings.ts
🧰 Additional context used
📓 Path-based instructions (2)
apps/judicial-system/web/src/routes/PublicProsecutor/Indictments/Overview/Overview.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/PublicProsecutor/components/ReviewDecision/ReviewDecision.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/PublicProsecutor/Indictments/Overview/Overview.tsx (4)
Learnt from: oddsson
PR: island-is/island.is#16731
File: apps/judicial-system/web/src/routes/Shared/IndictmentOverview/IndictmentOverview.tsx:172-186
Timestamp: 2024-11-12T15:15:20.157Z
Learning: In `IndictmentOverview.tsx`, since the defendants data does not change, using `useMemo` to memoize the filtering logic is unnecessary.
Learnt from: thorhildurt
PR: island-is/island.is#17198
File: apps/judicial-system/web/src/routes/Prison/IndictmentOverview/IndictmentOverview.tsx:42-50
Timestamp: 2024-12-11T14:25:44.741Z
Learning: In `IndictmentOverview.tsx`, when updating the punishment type, update the UI state before making the API call to immediately reflect the change.
Learnt from: unakb
PR: island-is/island.is#17112
File: apps/judicial-system/web/src/routes/Court/Indictments/Summary/Summary.tsx:166-178
Timestamp: 2024-12-04T10:10:49.089Z
Learning: In the Judicial System application, error handling for failed case transitions in the `Summary` component (`apps/judicial-system/web/src/routes/Court/Indictments/Summary/Summary.tsx`) is managed externally via a toaster notification. Therefore, additional error handling within the modal is not necessary.
Learnt from: unakb
PR: island-is/island.is#15378
File: apps/judicial-system/web/src/routes/Court/Indictments/Summary/Summary.tsx:86-100
Timestamp: 2024-11-12T15:15:11.835Z
Learning: User unakb prefers explicit case handling in switch statements for key functionalities like `getRulingDecisionTagColor` to ensure clarity and avoid assumptions that a case was overlooked.
🪛 Biome (1.9.4)
apps/judicial-system/web/src/routes/PublicProsecutor/components/ReviewDecision/ReviewDecision.tsx

[error] 112-112: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

🔇 Additional comments (6)
apps/judicial-system/web/src/routes/PublicProsecutor/components/ReviewDecision/ReviewDecision.tsx (4)

8-11: LGTM! Well-structured imports with proper access control.

The addition of isPublicProsecutorUser and modal-related imports aligns well with the feature requirements.

Also applies to: 21-21


27-33: LGTM! Type-safe props interface.

The Props interface changes enhance type safety and provide better state management through:

  • Strongly typed modal visibility with ConfirmationModal
  • Optional currentDecision for existing decisions
  • Improved callback signature with optional decision parameter

Line range hint 39-54: LGTM! Proper state initialization.

The state is correctly initialized with the current decision, enabling the modification of existing decisions.


Line range hint 122-135: LGTM! Type-safe modal handling.

The modal implementation demonstrates good practices:

  • Type-safe visibility check with isConfirmProsecutorDecisionModal
  • Consistent state management across all modal actions
apps/judicial-system/web/src/routes/PublicProsecutor/Indictments/Overview/Overview.tsx (2)

46-51: LGTM! Well-structured state management.

The state management implementation:

  • Tracks decision changes with isReviewedDecisionChanged
  • Uses type-safe ConfirmationModal for modal state

74-81: Follow codebase style conventions.

Based on the codebase conventions:

  1. Move the function definition above the return statement
  2. Add parentheses to the if statement
+  const onSelect = (decision?: IndictmentCaseReviewDecision) => {
+    if (!decision) {
+      return
+    }
+
+    const isDecisionChanged = decision !== workingCase.indictmentReviewDecision
+    setIsReviewedDecisionChanged(isDecisionChanged)
+  }
+
   return (

@oddsson oddsson added the automerge Merge this PR as soon as all checks pass label Jan 6, 2025
@kodiakhq kodiakhq bot merged commit 614056f into main Jan 6, 2025
97 checks passed
@kodiakhq kodiakhq bot deleted the j-s/add-option-to-change-prosecutor-result branch January 6, 2025 15:16
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