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

fix(j-s): Double service not required #16934

Closed
wants to merge 28 commits into from

Conversation

oddsson
Copy link
Member

@oddsson oddsson commented Nov 19, 2024

Double service not required

Asana

What

When a service is not required, we'd show "Birting dóms ekki þörf" twice in some info cards. This has now been fixed.

Why

It's a bug

Screenshots / Gifs

Before

Screenshot 2024-11-19 at 10 32 15

After

Screenshot 2024-11-19 at 10 31 47

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 display of appeal expiration information for defendants.
    • Enhanced clarity in the presentation of the defender's information.
    • Simplified rendering logic for past cases, improving usability.
  • Bug Fixes

    • Streamlined logic for displaying verdict view dates, ensuring accuracy in relevant cases.
    • Removed unnecessary loading states for the past cases table, enhancing performance.

@oddsson oddsson requested review from a team as code owners November 19, 2024 10:33
@oddsson oddsson requested a review from stjanilofts November 19, 2024 10:33
Copy link
Contributor

coderabbitai bot commented Nov 19, 2024

Walkthrough

The pull request introduces several modifications across multiple components in the judicial system application. Key changes include the removal of the serviceNotRequired parameter from the getVerdictViewDateText function in the DefendantInfo component, simplifying its signature and refining the rendering logic for appeal expiration information. The MobilePastCase component has been removed entirely. The PastCasesTable component has been updated to streamline props and eliminate unnecessary sorting logic, while the Table component has added new utility functions for rendering case-related information. Additionally, several style declarations have been removed from Table.css.ts.

Changes

File Path Change Summary
apps/judicial-system/web/src/components/InfoCard/DefendantInfo/DefendantInfo.tsx - Removed serviceNotRequired parameter from getVerdictViewDateText function.
- Altered rendering logic for appeal expiration information.
- Refined conditions for displaying verdict view date.
- Improved clarity and conciseness of the defender's information display.
apps/judicial-system/web/src/components/Table/PastCasesTable/MobilePastCase.tsx - Component MobilePastCase removed.
apps/judicial-system/web/src/components/Table/PastCasesTable/PastCasesTable.tsx - Removed optional loading and testid properties from props.
- Streamlined rendering logic using cases prop directly.
- Integrated context menu functionality into the Table component.
apps/judicial-system/web/src/components/Table/Table.css.ts - Removed styles: largeColumn, row, and loadingContainer.
apps/judicial-system/web/src/components/Table/Table.tsx - Added functions: handleCaseClick, renderProsecutorText, renderPostponedOrCourtDateText, renderDurationDate.
apps/judicial-system/web/src/routes/Shared/Cases/ActiveCases.tsx - Simplified return statement in generateContextMenuItems function.
apps/judicial-system/web/src/routes/Shared/Cases/Cases.tsx - Removed loading and testid props from PastCasesTable rendering.

Possibly related PRs

  • feat(j-s): Public defender staff overview after review #14848: This PR modifies the DefendantInfo component, which is directly related to the changes made in the main PR regarding the display of defendant information and verdict view dates.
  • feat(j-s): Indictment View Tag #14922: This PR adds a new optional prop displayAppealExpirationInfo to the DefendantInfo component, which aligns with the changes in the main PR that also involve rendering logic for appeal expiration information.
  • fix(j-s): Display correct verdict appeal info for defenders  #16533: This PR focuses on displaying the correct verdict appeal information for defenders, which is closely related to the changes in the main PR that involve the logic for rendering verdict view dates based on service requirements.
  • fix(j-s): Fix InfoCard #16830: This PR addresses the display of service requirements for prosecutors, which is relevant to the changes in the main PR that involve the rendering logic for the DefendantInfo component and its handling of service requirements.

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 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.

@oddsson oddsson removed request for a team and stjanilofts November 19, 2024 10:34
Copy link

codecov bot commented Nov 19, 2024

Codecov Report

Attention: Patch coverage is 20.00000% with 4 lines in your changes missing coverage. Please review.

Project coverage is 36.46%. Comparing base (b3e05fd) to head (2c70c10).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
...omponents/InfoCard/DefendantInfo/DefendantInfo.tsx 20.00% 4 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main   #16934   +/-   ##
=======================================
  Coverage   36.46%   36.46%           
=======================================
  Files        6903     6903           
  Lines      144583   144604   +21     
  Branches    41283    41289    +6     
=======================================
+ Hits        52718    52726    +8     
- Misses      91865    91878   +13     
Flag Coverage Δ
air-discount-scheme-web 0.00% <ø> (ø)
api 3.34% <ø> (ø)
application-api-files 62.35% <ø> (ø)
application-core 71.06% <ø> (+0.07%) ⬆️
application-system-api 41.02% <ø> (ø)
application-template-api-modules 27.73% <ø> (ø)
application-templates-accident-notification 28.98% <ø> (ø)
application-templates-car-recycling 3.12% <ø> (ø)
application-templates-criminal-record 25.87% <ø> (ø)
application-templates-driving-license 18.14% <ø> (ø)
application-templates-estate 12.14% <ø> (ø)
application-templates-example-payment 24.80% <ø> (ø)
application-templates-financial-aid 15.48% <ø> (ø)
application-templates-general-petition 23.07% <ø> (ø)
application-templates-inheritance-report 6.52% <ø> (ø)
application-templates-marriage-conditions 15.04% <ø> (ø)
application-templates-mortgage-certificate 43.36% <ø> (ø)
application-templates-parental-leave 29.86% <ø> (ø)
application-types 6.60% <ø> (ø)
application-ui-components 1.27% <ø> (ø)
application-ui-shell 20.82% <ø> (-0.02%) ⬇️
clients-charge-fjs-v2 24.11% <ø> (ø)
judicial-system-web 27.16% <20.00%> (ø)
services-endorsements-api 53.21% <ø> (ø)
web 1.77% <ø> (ø)

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

Files with missing lines Coverage Δ
...omponents/InfoCard/DefendantInfo/DefendantInfo.tsx 75.60% <20.00%> (ø)

... and 3 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 b3e05fd...2c70c10. Read the comment docs.

---- 🚨 Try these New Features:

@datadog-island-is
Copy link

datadog-island-is bot commented Nov 19, 2024

Datadog Report

Branch report: j-s/duplicate-service-not-required
Commit report: b203561
Test service: judicial-system-web

❌ 4 Failed (0 Known Flaky), 329 Passed, 0 Skipped, 56.05s Total Time
🔻 Test Sessions change in coverage: 1 decreased (-0.16%)

❌ Failed Tests (4)

  • Cases All user types - sorting should order the table data by accused name in ascending order when the user clicks the accused name table header - apps/judicial-system/web/src/routes/Shared/Cases/Cases.spec.tsx - Details

    Expand for error
     expect(element).toHaveTextContent()
     
     Expected element to have text content:
       D. M. Kil
     Received:
       stringJon Harring Sr.kt. stringÓþekkt16.9.2020DrögOpna mál í nýjum flipa
    
  • Cases All user types - sorting should order the table data by accused name in descending order when the user clicks the accused name table header twice - apps/judicial-system/web/src/routes/Shared/Cases/Cases.spec.tsx - Details

    Expand for error
     expect(element).toHaveTextContent()
     
     Expected element to have text content:
       D. M. Kil
     Received:
       stringJon Harring Sr.kt. stringÓþekkt16.9.2020DrögOpna mál í nýjum flipa
    
  • Cases All user types - sorting should order the table data by created in acending order when the user clicks the created table header twice - apps/judicial-system/web/src/routes/Shared/Cases/Cases.spec.tsx - Details

    Expand for error
     expect(element).toHaveTextContent()
     
     Expected element to have text content:
       Erlingur L Kristinsson
     Received:
       stringJon Harring Sr.kt. stringÓþekkt16.9.2020DrögOpna mál í nýjum flipa
    
  • Cases All user types - sorting should order the table data by created in ascending order when the user clicks the created table header - apps/judicial-system/web/src/routes/Shared/Cases/Cases.spec.tsx - Details

    Expand for error
     expect(element).toHaveTextContent()
     
     Expected element to have text content:
       Erlingur L Kristinsson
     Received:
       stringJon Harring Sr.kt. stringÓþekkt16.9.2020DrögOpna mál í nýjum flipa
    

🔻 Code Coverage Decreases vs Default Branch (1)

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 (1)
apps/judicial-system/web/src/components/InfoCard/DefendantInfo/DefendantInfo.tsx (1)

135-141: Consider simplifying the conditional logic.

While the current implementation correctly fixes the duplicate message issue, we can improve readability by combining the conditions.

Consider this refactor:

-      {displayVerdictViewDate &&
-        defendant.serviceRequirement &&
-        defendant.serviceRequirement !== ServiceRequirement.NOT_REQUIRED && (
+      {displayVerdictViewDate && defendant.serviceRequirement === ServiceRequirement.REQUIRED && (
         <Text marginTop={1} fontWeight="semiBold">
           {getVerdictViewDateText(formatMessage, defendant.verdictViewDate)}
         </Text>
       )}

This change:

  1. Simplifies the conditions by using a direct equality check
  2. Makes the intent clearer - we only show the verdict view date when service is explicitly required
  3. Maintains the same functionality while being more concise
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 910627c and 2c70c10.

📒 Files selected for processing (1)
  • apps/judicial-system/web/src/components/InfoCard/DefendantInfo/DefendantInfo.tsx (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
apps/judicial-system/web/src/components/InfoCard/DefendantInfo/DefendantInfo.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/components/InfoCard/DefendantInfo/DefendantInfo.tsx (2)
Learnt from: oddsson
PR: island-is/island.is#15461
File: apps/judicial-system/web/src/components/InfoCard/DefendantInfo/DefendantInfo.tsx:36-62
Timestamp: 2024-11-12T15:15:11.835Z
Learning: The user prefers readability over optimization in the `getAppealExpirationInfo` function within `DefendantInfo.tsx`.
Learnt from: unakb
PR: island-is/island.is#14922
File: apps/judicial-system/web/src/components/InfoCard/DefendantInfo/DefendantInfo.tsx:43-49
Timestamp: 2024-11-12T15:15:20.157Z
Learning: The `getAppealExpirationInfo` function in `DefendantInfo.tsx` correctly uses `today < expiryDate` to determine if the current date is before the appeal expiration date.
🔇 Additional comments (1)
apps/judicial-system/web/src/components/InfoCard/DefendantInfo/DefendantInfo.tsx (1)

129-132: LGTM! Clean and readable implementation.

The simplified component structure improves readability while maintaining the same functionality.

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

🧹 Outside diff range and nitpick comments (3)
apps/judicial-system/web/src/routes/Shared/Cases/ActiveCases.tsx (1)

60-73: LGTM! Consider enhancing type safety.

The simplified arrow function with implicit return improves readability while maintaining the same functionality. The conditional menu items are handled correctly using the spread operator.

Consider adding explicit return type for better type safety:

-      generateContextMenuItems={(row) => [
+      generateContextMenuItems={(row): ContextMenuItem[] => [
apps/judicial-system/web/src/components/Table/Table.tsx (2)

101-105: LGTM: Well-structured click handler with good separation of concerns

Consider adding TypeScript return type annotation for better type safety:

-  const handleCaseClick = (theCase: CaseListEntry) => {
+  const handleCaseClick = (theCase: CaseListEntry): void => {

125-146: Consider extracting date formatting logic

The court date formatting logic could be moved to a separate utility function to improve reusability and testing.

+ const formatCourtDateTime = (date: string): string => {
+   const parsedDate = parseISO(date)
+   return `${formatMessage(strings.hearing)} ${formatDate(parsedDate, 'd.M.y')} kl. ${formatDate(parsedDate, 'kk:mm')}`
+ }

  const renderPostponedOrCourtDateText = (
    postponedIndefinitelyExplanation?: string | null,
    caseState?: CaseState | null,
    courtDate?: string | null,
  ) => {
    if (postponedIndefinitelyExplanation) {
      return <Text>{formatMessage(strings.postponed)}</Text>
    }

    if (!isCompletedCase(caseState) && courtDate) {
      return (
        <Text fontWeight="medium" variant="small">
-         {`${formatMessage(strings.hearing)} ${formatDate(
-           parseISO(courtDate),
-           'd.M.y',
-         )} kl. ${formatDate(parseISO(courtDate), 'kk:mm')}`}
+         {formatCourtDateTime(courtDate)}
        </Text>
      )
    }

    return null
  }
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 2c70c10 and cf955e3.

📒 Files selected for processing (6)
  • apps/judicial-system/web/src/components/Table/PastCasesTable/MobilePastCase.tsx (0 hunks)
  • apps/judicial-system/web/src/components/Table/PastCasesTable/PastCasesTable.tsx (3 hunks)
  • apps/judicial-system/web/src/components/Table/Table.css.ts (0 hunks)
  • apps/judicial-system/web/src/components/Table/Table.tsx (5 hunks)
  • apps/judicial-system/web/src/routes/Shared/Cases/ActiveCases.tsx (1 hunks)
  • apps/judicial-system/web/src/routes/Shared/Cases/Cases.tsx (1 hunks)
💤 Files with no reviewable changes (2)
  • apps/judicial-system/web/src/components/Table/PastCasesTable/MobilePastCase.tsx
  • apps/judicial-system/web/src/components/Table/Table.css.ts
✅ Files skipped from review due to trivial changes (1)
  • apps/judicial-system/web/src/routes/Shared/Cases/Cases.tsx
🧰 Additional context used
📓 Path-based instructions (3)
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/components/Table/Table.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/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."
📓 Learnings (1)
apps/judicial-system/web/src/components/Table/PastCasesTable/PastCasesTable.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 (5)
apps/judicial-system/web/src/components/Table/Table.tsx (5)

10-15: LGTM: Well-structured type imports

The new imports enhance type safety and provide clear domain-specific utilities for case type checking.


107-123: LGTM: Clear prosecutor text rendering logic

The function has good null handling and clear conditions.


148-169: LGTM: Well-structured duration date rendering

Good use of type guards and clear conditional logic.


204-220: LGTM: Consistent mobile implementation

Good use of the new rendering functions with proper prop passing.


260-260: LGTM: Consistent click handling in desktop view

The implementation maintains consistency with the mobile view.

Comment on lines +95 to +98
<ColumnCaseType
type={row.type}
decision={row.decision}
parentCaseId={row.parentCaseId}
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

Remove unnecessary props from ColumnCaseType component

According to previous implementations and retrieved learnings, the ColumnCaseType component should only receive the type prop. The decision and parentCaseId props are not required and can be removed to simplify the component interface.

Apply this diff to remove the unnecessary props:

-<ColumnCaseType
-  type={row.type}
-  decision={row.decision}
-  parentCaseId={row.parentCaseId}
-/>
+<ColumnCaseType
+  type={row.type}
+/>
📝 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
<ColumnCaseType
type={row.type}
decision={row.decision}
parentCaseId={row.parentCaseId}
<ColumnCaseType
type={row.type}

@oddsson oddsson closed this Nov 19, 2024
@oddsson oddsson deleted the j-s/duplicate-service-not-required branch November 19, 2024 14:31
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.

2 participants