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(web): file-restrictions-message #1847

Merged
merged 4 commits into from
Jan 24, 2025
Merged

Conversation

Harman-singh-waraich
Copy link
Contributor

@Harman-singh-waraich Harman-singh-waraich commented Jan 23, 2025

PR-Codex overview

This PR introduces a new utility function to generate file uploader messages based on role restrictions and updates components to utilize this function, enhancing user feedback regarding file upload requirements.

Detailed summary

  • Added getFileUploaderMsg function in web/src/utils/index.ts to generate messages based on role restrictions.
  • Updated SubmitEvidenceModal to use getFileUploaderMsg for the file uploader message.
  • Updated Policy component to include file uploader message using getFileUploaderMsg.
  • Adjusted styles in StyledFileUploader components for better layout.

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced file upload functionality with role-based access control.
    • Added dynamic file upload messages based on user roles and permissions.
  • Improvements

    • Improved user interface responsiveness for file upload components.
    • Increased margin for file uploader component for better layout.
    • Added more contextual information for file upload restrictions.
  • Bug Fixes

    • Improved error handling for file upload processes.
    • Added better user feedback for file upload limitations.

Copy link
Contributor

coderabbitai bot commented Jan 23, 2025

Walkthrough

This pull request introduces role-based file upload restrictions across multiple components. The changes enhance file upload functionality by adding dynamic messaging and role-specific upload constraints. A new utility function, getFileUploaderMsg, is created to generate context-aware upload messages based on user roles and file restrictions. The modifications span the SubmitEvidenceModal, Policy component, and a new utility function in the index.ts file, aiming to provide more informative and controlled file upload experiences.

Changes

File Change Summary
web/src/pages/Cases/CaseDetails/Evidence/SubmitEvidenceModal.tsx - Updated import statements
- Added roleRestrictions from useAtlasProvider
- Integrated dynamic file uploader messaging
web/src/pages/Resolver/Policy/index.tsx - Added useIsDesktop and getFileUploaderMsg imports
- Updated StyledFileUploader styling
- Conditionally set file uploader variant
web/src/utils/index.ts - Added new Role type definition
- Created getFileUploaderMsg utility function
- Imported Roles from @kleros/kleros-app

Possibly related PRs

Suggested labels

Type: Feature🗿, Type: Enhancement :sparkles:, Package: Web

Suggested reviewers

  • alcercu
  • kemuru

Poem

🐰 Uploading files with grace and might,
Roles dancing through each digital height
Restrictions whisper, "Upload just right!"
A rabbit's code, a regulatory delight 📤✨


🪧 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 or @coderabbitai title anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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

netlify bot commented Jan 23, 2025

Deploy Preview for kleros-v2-testnet ready!

Name Link
🔨 Latest commit 2735f07
🔍 Latest deploy log https://app.netlify.com/sites/kleros-v2-testnet/deploys/679353c5e6a3a50008574654
😎 Deploy Preview https://deploy-preview-1847--kleros-v2-testnet.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

netlify bot commented Jan 23, 2025

Deploy Preview for kleros-v2-neo ready!

Name Link
🔨 Latest commit 2735f07
🔍 Latest deploy log https://app.netlify.com/sites/kleros-v2-neo/deploys/679353c5ad11860008f17c9c
😎 Deploy Preview https://deploy-preview-1847--kleros-v2-neo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

netlify bot commented Jan 23, 2025

Deploy Preview for kleros-v2-university ready!

Name Link
🔨 Latest commit 2735f07
🔍 Latest deploy log https://app.netlify.com/sites/kleros-v2-university/deploys/679353c59fb0980008fa674b
😎 Deploy Preview https://deploy-preview-1847--kleros-v2-university.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

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 (3)
web/src/utils/index.ts (1)

24-31: Improve readability and add validation for edge cases.

The function logic is correct but could be improved for better maintainability and robustness.

Consider breaking down the complex string manipulation and adding validation:

 export const getFileUploaderMsg = (role: Roles, roleRestrictions?: Role[]) => {
   if (!roleRestrictions) return;
   const restrictions = roleRestrictions.find((supportedRoles) => Roles[supportedRoles.name] === role);
 
   if (!restrictions) return;
+
+  const { allowedMimeTypes, maxSize } = restrictions.restriction;
+  if (!allowedMimeTypes.length) return;
+
+  const fileTypes = allowedMimeTypes
+    .map((type) => type.split("/")?.[1])
+    .filter(Boolean)
+    .join(", ");
+  const maxSizeMB = (maxSize / (1024 * 1024)).toFixed(2);
 
-  return `Allowed file types: [${restrictions.restriction.allowedMimeTypes.map((type) => type.split("/")?.[1] ?? null).join(", ")}], Max allowed size: ${(restrictions.restriction.maxSize / (1024 * 1024)).toFixed(2)} MB.`;
+  return `Allowed file types: [${fileTypes}], Max allowed size: ${maxSizeMB} MB.`;
 };
web/src/pages/Resolver/Policy/index.tsx (1)

88-89: Consider separating the message template from the restrictions.

The message template is hardcoded with the restrictions message, which could make it harder to maintain or localize.

Consider extracting the template:

+const POLICY_UPLOAD_MESSAGE = "You can attach additional information as a PDF file. Important: the above description must reference the relevant parts of the file content.";
+
 <StyledFileUploader
   callback={handleFileUpload}
   variant={isDesktop ? "info" : undefined}
-  msg={`You can attach additional information as a PDF file. Important: the above description must reference the relevant parts of the file content.\n${getFileUploaderMsg(Roles.Policy, roleRestrictions)}`}
+  msg={`${POLICY_UPLOAD_MESSAGE}\n${getFileUploaderMsg(Roles.Policy, roleRestrictions)}`}
 />
web/src/pages/Cases/CaseDetails/Evidence/SubmitEvidenceModal.tsx (1)

102-106: Consider making the variant prop consistent with Policy component.

The FileUploader's variant is fixed to "info" while in Policy it's conditional based on desktop view.

Consider using the same desktop-aware approach:

+const isDesktop = useIsDesktop();
+
 <StyledFileUploader
   callback={(file: File) => setFile(file)}
   msg={getFileUploaderMsg(Roles.Evidence, roleRestrictions)}
-  variant="info"
+  variant={isDesktop ? "info" : undefined}
 />
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f3f05ab and 19908c6.

📒 Files selected for processing (3)
  • web/src/pages/Cases/CaseDetails/Evidence/SubmitEvidenceModal.tsx (5 hunks)
  • web/src/pages/Resolver/Policy/index.tsx (3 hunks)
  • web/src/utils/index.ts (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (13)
  • GitHub Check: Redirect rules - kleros-v2-testnet
  • GitHub Check: Redirect rules - kleros-v2-testnet
  • GitHub Check: Redirect rules - kleros-v2-neo
  • GitHub Check: Header rules - kleros-v2-testnet
  • GitHub Check: Header rules - kleros-v2-neo
  • GitHub Check: Header rules - kleros-v2-testnet
  • GitHub Check: Pages changed - kleros-v2-testnet
  • GitHub Check: Pages changed - kleros-v2-neo
  • GitHub Check: Pages changed - kleros-v2-testnet
  • GitHub Check: SonarCloud
  • GitHub Check: Analyze (javascript)
  • GitHub Check: dependency-review
  • GitHub Check: contracts-testing
🔇 Additional comments (3)
web/src/utils/index.ts (1)

16-22: LGTM! Well-structured type definition.

The Role type clearly defines the structure for file restrictions with appropriate typing.

web/src/pages/Resolver/Policy/index.tsx (1)

51-54: LGTM! Proper styling for multiline text.

The styling ensures proper alignment and wrapping of the file restrictions message.

web/src/pages/Cases/CaseDetails/Evidence/SubmitEvidenceModal.tsx (1)

Line range hint 128-132: LGTM! Proper error handling with user feedback.

The error handling provides both console logging for debugging and user-friendly toast messages.

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

netlify bot commented Jan 23, 2025

Deploy Preview for kleros-v2-testnet-devtools ready!

Name Link
🔨 Latest commit 2735f07
🔍 Latest deploy log https://app.netlify.com/sites/kleros-v2-testnet-devtools/deploys/679353c54e57920008dfbb0b
😎 Deploy Preview https://deploy-preview-1847--kleros-v2-testnet-devtools.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

coderabbitai[bot]
coderabbitai bot previously approved these changes Jan 23, 2025
@kemuru kemuru self-requested a review January 23, 2025 17:25
Copy link
Contributor

@kemuru kemuru left a comment

Choose a reason for hiding this comment

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

good but I would remove these extra spaces at the beginning of the brackets

image

same for Escrow V2, Curate V2

@kemuru kemuru self-requested a review January 23, 2025 17:28
kemuru
kemuru previously approved these changes Jan 23, 2025
Copy link
Contributor

@kemuru kemuru left a comment

Choose a reason for hiding this comment

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

is markdown also allowed here?

image

same for Escrow V2, Curate V2. let's check that the fetched roles from the query are really allowed in the respective forms. some only accept PDFs.

Copy link

codeclimate bot commented Jan 24, 2025

Code Climate has analyzed commit 2735f07 and detected 1 issue on this pull request.

Here's the issue category breakdown:

Category Count
Complexity 1

View more on Code Climate.

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)
web/src/pages/Resolver/Policy/index.tsx (1)

88-89: Optimize the message formatting.

Since white-space: pre-line is already set in the styles, the explicit \n in the template literal is redundant.

-        msg={`You can attach additional information here. Important: the above description must reference the relevant parts of the file content.\n${getFileUploaderMsg(Roles.Policy, roleRestrictions)}`}
+        msg={`You can attach additional information here. Important: the above description must reference the relevant parts of the file content.${getFileUploaderMsg(Roles.Policy, roleRestrictions)}`}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c813e76 and 2735f07.

📒 Files selected for processing (2)
  • web/src/pages/Resolver/Policy/index.tsx (3 hunks)
  • web/src/utils/index.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • web/src/utils/index.ts
⏰ Context from checks skipped due to timeout of 90000ms (17)
  • GitHub Check: Redirect rules - kleros-v2-university
  • GitHub Check: Header rules - kleros-v2-university
  • GitHub Check: Pages changed - kleros-v2-university
  • GitHub Check: Redirect rules - kleros-v2-testnet
  • GitHub Check: Redirect rules - kleros-v2-testnet
  • GitHub Check: Header rules - kleros-v2-testnet
  • GitHub Check: Header rules - kleros-v2-testnet
  • GitHub Check: Pages changed - kleros-v2-testnet
  • GitHub Check: Pages changed - kleros-v2-testnet
  • GitHub Check: Redirect rules - kleros-v2-testnet-devtools
  • GitHub Check: Header rules - kleros-v2-testnet-devtools
  • GitHub Check: Pages changed - kleros-v2-testnet-devtools
  • GitHub Check: contracts-testing
  • GitHub Check: Analyze (javascript)
  • GitHub Check: SonarCloud
  • GitHub Check: dependency-review
  • GitHub Check: Mend Security Check
🔇 Additional comments (4)
web/src/pages/Resolver/Policy/index.tsx (4)

4-4: LGTM! Import changes are well-organized.

The new imports align with the PR objectives and follow a logical grouping pattern.

Also applies to: 8-11


44-44: Verify the significant margin increase.

The margin-bottom has been increased significantly from 72 to 150. Please confirm if this large increase is intentional and necessary for accommodating the new file restriction messages.

The new small text styles look good and will properly handle multi-line messages.

Also applies to: 51-54


59-60: LGTM! Role-based restrictions are properly integrated.

The addition of roleRestrictions and responsive desktop handling improves the component's functionality.


59-59: Verify consistent role-based message handling across components.

The implementation looks good, but let's verify that the role-based message handling is consistent with the SubmitEvidenceModal component mentioned in the PR description.

Also applies to: 88-89

✅ Verification successful

Role-based message handling is consistent across components

Both SubmitEvidenceModal and Policy components follow the same pattern:

  • Use getFileUploaderMsg with appropriate role enums
  • Pass roleRestrictions from context
  • Display messages in file upload components
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for similar implementations in other components
rg -l "getFileUploaderMsg" "web/src/pages"
rg "roleRestrictions.*Roles\." "web/src/pages"

Length of output: 192


Script:

#!/bin/bash
# Get the context around getFileUploaderMsg usage in both files
echo "=== SubmitEvidenceModal.tsx ==="
rg -B 2 -A 2 "getFileUploaderMsg" "web/src/pages/Cases/CaseDetails/Evidence/SubmitEvidenceModal.tsx"
echo -e "\n=== Policy/index.tsx ==="
rg -B 2 -A 2 "getFileUploaderMsg" "web/src/pages/Resolver/Policy/index.tsx"

# Check for roleRestrictions usage
echo -e "\n=== Role Restrictions Usage ==="
ast-grep --pattern 'const { $$$, roleRestrictions, $$$ } = $_'

Length of output: 1310

@kemuru kemuru self-requested a review January 24, 2025 08:52
Copy link
Contributor

@kemuru kemuru left a comment

Choose a reason for hiding this comment

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

amazing

Copy link
Contributor

@alcercu alcercu left a comment

Choose a reason for hiding this comment

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

lgtm

@alcercu alcercu added this pull request to the merge queue Jan 24, 2025
Merged via the queue into dev with commit 4ed43ef Jan 24, 2025
26 of 27 checks passed
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.

3 participants