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

chore(j-s): Court Autofill #15421

Merged
merged 3 commits into from
Jul 3, 2024
Merged

Conversation

gudjong
Copy link
Member

@gudjong gudjong commented Jul 2, 2024

Court Autofill

Autofilla dómstól þegar farið er á málsmeðferðar skjá

What

  • Delays court autofill for indictment cases until the user enters the court selection screen. Previously, the court was autofilled during case creation.
  • Court autofill for non indictment cases was not changed.

Why

  • The court should not be autofilled until the user is ready to select a court.

Screenshots / Gifs

Before court selection

image

After court selection

image

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

    • Improved handling of case state and court assignment based on case type.
    • Enhanced GraphQL query for user information with additional fields.
  • Bug Fixes

    • Corrected conditions for indictment case handling and defender email updates.
  • Refactor

    • Streamlined logic for setting case properties in multiple service files.
  • Tests

    • Updated test cases to reflect new logic for court ID assignment.

@gudjong gudjong requested a review from a team as a code owner July 2, 2024 15:47
Copy link
Contributor

coderabbitai bot commented Jul 2, 2024

Walkthrough

The recent updates enhance the logic for determining the state and court assignment of cases based on whether they are request cases, streamline conditions for indictment cases, and refine the retrieval of user and institution information in the frontend. These changes ensure more accurate and context-sensitive handling of various case types across different modules.

Changes

File Path Change Summary
case.service.ts Updated case state, courtId assignment, and indictment case conditions using isRequestCase function.
internalCase.service.ts Adjusted logic for state, courtId, and prosecutorsOfficeId based on request case type using isRequestCase.
currentUser.graphql Modified currentUser query to include name and defaultCourtId, removing some other fields.
Processing.tsx Added context handling and case initialization logic based on user’s default court information.
caseController/create.spec.ts, internalCaseController/create.spec.ts Removed courtId from test case object creation scenarios.

Sequence Diagrams

sequenceDiagram
    participant Frontend as User Interface
    participant BService as Backend Service
    participant Database as Database

    Note over Frontend, BService: Case Creation Process

    Frontend->>BService: Create Case (isRequestCase, caseType)
    BService->>BService: Determine State and courtId
    BService->>Database: Store Case (with state and courtId)
    Database-->>BService: Confirmation
    BService-->>Frontend: Case Created

    Note over Frontend, BService: Case Update Process

    Frontend->>BService: Update Case (caseType)
    BService->>BService: Evaluate indictment conditions
    BService->>Database: Update Case
    Database-->>BService: Confirmation
    BService-->>Frontend: Case Updated
Loading

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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 8b5cb60 and f1a4084.

Files selected for processing (4)
  • apps/judicial-system/backend/src/app/modules/case/case.service.ts (6 hunks)
  • apps/judicial-system/backend/src/app/modules/case/internalCase.service.ts (2 hunks)
  • apps/judicial-system/web/src/components/UserProvider/currentUser.graphql (1 hunks)
  • apps/judicial-system/web/src/routes/Prosecutor/Indictments/Processing/Processing.tsx (3 hunks)
Additional context used
Path-based instructions (4)
apps/judicial-system/web/src/components/UserProvider/currentUser.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/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/backend/src/app/modules/case/internalCase.service.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/case.service.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/web/src/routes/Prosecutor/Indictments/Processing/Processing.tsx (1)
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-06-27T14:37:07.823Z
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.
Additional comments not posted (8)
apps/judicial-system/web/src/routes/Prosecutor/Indictments/Processing/Processing.tsx (2)

19-19: Ensure the UserContext import is correct and available.

The UserContext is imported but its definition is not provided. Ensure it is correctly defined and exported from the referenced module.

Verification successful

The UserContext is correctly defined and exported.

  • apps/judicial-system/web/src/components/UserProvider/UserProvider.tsx: export const UserContext = createContext<UserProvider>({})
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the definition and export of `UserContext`.

# Test: Search for the definition of `UserContext`. Expect: `UserContext` to be defined and exported.
rg --type typescript 'export const UserContext'

Length of output: 84



Script:

#!/bin/bash
# Description: Verify the definition and export of `UserContext`.

# Test: Search for the definition of `UserContext`. Expect: `UserContext` to be defined and exported.
rg 'export const UserContext'

Length of output: 248


31-31: Ensure the useOnceOn import is correct and available.

The useOnceOn hook is imported but its definition is not provided. Ensure it is correctly defined and exported from the referenced module.

Verification successful

The useOnceOn hook is correctly defined and exported.

The useOnceOn hook is defined in apps/judicial-system/web/src/utils/hooks/useOnceOn/index.ts and is exported as the default export. Additionally, it is re-exported from apps/judicial-system/web/src/utils/hooks/index.ts.

  • Definition: apps/judicial-system/web/src/utils/hooks/useOnceOn/index.ts
  • Default Export: apps/judicial-system/web/src/utils/hooks/useOnceOn/index.ts
  • Re-export: apps/judicial-system/web/src/utils/hooks/index.ts
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the definition and export of `useOnceOn`.

# Test: Search for the definition of `useOnceOn`. Expect: `useOnceOn` to be defined and exported.
rg --type typescript 'export const useOnceOn'

Length of output: 82



Script:

#!/bin/bash
# Description: Verify the definition and export of `useOnceOn`.

# Test: Search for the definition of `useOnceOn`. Expect: `useOnceOn` to be defined and exported.
rg --type ts 'export const useOnceOn'

Length of output: 39



Script:

#!/bin/bash
# Description: Verify the definition and export of `useOnceOn`.

# Test: Search for the term `useOnceOn` to verify its definition and export.
rg 'useOnceOn'

Length of output: 2837

apps/judicial-system/backend/src/app/modules/case/internalCase.service.ts (3)

33-33: Ensure the isRequestCase import is correct and available.

The isRequestCase function is imported but its definition is not provided. Ensure it is correctly defined and exported from the referenced module.

Verification successful

The isRequestCase import is correct and available.

The function isRequestCase is defined and exported in libs/judicial-system/types/src/lib/case.ts, confirming that the import in internalCase.service.ts is valid.

  • libs/judicial-system/types/src/lib/case.ts: export const isRequestCase = (type?: CaseType | null): boolean => {
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the definition and export of `isRequestCase`.

# Test: Search for the definition of `isRequestCase`. Expect: `isRequestCase` to be defined and exported.
rg --type typescript 'export const isRequestCase'

Length of output: 86



Script:

#!/bin/bash
# Description: Verify the definition and export of `isRequestCase`.

# Test: Search for the definition of `isRequestCase`. Expect: `isRequestCase` to be defined and exported.
rg 'export const isRequestCase'

Length of output: 307


357-359: Ensure the state assignment logic for request cases is correct.

The state assignment for request cases is set to CaseState.NEW. Verify that this change aligns with the overall case management logic.

Verification successful

The state assignment logic for request cases is correct and consistent.

The usage of isRequestCase to assign CaseState.NEW to request cases is consistent across the codebase.

  • apps/judicial-system/backend/src/app/modules/case/internalCase.service.ts
  • apps/judicial-system/backend/src/app/modules/case/case.service.ts
  • apps/judicial-system/backend/src/app/modules/case/state/case.state.ts
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the state assignment logic for request cases.

# Test: Search for all occurrences of `isRequestCase` usage. Expect: Consistent state assignment logic.
rg --type typescript 'isRequestCase'

Length of output: 71



Script:

#!/bin/bash
# Description: Verify the state assignment logic for request cases.

# Test: Search for all occurrences of `isRequestCase` usage. Expect: Consistent state assignment logic.
rg --type ts 'isRequestCase'

Length of output: 3469



Script:

#!/bin/bash
# Description: Extract and review the state assignment logic for request cases.

# Extract lines around the usage of `isRequestCase` in relevant files.
rg --type ts -C 5 'isRequestCase' apps/judicial-system/backend/src/app/modules/case/internalCase.service.ts apps/judicial-system/backend/src/app/modules/case/case.service.ts apps/judicial-system/backend/src/app/modules/case/state/case.state.ts

Length of output: 9971


364-366: Ensure the courtId assignment logic for request cases is correct.

The courtId assignment for request cases is set to the creator's institution's default court ID. Verify that this change aligns with the overall case management logic.

Verification successful

Verified the courtId assignment logic for request cases.

The courtId assignment for request cases is consistent with the overall case management logic. The isRequestCase function correctly identifies request cases, and the use of creator.institution?.defaultCourtId ensures the appropriate court ID is assigned.

  • The isRequestCase function is defined in libs/judicial-system/types/src/lib/case.ts.
  • The courtId assignment logic in internalCase.service.ts aligns with the expected behavior.
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the `courtId` assignment logic for request cases.

# Test: Search for all occurrences of `courtId` assignment. Expect: Consistent assignment logic.
rg --type typescript 'courtId'

Length of output: 65



Script:

#!/bin/bash
# Description: Verify the `courtId` assignment logic for request cases.

# Test: Search for all occurrences of `courtId` assignment. Expect: Consistent assignment logic.
rg --type ts 'courtId'

Length of output: 30471



Script:

#!/bin/bash
# Extract the implementation of `isRequestCase`
ast-grep --lang ts --pattern 'function isRequestCase($_) { $$$ }'

# Extract the context around the `courtId` assignment in `internalCase.service.ts`
rg --context 10 'courtId' apps/judicial-system/backend/src/app/modules/case/internalCase.service.ts

Length of output: 4383



Script:

#!/bin/bash
# Locate the implementation of `isRequestCase`
rg 'function isRequestCase' --type ts

# Check the usage of `creator.institution?.defaultCourtId`
rg 'creator.institution?.defaultCourtId' --type ts

Length of output: 92



Script:

#!/bin/bash
# Search for the usage of `isRequestCase`
rg 'isRequestCase' --type ts

# Search for the usage of `defaultCourtId`
rg 'defaultCourtId' --type ts

# List all function definitions in TypeScript files to locate `isRequestCase`
rg 'function ' --type ts

Length of output: 106930



Script:

#!/bin/bash
# Extract the implementation of `isRequestCase` from `case.ts`
rg --context 10 'export const isRequestCase' libs/judicial-system/types/src/lib/case.ts

# Review the context around the usage of `defaultCourtId` in `internalCase.service.ts`
rg --context 10 'defaultCourtId' apps/judicial-system/backend/src/app/modules/case/internalCase.service.ts

Length of output: 2444

apps/judicial-system/backend/src/app/modules/case/case.service.ts (3)

1211-1211: LGTM!

The changes improve readability and correctness.

Also applies to: 1226-1226, 1236-1236


1330-1332: Verify function usage for create.

Ensure that all calls to create correctly handle the new logic introduced by isRequestCase.


452-454: Verify function usage for createCase.

Ensure that all calls to createCase correctly handle the new logic introduced by isRequestCase.

Verification successful

Verify function usage for createCase.

The implementation of the createCase function correctly integrates the logic for isRequestCase. The function sets the state to CaseState.NEW or CaseState.DRAFT based on the result of isRequestCase. The invocations of createCase in case.service.ts also appropriately handle this logic.

  • apps/judicial-system/backend/src/app/modules/case/case.service.ts:
    • Line 452: The state is set based on isRequestCase.

The integration and usage of the new logic introduced by isRequestCase are consistent and correctly handled in the relevant code segments.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify all function calls to `createCase` handle the new logic introduced by `isRequestCase`.

# Test: Search for the function usage. Expect: Correct handling of `isRequestCase`.
rg --type ts $'createCase'

Length of output: 18558



Script:

#!/bin/bash
# Description: Extract and examine the relevant code segments where `createCase` is invoked to ensure correct handling of `isRequestCase`.

# Extracting the relevant code segments from the backend service file
echo "Extracting invocations of createCase in case.service.ts..."
rg --context 5 'createCase' apps/judicial-system/backend/src/app/modules/case/case.service.ts

# Extracting the relevant code segments from other related files
echo "Extracting invocations of createCase in related files..."
rg --context 5 'createCase' apps/judicial-system/backend/src/app/modules/court/court.service.ts
rg --context 5 'createCase' apps/judicial-system/backend/src/app/modules/court/test/createCourtCase.spec.ts
rg --context 5 'createCase' apps/judicial-system/backend/src/app/modules/case/test/caseController/create.spec.ts

Length of output: 5092



Script:

#!/bin/bash
# Description: Extract and analyze the complete `createCase` function implementation and its invocations to ensure correct handling of `isRequestCase`.

# Extracting the complete `createCase` function implementation from case.service.ts
echo "Extracting the complete createCase function implementation from case.service.ts..."
ast-grep --lang typescript --pattern $'class CaseService {
  $$$
  private async createCase(caseToCreate: CreateCaseDto, transaction: Transaction): Promise<string> {
    $$$
  }
  $$$
}' apps/judicial-system/backend/src/app/modules/case/case.service.ts

Length of output: 148824

Copy link

codecov bot commented Jul 2, 2024

Codecov Report

Attention: Patch coverage is 57.89474% with 8 lines in your changes missing coverage. Please review.

Project coverage is 37.03%. Comparing base (eec2f4d) to head (b22473d).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #15421      +/-   ##
==========================================
+ Coverage   37.02%   37.03%   +0.01%     
==========================================
  Files        6540     6540              
  Lines      133692   133273     -419     
  Branches    38246    38210      -36     
==========================================
- Hits        49496    49362     -134     
+ Misses      84196    83911     -285     
Flag Coverage Δ
judicial-system-web 28.28% <0.00%> (-0.02%) ⬇️

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

Files Coverage Δ
...ystem/backend/src/app/modules/case/case.service.ts 91.15% <100.00%> (-0.02%) ⬇️
...ckend/src/app/modules/case/internalCase.service.ts 85.40% <100.00%> (+0.03%) ⬆️
...s/Prosecutor/Indictments/Processing/Processing.tsx 0.00% <0.00%> (ø)

... and 200 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 eec2f4d...b22473d. Read the comment docs.

@datadog-island-is
Copy link

datadog-island-is bot commented Jul 2, 2024

Datadog Report

All test runs f5e6642 🔗

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

Test Services
Service Name Failed Known Flaky New Flaky Passed Skipped Total Time Code Coverage Change Test Service View
judicial-system-backend 0 0 0 19872 0 16m 31.19s 1 no change Link
judicial-system-web 0 0 0 317 0 1m 4.96s 1 decreased (-0.02%) Link

🔻 Code Coverage Decreases vs Default Branch (1)

  • judicial-system-web - jest 32.52% (-0.02%) - 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 (3)
apps/judicial-system/backend/src/app/modules/case/test/caseController/create.spec.ts (1)

Line range hint 58-58: Fix the assertion to remove courtId.

The courtId should be removed from the expect statement to align with the new logic.

-          courtId,
apps/judicial-system/backend/src/app/modules/case/test/internalCaseController/create.spec.ts (2)

Line range hint 56-56: Fix the assertion to remove courtId.

The courtId should be removed from the expect statement to align with the new logic.

-          courtId,

Line range hint 190-190: Fix the assertion to remove courtId.

The courtId should be removed from the expect statement to align with the new logic.

-          courtId,
Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between f1a4084 and 8a0b23f.

Files selected for processing (2)
  • apps/judicial-system/backend/src/app/modules/case/test/caseController/create.spec.ts (1 hunks)
  • apps/judicial-system/backend/src/app/modules/case/test/internalCaseController/create.spec.ts (1 hunks)
Additional context used
Path-based instructions (2)
apps/judicial-system/backend/src/app/modules/case/test/caseController/create.spec.ts (1)

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

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
apps/judicial-system/backend/src/app/modules/case/test/internalCaseController/create.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."
Additional comments not posted (12)
apps/judicial-system/backend/src/app/modules/case/test/caseController/create.spec.ts (4)

Line range hint 73-73: LGTM!

The changes align with the new logic.


Line range hint 84-84: LGTM!

The changes align with the new logic.


Line range hint 101-101: LGTM!

The changes align with the new logic.


Line range hint 117-117: LGTM!

The changes align with the new logic.

apps/judicial-system/backend/src/app/modules/case/test/internalCaseController/create.spec.ts (8)

Line range hint 84-84: LGTM!

The changes align with the new logic.


Line range hint 107-107: LGTM!

The changes align with the new logic.


Line range hint 130-130: LGTM!

The changes align with the new logic.


Line range hint 160-160: LGTM!

The changes align with the new logic.


Line range hint 210-210: LGTM!

The changes align with the new logic.


Line range hint 226-226: LGTM!

The changes align with the new logic.


Line range hint 247-247: LGTM!

The changes align with the new logic.


Line range hint 268-268: LGTM!

The changes align with the new logic.

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.

Just the rabbit comments

@gudjong gudjong added the automerge Merge this PR as soon as all checks pass label Jul 3, 2024
@kodiakhq kodiakhq bot merged commit b15b54f into main Jul 3, 2024
33 checks passed
@kodiakhq kodiakhq bot deleted the j-s/delay-indictment-court-autofill branch July 3, 2024 23:08
oskarjs pushed a commit that referenced this pull request Aug 20, 2024
* Delays indictment case court autofill until court selection screen

* Updates tests

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
@coderabbitai coderabbitai bot mentioned this pull request Oct 4, 2024
6 tasks
@coderabbitai coderabbitai bot mentioned this pull request Nov 15, 2024
6 tasks
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.

2 participants