Checkmate icon indicating copy to clipboard operation
Checkmate copied to clipboard

fix: modal centered respective to parent

Open Trained-Monkey opened this issue 7 months ago • 2 comments

Modal shifts itself by how much width sidebar is taking

Describe your changes

Added a new sidebar width constant in themes used to set sidebar sizes. This value is also used to shift modal depending on whether the sidebar is collapsed or not.

Reasoning for approach

Reading over previous pull requests on this issue (#1728 and #1950 ), it seemed like a solution primarily focusing on css was preferred. However, as the Material UI modal attaches itself to the document.body, a pure css solution did not look possible. This was the only method I could think of that was primarily css and did not involving passing around a ref of the parent component.

Write your issue number after "Fixes "

Fixes #1705

Sidebar Expanded Upptime Pagespeed Sidebar Collapsed Uptimes

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.

  • [x] (Do not skip this or your PR will be closed) I deployed the application locally.
  • [x] (Do not skip this or your PR will be closed) I have performed a self-review and testing of my code.
  • [x] I have included the issue # in the PR.
  • [x] I have added i18n support to visible strings (instead of <div>Add</div>, use):
const { t } = useTranslation();
<div>{t('add')}</div>
  • [x] I have not included any files that are not related to my pull request, including package-lock and package-json if dependencies have not changed
  • [x] I didn't use any hardcoded values (otherwise it will not scale, and will make it difficult to maintain consistency across the application).
  • [x] I made sure font sizes, color choices etc are all referenced from the theme. I have no hardcoded dimensions.
  • [x] My PR is granular and targeted to one specific feature.
  • [x] I took a screenshot or a video and attached to this PR if there is a UI change.

Summary by CodeRabbit

  • New Features
    • Dialogs now anchor and position relative to the main content area for improved alignment and user experience.
    • Background scrolling is disabled when dialogs are open to prevent unwanted page movement.
  • Enhancements
    • Consistent spacing is applied across stacked elements for a more uniform layout.
  • Chores
    • Introduced a utility for managing dialog anchor references across components.

Trained-Monkey avatar May 13 '25 15:05 Trained-Monkey

Walkthrough

The changes introduce a DialogAnchorContext to manage dialog anchoring in the UI. The HomeLayout now provides a reference to its main container via this context, and GenericDialog consumes it to anchor modals relative to the container, adjusting positioning and scroll locking accordingly.

Changes

File(s) Change Summary
client/src/Utils/DialogAnchorContext.jsx Added new DialogAnchorContext for sharing dialog anchor references.
client/src/Components/Layouts/HomeLayout/index.jsx Provided dialogAnchorRef via DialogAnchorContext.Provider and positioned the container as relative.
client/src/Components/Dialog/genericDialog.jsx Consumed DialogAnchorContext, anchored modal to container, updated positioning logic, and managed scroll lock.

Sequence Diagram(s)

sequenceDiagram
    participant HomeLayout
    participant DialogAnchorContext
    participant GenericDialog
    participant Modal

    HomeLayout->>DialogAnchorContext: Provide dialogAnchorRef
    GenericDialog->>DialogAnchorContext: Consume dialogAnchorRef
    GenericDialog->>Modal: Set container to dialogAnchorRef.current
    GenericDialog->>GenericDialog: Compute verticalOffset based on anchor position
    GenericDialog->>Modal: Apply absolute positioning and styles
    GenericDialog->>document.body: Toggle overflow for scroll lock

Assessment against linked issues

Objective Addressed Explanation
Modal displays in the center of its parent component instead of the viewport (#1705)

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes detected. All modifications directly support dialog anchoring and positioning as described in the linked issue.


And remember: Canadians center their modals politely—right in the middle, eh? Americans, on the other hand, just throw them in the middle of the screen and call it "freedom of placement."


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between b967b2be2e0fe0803e01b80cc781f6ef575d36fd and 6fa5d592f99ff1e39aa1903dcf41eb3ff3f4f858.

📒 Files selected for processing (3)
  • client/src/Components/Dialog/genericDialog.jsx (1 hunks)
  • client/src/Components/Layouts/HomeLayout/index.jsx (1 hunks)
  • client/src/Utils/DialogAnchorContext.jsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • client/src/Utils/DialogAnchorContext.jsx
  • client/src/Components/Layouts/HomeLayout/index.jsx
  • client/src/Components/Dialog/genericDialog.jsx
✨ 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:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate sequence diagram to generate a sequence diagram of the changes in 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.

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.

coderabbitai[bot] avatar May 13 '25 15:05 coderabbitai[bot]

Hi, I've modified the code so that it now correctly centered to the parent component. One thing to note is as a result of this, if the users display is too small, it may appear slightly off center since some of the parent component will be off screen.

Trained-Monkey avatar May 17 '25 03:05 Trained-Monkey

Overall, Looks good, and is working as expected.

vishnusn77 avatar Jun 15 '25 20:06 vishnusn77

Hi, I've implemented changes to fix the highlighted issues.

Opening modal now checks if there is a scrollbar present and allocates space accordingly.

DialogAnchor is now contained in a react context.

Trained-Monkey avatar Jun 22 '25 10:06 Trained-Monkey

@Trained-Monkey could you check the "format checks" please? We would like this PR go in to the next release :)

gorkem-bwl avatar Jun 24 '25 14:06 gorkem-bwl

Hi, I have ran the format checks, they should be good now.

Trained-Monkey avatar Jun 24 '25 14:06 Trained-Monkey

Great, passing now :)

gorkem-bwl avatar Jun 24 '25 14:06 gorkem-bwl

Hey @Trained-Monkey , apologies for the long delay on this PR. After discussion with the team we're not 100% comfortable with the DOM manipulation that's needed to make this PR work. We're going to table this issue for now, but if you come up with an approach that doesn't require manipulation of the DOM please let us know and we'll consider it.

Thank you for your effort here, we do appreciate it, but we're not quite ready to move on this one.

ajhollid avatar Jul 16 '25 15:07 ajhollid