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): Fix InfoCard #16830

Merged
merged 25 commits into from
Nov 13, 2024
Merged

fix(j-s): Fix InfoCard #16830

merged 25 commits into from
Nov 13, 2024

Conversation

oddsson
Copy link
Member

@oddsson oddsson commented Nov 12, 2024

Fix InfoCard

Asana

What

We are currently showing the service requirement for prosecutors in incomplete cases. This pr fixes that. Now, we only show the service requirement if the court has selected the service requirement.

Why

It's a bug

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

    • Enhanced rendering of defendant information with clearer logic for displaying defender details.
  • Bug Fixes

    • Improved clarity in modal state management for indictment actions.
  • Refactor

    • Streamlined rendering logic in the DefendantInfo and Overview components, enhancing maintainability and clarity.
  • Tests

    • Adjusted assertion logic in test cases for the InfoCard component to improve specificity and correctness.

@oddsson oddsson requested review from a team as code owners November 12, 2024 21:42
@oddsson oddsson requested a review from johannaagma November 12, 2024 21:42
Copy link
Contributor

coderabbitai bot commented Nov 12, 2024

Walkthrough

The pull request introduces modifications to the DefendantInfo and Overview components. In DefendantInfo.tsx, new variables are added to streamline the rendering of defender information, and the logic for displaying the verdict view date is updated. In Overview.tsx, the rendering logic and modal state handling are refined, improving clarity without altering existing functionalities. Both components see enhancements aimed at simplifying their respective structures and improving maintainability.

Changes

File Change Summary
apps/judicial-system/web/src/components/InfoCard/DefendantInfo/DefendantInfo.tsx Added hasDefender and defenderLabel variables; refactored rendering logic for defender information; updated verdict view date condition.
apps/judicial-system/web/src/routes/Prosecutor/Indictments/Overview/Overview.tsx Simplified displayVerdictViewDate prop; refined modal type handling in handleNextButtonClick; preserved existing modal rendering logic.
apps/judicial-system/web/src/components/InfoCard/InfoCard.spec.tsx Modified test assertions for InfoCard; corrected nesting issue in test cases; enhanced specificity of assertions.

Possibly related PRs

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.

Copy link

codecov bot commented Nov 12, 2024

Codecov Report

Attention: Patch coverage is 90.00000% with 1 line in your changes missing coverage. Please review.

Project coverage is 36.44%. Comparing base (8e604b7) to head (efb9fea).
Report is 1 commits behind head on main.

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

Impacted file tree graph

@@           Coverage Diff           @@
##             main   #16830   +/-   ##
=======================================
  Coverage   36.43%   36.44%           
=======================================
  Files        6852     6852           
  Lines      143524   143480   -44     
  Branches    40961    40934   -27     
=======================================
- Hits        52300    52291    -9     
+ Misses      91224    91189   -35     
Flag Coverage Δ
download-service 44.13% <ø> (ø)
judicial-system-web 27.13% <90.00%> (+<0.01%) ⬆️

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

Files with missing lines Coverage Δ
...outes/Prosecutor/Indictments/Overview/Overview.tsx 0.00% <ø> (ø)
...omponents/InfoCard/DefendantInfo/DefendantInfo.tsx 75.60% <90.00%> (+0.60%) ⬆️

... and 4 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 8e604b7...efb9fea. Read the comment docs.

@datadog-island-is
Copy link

datadog-island-is bot commented Nov 12, 2024

Datadog Report

All test runs 0dc126c 🔗

2 Total Test Services: 0 Failed, 2 Passed
⬆️ Test Sessions change in coverage: 1 increased (+0.04%), 1 no change

Test Services
Service Name Failed Known Flaky New Flaky Passed Skipped Total Time Code Coverage Change Test Service View
download-service 0 0 0 1 0 20.83s 1 no change Link
judicial-system-web 0 0 0 333 0 1m 14.03s 1 increased (+0.04%) Link

@oddsson oddsson removed request for a team and johannaagma November 13, 2024 09: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: 0

🧹 Outside diff range and nitpick comments (1)
apps/judicial-system/web/src/components/InfoCard/DefendantInfo/DefendantInfo.tsx (1)

116-130: Consider removing explicit whitespace handling

While the defender info rendering is well-structured, the explicit whitespace handling with whiteSpace="pre" might not be necessary. Consider letting the UI component handle the spacing naturally.

-        <Text as="span" whiteSpace="pre" fontWeight="semiBold">
+        <Text as="span" fontWeight="semiBold">
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between c40a213 and 6081f15.

📒 Files selected for processing (2)
  • apps/judicial-system/web/src/components/InfoCard/DefendantInfo/DefendantInfo.tsx (3 hunks)
  • apps/judicial-system/web/src/routes/Prosecutor/Indictments/Overview/Overview.tsx (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
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."
apps/judicial-system/web/src/routes/Prosecutor/Indictments/Overview/Overview.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/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:20.157Z
Learning: The user prefers readability over optimization in the `getAppealExpirationInfo` function within `DefendantInfo.tsx`.
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`.
apps/judicial-system/web/src/routes/Prosecutor/Indictments/Overview/Overview.tsx (5)
Learnt from: oddsson
PR: island-is/island.is#16731
File: apps/judicial-system/web/src/routes/Shared/IndictmentOverview/IndictmentOverview.tsx:172-186
Timestamp: 2024-11-12T15:15:20.157Z
Learning: In `IndictmentOverview.tsx`, since the defendants data does not change, using `useMemo` to memoize the filtering logic is unnecessary.
Learnt from: unakb
PR: island-is/island.is#14712
File: apps/judicial-system/web/src/routes/PublicProsecutor/Indictments/Overview/IndictmentOverview.tsx:0-0
Timestamp: 2024-11-12T15:15:11.835Z
Learning: The judicial system application uses a toaster notification system to handle errors globally.
Learnt from: unakb
PR: island-is/island.is#14712
File: apps/judicial-system/web/src/routes/PublicProsecutor/Indictments/Overview/IndictmentOverview.tsx:0-0
Timestamp: 2024-11-12T15:15:11.835Z
Learning: The judicial system application uses a toaster notification system to handle errors globally.
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.
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.
🔇 Additional comments (3)
apps/judicial-system/web/src/components/InfoCard/DefendantInfo/DefendantInfo.tsx (2)

78-87: Well-structured defender information handling!

The introduction of these variables improves code readability and maintainability by consolidating the defender information logic. The TypeScript types are properly maintained, ensuring type safety.


Line range hint 140-147: Correctly implements the service requirement display fix

The additional check for defendant.serviceRequirement properly addresses the PR objective, ensuring the verdict view date is only displayed when the service requirement is selected.

Let's verify this change doesn't affect other components:

✅ Verification successful

The service requirement check is correctly implemented and verified

The additional check for defendant.serviceRequirement in the verdict view date display is properly implemented and consistent with the codebase:

  • The test file confirms proper handling of all service requirement states (REQUIRED, NOT_REQUIRED, NOT_APPLICABLE)
  • The Completed.tsx component shows service requirement is a required field for rulings
  • BlueBoxWithDate.tsx demonstrates consistent usage of the service requirement check for verdict view date display
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for other components that might be affected by this change
rg -l "serviceRequirement" --type ts --type tsx

# Search for test files that should be updated
rg -l "DefendantInfo.*verdictViewDate" --type test

Length of output: 157


Script:

#!/bin/bash
# Search for files containing serviceRequirement
rg -l "serviceRequirement"

# Search for test files containing DefendantInfo and verdictViewDate
rg -l "DefendantInfo.*verdictViewDate" --type-list
rg -l "DefendantInfo.*verdictViewDate"

Length of output: 1622


Script:

#!/bin/bash
# Check the test file for verdict view date related tests
cat apps/judicial-system/web/src/components/InfoCard/DefendantInfo/DefendantInfo.spec.ts

# Check other components that use serviceRequirement for potential impacts
cat apps/judicial-system/web/src/routes/Court/Indictments/Completed/Completed.tsx
cat apps/judicial-system/web/src/components/BlueBoxWithIcon/BlueBoxWithDate.tsx

Length of output: 25241

apps/judicial-system/web/src/routes/Prosecutor/Indictments/Overview/Overview.tsx (1)

228-228: Verify the service requirements display logic

While the shorthand syntax for displayVerdictViewDate is valid, let's verify that this change correctly addresses the core issue of displaying service requirements only when selected by the court.

Let's analyze the InfoCard component implementation:

@oddsson oddsson added the automerge Merge this PR as soon as all checks pass label Nov 13, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (3)
apps/judicial-system/web/src/components/InfoCard/InfoCard.spec.tsx (3)

Line range hint 89-134: Fix nested render calls in test case

There's a critical issue with nested render calls in the test "should display the assigned defender name, email and phonenumber if that info is provided". This will create multiple test environments and may cause unreliable results.

Apply this fix to remove the nested render:

test('should display the assigned defender name, email and phonenumber if that info is provided', async () => {
  // Arrange
  render(
    <MockedProvider>
      <LocaleProvider locale="is" messages={{}}>
-       render(
-       <MockedProvider>
-         <LocaleProvider locale="is" messages={{}}>
          <InfoCard
            sections={[
              {
                id: 'sec_id',
                items: [
                  {
                    id: 'itm_id',
                    title: 'Titill',
                    values: [
                      <DefendantInfo
                        defendant={{
                          id: 'def_id',
                          defenderName: 'Joe',
                          defenderEmail: '[email protected]',
                          defenderPhoneNumber: '455-5544',
                        }}
                      />,
                    ],
                  },
                ],
              },
            ]}
          />
-         </LocaleProvider>
-       </MockedProvider>
-       , )
      </LocaleProvider>
    </MockedProvider>,
  )

Line range hint 35-36: Standardize assertion methods across tests

The tests use inconsistent assertion styles. Some use direct text matching while others use content matching functions. For better maintainability and reliability, we should standardize on using the content matching approach.

Standardize all assertions to use the content matching pattern:

- expect(await screen.findByText('Joe')).toBeTruthy()
+ expect(
+   await screen.findByText(
+     (_, element) => element?.textContent === 'Joe',
+   ),
+ ).toBeTruthy()

Also applies to: 73-77, 127-132, 152-155


Line range hint 9-10: Enhance test coverage with edge cases and accessibility tests

While the basic defender information scenarios are covered, consider adding:

  1. Tests for error states (e.g., malformed defender data)
  2. Accessibility tests using jest-axe
  3. Edge cases (e.g., very long defender names/emails)

Would you like me to provide examples of these additional test cases?

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 6081f15 and 7730bbe.

📒 Files selected for processing (1)
  • apps/judicial-system/web/src/components/InfoCard/InfoCard.spec.tsx (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
apps/judicial-system/web/src/components/InfoCard/InfoCard.spec.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."

@thordurhhh thordurhhh added automerge Merge this PR as soon as all checks pass and removed automerge Merge this PR as soon as all checks pass labels Nov 13, 2024
@kodiakhq kodiakhq bot merged commit f27b1ba into main Nov 13, 2024
34 checks passed
@kodiakhq kodiakhq bot deleted the j-s/fix-info-card branch November 13, 2024 11:54
jonnigs pushed a commit that referenced this pull request Nov 26, 2024
* Checkpoint

* Refactor AlertMessage

* Format date

* Cleanup

* Cleanup

* Merge

* Add key

* Refactor

* Remove console.log

* Refactoring

* Merge

* Show to prosecutors

* Fix tests

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
Co-authored-by: Guðjón Guðjónsson <[email protected]>
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.

4 participants