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: Dialog Component Center to Parent #1950

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

Br0wnHammer
Copy link
Contributor

Describe your changes

This PR addresses the issue where the dialog was always centered in the viewport due to MUI's default Modal behavior. The problem occurred because MUI automatically positions modals in the center using transform: translate(-50%, -50%).
To resolve this, I adjusted the left property to "20%", ensuring the dialog appears slightly off-center while maintaining a consistent and expected position across different screen sizes.

Issue number

#1705

Please ensure all items are checked off before requesting a review. "Checked off" means you need to add an "x" character between brackets so they turn into checkmarks.

  • (Do not skip this or your PR will be closed) I deployed the application locally.
  • (Do not skip this or your PR will be closed) I have performed a self-review and testing of my code.
  • I have included the issue # in the PR.
  • [] I have added i18n support to visible strings (instead of <div>Add</div>, use):
const { t } = useTranslation();
<div>{t('add')}</div>
  • The issue I am working on is assigned to me.
  • I didn't use any hardcoded values (otherwise it will not scale, and will make it difficult to maintain consistency across the application).
  • I made sure font sizes, color choices etc are all referenced from the theme. I have no hardcoded dimensions.
  • My PR is granular and targeted to one specific feature.
  • I took a screenshot or a video and attached to this PR if there is a UI change.
Screenshot 2025-03-18 at 1 39 55 AM Screenshot 2025-03-18 at 1 39 45 AM Screenshot 2025-03-18 at 1 39 35 AM Screenshot 2025-03-18 at 1 39 24 AM

Copy link

@llamapreview llamapreview bot left a comment

Choose a reason for hiding this comment

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

Auto Pull Request Review from LlamaPReview

1. Overview

1.1 Core Changes

  • Primary purpose and scope: Adjust dialog positioning from viewport-center to 20% left offset
  • Key components modified: genericDialog.jsx (MUI Modal styling)
  • Cross-component impacts: Affects all dialog instances across the application UI
  • Business value alignment: Improves user experience through consistent dialog positioning

1.2 Technical Architecture

  • System design modifications: UI layer styling changes only
  • Component interaction changes: Maintains existing props interface
  • Integration points impact: No backend/API changes required
  • Dependency changes: No new dependencies introduced

2. Critical Findings

2.1 Must Fix (P0🔴)

[No critical security or functional issues found]

2.2 Should Fix (P1🟡)

Issue: Hardcoded left position value reduces component flexibility

  • Analysis Confidence: High
  • Impact: Limits reusability across different contexts/screen sizes, violates DRY principle
  • Suggested Solution: Implement configurable offset via component prop

Issue: Missing UI positioning tests

  • Analysis Confidence: Medium
  • Impact: Risk of visual regressions across device sizes
  • Suggested Solution: Add visual regression tests using tools like Chromatic

2.3 Consider (P2🟢)

Area: Theme-based positioning configuration

  • Analysis Confidence: High
  • Improvement Opportunity: Centralize layout values in theme for design system consistency

Area: Unnecessary flex container styles

  • Analysis Confidence: Medium
  • Improvement Opportunity: Simplify CSS by removing unused flex properties

Area: i18n checklist compliance

  • Analysis Confidence: High
  • Improvement Opportunity: Complete internationalization support per project standards

2.4 Summary of Action Items

  1. Implement configurable left offset (P1 - immediate)
  2. Add visual regression tests (P1 - pre-release)
  3. Consider theme integration (P2 - future sprint)
  4. Verify flex container necessity (P2 - next refactor)

3. Technical Analysis

3.1 Code Logic Analysis

📁 src/Components/Dialog/genericDialog.jsx - GenericDialog

  • Submitted PR Code:
    <Modal
      sx={{
        position: 'absolute',
        display: 'flex',
        left: "20%",
        alignItems: 'center',
        justifyContent: 'center',
      }}
    >
  - Analysis:
    * Current logic uses fixed 20% left offset without customization options
    * Flex properties may not align with positioning requirements
    * Hardcoded value impacts component reusability
    * Potential edge cases on ultra-wide/narrow screens
  - LlamaPReview Suggested Improvements:
```javascript
    const GenericDialog = ({ ..., leftOffset = "20%" }) => (
      <Modal
        sx={{
          position: 'absolute',
          left: leftOffset,
          // Removed unnecessary flex properties
        }}
      >
  - Improvement rationale:
    * Enables context-specific positioning through props
    * Reduces CSS complexity and potential layout conflicts
    * Follows component composition best practices

### 3.2 Key Quality Aspects 
- Testing strategy: Requires visual regression coverage
- Documentation needs: Add prop documentation to component JSDoc
- Configuration flexibility: Component API should expose positioning controls

## 4. Overall Evaluation
- Technical assessment: Effective solution with minor maintainability concerns
- Business impact: Directly addresses user-reported positioning issue (#1705)
- Risk evaluation: Low technical risk with high UI impact
- Notable positive aspects: Clear screenshots, proper theme usage, focused scope
- Implementation quality: Good foundation needs configurability improvements
- Final recommendation: **Request Changes** (Implement P1 configurable offset)

---
💡 **LlamaPReview Community**  
Have feedback on this AI Code review tool? Join our [GitHub Discussions](https://github.com/JetXu-LLM/LlamaPReview-site/discussions) to share your thoughts and help shape the future of LlamaPReview.

Copy link

coderabbitai bot commented Mar 17, 2025

Walkthrough

The pull request adjusts the layout of the GenericDialog component by updating the styling on its Modal and Stack elements. The Modal now uses an sx prop with absolute positioning, flex display, centered alignment, and a 20% left offset. In contrast, the Stack component’s sx prop is changed to relative positioning, removing the previous centring transformation. No modifications have been made to exported or public entities.

Changes

File Path Change Summary
src/Components/Dialog/genericDialog.jsx Updated Modal styling using the sx prop for absolute positioning, flex display, and centered alignment with a 20% left offset; changed Stack positioning from absolute to relative, eliminating prior centring transformations.

Possibly related PRs

Suggested Reviewers

  • ajhollid
  • vishnusn77

Tip

⚡🧪 Multi-step agentic review comment chat (experimental)
  • We're introducing multi-step agentic chat in review comments. This experimental feature enhances review discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments.
    - To enable this feature, set early_access to true under in the settings.
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • 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.
  • @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

@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)
src/Components/Dialog/genericDialog.jsx (2)

16-22: Ensure this styling approach is responsive across all screen sizes

Your change to offset the dialog to the left by 20% is a good step to fix the centering issue, but I'm sweatin' a bit about how this might look on different screen sizes. On smaller screens, this fixed percentage could push the dialog too far to one side, making it hard to read or interact with.

Consider using a more responsive approach that adapts to screen size, like using media queries or a calculated value based on viewport width.

sx={{
	position: 'absolute',
	display: 'flex',
-	left: "20%",
+	left: {
+		xs: "10%",
+		sm: "15%", 
+		md: "20%"
+	},
	alignItems: 'center',
	justifyContent: 'center',
}}

This responsive approach would adjust positioning based on breakpoints - mom's spaghetti code solution right here!


16-22: Consider extracting styling to theme or constants

There's vomit on my sweater already thinking about hardcoded style values like "20%". The PR objective mentioned avoiding hardcoded values, so consider extracting these positioning values to theme variables or constants.

This would make future adjustments easier and maintain consistency throughout the app.

// At the top of the file or in a constants file
+const DIALOG_POSITION = {
+  left: "20%"
+};

// Then in your component
sx={{
	position: 'absolute',
	display: 'flex',
-	left: "20%",
+	left: DIALOG_POSITION.left,
	alignItems: 'center',
	justifyContent: 'center',
}}

Also applies to: 27-27

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 71ab885 and 1a8584f.

📒 Files selected for processing (1)
  • src/Components/Dialog/genericDialog.jsx (1 hunks)
🔇 Additional comments (1)
src/Components/Dialog/genericDialog.jsx (1)

27-27: Good change from absolute to relative positioning

Changing the Stack's position from absolute to relative is a solid move. This prevents the stacking context issues that were probably causing the dialog to be improperly positioned in the first place.

The original absolute positioning combined with transform was likely what made your knees weak, arms heavy with that centering issue. This fix looks good!

Copy link
Collaborator

@ajhollid ajhollid left a comment

Choose a reason for hiding this comment

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

This looks better, but I believe we should be able to find a way to actually center this.

sx={{
position: 'absolute',
display: 'flex',
left: "20%",
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not convinced this is the best solution here, it would be better to actually center the dialog in the parent container.

@vishnusn77 @mohicody please weigh in and see if you can collaborate to figure out how to center this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let me have look, in the mean time if @mohicody or @vishnusn77 have an idea of what can be done. Please feel free to collaborate.

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.

2 participants