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

feat(j-s): show error state for invalid items in SelectableList #17504

Merged
merged 7 commits into from
Jan 17, 2025

Conversation

thorhildurt
Copy link
Member

@thorhildurt thorhildurt commented Jan 15, 2025

Asana task

What

  • Add client validation using the file name to prevent users to upload unsupported files to RVG. We don't get the filetype from LOKE.
  • Add suport for invalid item state for selectable list
  • Used when rendering police case files that are invalid

Why

  • We want to prevent the users from uploading invalid filed into the system since we only support .pdf

Screenshots / Gifs

Screenshot 2025-01-15 at 11 51 17

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
  • Extra: Test with the dev setup of LÖKE via xRoad

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced file selection with validation for police case files.
    • Added support for marking invalid items in selectable lists.
  • Improvements

    • Implemented visual indicators for invalid files, including a red background for invalid items.
    • Added tooltips to provide additional context for invalid selections.
    • Restricted selection of invalid items in lists.
  • Localization

    • Added new error message for invalid file types in police case files.

These updates improve user experience by providing clearer guidance and preventing incorrect file selections.

@thorhildurt thorhildurt requested a review from a team as a code owner January 15, 2025 11:50
@thorhildurt thorhildurt self-assigned this Jan 15, 2025
Copy link
Contributor

coderabbitai bot commented Jan 15, 2025

Walkthrough

The pull request introduces modifications to the SelectableList component and related files in the judicial system web application. It adds optional properties invalid and tooltipText to the Item interface, enhancing item state management. The selection logic is updated to prevent selecting invalid items, which are visually indicated in the UI. Additionally, a new validation function for file names ensures only PDF files are accepted, and a new localization message is added for user feedback regarding invalid file types.

Changes

File Change Summary
apps/judicial-system/web/src/components/SelectableList/SelectableList.tsx - Added invalid and tooltipText properties to Item interface
- Updated selection logic to prevent checking invalid items
- Modified checkbox rendering to show visual indicators for invalid items
apps/judicial-system/web/src/routes/Prosecutor/components/PoliceCaseFiles/PoliceCaseFiles.strings.ts - Added new localization message invalidPoliceCaseFileFromLOKE for PDF file validation
apps/judicial-system/web/src/routes/Prosecutor/components/PoliceCaseFiles/PoliceCaseFiles.tsx - Implemented PDF file validation in policeCaseFileList mapping
- Added invalid and tooltipText properties for non-PDF files

Possibly related PRs

Suggested labels

high priority

Suggested reviewers

  • oddsson

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 15, 2025

Datadog Report

All test runs 2f58c57 🔗

2 Total Test Services: 0 Failed, 2 Passed
🔻 Test Sessions change in coverage: 1 decreased (-0.02%), 1 no change

Test Services
Service Name Failed Known Flaky New Flaky Passed Skipped Total Time Code Coverage Change Test Service View
judicial-system-backend 0 0 0 21112 0 18m 33.07s 1 no change Link
judicial-system-web 0 0 0 333 0 57.75s 1 decreased (-0.02%) Link

🔻 Code Coverage Decreases vs Default Branch (1)

  • judicial-system-web - jest 32.46% (-0.02%) - Details

Copy link

codecov bot commented Jan 15, 2025

Codecov Report

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

Project coverage is 35.61%. Comparing base (687431b) to head (aef1506).
Report is 7 commits behind head on main.

Files with missing lines Patch % Lines
...b/src/components/SelectableList/SelectableList.tsx 0.00% 15 Missing ⚠️
...tor/components/PoliceCaseFiles/PoliceCaseFiles.tsx 0.00% 8 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #17504      +/-   ##
==========================================
- Coverage   35.61%   35.61%   -0.01%     
==========================================
  Files        7017     7015       -2     
  Lines      150430   150367      -63     
  Branches    42974    42949      -25     
==========================================
- Hits        53570    53546      -24     
+ Misses      96860    96821      -39     
Flag Coverage Δ
judicial-system-backend 55.80% <ø> (ø)
judicial-system-web 27.95% <0.00%> (-0.03%) ⬇️

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

Files with missing lines Coverage Δ
...ponents/PoliceCaseFiles/PoliceCaseFiles.strings.ts 100.00% <ø> (ø)
...tor/components/PoliceCaseFiles/PoliceCaseFiles.tsx 7.40% <0.00%> (-2.60%) ⬇️
...b/src/components/SelectableList/SelectableList.tsx 5.55% <0.00%> (-1.12%) ⬇️

... and 16 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 687431b...aef1506. Read the comment docs.

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/components/SelectableList/SelectableList.tsx (1)

91-95: Consider extracting the invalid item filtering logic.

The invalid item filtering logic is repeated in multiple places. Consider extracting it into a helper function for better maintainability.

+ const isItemValid = (item: Item) => !item.invalid
+ const getValidItems = (items: Item[]) => items.filter(isItemValid)

  // Usage in useEffect
  checked: (selectableItems.find((i) => i.id === item.id)?.checked && isItemValid(item)) ?? false,

  // Usage in select all checkbox
  checked={
    selectableItems.length > 0 &&
    getValidItems(selectableItems).every((item) => item.checked)
  }

  // Usage in select all handler
  checked: evt.target.checked && isItemValid(item),

Also applies to: 122-125, 128-132

apps/judicial-system/web/src/routes/Prosecutor/components/PoliceCaseFiles/PoliceCaseFiles.tsx (1)

59-73: Enhance file validation robustness.

While the current implementation works, it could be improved in several ways:

  1. Extract the PDF validation to a named function
  2. Make the file extension a constant
  3. Add case-insensitive validation
+ const ALLOWED_FILE_EXTENSION = '.pdf'
+ const isPDFFile = (filename: string): boolean => 
+   filename.toLowerCase().endsWith(ALLOWED_FILE_EXTENSION.toLowerCase())

  items={policeCaseFileList?.map((p) => {
-   const invalid = !p.name.endsWith('.pdf')
+   const invalid = !isPDFFile(p.name)
    return {
      id: p.id,
      name: p.name,
      ...(invalid
        ? {
            invalid,
            tooltipText: formatMessage(
              strings.invalidPoliceCaseFileFromLOKE,
            ),
          }
        : {}),
    }
  })}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 2dbccbb and dd12807.

📒 Files selected for processing (3)
  • apps/judicial-system/web/src/components/SelectableList/SelectableList.tsx (6 hunks)
  • apps/judicial-system/web/src/routes/Prosecutor/components/PoliceCaseFiles/PoliceCaseFiles.strings.ts (1 hunks)
  • apps/judicial-system/web/src/routes/Prosecutor/components/PoliceCaseFiles/PoliceCaseFiles.tsx (1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
apps/judicial-system/web/src/routes/Prosecutor/components/PoliceCaseFiles/PoliceCaseFiles.strings.ts (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/components/PoliceCaseFiles/PoliceCaseFiles.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/SelectableList/SelectableList.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."
🔇 Additional comments (3)
apps/judicial-system/web/src/routes/Prosecutor/components/PoliceCaseFiles/PoliceCaseFiles.strings.ts (1)

41-47: LGTM! Well-structured localization message.

The new error message is properly defined with a clear description and follows the established naming convention.

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

24-25: LGTM! Well-defined interface extensions.

The new optional properties invalid and tooltipText are appropriately typed and named.


189-192: LGTM! Clear visual feedback for invalid items.

The implementation provides clear visual feedback with:

  • Red background for invalid items
  • Warning icon
  • Tooltip with error message
  • Disabled checkbox state

Also applies to: 208-208, 218-229

coderabbitai[bot]
coderabbitai bot previously approved these changes Jan 15, 2025
Copy link
Member

@gudjong gudjong left a comment

Choose a reason for hiding this comment

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

Please only apply the new restrictions to files uploaded for case files records (Skjalaskrár) in indictment cases.

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

71-77: Consider improving type safety in the items mapping.

The current implementation could benefit from explicit type annotations to ensure type safety and improve maintainability.

Consider this improvement:

-          items={policeCaseFileList?.map((p) => {
-            return {
+          items={policeCaseFileList?.map((p): Item => {
+            return {
               id: p.id,
               name: p.name,
               ...(isIndictment ? validateFileName(p.name) : {}),
             }
           })}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between dd12807 and ef1f6cb.

📒 Files selected for processing (2)
  • apps/judicial-system/web/src/routes/Prosecutor/components/PoliceCaseFiles/PoliceCaseFiles.strings.ts (1 hunks)
  • apps/judicial-system/web/src/routes/Prosecutor/components/PoliceCaseFiles/PoliceCaseFiles.tsx (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/judicial-system/web/src/routes/Prosecutor/components/PoliceCaseFiles/PoliceCaseFiles.strings.ts
🧰 Additional context used
📓 Path-based instructions (1)
apps/judicial-system/web/src/routes/Prosecutor/components/PoliceCaseFiles/PoliceCaseFiles.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."
🔇 Additional comments (3)
apps/judicial-system/web/src/routes/Prosecutor/components/PoliceCaseFiles/PoliceCaseFiles.tsx (3)

5-5: LGTM! Import changes are appropriate.

The addition of CaseType import is necessary for the new validation logic.


48-56: LGTM! Validation function is well-implemented.

The function provides clear validation metadata with appropriate error messaging. The implementation is correct as the actual restriction to PDF files is controlled by the caller based on the case type.


65-65: LGTM! Validation is correctly applied only to indictment cases.

The implementation properly:

  • Checks the case type before applying validation
  • Only restricts PDF files for indictment cases
  • Preserves support for other file types in non-indictment cases

Also applies to: 71-77

@gudjong gudjong added the deprecated:automerge (Disabled) Merge this PR as soon as all checks pass label Jan 17, 2025
@thorhildurt thorhildurt removed the deprecated:automerge (Disabled) Merge this PR as soon as all checks pass label Jan 17, 2025
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 (1)
apps/judicial-system/web/src/routes/Prosecutor/components/PoliceCaseFiles/PoliceCaseFiles.tsx (1)

56-64: Enhance file validation robustness.

The current validation might miss edge cases. Consider these improvements:

  1. Make the extension check case-insensitive
  2. Add MIME type validation when possible
 const validateFileName = (filename: string) => {
-  const invalid = !filename.endsWith('.pdf')
+  const invalid = !filename.toLowerCase().endsWith('.pdf')
   if (!invalid) return {}

   return {
     invalid,
     tooltipText: formatMessage(strings.invalidPoliceCaseFileFromLOKE),
   }
 }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ef1f6cb and aef1506.

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

5-5: LGTM!

The import addition is necessary and follows best practices.


54-54: LGTM!

The type check correctly determines when to apply PDF-only validation, as required for indictment cases.


70-76: LGTM!

The mapping elegantly applies validation only for indictment cases while preserving the required fields.

@robertaandersen robertaandersen added this pull request to the merge queue Jan 17, 2025
Merged via the queue into main with commit 5844fd2 Jan 17, 2025
37 checks passed
@robertaandersen robertaandersen deleted the j-s/handle-invalid-file-names-from-loke branch January 17, 2025 13:43
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.

4 participants