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): Generated PDFs #16625

Merged
merged 2 commits into from
Oct 29, 2024
Merged

fix(j-s): Generated PDFs #16625

merged 2 commits into from
Oct 29, 2024

Conversation

gudjong
Copy link
Member

@gudjong gudjong commented Oct 29, 2024

Generated PDFs

Yfirlit sækjanda að máli loknu - engin generated skjöl birtast

What

  • Shows generated PDF files to prosecutors in completed indictment cases.

Why

  • Verified bug.

Screenshots / Gifs

image

Checklist:

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • Formatting passes locally with my changes
  • I have rebased against main before asking for a review

Summary by CodeRabbit

  • New Features

    • Unconditional rendering of the IndictmentCaseFilesList component in the Indictment Overview, improving visibility of case files.
    • Enhanced role-based access control for displaying generated PDF files based on user roles.
  • Bug Fixes

    • Simplified rendering logic for the IndictmentCaseFilesList, ensuring consistent behavior regardless of case file presence.
  • Documentation

    • Updated comments to clarify changes in date handling for verdict viewing.

@gudjong gudjong requested a review from a team as a code owner October 29, 2024 14:07
Copy link
Contributor

coderabbitai bot commented Oct 29, 2024

Walkthrough

The pull request introduces changes across three components: IndictmentOverview, Overview, and IndictmentCaseFilesList. The primary modification involves the unconditional rendering of the IndictmentCaseFilesList component, which previously depended on the presence of workingCase.caseFiles. Additionally, there are updates to user role checks and variable names in the IndictmentOverview component. Commented-out sections related to future features have been noted but do not impact current functionality. Overall, the modifications streamline rendering logic while preserving component structure and existing functionalities.

Changes

File Change Summary
apps/judicial-system/web/src/routes/Court/Indictments/Overview/Overview.tsx Unconditional rendering of IndictmentCaseFilesList; commented-out sections noted.
apps/judicial-system/web/src/routes/PublicProsecutor/Indictments/Overview/Overview.tsx Simplified conditional rendering of IndictmentCaseFilesList; updated comment in handleDefendantViewsVerdict function.
apps/judicial-system/web/src/routes/Shared/IndictmentOverview/IndictmentOverview.tsx Added isProsecutionUser import; renamed shouldDisplayGeneratedPDFs to shouldDisplayGeneratedPdfFiles; updated logic for PDF visibility. Removed commented-out display logic.

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 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 Oct 29, 2024

Codecov Report

Attention: Patch coverage is 0% with 2 lines in your changes missing coverage. Please review.

Project coverage is 36.79%. Comparing base (701c1e8) to head (52b096d).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...s/Shared/IndictmentOverview/IndictmentOverview.tsx 0.00% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main   #16625   +/-   ##
=======================================
  Coverage   36.78%   36.79%           
=======================================
  Files        6855     6855           
  Lines      142315   142283   -32     
  Branches    40584    40571   -13     
=======================================
  Hits        52348    52348           
+ Misses      89967    89935   -32     
Flag Coverage Δ
judicial-system-web 27.73% <0.00%> (+<0.01%) ⬆️

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

Files with missing lines Coverage Δ
...src/routes/Court/Indictments/Overview/Overview.tsx 0.00% <ø> (ø)
...PublicProsecutor/Indictments/Overview/Overview.tsx 8.06% <ø> (+0.25%) ⬆️
...s/Shared/IndictmentOverview/IndictmentOverview.tsx 0.00% <0.00%> (ø)

... 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 701c1e8...52b096d. Read the comment docs.

@datadog-island-is
Copy link

datadog-island-is bot commented Oct 29, 2024

Datadog Report

Branch report: j-s/fix-indictment-files
Commit report: abb0f0c
Test service: judicial-system-web

✅ 0 Failed, 338 Passed, 0 Skipped, 1m 15.48s Total Time
🔻 Test Sessions change in coverage: 1 decreased (-0.01%)

🔻 Code Coverage Decreases vs Default Branch (1)

@gudjong gudjong added automerge Merge this PR as soon as all checks pass high priority VIP-Kodiak PR labels Oct 29, 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 (2)
apps/judicial-system/web/src/routes/Shared/IndictmentOverview/IndictmentOverview.tsx (1)

Line range hint 72-91: LGTM: Enhanced access control logic with improved naming.

The updated logic correctly implements the requirement to show generated PDF files to prosecutors while maintaining existing access for defenders and civil claimants. The variable renaming improves consistency.

Consider extracting complex conditions into separate helper functions for better readability:

const hasDefenderAccess = (defendant: Defendant) =>
  defendant.isDefenderChoiceConfirmed &&
  defendant.caseFilesSharedWithDefender &&
  defendant.defenderNationalId &&
  normalizeAndFormatNationalId(user?.nationalId).includes(
    defendant.defenderNationalId,
  )

const hasCivilClaimantAccess = (civilClaimant: CivilClaimant) =>
  civilClaimant.hasSpokesperson &&
  civilClaimant.isSpokespersonConfirmed &&
  civilClaimant.caseFilesSharedWithSpokesperson &&
  civilClaimant.spokespersonNationalId &&
  normalizeAndFormatNationalId(user?.nationalId).includes(
    civilClaimant.spokespersonNationalId,
  )

const shouldDisplayGeneratedPdfFiles =
  isProsecutionUser(user) ||
  workingCase.defendants?.some(hasDefenderAccess) ||
  workingCase.civilClaimants?.some(hasCivilClaimantAccess)
apps/judicial-system/web/src/routes/PublicProsecutor/Indictments/Overview/Overview.tsx (1)

168-170: Consider adding a comment explaining the unconditional rendering.

To improve code maintainability, consider adding a comment explaining why the IndictmentCaseFilesList is rendered unconditionally, as this is a significant change from the previous conditional rendering approach.

 <Box component="section" marginBottom={5}>
+  {/* Always render the files list to ensure visibility of generated PDFs,
+     empty states are handled within the component */}
   <IndictmentCaseFilesList workingCase={workingCase} />
 </Box>
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between b86cd04 and c6ab3ee.

📒 Files selected for processing (3)
  • apps/judicial-system/web/src/routes/Court/Indictments/Overview/Overview.tsx (1 hunks)
  • apps/judicial-system/web/src/routes/PublicProsecutor/Indictments/Overview/Overview.tsx (1 hunks)
  • apps/judicial-system/web/src/routes/Shared/IndictmentOverview/IndictmentOverview.tsx (3 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
apps/judicial-system/web/src/routes/Court/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."
apps/judicial-system/web/src/routes/PublicProsecutor/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."
apps/judicial-system/web/src/routes/Shared/IndictmentOverview/IndictmentOverview.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/Court/Indictments/Overview/Overview.tsx (2)
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-06-27T14:37:07.823Z
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-10-08T15:39:04.351Z
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/PublicProsecutor/Indictments/Overview/Overview.tsx (2)
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-06-27T14:37:07.823Z
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-10-08T15:39:04.351Z
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 (6)
apps/judicial-system/web/src/routes/Court/Indictments/Overview/Overview.tsx (2)

135-137: LGTM! Good fix for the PDF visibility issue.

The unconditional rendering of IndictmentCaseFilesList is a clean solution that properly delegates empty state handling to the component itself, improving separation of concerns.


135-137: Verify empty state handling in IndictmentCaseFilesList.

Since we're now always rendering the component, let's ensure it properly handles cases where workingCase.caseFiles is empty or undefined.

✅ Verification successful

Let me gather more information about the IndictmentCaseFilesList component to verify its empty state handling.


Let's examine the actual implementation of the IndictmentCaseFilesList component.


Empty state handling is properly implemented in IndictmentCaseFilesList

The component safely handles empty or undefined caseFiles through:

  • Optional chaining when filtering case files (e.g., cf?.filter())
  • Conditional rendering with null checks (e.g., indictments && indictments.length > 0)
  • Each section only renders when its corresponding files exist and have items
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if IndictmentCaseFilesList handles empty states

# Test: Look for empty state handling in the component
ast-grep --pattern 'export const IndictmentCaseFilesList = ({ workingCase }: Props) => {
  $$$
  if (!workingCase.caseFiles $$$) {
    $$$
  }
  $$$
}'

# Test: Check for null checks or optional chaining
rg -A 3 'workingCase\?.caseFiles|workingCase\.caseFiles\?' apps/judicial-system/web/src/components

Length of output: 771


Script:

#!/bin/bash
# Find and examine the IndictmentCaseFilesList component implementation
rg -l "IndictmentCaseFilesList" apps/judicial-system/web/src/

Length of output: 829


Script:

#!/bin/bash
# Get the implementation of IndictmentCaseFilesList component
cat apps/judicial-system/web/src/components/IndictmentCaseFilesList/IndictmentCaseFilesList.tsx

# Also check its test file for empty state scenarios
cat apps/judicial-system/web/src/components/IndictmentCaseFilesList/IndictmentCaseFilesList.spec.tsx

Length of output: 10806

apps/judicial-system/web/src/routes/Shared/IndictmentOverview/IndictmentOverview.tsx (3)

11-11: LGTM: Import addition aligns with role-based access control requirements.

The addition of isProsecutionUser import is well-placed alongside other role-checking utilities and follows TypeScript conventions.


176-176: LGTM: Consistent prop naming.

The prop name update maintains consistency with the renamed variable shouldDisplayGeneratedPdfFiles.


184-192: Verify the unconditional rendering of IndictmentCaseFilesList.

The component is now rendered unconditionally, which aligns with the PR objective but should be verified to ensure this doesn't cause issues when workingCase has no files.

Let's verify the component's behavior:

✅ Verification successful

Unconditional rendering of IndictmentCaseFilesList is safe and appropriate

The component implementation shows proper handling of empty or undefined cases:

  • All file type sections (indictments, criminalRecords, etc.) are rendered conditionally using && operators
  • Each section checks for both existence and non-empty array before rendering
  • The component uses TypeScript Props interface ensuring workingCase is always provided
  • The implementation includes proper null checks on optional fields like workingCase.defendants
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for IndictmentCaseFilesList implementation to verify null/empty case handling
ast-grep --pattern 'const IndictmentCaseFilesList: FC = ({ workingCase, displayGeneratedPDFs }) => {
  $$$
}'

Length of output: 111


Script:

#!/bin/bash
# Let's try a different pattern to find the IndictmentCaseFilesList component
ast-grep --pattern 'const IndictmentCaseFilesList = ({$_}) => {
  $$$
}'

# Also search for any imports or references to this component
rg "IndictmentCaseFilesList" -A 3

Length of output: 9873


Script:

#!/bin/bash
# Let's check the component implementation and its test file
cat apps/judicial-system/web/src/components/IndictmentCaseFilesList/IndictmentCaseFilesList.tsx
cat apps/judicial-system/web/src/components/IndictmentCaseFilesList/IndictmentCaseFilesList.spec.tsx

Length of output: 10806

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

168-170: LGTM! Please verify empty state handling.

The unconditional rendering of IndictmentCaseFilesList aligns with the PR objective to fix PDF visibility issues. This change simplifies the component logic by delegating empty state handling to the child component.

Let's verify the empty state handling in IndictmentCaseFilesList:

✅ Verification successful

Empty state handling is properly implemented - change is safe

The IndictmentCaseFilesList component safely handles empty states through:

  • Null checks with optional chaining for workingCase.caseFiles
  • Conditional rendering using && operators for each file category section
  • Empty array handling through .length checks
  • Type-safe filtering of case files by category

The unconditional rendering in Overview.tsx is appropriate as the component internally manages all possible states of workingCase.caseFiles.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for empty state handling in IndictmentCaseFilesList
ast-grep --pattern 'export const IndictmentCaseFilesList = ({ workingCase }) => {
  $$$
}'

Length of output: 92


Script:

#!/bin/bash
# Let's try finding the IndictmentCaseFilesList component with a broader search
fd "IndictmentCaseFilesList" --type f --exec cat {}

Length of output: 12890

@kodiakhq kodiakhq bot merged commit dc950b2 into main Oct 29, 2024
30 checks passed
@kodiakhq kodiakhq bot deleted the j-s/fix-indictment-files branch October 29, 2024 15:19
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 high priority VIP-Kodiak PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants