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 FileUploadDialog overflow | Use ShadCN component #10047

Open
wants to merge 12 commits into
base: develop
Choose a base branch
from

Conversation

rajku-dev
Copy link
Contributor

@rajku-dev rajku-dev commented Jan 19, 2025

Proposed Changes

BEFORE

AFTER

@ohcnetwork/care-fe-code-reviewers

Merge Checklist

  • Add specs that demonstrate bug / test a new feature.
  • Update product documentation.
  • Ensure that UI text is kept in I18n files.
  • Prep screenshot or demo video for changelog entry, and attach it to issue.
  • Request for Peer Reviews
  • Completion of QA

Summary by CodeRabbit

  • UI Improvements

    • Replaced existing text form field with new input components.
    • Enhanced file upload dialog input styling.
    • Added more explicit label and error handling for file name input.
  • Styling Updates

    • Adjusted dialog content width.
    • Implemented conditional styling for input fields.

@rajku-dev rajku-dev requested a review from a team as a code owner January 19, 2025 01:44
Copy link
Contributor

coderabbitai bot commented Jan 19, 2025

Walkthrough

The pull request modifies the FilesTab.tsx component by replacing the TextFormField with Input and Label components. This change enhances the input handling and styling for file name input in the file upload dialog. Additionally, the dialog's content width has been adjusted with the inclusion of the max-w-fit class, addressing potential layout issues.

Changes

File Change Summary
src/components/Files/FilesTab.tsx - Replaced TextFormField with Input and Label components
- Updated file name input structure and styling
- Modified error message handling
- Added max-w-fit class to DialogContent

Assessment against linked issues

Objective Addressed Explanation
Fix form elements overflowing in upload file dialog [#10046]

Suggested labels

tested

Suggested reviewers

  • Jacobjeevan
  • rithviknishad

Poem

🐰 A rabbit's tale of file upload glee,
Components dancing, now sleek and free!
Input and Label, a stylish pair,
Fixing overflow with technical flair.
Code refactored, errors at bay,
Upload dialog shines another day! 📤✨


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.

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

Deploy Preview for care-ohc ready!

Name Link
🔨 Latest commit 3b632d6
🔍 Latest deploy log https://app.netlify.com/sites/care-ohc/deploys/679068d54cff5d00081fa3a7
😎 Deploy Preview https://deploy-preview-10047--care-ohc.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 (1)
src/components/Files/FilesTab.tsx (1)

605-633: Well-structured form field implementation with ShadCN components!

The implementation:

  • Maintains accessibility with proper labels and ARIA attributes
  • Handles error states effectively
  • Uses consistent styling

Consider adding data-testid attributes for better test coverage:

 <Input
   name={`file_name_${index}`}
   type="text"
   id={`upload-file-name-${index}`}
+  data-testid={`upload-file-name-${index}`}
   required
   className={`block w-full rounded-md border px-3 py-2 text-sm ${
     index === 0 && fileUpload.error
       ? "border-red-500 focus:ring-red-500"
       : "border-gray-300 focus:ring-primary"
   }`}
   value={fileUpload.fileNames[index] || ""}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 206ee47 and c24a77d.

📒 Files selected for processing (1)
  • src/components/Files/FilesTab.tsx (3 hunks)
🔇 Additional comments (2)
src/components/Files/FilesTab.tsx (2)

22-23: LGTM! Clean import of ShadCN components.

The addition of Input and Label components from the UI library aligns with the PR objective to use ShadCN components.


580-580: Good fix for the dialog overflow!

The max-w-fit class allows the dialog to adapt its width based on content, preventing overflow issues.

Co-authored-by: Rithvik Nishad <rithvikn2001@gmail.com>
@github-actions github-actions bot added the Deploy-Failed Deplyment is not showing preview label Jan 19, 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)
src/components/Files/FilesTab.tsx (1)

628-632: Enhance error message accessibility.

Consider adding aria-invalid and aria-errormessage attributes to improve accessibility of the error state.

 <Input
   name={`file_name_${index}`}
   type="text"
   id={`upload-file-name-${index}`}
   required
   className={
     index === 0 && fileUpload.error
       ? "border-red-500 focus:ring-red-500"
       : "border-gray-300 focus:ring-primary"
   }
+  aria-invalid={index === 0 && fileUpload.error ? "true" : undefined}
+  aria-errormessage={index === 0 && fileUpload.error ? `error-${index}` : undefined}
   value={fileUpload.fileNames[index] || ""}
   disabled={fileUpload.uploading}
   onChange={(e) =>
     fileUpload.setFileName(e.target.value, index)
   }
 />
 {index === 0 && fileUpload.error && (
-  <p className="mt-1 text-sm text-red-500">
+  <p id={`error-${index}`} className="mt-1 text-sm text-red-500">
     {fileUpload.error}
   </p>
 )}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c24a77d and cb68635.

📒 Files selected for processing (1)
  • src/components/Files/FilesTab.tsx (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: cypress-run (1)
🔇 Additional comments (3)
src/components/Files/FilesTab.tsx (3)

22-23: LGTM! Clean import of ShadCN components.

The addition of Input and Label components from the UI library aligns with the PR objective of using ShadCN components.


605-633: Clean implementation of ShadCN components.

The replacement of TextFormField with Label and Input components is well-structured and maintains all necessary functionality while following the configured styles.


580-580: Dialog width adjustment looks good.

The addition of max-w-fit class should resolve the overflow issues by allowing the dialog to adjust its width based on content.

Let's check if there are any other dialogs in the codebase that might benefit from this fix:

✅ Verification successful

Dialog width variations are intentional and appropriate

The max-w-fit class in FilesTab is specific to its use case, while other dialogs in the codebase intentionally use different width constraints based on their content and purpose (e.g., sm:max-w-md for notes, no constraints for commands). This is the correct approach as dialog widths should be tailored to their specific content requirements.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for other DialogContent components that might need width adjustment
ast-grep --pattern 'DialogContent className="$_"'

Length of output: 51


Script:

#!/bin/bash
# Search for Dialog-related components and their className usage
rg -i "dialog.*content.*class" -A 2 -B 2

# Also search for specific Dialog imports to understand the component usage
rg -i "import.*dialog" -A 2

Length of output: 6983

@Jacobjeevan
Copy link
Contributor

This doesn't really solve the issue if file name is long 🤔

image

@rajku-dev
Copy link
Contributor Author

This doesn't really solve the issue if file name is long 🤔

image

I have fixed this overfitting issue, please check again.
can we add file preview feature in it?

@github-actions github-actions bot added needs-triage question Further information is requested labels Jan 20, 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: 1

🧹 Nitpick comments (1)
src/components/Files/FilesTab.tsx (1)

594-594: Consider using relative width for file name truncation.

Using max-w-xs might be too restrictive. Consider using a percentage-based width or a larger fixed width to better utilize available space.

-                  <span className="truncate max-w-xs">{file.name}</span>
+                  <span className="truncate max-w-[calc(100%-2rem)]">{file.name}</span>
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between cb68635 and 0640bfe.

📒 Files selected for processing (1)
  • src/components/Files/FilesTab.tsx (4 hunks)
🔇 Additional comments (2)
src/components/Files/FilesTab.tsx (2)

22-23: LGTM! Using ShadCN components.

The imports align with the PR objective of using ShadCN UI components.


605-633: LGTM! Well-structured form field implementation.

The replacement of TextFormField with Input and Label components is well-implemented:

  • Proper error handling and display
  • Consistent styling that matches configured styles
  • Clear labeling and accessibility attributes

src/components/Files/FilesTab.tsx Show resolved Hide resolved
@Jacobjeevan
Copy link
Contributor

Jacobjeevan commented Jan 20, 2025

This doesn't really solve the issue if file name is long 🤔
image

I have fixed this overfitting issue, please check again. can we add file preview feature in it?

Should add tool tip (that displays the full name) like elsewhere, when we are using truncate (in most cases).

@coderabbitai should make this suggestion for future.

Copy link
Contributor

coderabbitai bot commented Jan 20, 2025

Tip

For best results, initiate chat on the files or code changes.

@Jacobjeevan Thank you for the feedback. I'll remember to suggest adding tooltips whenever text truncation is used in the UI.

🐰 thoughtfully taking notes


✏️ Learnings added
Learnt from: Jacobjeevan
URL: https://github.com/ohcnetwork/care_fe/pull/10047

Timestamp: 2025-01-20T13:52:21.214Z
Learning: When using text truncation (truncate class or similar) in the UI, always add a tooltip to show the full text. This is particularly important for elements like file names, long descriptions, or any truncated content to maintain good user experience and accessibility.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

Copy link
Contributor

coderabbitai bot commented Jan 20, 2025

Tip

For best results, initiate chat on the files or code changes.

@Jacobjeevan Thank you for the feedback. I'll remember to suggest adding tooltips whenever text truncation is used in the UI.

🐰 thoughtfully taking notes


✏️ Learnings added
Learnt from: Jacobjeevan
URL: https://github.com/ohcnetwork/care_fe/pull/10047

Timestamp: 2025-01-20T13:52:44.622Z
Learning: When using text truncation (truncate class or similar) in the UI, always add a tooltip to show the full text. This is particularly important for elements like file names, long descriptions, or any truncated content to maintain good user experience and accessibility.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

@Jacobjeevan Jacobjeevan removed question Further information is requested Deploy-Failed Deplyment is not showing preview needs-triage labels Jan 20, 2025
@rajku-dev
Copy link
Contributor Author

This doesn't really solve the issue if file name is long 🤔
image

I have fixed this overfitting issue, please check again. can we add file preview feature in it?

Should add tool tip (that displays the full name) like elsewhere, when we are using truncate (in most cases).

@coderabbitai should make this suggestion for future.

made the changes as requested,
please let me know if further changes are required
Thank You.

Copy link
Contributor

coderabbitai bot commented Jan 20, 2025

Tip

For best results, initiate chat on the files or code changes.

@rajku-dev The tooltip implementation for long filenames looks good! The conditional rendering based on filename length and the use of ShadCN's Tooltip components is well done. The changes effectively address the original issue with file name overflow.

🔗 Analysis chain
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Get the current content of FilesTab.tsx
cat src/components/Files/FilesTab.tsx

Length of output: 22653


If you found this review helpful, would you consider giving us a shout-out on X?
Thank you for using CodeRabbit!

Copy link
Contributor

@Jacobjeevan Jacobjeevan left a comment

Choose a reason for hiding this comment

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

I meant using the tool tip component 😅 But this works fine for file names.

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)
src/components/Files/FilesTab.tsx (1)

607-635: Consider adding aria-invalid and aria-errormessage for better accessibility.

The form field implementation looks good, but could be enhanced for screen readers.

 <Input
   name={`file_name_${index}`}
   type="text"
   id={`upload-file-name-${index}`}
   required
+  aria-invalid={index === 0 && !!fileUpload.error}
+  aria-errormessage={index === 0 && fileUpload.error ? `error-${index}` : undefined}
   className={
     index === 0 && fileUpload.error
       ? "border-red-500 focus:ring-red-500"
       : "border-gray-300 focus:ring-primary"
   }
   value={fileUpload.fileNames[index] || ""}
   disabled={fileUpload.uploading}
   onChange={(e) =>
     fileUpload.setFileName(e.target.value, index)
   }
 />
 {index === 0 && fileUpload.error && (
-  <p className="mt-1 text-sm text-red-500">
+  <p id={`error-${index}`} className="mt-1 text-sm text-red-500">
     {fileUpload.error}
   </p>
 )}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4cc0c3e and 3b632d6.

📒 Files selected for processing (1)
  • src/components/Files/FilesTab.tsx (4 hunks)
🧰 Additional context used
📓 Learnings (1)
src/components/Files/FilesTab.tsx (1)
Learnt from: rajku-dev
PR: ohcnetwork/care_fe#10047
File: src/components/Files/FilesTab.tsx:580-580
Timestamp: 2025-01-20T09:46:46.025Z
Learning: In FileUploadDialog, using `max-w-fit` on the dialog content is acceptable when the internal content (like filenames) is already constrained with classes like `max-w-xs` and `truncate`.
🔇 Additional comments (3)
src/components/Files/FilesTab.tsx (3)

22-23: LGTM! Clean import additions.

The new imports for ShadCN components follow the project's conventions.


580-580: LGTM! Appropriate width constraint.

The max-w-fit class is correctly used here since the internal content (filename) is already constrained with max-w-xs and truncate.


594-596: LGTM! Good handling of long filenames.

The implementation properly handles long filenames with:

  • Width constraint using max-w-xs
  • Truncation with truncate
  • Accessibility support via title attribute

@nihal467
Copy link
Member

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Form Elements Overflowing in Upload File Dialog
4 participants