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): Indictment Deletion #15028

Merged
merged 3 commits into from
May 31, 2024
Merged

feat(j-s): Indictment Deletion #15028

merged 3 commits into from
May 31, 2024

Conversation

gudjong
Copy link
Member

@gudjong gudjong commented May 30, 2024

Indictment Deletion

Afturköllun ákæru áður en mál er sent á dómstól

What

  • Prevents indictment deleteion after it has been submitted to a district court.

Why

  • Submitted indictment cancellation is handle differently.

Screenshots / Gifs

image
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

  • Bug Fixes

    • Removed invalid state transitions from SUBMITTED and RECEIVED to DELETED in the case management system.
  • Enhancements

    • Updated logic for displaying options based on user type and case state in the Active Cases view.

@gudjong gudjong requested a review from a team as a code owner May 30, 2024 17:41
@gudjong gudjong added the automerge Merge this PR as soon as all checks pass label May 30, 2024
Copy link
Contributor

coderabbitai bot commented May 30, 2024

Walkthrough

The recent updates primarily focus on refining the state transition logic within the judicial system's backend and frontend components. Notably, transitions from SUBMITTED and RECEIVED states to the DELETED state have been removed in both backend state management and corresponding test files. Additionally, the frontend logic for displaying options based on user type and case state has been updated, enhancing the user interface's responsiveness to different user roles and case statuses.

Changes

Files Change Summary
apps/judicial-system/backend/src/app/modules/case/state/case.state.spec.ts Removed CaseState.SUBMITTED and CaseState.RECEIVED from allowedFromStates in Transition Case test suite.
apps/judicial-system/backend/src/app/modules/case/state/case.state.ts Removed transitions from SUBMITTED and RECEIVED states to DELETED state in indictmentCaseStateMachine.
apps/judicial-system/web/src/routes/Shared/Cases/ActiveCases.tsx Updated logic for displaying options based on isProsecutionUser and case state; added isRequestCase to imports.
apps/judicial-system/backend/src/app/modules/case/test/caseController/transition.spec.ts Removed DELETE transition from SUBMITTED to DELETED and from RECEIVED to DELETED in transition.spec.ts.

Sequence Diagram(s) (Beta)

sequenceDiagram
    participant User
    participant Frontend
    participant Backend
    participant StateMachine

    User->>Frontend: Access Active Cases
    Frontend->>Backend: Fetch Cases
    Backend->>StateMachine: Get Case States
    StateMachine-->>Backend: Return Case States
    Backend-->>Frontend: Return Cases with States
    Frontend-->>User: Display Cases with Options

    User->>Frontend: Attempt to Delete Case
    Frontend->>Backend: Request Case Deletion
    Backend->>StateMachine: Validate Transition (SUBMITTED/RECEIVED to DELETED)
    StateMachine-->>Backend: Transition Not Allowed
    Backend-->>Frontend: Transition Error
    Frontend-->>User: Display Error Message
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: 0

Outside diff range and nitpick comments (4)
apps/judicial-system/backend/src/app/modules/case/state/case.state.ts (2)

Line range hint 327-344: Consider converting this function expression to an arrow function for consistency and conciseness.

- export const transitionCase = function (
+ export const transitionCase = (
    transition: CaseTransition,
    caseType: CaseType,
    currentState: CaseState,
    currentAppealState?: CaseAppealState,
  ): CaseStates {
    if (isIndictmentCase(caseType)) {
      return transitionIndictmentCase(transition, currentState)
    }

    if (isRequestCase(caseType)) {
      return transitionRequestCase(transition, currentState, currentAppealState)
    }

    throw new ForbiddenException(
      `The transition ${transition} cannot be applied to a ${caseType} case`,
    )
  }

Line range hint 2-18: Some imports are only used as types and should be imported using import type.

- import {
+ import type {
    CaseAppealState,
    CaseState,
    CaseTransition,
    CaseType,
    IndictmentCaseState,
    IndictmentCaseTransition,
    isIndictmentCase,
    isIndictmentCaseState,
    isIndictmentCaseTransition,
    isRequestCase,
    isRequestCaseState,
    isRequestCaseTransition,
    RequestCaseState,
    RequestCaseTransition,
  } from '@island.is/judicial-system/types'
apps/judicial-system/web/src/routes/Shared/Cases/ActiveCases.tsx (2)

Line range hint 223-223: JSX elements without children should be self-closing for better readability and consistency.

- <Box display="flex" flexDirection="column">
+ <Box display="flex" flexDirection="column" />

Line range hint 1-1: Imports that are only used as types should be imported using import type to avoid unnecessary runtime imports and to clarify their usage.

- import React, { useContext, useEffect, useMemo, useState } from 'react'
+ import type { FC, PropsWithChildren } from 'react'
+ import React, { useContext, useEffect, useMemo, useState } from 'react'

- import { Box, IconMapIcon, Text } from '@island.is/island-ui/core'
+ import type { IconMapIcon } from '@island.is/island-ui/core'
+ import { Box, Text } from '@island.is/island-ui/core'

- import {
+ import type {
    CaseListEntry,
    CaseState,
  } from '@island.is/judicial-system-web/src/graphql/schema'

- import {
+ import type {
    directionType,
    sortableTableColumn,
    SortConfig,
  } from '@island.is/judicial-system-web/src/types'

Also applies to: 8-9, 35-39, 39-44

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between b2d46d9 and 769aae5.

Files selected for processing (3)
  • apps/judicial-system/backend/src/app/modules/case/state/case.state.spec.ts (1 hunks)
  • apps/judicial-system/backend/src/app/modules/case/state/case.state.ts (1 hunks)
  • apps/judicial-system/web/src/routes/Shared/Cases/ActiveCases.tsx (2 hunks)
Additional context used
Path-based instructions (3)
apps/judicial-system/backend/src/app/modules/case/state/case.state.ts (1)

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

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
apps/judicial-system/web/src/routes/Shared/Cases/ActiveCases.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/state/case.state.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/web/src/routes/Shared/Cases/ActiveCases.tsx (1)
User: oddsson
PR: island-is/island.is#14673
File: apps/judicial-system/web/src/routes/PublicProsecutor/Tables/CasesForReview.tsx:79-79
Timestamp: 2024-05-06T23:16:04.892Z
Learning: The implementation of `mapIndictmentCaseStateToTagVariant` in `TagCaseState.tsx`, which maps only `CaseState.ACCEPTED` to a specific tag and defaults others to an "unknown" status, is intentional as per the application's requirements.
Biome
apps/judicial-system/backend/src/app/modules/case/state/case.state.ts

[error] 327-344: This function expression can be turned into an arrow function.


[error] 2-18: Some named imports are only used as types.

apps/judicial-system/web/src/routes/Shared/Cases/ActiveCases.tsx

[error] 223-223: JSX elements without children should be marked as self-closing. In JSX, it is valid for any element to be self-closing.


[error] 1-1: The default import is only used as a type.


[error] 8-9: Some named imports are only used as types.


[error] 35-39: Some named imports are only used as types.


[error] 39-44: All these imports are only used as types.

Additional comments not posted (1)
apps/judicial-system/backend/src/app/modules/case/state/case.state.spec.ts (1)

Line range hint 1-1: This file does not contain any specific changes to review based on the provided context. The tests seem to be well-structured and cover various scenarios for state transitions.

Copy link

codecov bot commented May 30, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 37.12%. Comparing base (7984866) to head (7077af2).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #15028      +/-   ##
==========================================
- Coverage   37.12%   37.12%   -0.01%     
==========================================
  Files        6393     6391       -2     
  Lines      130123   130049      -74     
  Branches    37132    37107      -25     
==========================================
- Hits        48310    48279      -31     
+ Misses      81813    81770      -43     
Flag Coverage Δ
judicial-system-web 28.00% <100.00%> (+0.02%) ⬆️
web 1.91% <ø> (ø)

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

Files Coverage Δ
...m/backend/src/app/modules/case/state/case.state.ts 97.05% <ø> (ø)
...system/web/src/routes/Shared/Cases/ActiveCases.tsx 62.96% <100.00%> (+1.42%) ⬆️

... and 21 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 7984866...7077af2. Read the comment docs.

@datadog-island-is
Copy link

datadog-island-is bot commented May 30, 2024

Datadog Report

All test runs c682e3e 🔗

2 Total Test Services: 0 Failed, 2 Passed
➡️ Test Sessions change in coverage: 2 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 18958 0 19m 32.15s 1 no change Link
judicial-system-web 0 0 0 312 0 1m 22.82s 1 no change Link

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 (2)
apps/judicial-system/backend/src/app/modules/case/test/caseController/transition.spec.ts (2)

Line range hint 1-2: Optimize imports by using TypeScript's type-only import syntax.

- import each from 'jest-each'
- import { Transaction } from 'sequelize'
- import { uuid } from 'uuidv4'
+ import type each from 'jest-each'
+ import type { Transaction } from 'sequelize'
+ import type { uuid } from 'uuidv4'

This change ensures that these imports are only used for type checking and not included in the JavaScript runtime, aligning with TypeScript best practices.

Also applies to: 4-5, 6-7, 7-24, 29-30, 31-32, 32-33


Line range hint 161-166: Remove duplicate setup and teardown hooks to streamline test setup.

It appears that setup and teardown hooks are duplicated across different test suites. Consolidating these can help reduce redundancy and potential confusion during test maintenance.

Also applies to: 345-350, 645-652

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 769aae5 and 2fa25cd.

Files selected for processing (1)
  • apps/judicial-system/backend/src/app/modules/case/test/caseController/transition.spec.ts (1 hunks)
Additional context used
Path-based instructions (1)
apps/judicial-system/backend/src/app/modules/case/test/caseController/transition.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."
Biome
apps/judicial-system/backend/src/app/modules/case/test/caseController/transition.spec.ts

[error] 161-166: Disallow duplicate setup and teardown hooks.


[error] 345-350: Disallow duplicate setup and teardown hooks.


[error] 645-652: Disallow duplicate setup and teardown hooks.


[error] 1-2: All these imports are only used as types.


[error] 4-5: All these imports are only used as types.


[error] 6-7: Some named imports are only used as types.


[error] 7-24: Some named imports are only used as types.


[error] 29-30: All these imports are only used as types.


[error] 31-32: All these imports are only used as types.


[error] 32-33: All these imports are only used as types.

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.

lgtm!

@kodiakhq kodiakhq bot merged commit 4f31949 into main May 31, 2024
36 checks passed
@kodiakhq kodiakhq bot deleted the j-s/delete-case branch May 31, 2024 15:28
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