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): Refactor TagCaseState component #17844

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

Conversation

oddsson
Copy link
Member

@oddsson oddsson commented Feb 5, 2025

Refactor TagCaseState component

Asana

What

This PR implements a significant refactor to the TagCaseState component. The CaseState component is responsible for rendering the state of a case in a tag component. The refactoring done in this component is

  1. Change the component's props to accept a CaseListEntry parameter instead of deconstructed properties of CaseListEntry. This means that the component accepts a prop, theCase: CaseListEntry instead of
state: CaseState,
type: CaseType,
courtDate: string
...
  1. Implements a new interface Tag for cleaner code.

Why

This makes calling the function and all code related to it much cleaner.

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

  • Refactor

    • Streamlined the way case status information is provided across various parts of the application by consolidating several data properties into a single, unified object. This enhances consistency and maintainability in displaying case state tags.
  • Tests

    • Adjusted test cases to support the updated component interfaces and ensure the new data structure functions as expected.
  • Chores

    • Removed redundant role-checking logic for a cleaner, more focused component behavior.

Copy link
Contributor

coderabbitai bot commented Feb 5, 2025

Walkthrough

This pull request refactors how the TagCaseState component receives its data. Instead of passing multiple discrete props, components across the judicial system now pass a single consolidated prop named theCase (of type CaseListEntry). The changes span several UI components, tests, and related helper functions. Additionally, redundant logic such as the isDistrictCourtUser function has been removed, and the TagCaseState component’s internal functions and tests have been updated to work with the new prop structure and integrated user context.

Changes

Files Change Summary
apps/.../PageTitle.tsx, apps/.../PastCasesTable.tsx, apps/.../CasesAwaitingAssignmentTable.tsx, apps/.../CasesInProgressTable.tsx, apps/.../DefenderCasesTable.tsx, apps/.../CasesAwaitingConfirmationTable.tsx, apps/.../CasesAwaitingReview.tsx, apps/.../CasesForReview.tsx, apps/.../ActiveCases.tsx, apps/.../MobileCase.tsx, apps/.../PrisonCases.tsx Updated various components to pass a single consolidated theCase prop to TagCaseState, replacing multiple individual props and removing extra role-based flags.
apps/.../TagCaseState/TagCaseState.tsx, apps/.../TagCaseState/TagCaseState.spec.ts Refactored the TagCaseState component and its tests: updated prop interfaces and function signatures to use the single theCase object, integrating type and user context changes.
apps/.../Table/Table.tsx Removed the isDistrictCourtUser function and its usage, thereby eliminating the passing of district court role information to child components.

Sequence Diagram(s)

sequenceDiagram
    participant Parent as Parent Component
    participant TCS as TagCaseState Component
    participant UC as UserContext
    Parent->>TCS: Pass `theCase` prop (case data)
    TCS->>UC: Retrieve user details
    TCS->>TCS: Map case state to tag variant using `theCase` and user
    TCS-->>Parent: Render tag with computed variant
Loading

Possibly related PRs

Suggested labels

automerge

Suggested reviewers

  • thorhildurt

Tip

🌐 Web search-backed reviews and chat
  • We have enabled web search-based reviews and chat for all users. This feature allows CodeRabbit to access the latest documentation and information on the web.
  • You can disable this feature by setting web_search: false in the knowledge_base settings.
  • Please share any feedback in the Discord discussion.
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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

nx-cloud bot commented Feb 5, 2025

View your CI Pipeline Execution ↗ for commit 04c6b51.

Command Status Duration Result
nx run-many --target=lint --projects=judicial-s... ❌ Failed 17s View ↗
nx run-many --target=build --projects=judicial-... ✅ Succeeded 6m 52s View ↗
nx run-many --projects judicial-system-web --ta... ✅ Succeeded 3m 38s View ↗
nx run-many --target=codegen/frontend-client --... ✅ Succeeded 13s View ↗
nx run-many --target=codegen/backend-schema --a... ✅ Succeeded 21s View ↗

☁️ Nx Cloud last updated this comment at 2025-02-05 17:41:29 UTC

@oddsson oddsson changed the title J s/sort by state chore(j-s): Refactor CaseState component Feb 5, 2025
@oddsson oddsson changed the title chore(j-s): Refactor CaseState component chore(j-s): Refactor TagCaseState component Feb 5, 2025
@oddsson oddsson marked this pull request as ready for review February 5, 2025 17:29
@oddsson oddsson requested a review from a team as a code owner February 5, 2025 17: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: 1

🧹 Nitpick comments (1)
apps/judicial-system/web/src/components/Tags/TagCaseState/TagCaseState.tsx (1)

61-139: Consider refactoring complex conditional logic.

The mapCaseStateToTagVariant function contains complex nested conditions that could be simplified for better maintainability.

Consider extracting the subpoena service check and indictment decision handling into separate functions:

+const isAwaitingSubpoenaService = (theCase: CaseListEntry): boolean => {
+  return (
+    isIndictmentCase(theCase.type) &&
+    theCase.defendants &&
+    theCase.courtDate &&
+    !haveAllSubpoenasBeenServiced(theCase.defendants)
+  )
+}

+const getIndictmentDecisionTag = (
+  decision: IndictmentDecision,
+  formatMessage: IntlShape['formatMessage'],
+): CaseStateTag | null => {
+  switch (decision) {
+    case IndictmentDecision.POSTPONING:
+    case IndictmentDecision.SCHEDULING:
+    case IndictmentDecision.COMPLETING:
+      return { color: 'mint', text: formatMessage(strings.scheduled) }
+    // ... other cases
+  }
+  return null
+}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c81f657 and 04c6b51.

📒 Files selected for processing (14)
  • apps/judicial-system/web/src/components/PageTitle/PageTitle.tsx (2 hunks)
  • apps/judicial-system/web/src/components/Table/PastCasesTable/PastCasesTable.tsx (1 hunks)
  • apps/judicial-system/web/src/components/Table/Table.tsx (0 hunks)
  • apps/judicial-system/web/src/components/Tags/TagCaseState/TagCaseState.spec.ts (7 hunks)
  • apps/judicial-system/web/src/components/Tags/TagCaseState/TagCaseState.tsx (6 hunks)
  • apps/judicial-system/web/src/routes/Court/components/CasesAwaitingAssignmentTable/CasesAwaitingAssignmentTable.tsx (1 hunks)
  • apps/judicial-system/web/src/routes/Court/components/CasesInProgressTable/CasesInProgressTable.tsx (1 hunks)
  • apps/judicial-system/web/src/routes/Defender/Cases/components/DefenderCasesTable.tsx (1 hunks)
  • apps/judicial-system/web/src/routes/Prosecutor/components/CasesAwaitingConfirmationTable/CasesAwaitingConfirmationTable.tsx (1 hunks)
  • apps/judicial-system/web/src/routes/PublicProsecutor/Tables/CasesAwaitingReview.tsx (1 hunks)
  • apps/judicial-system/web/src/routes/PublicProsecutor/Tables/CasesForReview.tsx (1 hunks)
  • apps/judicial-system/web/src/routes/Shared/Cases/ActiveCases.tsx (1 hunks)
  • apps/judicial-system/web/src/routes/Shared/Cases/MobileCase.tsx (1 hunks)
  • apps/judicial-system/web/src/routes/Shared/Cases/PrisonCases.tsx (1 hunks)
💤 Files with no reviewable changes (1)
  • apps/judicial-system/web/src/components/Table/Table.tsx
🧰 Additional context used
📓 Path-based instructions (1)
`apps/**/*`: "Confirm that the code adheres to the following...

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/Court/components/CasesInProgressTable/CasesInProgressTable.tsx
  • apps/judicial-system/web/src/components/PageTitle/PageTitle.tsx
  • apps/judicial-system/web/src/routes/Court/components/CasesAwaitingAssignmentTable/CasesAwaitingAssignmentTable.tsx
  • apps/judicial-system/web/src/routes/PublicProsecutor/Tables/CasesForReview.tsx
  • apps/judicial-system/web/src/routes/Shared/Cases/ActiveCases.tsx
  • apps/judicial-system/web/src/routes/Prosecutor/components/CasesAwaitingConfirmationTable/CasesAwaitingConfirmationTable.tsx
  • apps/judicial-system/web/src/routes/PublicProsecutor/Tables/CasesAwaitingReview.tsx
  • apps/judicial-system/web/src/routes/Shared/Cases/PrisonCases.tsx
  • apps/judicial-system/web/src/routes/Shared/Cases/MobileCase.tsx
  • apps/judicial-system/web/src/components/Tags/TagCaseState/TagCaseState.spec.ts
  • apps/judicial-system/web/src/components/Table/PastCasesTable/PastCasesTable.tsx
  • apps/judicial-system/web/src/routes/Defender/Cases/components/DefenderCasesTable.tsx
  • apps/judicial-system/web/src/components/Tags/TagCaseState/TagCaseState.tsx
📓 Learnings (11)
apps/judicial-system/web/src/routes/Court/components/CasesInProgressTable/CasesInProgressTable.tsx (2)
Learnt from: gudjong
PR: island-is/island.is#16760
File: apps/judicial-system/web/src/routes/Shared/Cases/PrisonCases.tsx:112-118
Timestamp: 2024-11-12T15:15:11.835Z
Learning: In `apps/judicial-system/web/src/routes/Prosecutor/components/CasesAwaitingConfirmationTable/CasesAwaitingConfirmationTable.tsx`, `apps/judicial-system/web/src/routes/Court/components/CasesAwaitingAssignmentTable/CasesAwaitingAssignmentTable.tsx`, and one instance in `apps/judicial-system/web/src/routes/Shared/Cases/PrisonCases.tsx`, it's correct to pass only the `type` prop to `ColumnCaseType` without the `decision` and `parentCaseId` props.
Learnt from: oddsson
PR: island-is/island.is#14673
File: apps/judicial-system/web/src/routes/PublicProsecutor/Tables/CasesForReview.tsx:79-79
Timestamp: 2024-11-12T15:15:11.835Z
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.
apps/judicial-system/web/src/routes/Court/components/CasesAwaitingAssignmentTable/CasesAwaitingAssignmentTable.tsx (2)
Learnt from: gudjong
PR: island-is/island.is#16760
File: apps/judicial-system/web/src/routes/Shared/Cases/PrisonCases.tsx:112-118
Timestamp: 2024-11-12T15:15:11.835Z
Learning: In `apps/judicial-system/web/src/routes/Prosecutor/components/CasesAwaitingConfirmationTable/CasesAwaitingConfirmationTable.tsx`, `apps/judicial-system/web/src/routes/Court/components/CasesAwaitingAssignmentTable/CasesAwaitingAssignmentTable.tsx`, and one instance in `apps/judicial-system/web/src/routes/Shared/Cases/PrisonCases.tsx`, it's correct to pass only the `type` prop to `ColumnCaseType` without the `decision` and `parentCaseId` props.
Learnt from: oddsson
PR: island-is/island.is#14673
File: apps/judicial-system/web/src/routes/PublicProsecutor/Tables/CasesForReview.tsx:79-79
Timestamp: 2024-11-12T15:15:11.835Z
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.
apps/judicial-system/web/src/routes/PublicProsecutor/Tables/CasesForReview.tsx (3)
Learnt from: oddsson
PR: island-is/island.is#14673
File: apps/judicial-system/web/src/routes/PublicProsecutor/Tables/CasesForReview.tsx:79-79
Timestamp: 2024-11-12T15:15:11.835Z
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.
Learnt from: gudjong
PR: island-is/island.is#16760
File: apps/judicial-system/web/src/routes/Shared/Cases/PrisonCases.tsx:112-118
Timestamp: 2024-11-12T15:15:11.835Z
Learning: In `apps/judicial-system/web/src/routes/Prosecutor/components/CasesAwaitingConfirmationTable/CasesAwaitingConfirmationTable.tsx`, `apps/judicial-system/web/src/routes/Court/components/CasesAwaitingAssignmentTable/CasesAwaitingAssignmentTable.tsx`, and one instance in `apps/judicial-system/web/src/routes/Shared/Cases/PrisonCases.tsx`, it's correct to pass only the `type` prop to `ColumnCaseType` without the `decision` and `parentCaseId` props.
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.
apps/judicial-system/web/src/routes/Shared/Cases/ActiveCases.tsx (5)
Learnt from: gudjong
PR: island-is/island.is#16760
File: apps/judicial-system/web/src/routes/Shared/Cases/PrisonCases.tsx:112-118
Timestamp: 2024-11-12T15:15:11.835Z
Learning: In `apps/judicial-system/web/src/routes/Prosecutor/components/CasesAwaitingConfirmationTable/CasesAwaitingConfirmationTable.tsx`, `apps/judicial-system/web/src/routes/Court/components/CasesAwaitingAssignmentTable/CasesAwaitingAssignmentTable.tsx`, and one instance in `apps/judicial-system/web/src/routes/Shared/Cases/PrisonCases.tsx`, it's correct to pass only the `type` prop to `ColumnCaseType` without the `decision` and `parentCaseId` props.
Learnt from: oddsson
PR: island-is/island.is#14673
File: apps/judicial-system/web/src/routes/PublicProsecutor/Tables/CasesForReview.tsx:79-79
Timestamp: 2024-11-12T15:15:11.835Z
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.
Learnt from: oddsson
PR: island-is/island.is#16939
File: apps/judicial-system/web/src/components/Table/PastCasesTable/PastCasesTable.tsx:136-139
Timestamp: 2024-11-20T10:15:04.980Z
Learning: The properties `isValidToDateInThePast`, `indictmentRulingDecision`, and `indictmentDecision` are defined in the `CaseListEntry` interface used in the `PastCasesTable` component.
Learnt from: oddsson
PR: island-is/island.is#16939
File: apps/judicial-system/web/src/components/Table/PastCasesTable/PastCasesTable.tsx:126-131
Timestamp: 2024-11-19T21:47:09.093Z
Learning: The `CaseListEntry` interface in `@island.is/judicial-system-web/src/graphql/schema` includes the properties `isValidToDateInThePast`, `indictmentRulingDecision`, and `indictmentDecision`.
Learnt from: oddsson
PR: island-is/island.is#17611
File: apps/judicial-system/web/src/components/Table/Table.spec.tsx:101-101
Timestamp: 2025-01-24T06:55:16.117Z
Learning: The case entity retains the `created` field even after introducing `caseSentToCourtDate`.
apps/judicial-system/web/src/routes/Prosecutor/components/CasesAwaitingConfirmationTable/CasesAwaitingConfirmationTable.tsx (2)
Learnt from: oddsson
PR: island-is/island.is#14673
File: apps/judicial-system/web/src/routes/PublicProsecutor/Tables/CasesForReview.tsx:79-79
Timestamp: 2024-11-12T15:15:11.835Z
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.
Learnt from: gudjong
PR: island-is/island.is#16760
File: apps/judicial-system/web/src/routes/Shared/Cases/PrisonCases.tsx:112-118
Timestamp: 2024-11-12T15:15:11.835Z
Learning: In `apps/judicial-system/web/src/routes/Prosecutor/components/CasesAwaitingConfirmationTable/CasesAwaitingConfirmationTable.tsx`, `apps/judicial-system/web/src/routes/Court/components/CasesAwaitingAssignmentTable/CasesAwaitingAssignmentTable.tsx`, and one instance in `apps/judicial-system/web/src/routes/Shared/Cases/PrisonCases.tsx`, it's correct to pass only the `type` prop to `ColumnCaseType` without the `decision` and `parentCaseId` props.
apps/judicial-system/web/src/routes/PublicProsecutor/Tables/CasesAwaitingReview.tsx (2)
Learnt from: oddsson
PR: island-is/island.is#14673
File: apps/judicial-system/web/src/routes/PublicProsecutor/Tables/CasesForReview.tsx:79-79
Timestamp: 2024-11-12T15:15:11.835Z
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.
Learnt from: gudjong
PR: island-is/island.is#16760
File: apps/judicial-system/web/src/routes/Shared/Cases/PrisonCases.tsx:112-118
Timestamp: 2024-11-12T15:15:11.835Z
Learning: In `apps/judicial-system/web/src/routes/Prosecutor/components/CasesAwaitingConfirmationTable/CasesAwaitingConfirmationTable.tsx`, `apps/judicial-system/web/src/routes/Court/components/CasesAwaitingAssignmentTable/CasesAwaitingAssignmentTable.tsx`, and one instance in `apps/judicial-system/web/src/routes/Shared/Cases/PrisonCases.tsx`, it's correct to pass only the `type` prop to `ColumnCaseType` without the `decision` and `parentCaseId` props.
apps/judicial-system/web/src/routes/Shared/Cases/PrisonCases.tsx (3)
Learnt from: gudjong
PR: island-is/island.is#16760
File: apps/judicial-system/web/src/routes/Shared/Cases/PrisonCases.tsx:112-118
Timestamp: 2024-11-12T15:15:11.835Z
Learning: In `apps/judicial-system/web/src/routes/Prosecutor/components/CasesAwaitingConfirmationTable/CasesAwaitingConfirmationTable.tsx`, `apps/judicial-system/web/src/routes/Court/components/CasesAwaitingAssignmentTable/CasesAwaitingAssignmentTable.tsx`, and one instance in `apps/judicial-system/web/src/routes/Shared/Cases/PrisonCases.tsx`, it's correct to pass only the `type` prop to `ColumnCaseType` without the `decision` and `parentCaseId` props.
Learnt from: thorhildurt
PR: island-is/island.is#17285
File: apps/judicial-system/web/src/routes/Shared/Cases/PrisonCases.tsx:223-225
Timestamp: 2024-12-18T17:15:59.181Z
Learning: The system currently only allows adding one defendant, so the punishment type logic in the table can default to the first defendant, with a plan to support multiple defendants in the future.
Learnt from: oddsson
PR: island-is/island.is#14673
File: apps/judicial-system/web/src/routes/PublicProsecutor/Tables/CasesForReview.tsx:79-79
Timestamp: 2024-11-12T15:15:11.835Z
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.
apps/judicial-system/web/src/routes/Shared/Cases/MobileCase.tsx (1)
Learnt from: gudjong
PR: island-is/island.is#16760
File: apps/judicial-system/web/src/routes/Shared/Cases/PrisonCases.tsx:112-118
Timestamp: 2024-11-12T15:15:11.835Z
Learning: In `apps/judicial-system/web/src/routes/Prosecutor/components/CasesAwaitingConfirmationTable/CasesAwaitingConfirmationTable.tsx`, `apps/judicial-system/web/src/routes/Court/components/CasesAwaitingAssignmentTable/CasesAwaitingAssignmentTable.tsx`, and one instance in `apps/judicial-system/web/src/routes/Shared/Cases/PrisonCases.tsx`, it's correct to pass only the `type` prop to `ColumnCaseType` without the `decision` and `parentCaseId` props.
apps/judicial-system/web/src/components/Tags/TagCaseState/TagCaseState.spec.ts (1)
Learnt from: oddsson
PR: island-is/island.is#16939
File: apps/judicial-system/web/src/components/Table/PastCasesTable/PastCasesTable.tsx:126-131
Timestamp: 2024-11-19T21:47:09.093Z
Learning: The `CaseListEntry` interface in `@island.is/judicial-system-web/src/graphql/schema` includes the properties `isValidToDateInThePast`, `indictmentRulingDecision`, and `indictmentDecision`.
apps/judicial-system/web/src/components/Table/PastCasesTable/PastCasesTable.tsx (3)
Learnt from: oddsson
PR: island-is/island.is#16939
File: apps/judicial-system/web/src/components/Table/PastCasesTable/PastCasesTable.tsx:136-139
Timestamp: 2024-11-20T10:15:04.980Z
Learning: The properties `isValidToDateInThePast`, `indictmentRulingDecision`, and `indictmentDecision` are defined in the `CaseListEntry` interface used in the `PastCasesTable` component.
Learnt from: oddsson
PR: island-is/island.is#16939
File: apps/judicial-system/web/src/components/Table/PastCasesTable/PastCasesTable.tsx:126-131
Timestamp: 2024-11-19T21:47:09.093Z
Learning: The `CaseListEntry` interface in `@island.is/judicial-system-web/src/graphql/schema` includes the properties `isValidToDateInThePast`, `indictmentRulingDecision`, and `indictmentDecision`.
Learnt from: gudjong
PR: island-is/island.is#16760
File: apps/judicial-system/web/src/routes/Shared/Cases/PrisonCases.tsx:112-118
Timestamp: 2024-11-12T15:15:11.835Z
Learning: In `apps/judicial-system/web/src/routes/Prosecutor/components/CasesAwaitingConfirmationTable/CasesAwaitingConfirmationTable.tsx`, `apps/judicial-system/web/src/routes/Court/components/CasesAwaitingAssignmentTable/CasesAwaitingAssignmentTable.tsx`, and one instance in `apps/judicial-system/web/src/routes/Shared/Cases/PrisonCases.tsx`, it's correct to pass only the `type` prop to `ColumnCaseType` without the `decision` and `parentCaseId` props.
apps/judicial-system/web/src/routes/Defender/Cases/components/DefenderCasesTable.tsx (2)
Learnt from: gudjong
PR: island-is/island.is#16760
File: apps/judicial-system/web/src/routes/Shared/Cases/PrisonCases.tsx:112-118
Timestamp: 2024-11-12T15:15:11.835Z
Learning: In `apps/judicial-system/web/src/routes/Prosecutor/components/CasesAwaitingConfirmationTable/CasesAwaitingConfirmationTable.tsx`, `apps/judicial-system/web/src/routes/Court/components/CasesAwaitingAssignmentTable/CasesAwaitingAssignmentTable.tsx`, and one instance in `apps/judicial-system/web/src/routes/Shared/Cases/PrisonCases.tsx`, it's correct to pass only the `type` prop to `ColumnCaseType` without the `decision` and `parentCaseId` props.
Learnt from: oddsson
PR: island-is/island.is#14673
File: apps/judicial-system/web/src/routes/PublicProsecutor/Tables/CasesForReview.tsx:79-79
Timestamp: 2024-11-12T15:15:11.835Z
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.
🪛 ESLint
apps/judicial-system/web/src/components/PageTitle/PageTitle.tsx

[error] 1-20: Run autofix to sort these imports!

(simple-import-sort/imports)

🪛 Biome (1.9.4)
apps/judicial-system/web/src/components/Tags/TagCaseState/TagCaseState.tsx

[error] 22-22: Shouldn't redeclare 'Tag'. Consider to delete it or rename it.

'Tag' is defined here:

(lint/suspicious/noRedeclare)

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: tests (judicial-system-web)
  • GitHub Check: build (judicial-system-web)
🔇 Additional comments (15)
apps/judicial-system/web/src/routes/Prosecutor/components/CasesAwaitingConfirmationTable/CasesAwaitingConfirmationTable.tsx (1)

124-124: LGTM! The prop consolidation aligns with the refactoring objectives.

The change to use a single theCase prop improves the component's interface by reducing prop drilling and enhancing maintainability.

Let's verify that this change is consistent across all usages of TagCaseState:

✅ Verification successful

🏁 Script executed:

#!/bin/bash
# Description: Check for any remaining instances of old prop usage in TagCaseState
# Expect: All instances should use the new `theCase` prop format

# Search for TagCaseState usage patterns
rg -A 2 '<TagCaseState' apps/

Length of output: 3997


LGTM! The usage of the consolidated theCase prop is consistent.

The shell script output confirms that all instances of <TagCaseState> across the repository now use the single theCase prop, aligning with the refactoring objectives.

apps/judicial-system/web/src/components/PageTitle/PageTitle.tsx (2)

20-20: LGTM! Import added for CaseListEntry type.

The import is correctly placed and aligns with the refactoring objectives.

🧰 Tools
🪛 ESLint

[error] 1-20: Run autofix to sort these imports!

(simple-import-sort/imports)


58-58: LGTM! TagCaseState prop structure updated.

The component now correctly uses the consolidated theCase prop with appropriate type casting.

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

77-77: LGTM! TagCaseState implementation updated.

The component correctly uses the new prop structure and includes a key prop for the array element.

apps/judicial-system/web/src/routes/Court/components/CasesAwaitingAssignmentTable/CasesAwaitingAssignmentTable.tsx (1)

91-91: LGTM! TagCaseState cell implementation updated.

The table cell correctly uses the new prop structure, maintaining consistency with other components.

apps/judicial-system/web/src/routes/PublicProsecutor/Tables/CasesAwaitingReview.tsx (1)

92-95: LGTM! TagCaseState implementation updated while preserving custom behavior.

The component correctly uses the new prop structure while maintaining the custom state mapping functionality.

apps/judicial-system/web/src/components/Tags/TagCaseState/TagCaseState.tsx (2)

27-33: LGTM! Props interface refactoring improves maintainability.

The consolidation of multiple props into a single theCase prop of type CaseListEntry reduces prop drilling and improves type safety.


141-157: LGTM! Clean component implementation.

The component implementation is well-structured with proper context usage and prop handling.

apps/judicial-system/web/src/routes/Defender/Cases/components/DefenderCasesTable.tsx (1)

108-108: LGTM! Consistent with TagCaseState refactoring.

The update to use the consolidated theCase prop is clean and follows the new component API.

apps/judicial-system/web/src/routes/PublicProsecutor/Tables/CasesForReview.tsx (1)

105-110: LGTM! Proper integration of custom mapping function.

The implementation correctly uses both the new theCase prop and the customMapCaseStateToTag function.

apps/judicial-system/web/src/components/Table/PastCasesTable/PastCasesTable.tsx (1)

126-126: LGTM! Clean conditional rendering with new API.

The conditional rendering of TagCaseState with the new theCase prop is well-implemented.

apps/judicial-system/web/src/routes/Court/components/CasesInProgressTable/CasesInProgressTable.tsx (1)

157-157: LGTM! Clean refactor of TagCaseState props.

The change correctly implements the new prop structure by passing the entire case object to TagCaseState.

apps/judicial-system/web/src/components/Tags/TagCaseState/TagCaseState.spec.ts (1)

22-316: LGTM! Comprehensive test coverage for the refactored TagCaseState.

The test suite has been successfully updated to use the new function signature while maintaining thorough coverage of all case states and scenarios.

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

140-140: LGTM! Clean refactor of TagCaseState props.

The change correctly implements the new prop structure by passing the entire case object to TagCaseState.

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

97-97: LGTM! Clean refactor of TagCaseState props.

The change aligns with the PR objectives by simplifying the TagCaseState component's interface to accept a single CaseListEntry parameter. This improves code maintainability and type safety.

Let's verify the TypeScript types are properly enforced:

✅ Verification successful

🏁 Script executed:

#!/bin/bash
# Description: Verify TypeScript types for TagCaseState component usage

# Test: Check if TagCaseState component properly types the theCase prop
ast-grep --pattern 'interface TagCaseStateProps {
  $$$
  theCase: CaseListEntry
  $$$
}'

# Test: Check if there are any remaining instances of old prop usage
rg "TagCaseState.*caseState|TagCaseState.*caseType|TagCaseState.*isValidToDateInThePast|TagCaseState.*courtDate|TagCaseState.*indictmentDecision|TagCaseState.*indictmentRulingDecision|TagCaseState.*defendants"

Length of output: 303


Let's run another script to further verify that the updated interface for TagCaseState is in place and that no legacy props remain. This script will:

  • Search for the declaration of the TagCaseStateProps interface within files that mention TagCaseState
  • Show the snippet around the usage in ActiveCases.tsx to confirm that only the updated theCase prop is passed

Please execute the following shell script:

Once we have these additional details, we can more confidently verify that TypeScript type safety is enforced and the refactor is complete.


🏁 Script executed:

#!/bin/bash
# 1. Search for the interface declaration of TagCaseStateProps in files related to TagCaseState
fd -t f -e ts -e tsx -g "TagCaseState" . | xargs rg -n "interface TagCaseStateProps"

# 2. Display the relevant snippet from ActiveCases.tsx to verify usage of theCase prop
sed -n '90,105p' apps/judicial-system/web/src/routes/Shared/Cases/ActiveCases.tsx

Length of output: 722


LGTM! The updated usage of <TagCaseState> is correctly passing the single theCase prop, and no legacy props appear to be in use.

The snippet from ActiveCases.tsx confirms that the refactor is applied, and our searches did not reveal any lingering references to the old props.

Comment on lines +22 to +25
interface Tag {
color: TagVariant
text: string
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Rename the Tag interface to avoid naming conflicts.

The Tag interface conflicts with the imported Tag from '@island.is/island-ui/core'. Consider renaming it to something more specific like CaseStateTag or TagDefinition.

-interface Tag {
+interface CaseStateTag {
   color: TagVariant
   text: string
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
interface Tag {
color: TagVariant
text: string
}
interface CaseStateTag {
color: TagVariant
text: string
}
🧰 Tools
🪛 Biome (1.9.4)

[error] 22-22: Shouldn't redeclare 'Tag'. Consider to delete it or rename it.

'Tag' is defined here:

(lint/suspicious/noRedeclare)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant