Skip to content

[WIKI-570] fix: image alignment for read only editor#7509

Merged
pushya22 merged 1 commit intopreviewfrom
fix/image-alignment
Jul 30, 2025
Merged

[WIKI-570] fix: image alignment for read only editor#7509
pushya22 merged 1 commit intopreviewfrom
fix/image-alignment

Conversation

@aaryan610
Copy link
Member

@aaryan610 aaryan610 commented Jul 30, 2025

Description

This PR fixes the bug where image alignment options are visible in read only editors.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)

Summary by CodeRabbit

  • New Features

    • The image toolbar now adapts based on editor state, showing alignment options only when the editor is editable.
  • Bug Fixes

    • Improved toolbar behavior to prevent alignment actions from appearing in read-only mode.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 30, 2025

Walkthrough

The changes update the ImageToolbarRoot React component to require an editor prop and conditionally render the ImageAlignmentAction based on the editor's editability. The CustomImageBlock component is updated to pass the editor prop to ImageToolbarRoot. No other logic or exports are altered.

Changes

Cohort / File(s) Change Summary
Prop Passing in CustomImageBlock
packages/editor/src/core/extensions/custom-image/components/block.tsx
Passes the editor prop from CustomImageBlock to ImageToolbarRoot.
ImageToolbarRoot Prop and Conditional Rendering
packages/editor/src/core/extensions/custom-image/components/toolbar/root.tsx
Adds required editor prop, introduces isEditable derived from editor, and conditionally renders ImageAlignmentAction.

Sequence Diagram(s)

sequenceDiagram
    participant ParentComponent
    participant CustomImageBlock
    participant ImageToolbarRoot
    participant Editor

    ParentComponent->>CustomImageBlock: Passes editor prop
    CustomImageBlock->>ImageToolbarRoot: Passes editor prop
    ImageToolbarRoot->>Editor: Accesses isEditable
    alt Editor is editable
        ImageToolbarRoot->>ImageAlignmentAction: Render
    else Editor is not editable
        ImageToolbarRoot-->>ImageAlignmentAction: Do not render
    end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~7 minutes

Suggested labels

🐛bug, ready to merge

Suggested reviewers

  • Palanikannan1437

Poem

A bunny hopped through fields of code,
Passing props along the road.
If the editor can write and play,
Alignment tools will light the way!
With thoughtful checks and tidy flow,
The toolbar knows just when to show.
🐇✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 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 05f56d0 and a7997d0.

📒 Files selected for processing (2)
  • packages/editor/src/core/extensions/custom-image/components/block.tsx (1 hunks)
  • packages/editor/src/core/extensions/custom-image/components/toolbar/root.tsx (4 hunks)
🧰 Additional context used
🧠 Learnings (2)
packages/editor/src/core/extensions/custom-image/components/block.tsx (1)

Learnt from: SatishGandham
PR: #5864
File: packages/editor/src/core/extensions/custom-image/read-only-custom-image.ts:60-60
Timestamp: 2024-10-22T08:03:04.373Z
Learning: In packages/editor/src/core/extensions/custom-image/read-only-custom-image.ts, the getImageSource command returns a string directly, not a function.

packages/editor/src/core/extensions/custom-image/components/toolbar/root.tsx (1)

Learnt from: SatishGandham
PR: #5864
File: packages/editor/src/core/extensions/custom-image/read-only-custom-image.ts:60-60
Timestamp: 2024-10-22T08:03:04.373Z
Learning: In packages/editor/src/core/extensions/custom-image/read-only-custom-image.ts, the getImageSource command returns a string directly, not a function.

🔇 Additional comments (6)
packages/editor/src/core/extensions/custom-image/components/block.tsx (1)

283-283: LGTM! Correctly passes editor prop to ImageToolbarRoot.

The addition of the editor prop to ImageToolbarRoot is correct and necessary to support the conditional rendering of alignment actions based on editor editability.

packages/editor/src/core/extensions/custom-image/components/toolbar/root.tsx (5)

1-1: LGTM! Appropriate import for Editor type.

The import of the Editor type from @tiptap/core is necessary for the new editor prop type definition.


13-13: LGTM! Props interface correctly updated.

The addition of the editor: Editor prop to the Props interface is correct and follows TypeScript best practices.


23-23: LGTM! Proper destructuring of the new editor prop.

The destructuring correctly includes the editor prop alongside existing props.


26-27: LGTM! Clear derived value implementation.

The isEditable derived value properly extracts the editability state from the editor instance, making the conditional logic more readable.


40-46: LGTM! Correctly implements the read-only editor fix.

The conditional rendering of ImageAlignmentAction based on isEditable perfectly addresses the PR objective by hiding image alignment options when the editor is in read-only mode. Other toolbar actions (download and full-screen) remain available as expected.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/image-alignment

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 generate unit tests to generate unit tests 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.

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.

@makeplane
Copy link

makeplane bot commented Jul 30, 2025

Pull Request Linked with Plane Work Items

Comment Automatically Generated by Plane

@pushya22 pushya22 merged commit 6e1734c into preview Jul 30, 2025
5 of 8 checks passed
@pushya22 pushya22 deleted the fix/image-alignment branch July 30, 2025 08:42
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.

3 participants