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): Move DefenderCasesTable to new table component #17420

Merged
merged 9 commits into from
Jan 17, 2025

Conversation

oddsson
Copy link
Member

@oddsson oddsson commented Jan 7, 2025

Move DefenderCasesTable to new table component

Asana

What

A few months ago we created a Table component. Since then we've been gradually moving all tables to that component and this PR implements that for the DefenderCasesTable.

Why

Having one Table component for all tables is cleaner and less fragile than the alternative.

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 TagContainer component for improved tag layout.
  • Refactor

    • Simplified type declarations in the Defender Cases component.
    • Replaced custom table implementation with a more reusable Table component.
    • Removed dedicated CSS file for Defender Cases Table.
  • Code Cleanup

    • Removed unnecessary imports and styling-related code.
    • Streamlined context menu and table rendering logic.
  • Performance

    • Improved component structure for better maintainability.

Copy link
Contributor

coderabbitai bot commented Jan 7, 2025

Walkthrough

The pull request introduces changes to the Judicial System web application, focusing on the Defender Cases section. The modifications include adding a new variable to simplify user role checks, simplifying type declarations, removing a CSS file, and refactoring the DefenderCasesTable component to utilize a new Table component. Additionally, there are updates to import paths for certain components due to a reorganization of the directory structure. These changes aim to streamline the code structure and improve the rendering of case-related information for defender users.

Changes

File Change Summary
apps/judicial-system/web/src/components/ContextMenu/ContextMenuOptions/WithdrawAppealMenuOption.tsx Added isDefence variable to simplify user role condition check
apps/judicial-system/web/src/routes/Defender/Cases/Cases.tsx Removed unknown type parameter from FC and adjusted loading prop for DefenderCasesTable
apps/judicial-system/web/src/routes/Defender/Cases/components/DefenderCasesTable.css.ts Completely removed CSS file with all style definitions
apps/judicial-system/web/src/routes/Defender/Cases/components/DefenderCasesTable.tsx Significant refactoring to use new Table component, removed imports, simplified rendering logic
apps/judicial-system/web/src/components/PageTitle/PageTitle.tsx Updated import path for TagCaseState component
apps/judicial-system/web/src/components/Table/PastCasesTable/PastCasesTable.tsx Added TagContainer import and modified rendering logic for case state tags
apps/judicial-system/web/src/components/Tags/TagAppealState/TagAppealState.tsx Updated import path for UserContext
apps/judicial-system/web/src/components/Tags/TagContainer/TagContainer.tsx Introduced new TagContainer component
apps/judicial-system/web/src/components/index.ts Updated export paths for TagAppealState and TagCaseState
apps/judicial-system/web/src/routes/PublicProsecutor/Tables/CasesAwaitingReview.tsx Updated import path for TagCaseState
apps/judicial-system/web/src/routes/PublicProsecutor/Tables/CasesForReview.tsx Updated import path for TagCaseState
apps/judicial-system/web/src/routes/PublicProsecutor/Tables/CasesReviewed.tsx Replaced Box with TagContainer for tag display
apps/judicial-system/web/src/routes/Shared/Cases/PrisonCases.tsx Added TagContainer import and modified rendering logic for case state

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.

@datadog-island-is
Copy link

datadog-island-is bot commented Jan 7, 2025

Datadog Report

Branch report: j-s/defender-table-refactoring
Commit report: f67c752
Test service: judicial-system-web

✅ 0 Failed, 333 Passed, 0 Skipped, 1m 16.03s Total Time
⬆️ Test Sessions change in coverage: 1 increased (+0.05%)

@oddsson oddsson changed the title J s/defender table refactoring chore(j-s): Move DefenderCasesTable to new table component Jan 7, 2025
Copy link

codecov bot commented Jan 7, 2025

Codecov Report

Attention: Patch coverage is 16.12903% with 26 lines in your changes missing coverage. Please review.

Project coverage is 35.71%. Comparing base (0cef683) to head (cc58ea4).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...s/Defender/Cases/components/DefenderCasesTable.tsx 0.00% 18 Missing ⚠️
...c/routes/PublicProsecutor/Tables/CasesReviewed.tsx 0.00% 5 Missing ⚠️
...components/Table/PastCasesTable/PastCasesTable.tsx 50.00% 1 Missing ⚠️
...ial-system/web/src/routes/Defender/Cases/Cases.tsx 0.00% 1 Missing ⚠️
...system/web/src/routes/Shared/Cases/PrisonCases.tsx 0.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #17420      +/-   ##
==========================================
+ Coverage   35.60%   35.71%   +0.11%     
==========================================
  Files        7018     6974      -44     
  Lines      150426   149497     -929     
  Branches    42976    42821     -155     
==========================================
- Hits        53552    53397     -155     
+ Misses      96874    96100     -774     
Flag Coverage Δ
application-templates-new-primary-school ?
judicial-system-web 27.93% <16.12%> (+0.05%) ⬆️

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

Files with missing lines Coverage Δ
...nu/ContextMenuOptions/WithdrawAppealMenuOption.tsx 40.54% <100.00%> (+1.65%) ⬆️
...-system/web/src/components/PageTitle/PageTitle.tsx 71.42% <ø> (ø)
.../components/Tags/TagAppealState/TagAppealState.tsx 3.44% <ø> (ø)
...mponents/Tags/TagCaseState/TagCaseState.strings.ts 100.00% <ø> (ø)
.../src/components/Tags/TagCaseState/TagCaseState.tsx 76.92% <ø> (ø)
.../src/components/Tags/TagContainer/TagContainer.tsx 100.00% <100.00%> (ø)
...es/PublicProsecutor/Tables/CasesAwaitingReview.tsx 5.55% <ø> (ø)
.../routes/PublicProsecutor/Tables/CasesForReview.tsx 0.00% <ø> (ø)
...components/Table/PastCasesTable/PastCasesTable.tsx 81.48% <50.00%> (-1.28%) ⬇️
...ial-system/web/src/routes/Defender/Cases/Cases.tsx 0.00% <0.00%> (ø)
... and 3 more

... and 142 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 0cef683...cc58ea4. Read the comment docs.

@oddsson oddsson marked this pull request as ready for review January 7, 2025 10:36
@oddsson oddsson requested a review from a team as a code owner January 7, 2025 10:36
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 (2)
apps/judicial-system/web/src/routes/Defender/Cases/components/DefenderCasesTable.tsx (1)

96-101: Simplify ColumnCaseType props by passing only type

Based on prior implementations and retrieved learnings, it's sufficient to pass only the type prop to ColumnCaseType. The decision and parentCaseId props may not be necessary and can be omitted to simplify the component usage.

This suggestion is informed by learnings from previous pull requests.

Apply this diff to simplify the props:

<ColumnCaseType
  type={row.type}
- decision={row.decision}
- parentCaseId={row.parentCaseId}
/>
apps/judicial-system/web/src/routes/Defender/Cases/Cases.tsx (1)

21-21: Simplify component type declaration

Removed the unnecessary generic type parameter <unknown> from the FC type. Using FC without a type parameter is appropriate when the component does not have explicit props.

Apply this diff to simplify the type declaration:

-export const Cases: FC<unknown> = () => {
+export const Cases: FC = () => {
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 50422b0 and a67179b.

📒 Files selected for processing (4)
  • apps/judicial-system/web/src/components/ContextMenu/ContextMenuOptions/WithdrawAppealMenuOption.tsx (1 hunks)
  • apps/judicial-system/web/src/routes/Defender/Cases/Cases.tsx (2 hunks)
  • apps/judicial-system/web/src/routes/Defender/Cases/components/DefenderCasesTable.css.ts (0 hunks)
  • apps/judicial-system/web/src/routes/Defender/Cases/components/DefenderCasesTable.tsx (2 hunks)
💤 Files with no reviewable changes (1)
  • apps/judicial-system/web/src/routes/Defender/Cases/components/DefenderCasesTable.css.ts
🧰 Additional context used
📓 Path-based instructions (3)
apps/judicial-system/web/src/components/ContextMenu/ContextMenuOptions/WithdrawAppealMenuOption.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/Defender/Cases/Cases.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/Defender/Cases/components/DefenderCasesTable.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/Defender/Cases/Cases.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.
🔇 Additional comments (2)
apps/judicial-system/web/src/routes/Defender/Cases/components/DefenderCasesTable.tsx (1)

106-123: LGTM!

The use of Box with flexWrap="wrap" ensures that tags are displayed side by side when space allows and wrap to multiple lines when needed, enhancing responsiveness and user experience.

apps/judicial-system/web/src/components/ContextMenu/ContextMenuOptions/WithdrawAppealMenuOption.tsx (1)

45-45: Enhance readability by introducing isDefence variable

Storing the result of isDefenceUser(user) in the isDefence variable improves readability and avoids redundant function calls within the condition.

Copy link
Member

@thorhildurt thorhildurt left a comment

Choose a reason for hiding this comment

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

Niice! Looks good to me, only had one non-blocking question and then I noticed this when testing the checkbox selection:
Screenshot 2025-01-08 at 11 20 40
When there are cases assigned to a defender, for a given selection combo, we only show the header. Not sure if we want that or if we rather want to show the standard info alert when no cases exist for a given selection?

@oddsson oddsson requested a review from thorhildurt January 13, 2025 14:06
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 (3)
apps/judicial-system/web/src/routes/Defender/Cases/components/DefenderCasesTable.tsx (3)

26-29: Add JSDoc documentation for the Props interface.

Consider adding JSDoc documentation to describe the purpose of each prop and their expected values. This would improve maintainability and help other developers understand the component's API better.

+/**
+ * Props for the DefenderCasesTable component
+ * @property {CaseListEntry[]} cases - Array of cases to display in the table
+ * @property {boolean} [showingCompletedCases] - Flag to indicate if completed cases are being displayed
+ */
interface Props {
  cases: CaseListEntry[]
  showingCompletedCases?: boolean
}

47-81: Consider memoizing the table configuration.

The table header configuration and context menu items generator could be memoized to prevent unnecessary re-renders.

+const tableHeaders = useMemo(
+  () => [
+    {
+      title: formatMessage(tables.caseNumber),
+    },
+    // ... rest of the headers
+  ],
+  [formatMessage, showingCompletedCases]
+);

+const generateContextMenuItems = useCallback(
+  (row: CaseListEntry) => [
+    openCaseInNewTabMenuItem(row.id),
+    ...(shouldDisplayWithdrawAppealOption(row)
+      ? [withdrawAppealMenuOption(row.id)]
+      : []),
+  ],
+  [openCaseInNewTabMenuItem, shouldDisplayWithdrawAppealOption, withdrawAppealMenuOption]
+);

82-147: Enhance accessibility with ARIA labels.

Add appropriate ARIA labels to improve accessibility for screen readers, especially for interactive elements and status indicators.

 {
   cell: (row) => (
     <TagContainer>
       <TagCaseState
+        aria-label={`Case state: ${row.state}`}
         caseState={row.state}
         // ... other props
       />
       {row.appealState && (
         <TagAppealState
+          aria-label={`Appeal state: ${row.appealState}`}
           appealState={row.appealState}
           // ... other props
         />
       )}
     </TagContainer>
   ),
 }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a67179b and e6d168f.

📒 Files selected for processing (10)
  • apps/judicial-system/web/src/components/PageTitle/PageTitle.tsx (1 hunks)
  • apps/judicial-system/web/src/components/Table/PastCasesTable/PastCasesTable.tsx (2 hunks)
  • apps/judicial-system/web/src/components/Tags/TagAppealState/TagAppealState.tsx (1 hunks)
  • apps/judicial-system/web/src/components/Tags/TagContainer/TagContainer.tsx (1 hunks)
  • apps/judicial-system/web/src/components/index.ts (1 hunks)
  • apps/judicial-system/web/src/routes/Defender/Cases/components/DefenderCasesTable.tsx (2 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/PublicProsecutor/Tables/CasesReviewed.tsx (3 hunks)
  • apps/judicial-system/web/src/routes/Shared/Cases/PrisonCases.tsx (2 hunks)
✅ Files skipped from review due to trivial changes (6)
  • apps/judicial-system/web/src/components/PageTitle/PageTitle.tsx
  • apps/judicial-system/web/src/components/Tags/TagContainer/TagContainer.tsx
  • apps/judicial-system/web/src/routes/PublicProsecutor/Tables/CasesForReview.tsx
  • apps/judicial-system/web/src/components/Tags/TagAppealState/TagAppealState.tsx
  • apps/judicial-system/web/src/components/index.ts
  • apps/judicial-system/web/src/routes/PublicProsecutor/Tables/CasesAwaitingReview.tsx
🧰 Additional context used
📓 Path-based instructions (4)
apps/judicial-system/web/src/routes/Shared/Cases/PrisonCases.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/components/Table/PastCasesTable/PastCasesTable.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/Defender/Cases/components/DefenderCasesTable.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/Tables/CasesReviewed.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 (2)
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/PublicProsecutor/Tables/CasesReviewed.tsx (1)
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.
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: tests (judicial-system-backend)
🔇 Additional comments (3)
apps/judicial-system/web/src/routes/Defender/Cases/components/DefenderCasesTable.tsx (1)

4-24: LGTM! Well-organized imports.

The imports are logically grouped and follow the project structure correctly. All imported components and utilities are properly utilized in the implementation.

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

119-141: Clean refactor using TagContainer!

The replacement of the Box component with TagContainer improves the semantic structure while maintaining the existing conditional rendering logic.

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

161-182: Consistent implementation of TagContainer!

The refactor maintains the existing business logic while improving the semantic structure of the tag grouping.

Copy link
Member

@thorhildurt thorhildurt left a comment

Choose a reason for hiding this comment

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

Looks good, just one formatting issue raised from the bunny

@oddsson oddsson added the deprecated:automerge (Disabled) Merge this PR as soon as all checks pass label Jan 16, 2025
@kodiakhq kodiakhq bot merged commit b249dfa into main Jan 17, 2025
34 checks passed
@kodiakhq kodiakhq bot deleted the j-s/defender-table-refactoring branch January 17, 2025 08:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deprecated:automerge (Disabled) Merge this PR as soon as all checks pass
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants