Skip to content

feat: add avoidChangesNotSavedAlertOnClose prop #541

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

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

Conversation

hamza221
Copy link

@hamza221 hamza221 commented May 29, 2025

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features
    • Added a configuration option to disable the confirmation modal when closing the editor with unsaved changes.
  • Documentation
    • Updated documentation to include the new configuration property controlling the close confirmation modal behavior.

Copy link

coderabbitai bot commented May 29, 2025

Walkthrough

The openModal function in the ConfirmationModal component was updated to check the new avoidChangesNotSavedAlertOnClose configuration flag. If this flag is true, the modal is bypassed and the close handler is called immediately; otherwise, the modal opens as before. The new flag was added to the default config, TypeScript interface, demo config, and documented in the README.

Changes

File Change Summary
packages/react-filerobot-image-editor/src/components/Topbar/ConfirmationModal.jsx Updated openModal to check new avoidChangesNotSavedAlertOnClose config flag before opening modal; reordered function definition.
packages/react-filerobot-image-editor/src/context/defaultConfig.js Added avoidChangesNotSavedAlertOnClose boolean property with default false to default config.
packages/react-filerobot-image-editor/src/index.d.ts Added optional avoidChangesNotSavedAlertOnClose boolean property to FilerobotImageEditorConfig interface.
README.md Documented new avoidChangesNotSavedAlertOnClose boolean config property controlling modal on close.
public/demo-config.js Added commented avoidChangesNotSavedAlertOnClose boolean config option to demo config.

Poem

A modal once would always show,
But now it checks before the glow.
If closing swift is what you choose,
The alert’s gone, no time to lose!
With flags in place and code so bright,
The bunny hops away in light! 🐇✨

✨ 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.

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)
packages/react-filerobot-image-editor/src/components/Topbar/ConfirmationModal.jsx (2)

20-20: Consider simplifying the destructuring pattern.

The current pattern destructures config twice, which could be confusing. Consider using direct property access or a cleaner destructuring approach.

Apply this diff for a cleaner approach:

-    config: { onClose, avoidChangesNotSavedAlertOnLeave },
+    config: { onClose, avoidChangesNotSavedAlertOnLeave, ...restConfig },

Or alternatively, use direct property access in the function:

-    config: { onClose, avoidChangesNotSavedAlertOnLeave },

And reference it as config.avoidChangesNotSavedAlertOnLeave in the openModal function.


47-54: Logic implementation is correct, but consider renaming for clarity.

The conditional logic correctly implements the required functionality to skip the modal when avoidChangesNotSavedAlertOnLeave is true. However, the function name openModal is now misleading since it might not open the modal at all.

Consider renaming the function to better reflect its behavior:

-  const openModal = () => {
+  const handleModalAction = () => {
     // Don't open the modal if avoidChangesNotSavedAlertOnLeave is true
     if (avoidChangesNotSavedAlertOnLeave) {
       closeWithReason();
       return;
     }
     setIsModalOpened(true);
   };

And update the reference on line 59:

-        onClick: isResetted ? closeWithReason : openModal,
+        onClick: isResetted ? closeWithReason : handleModalAction,
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3d198dd and 719316e.

📒 Files selected for processing (1)
  • packages/react-filerobot-image-editor/src/components/Topbar/ConfirmationModal.jsx (2 hunks)

@hamza221 hamza221 force-pushed the fix/discard-confirmation-modal-on-config branch 2 times, most recently from 15c00a6 to d84942c Compare May 29, 2025 13:46
@AhmeeedMostafa
Copy link
Collaborator

@hamza221 this is not a bug, and this needs a different prop if you want to make it configurable, the alert here means the browser's alert for sudden leaving the page.

@hamza221 hamza221 force-pushed the fix/discard-confirmation-modal-on-config branch from d84942c to 1035cfe Compare June 11, 2025 10:09
@hamza221 hamza221 changed the title fix: don't show confirmation modal if avoidChangesNotSavedAlertOnLeave is set to true feat: add avoidChangesNotSavedAlertOnClose prop Jun 11, 2025
@hamza221
Copy link
Author

@hamza221 this is not a bug, and this needs a different prop if you want to make it configurable, the alert here means the browser's alert for sudden leaving the page.

Thank you for the feedback, switched to a feature commit

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 (1)
README.md (1)

500-509: Minor wording & comma for readability

-By default once the user makes any change/edit on the image and hasn't saved the image yet and then clicks on the close button, a confirmation modal will be shown asking if they really want to close without saving. Setting this to `true` will skip showing the confirmation modal and close immediately.
+By default, once the user has unsaved changes and clicks the close button, a confirmation modal is shown asking whether they really want to close without saving. Setting this to `true` skips the modal and closes immediately.
🧰 Tools
🪛 LanguageTool

[uncategorized] ~507-~507: Did you mean: “By default,”?
Context: ...: +v4.0.0 Default: false By default once the user makes any change/edit on ...

(BY_DEFAULT_COMMA)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d84942c and 1035cfe.

📒 Files selected for processing (5)
  • README.md (1 hunks)
  • packages/react-filerobot-image-editor/src/components/Topbar/ConfirmationModal.jsx (2 hunks)
  • packages/react-filerobot-image-editor/src/context/defaultConfig.js (1 hunks)
  • packages/react-filerobot-image-editor/src/index.d.ts (1 hunks)
  • public/demo-config.js (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • packages/react-filerobot-image-editor/src/context/defaultConfig.js
  • packages/react-filerobot-image-editor/src/index.d.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/react-filerobot-image-editor/src/components/Topbar/ConfirmationModal.jsx
🧰 Additional context used
🪛 LanguageTool
README.md

[uncategorized] ~507-~507: Did you mean: “By default,”?
Context: ...: +v4.0.0 Default: false By default once the user makes any change/edit on ...

(BY_DEFAULT_COMMA)

🔇 Additional comments (1)
public/demo-config.js (1)

344-348:

✅ Verification successful

Avoid property-name mismatches

You now expose two very similar flags:

// avoidChangesNotSavedAlertOnLeave
// avoidChangesNotSavedAlertOnClose   ← newly added

Having 27-character identifiers that differ by only four letters is a typo-trap; a misspelled key will silently fall back to the default.
Please run a quick search to make sure every usage in src/ is spelled exactly avoidChangesNotSavedAlertOnClose, and that comments for the Leave flag are still correct.


🏁 Script executed:

#!/bin/bash
# List all occurrences of both flags to catch misspellings.
rg -n $'avoidChangesNotSavedAlertOn(Leave|Close)'

Length of output: 1650


No mismatched properties detected

A search for both avoidChangesNotSavedAlertOnLeave and avoidChangesNotSavedAlertOnClose across the repo shows they’re consistently spelled in:

  • README.md
  • public/demo-config.js
  • packages/react-filerobot-image-editor/src/index.d.ts
  • packages/react-filerobot-image-editor/src/context/defaultConfig.js
  • ConfirmationModal.jsx
  • App/index.jsx

The comment on the Leave flag in public/demo-config.js remains unchanged from before, so its semantics are still accurate.

@hamza221 hamza221 force-pushed the fix/discard-confirmation-modal-on-config branch from 1035cfe to d8e63c0 Compare June 11, 2025 10:13
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 (1)
README.md (1)

500-509: Consistency & grammar: wrap property heading in backticks and add comma after "By default".

The new property heading should match other entries (use backticks), and the phrase "By default" should be followed by a comma for clarity.

-#### avoidChangesNotSavedAlertOnClose
+#### `avoidChangesNotSavedAlertOnClose`

-By default once the user makes any change/edit on the image and hasn't saved the image yet and then clicks on the close button, a confirmation modal will be shown asking if they really want to close without saving. Setting this to `true` will skip showing the confirmation modal and close immediately.
+By default, once the user makes any change/edit on the image and hasn't saved the image yet and then clicks on the close button, a confirmation modal will be shown asking if they really want to close without saving. Setting this to `true` will skip showing the confirmation modal and close immediately.
🧰 Tools
🪛 LanguageTool

[uncategorized] ~507-~507: Did you mean: “By default,”?
Context: ...: +v5.0.0 Default: false By default once the user makes any change/edit on ...

(BY_DEFAULT_COMMA)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 1035cfe and d8e63c0.

📒 Files selected for processing (5)
  • README.md (1 hunks)
  • packages/react-filerobot-image-editor/src/components/Topbar/ConfirmationModal.jsx (2 hunks)
  • packages/react-filerobot-image-editor/src/context/defaultConfig.js (1 hunks)
  • packages/react-filerobot-image-editor/src/index.d.ts (1 hunks)
  • public/demo-config.js (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
  • packages/react-filerobot-image-editor/src/index.d.ts
  • public/demo-config.js
  • packages/react-filerobot-image-editor/src/context/defaultConfig.js
  • packages/react-filerobot-image-editor/src/components/Topbar/ConfirmationModal.jsx
🧰 Additional context used
🪛 LanguageTool
README.md

[uncategorized] ~507-~507: Did you mean: “By default,”?
Context: ...: +v5.0.0 Default: false By default once the user makes any change/edit on ...

(BY_DEFAULT_COMMA)

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