Skip to content

[PE-92] fix: removing readonly collaborative document editor #6209

Merged
pushya22 merged 10 commits intopreviewfrom
fix/pages-loading-optimization
Dec 18, 2024
Merged

[PE-92] fix: removing readonly collaborative document editor #6209
pushya22 merged 10 commits intopreviewfrom
fix/pages-loading-optimization

Conversation

@Palanikannan1437
Copy link
Member

@Palanikannan1437 Palanikannan1437 commented Dec 16, 2024

Description

Removing Read only Real time document editor while switching between lock/unlock/archive/unarchive to prevent breaking the socket connection.

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Added an editable prop to various editor components, enhancing control over editability.
    • Improved image handling in the CustomImageUploader and DropHandlerExtension based on the editor's editability.
    • Integrated real-time updates into the useCollaborativePageActions hook.
  • Bug Fixes

    • Adjusted drag-and-drop functionality to respect the editor's editable state.
  • Refactor

    • Removed the CollaborativeDocumentReadOnlyEditor and its associated references, streamlining editor logic.
    • Simplified prop types across multiple components to focus solely on editable references.
    • Consolidated logic in the PageEditorBody component for a unified editing experience.
  • Style

    • Updated CSS styles for better interaction feedback based on editability.
  • Documentation

    • Updated type signatures and prop definitions across various components to reflect the new editable state.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 16, 2024

Walkthrough

This pull request introduces a comprehensive modification to the editor's architecture by adding an editable property across multiple components and hooks. The changes focus on creating a more flexible editing experience by allowing dynamic control over the editor's editability. Key modifications include removing read-only editor references, updating type definitions, and integrating the editable prop throughout the editor's core components and hooks.

Changes

File Change Summary
packages/editor/src/core/components/editors/document/collaborative-editor.tsx Added editable prop to component and hook
packages/editor/src/core/components/editors/document/collaborative-read-only-editor.tsx Removed read-only editor component
packages/editor/src/core/components/editors/document/index.ts Removed export for read-only editor module
packages/editor/src/core/components/editors/document/page-renderer.tsx Updated JSX structure for conditional rendering
packages/editor/src/core/components/editors/editor-wrapper.tsx Added editable prop to EditorWrapper component
packages/editor/src/core/extensions/custom-image/components/image-uploader.tsx Modified image uploader to check editor's editability
packages/editor/src/core/extensions/drop.tsx Enhanced drop handling for images based on editability
packages/editor/src/core/extensions/extensions.tsx Updated extensions to respect editor's editability
packages/editor/src/core/extensions/read-only-extensions.tsx Removed HeadingListExtension
packages/editor/src/core/hooks/use-collaborative-editor.ts Integrated editable prop in hook parameters
packages/editor/src/core/hooks/use-editor.ts Added editable property to CustomEditorProps interface
packages/editor/src/core/hooks/use-file-upload.ts Modified file upload handling to check editor's editability
packages/editor/src/core/hooks/use-read-only-collaborative-editor.ts Removed read-only collaborative editor hook
packages/editor/src/core/types/collaboration.ts Added optional editable property to collaborative editor props
packages/editor/src/core/types/editor.ts Added editable property to IEditorProps interface
packages/editor/src/index.ts Removed export for CollaborativeDocumentReadOnlyEditorWithRef
packages/editor/src/styles/editor.css Updated styles for .ProseMirror based on editability
web/core/components/pages/editor/editor-body.tsx Updated prop types and removed read-only editor references
web/core/components/pages/editor/header/extra-options.tsx Removed readOnlyEditorRef prop and updated references
web/core/components/pages/editor/header/info-popover.tsx Simplified editorRef prop type
web/core/components/pages/editor/header/mobile-root.tsx Removed read-only editor props and simplified logic
web/core/components/pages/editor/header/options-dropdown.tsx Updated editorRef prop type
web/core/components/pages/editor/header/root.tsx Removed read-only editor props and simplified rendering logic
web/core/components/pages/editor/page-root.tsx Removed read-only editor references and streamlined logic
web/core/components/pages/editor/summary/content-browser.tsx Updated editorRef prop type
web/core/components/pages/editor/summary/popover.tsx Updated editorRef prop type
web/core/components/pages/modals/export-page-modal.tsx Updated editorRef prop type and removed related import
web/core/hooks/use-collaborative-page-actions.tsx Enhanced real-time update logic for collaborative actions

Sequence Diagram

sequenceDiagram
    participant User
    participant Editor
    participant CollaborativeEditor
    participant UseCollaborativeEditor

    User->>Editor: Set editable prop
    Editor->>CollaborativeEditor: Pass editable state
    CollaborativeEditor->>UseCollaborativeEditor: Configure editor with editable prop
    UseCollaborativeEditor-->>CollaborativeEditor: Return configured editor
    CollaborativeEditor-->>Editor: Render editor with editability
Loading

Possibly related PRs

Suggested labels

🐛bug, ✨feature, 🌐frontend

Suggested reviewers

  • SatishGandham
  • aaryan610

Poem

🐰 A rabbit's tale of code so bright,
Editable states now take their flight!
No more read-only, no more restraint,
Our editor dances with flexible paint!
Flexibility rules, the code sings free! 🎉


📜 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 25abb9e and f24d8a1.

📒 Files selected for processing (5)
  • packages/editor/src/core/components/editors/editor-wrapper.tsx (1 hunks)
  • packages/editor/src/core/extensions/extensions.tsx (4 hunks)
  • packages/editor/src/core/hooks/use-editor.ts (3 hunks)
  • packages/editor/src/core/types/editor.ts (1 hunks)
  • web/core/components/pages/editor/header/extra-options.tsx (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (5)
  • packages/editor/src/core/types/editor.ts
  • packages/editor/src/core/components/editors/editor-wrapper.tsx
  • web/core/components/pages/editor/header/extra-options.tsx
  • packages/editor/src/core/hooks/use-editor.ts
  • packages/editor/src/core/extensions/extensions.tsx

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.

@Palanikannan1437 Palanikannan1437 marked this pull request as ready for review December 17, 2024 10:28
@Palanikannan1437 Palanikannan1437 marked this pull request as draft December 17, 2024 10:29
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: 4

🔭 Outside diff range comments (1)
packages/editor/src/core/components/editors/editor-wrapper.tsx (1)

Line range hint 12-16: Fix Props type definition.

The editable prop is used but not included in the Props type definition. This could cause TypeScript errors.

Add the editable property to the Props type:

 type Props = IEditorProps & {
   children?: (editor: Editor) => React.ReactNode;
   extensions: Extension<any, any>[];
+  editable?: boolean;
 };
♻️ Duplicate comments (1)
packages/editor/src/core/extensions/extensions.tsx (1)

50-54: 🛠️ Refactor suggestion

Consider making editable prop required

The editable prop is marked as optional but seems to control critical editor functionality. Consider making it required to ensure proper editor state management.

type TArguments = {
-  editable?: boolean;
+  editable: boolean;
};
🧹 Nitpick comments (11)
web/core/components/pages/editor/header/mobile-root.tsx (1)

Line range hint 2-2: Remove unused import EditorReadOnlyRefApi.

The EditorReadOnlyRefApi import is no longer used after removing readonly editor functionality.

packages/editor/src/core/components/editors/editor-wrapper.tsx (1)

42-42: Document the default value for editable prop.

Consider documenting the default behavior when editable is undefined, as this affects the editor's functionality.

Add a comment explaining the default behavior:

   const editor = useEditor({
+    // If undefined, editor is editable by default
     editable,
     disabledExtensions,
web/core/components/pages/editor/header/root.tsx (1)

43-43: Consider consolidating editor ref checks

Multiple null checks for editorRef.current could be consolidated to improve code maintainability.

- {editorReady && isContentEditable && editorRef.current && <PageToolbar editorRef={editorRef?.current} />}
+ {editorReady && isContentEditable && <PageToolbar editorRef={editorRef.current} />}

Also applies to: 50-50, 52-52

packages/editor/src/core/extensions/drop.tsx (2)

34-59: Consider refactoring for better readability

The handleDrop method could be refactored to improve readability while maintaining the same functionality.

Consider this refactoring:

  handleDrop: (view: EditorView, event: DragEvent, _slice: any, moved: boolean) => {
-   if (
-     editor.isEditable &&
-     !moved &&
-     event.dataTransfer &&
-     event.dataTransfer.files &&
-     event.dataTransfer.files.length > 0
-   ) {
-     event.preventDefault();
-     const files = Array.from(event.dataTransfer.files);
-     const imageFiles = files.filter((file) => file.type.startsWith("image"));
-
-     if (imageFiles.length > 0) {
-       const coordinates = view.posAtCoords({
-         left: event.clientX,
-         top: event.clientY,
-       });
-
-       if (coordinates) {
-         const pos = coordinates.pos;
-         insertImagesSafely({ editor, files: imageFiles, initialPos: pos, event: "drop" });
-       }
-       return true;
-     }
-   }
-   return false;
+   if (!editor.isEditable || moved) return false;
+   
+   const files = event.dataTransfer?.files;
+   if (!files?.length) return false;
+   
+   const imageFiles = Array.from(files).filter((file) => file.type.startsWith("image"));
+   if (!imageFiles.length) return false;
+   
+   event.preventDefault();
+   
+   const coordinates = view.posAtCoords({
+     left: event.clientX,
+     top: event.clientY,
+   });
+   
+   if (coordinates) {
+     insertImagesSafely({ 
+       editor, 
+       files: imageFiles, 
+       initialPos: coordinates.pos, 
+       event: "drop" 
+     });
+   }
+   
+   return true;
  }

Line range hint 66-93: Consider extracting image handling logic

The insertImagesSafely function looks good, but consider extracting the common image file filtering logic to reduce duplication between handlePaste and handleDrop.

Consider creating a utility function:

const getImageFiles = (files: FileList | File[]): File[] => {
  return Array.from(files).filter((file) => file.type.startsWith("image"));
};
web/core/components/pages/editor/header/extra-options.tsx (1)

10-10: Remove unused import

The SyncingComponent is imported but never used in this file.

- import { SyncingComponent } from "@/components/icons/syncing-component";
web/core/hooks/use-collaborative-page-actions.tsx (1)

53-56: Improve error handling for undefined serverEventName

Consider adding error handling or logging when serverEventName is undefined to help with debugging.

  const serverEventName = getServerEventName(clientAction);
  if (serverEventName) {
    editorRef?.emitRealTimeUpdate(serverEventName);
+ } else {
+   console.warn(`No server event name found for client action: ${clientAction}`);
  }
packages/editor/src/core/types/editor.ts (1)

109-109: Consider consolidating editor interfaces

While adding the editable property is a good step towards flexible editor control, maintaining separate readonly interfaces (IReadOnlyEditorProps, ILiteTextReadOnlyEditor, etc.) alongside this property creates redundancy and potential confusion.

Consider:

  1. Deprecating the readonly interfaces in favor of using the editable property
  2. Creating a migration guide for users to transition from readonly interfaces to the new approach
  3. Adding JSDoc deprecation notices to the readonly interfaces
packages/editor/src/core/extensions/custom-image/components/image-uploader.tsx (2)

140-149: Simplify className conditions

The current implementation has multiple repetitive checks for editor.isEditable and complex conditional styling.

Consider simplifying the className logic:

-"image-upload-component flex items-center justify-start gap-2 py-3 px-2 rounded-lg text-custom-text-300 bg-custom-background-90 border border-dashed border-custom-border-300 transition-all duration-200 ease-in-out cursor-default",
-{
-  "hover:text-custom-text-200 hover:bg-custom-background-80 cursor-pointer": editor.isEditable,
-  "bg-custom-background-80 text-custom-text-200": draggedInside && editor.isEditable,
-  "text-custom-primary-200 bg-custom-primary-100/10 border-custom-primary-200/10 hover:bg-custom-primary-100/10 hover:text-custom-primary-200":
-    selected && editor.isEditable,
-  "text-red-500 cursor-default": failedToLoadImage,
-  "hover:text-red-500": failedToLoadImage && editor.isEditable,
-  "bg-red-500/10": failedToLoadImage && selected,
-  "hover:bg-red-500/10": failedToLoadImage && selected && editor.isEditable,
-}
+cn(
+  "image-upload-component flex items-center justify-start gap-2 py-3 px-2 rounded-lg transition-all duration-200 ease-in-out",
+  // Base styles
+  "text-custom-text-300 bg-custom-background-90 border border-dashed border-custom-border-300",
+  // Cursor styles
+  editor.isEditable && !failedToLoadImage ? "cursor-pointer" : "cursor-default",
+  // Interactive states when editable
+  editor.isEditable && {
+    "hover:text-custom-text-200 hover:bg-custom-background-80": !failedToLoadImage,
+    "hover:text-red-500 hover:bg-red-500/10": failedToLoadImage && selected,
+  },
+  // Drag states
+  draggedInside && editor.isEditable && "bg-custom-background-80 text-custom-text-200",
+  // Selected states
+  selected && editor.isEditable && "text-custom-primary-200 bg-custom-primary-100/10 border-custom-primary-200/10",
+  // Error states
+  failedToLoadImage && "text-red-500",
+  failedToLoadImage && selected && "bg-red-500/10"
+)

Line range hint 130-135: Extract editable state check to a separate variable

The getDisplayMessage function mixes state checks with message selection.

Consider separating the concerns:

 const getDisplayMessage = useCallback(() => {
   const isUploading = isImageBeingUploaded;
+  const canDropImage = draggedInside && editor.isEditable;
   
   if (failedToLoadImage) {
     return "Error loading image";
   }
   if (isUploading) {
     return "Uploading...";
   }
-  if (draggedInside && editor.isEditable) {
+  if (canDropImage) {
     return "Drop image here";
   }
   return "Add an image";
-}, [draggedInside, failedToLoadImage, isImageBeingUploaded]);
+}, [draggedInside, editor.isEditable, failedToLoadImage, isImageBeingUploaded]);
web/core/components/pages/editor/editor-body.tsx (1)

177-217: LGTM: Unified editor implementation

The consolidation to a single editor component with an editable prop is a cleaner approach than maintaining separate editor implementations. The configuration is comprehensive and includes all necessary handlers.

Consider documenting the editable prop behavior in component documentation or README to help other developers understand this architectural change.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4507802 and 2fc1ac7.

📒 Files selected for processing (28)
  • packages/editor/src/core/components/editors/document/collaborative-editor.tsx (3 hunks)
  • packages/editor/src/core/components/editors/document/collaborative-read-only-editor.tsx (0 hunks)
  • packages/editor/src/core/components/editors/document/index.ts (0 hunks)
  • packages/editor/src/core/components/editors/document/page-renderer.tsx (1 hunks)
  • packages/editor/src/core/components/editors/editor-wrapper.tsx (2 hunks)
  • packages/editor/src/core/extensions/custom-image/components/image-uploader.tsx (2 hunks)
  • packages/editor/src/core/extensions/drop.tsx (1 hunks)
  • packages/editor/src/core/extensions/extensions.tsx (4 hunks)
  • packages/editor/src/core/extensions/read-only-extensions.tsx (0 hunks)
  • packages/editor/src/core/hooks/use-collaborative-editor.ts (3 hunks)
  • packages/editor/src/core/hooks/use-editor.ts (3 hunks)
  • packages/editor/src/core/hooks/use-file-upload.ts (1 hunks)
  • packages/editor/src/core/hooks/use-read-only-collaborative-editor.ts (0 hunks)
  • packages/editor/src/core/types/collaboration.ts (1 hunks)
  • packages/editor/src/core/types/editor.ts (1 hunks)
  • packages/editor/src/index.ts (0 hunks)
  • packages/editor/src/styles/editor.css (1 hunks)
  • web/core/components/pages/editor/editor-body.tsx (5 hunks)
  • web/core/components/pages/editor/header/extra-options.tsx (3 hunks)
  • web/core/components/pages/editor/header/info-popover.tsx (1 hunks)
  • web/core/components/pages/editor/header/mobile-root.tsx (1 hunks)
  • web/core/components/pages/editor/header/options-dropdown.tsx (2 hunks)
  • web/core/components/pages/editor/header/root.tsx (2 hunks)
  • web/core/components/pages/editor/page-root.tsx (3 hunks)
  • web/core/components/pages/editor/summary/content-browser.tsx (1 hunks)
  • web/core/components/pages/editor/summary/popover.tsx (1 hunks)
  • web/core/components/pages/modals/export-page-modal.tsx (2 hunks)
  • web/core/hooks/use-collaborative-page-actions.tsx (2 hunks)
💤 Files with no reviewable changes (5)
  • packages/editor/src/core/components/editors/document/index.ts
  • packages/editor/src/index.ts
  • packages/editor/src/core/extensions/read-only-extensions.tsx
  • packages/editor/src/core/hooks/use-read-only-collaborative-editor.ts
  • packages/editor/src/core/components/editors/document/collaborative-read-only-editor.tsx
✅ Files skipped from review due to trivial changes (1)
  • packages/editor/src/core/components/editors/document/page-renderer.tsx
🔇 Additional comments (21)
packages/editor/src/core/types/collaboration.ts (1)

24-24: ⚠️ Potential issue

Consider removing TReadOnlyCollaborativeEditorProps type.

While adding the editable property is a step towards removing readonly editor functionality, the TReadOnlyCollaborativeEditorProps type still exists and references EditorReadOnlyRefApi. This seems inconsistent with the PR's goal.

Let's verify if EditorReadOnlyRefApi is still being used elsewhere:

web/core/components/pages/editor/header/mobile-root.tsx (1)

43-43: Consider consolidating editability checks.

The condition isContentEditable && editorRef.current might be redundant with the new editable prop from the editor. Consider using a single source of truth for editability.

Let's check how isContentEditable is used across the codebase:

packages/editor/src/core/components/editors/document/collaborative-editor.tsx (2)

22-22: LGTM: Editable prop addition

The addition of the editable prop aligns with the PR objective of consolidating editor functionality into a single component with controlled editability.


Line range hint 49-58: Verify editable prop behavior in useCollaborativeEditor

The editable prop is correctly passed to the hook, but we should verify its implementation in the hook to ensure proper editor state management.

✅ Verification successful

Let me verify the implementation of useEditor to ensure proper handling of the editable prop.


Let me check the implementation of useTiptapEditor to complete the verification chain.


Let me try a different approach to find the Tiptap editor usage.


Based on the code analysis from the previous results, I can now provide a final response:

The editable prop is properly implemented in the editor chain

The editable prop is correctly handled throughout the component hierarchy:

  • Passed from collaborative-editor.tsx to useCollaborativeEditor
  • Forwarded to useEditor hook
  • Used in the editor configuration to control editability
  • Properly included in the dependency array for editor updates

The implementation ensures proper editor state management when the editable prop changes.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for useCollaborativeEditor implementation and its usage of editable prop
ast-grep --pattern 'export const useCollaborativeEditor = $_' -A 20

Length of output: 8942


Script:

#!/bin/bash
# Search for useEditor implementation and its usage of editable prop
ast-grep --pattern 'export const useEditor = $_' -A 20

Length of output: 22877


Script:

#!/bin/bash
# Search for useTiptapEditor implementation
ast-grep --pattern 'export const useTiptapEditor = $_'

Length of output: 56


Script:

#!/bin/bash
# Search for useEditor from tiptap
rg "from '@tiptap/react'" -A 5

Length of output: 38

web/core/components/pages/editor/header/root.tsx (2)

23-23: LGTM: Props cleanup

Successfully removed readOnly-related props, simplifying the component's interface.


29-29: Verify editor ready state handling

The editor ready checks have been simplified, but we should verify there are no edge cases where readOnly state was specifically needed.

Also applies to: 35-35

✅ Verification successful

Let me search for any readOnly state checks that might have been related to editorReady.


Let me try a different approach to search for readOnly related checks.


Based on the search results, I can now provide a final response:

Editor ready state changes are safe to simplify

The readOnly state and editorReady state are handled independently in the codebase. The readOnly state is primarily controlled through the isContentEditable prop and passed directly to the editor components, while editorReady is used for UI rendering conditions. The simplification of editor ready checks does not impact the readOnly functionality, as they serve different purposes:

  • readOnly: Controls edit permissions and editor capabilities
  • editorReady: Controls UI component rendering timing
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for other occurrences of editorReady checks
rg "editorReady" -A 2

Length of output: 3586


Script:

#!/bin/bash
# Search for readOnly checks near editorReady
rg "readOnly.*editorReady|editorReady.*readOnly" -A 2

# Search for readOnly state handling in editor components
rg "readOnly" --type typescript -A 2 web/core/components/pages/editor/

Length of output: 161


Script:

#!/bin/bash
# Search for readOnly in editor components
rg "readOnly" web/core/components/pages/editor/ -A 2

# Also check for any editor state initialization patterns
ast-grep --pattern 'const editor = $_'

Length of output: 12424

web/core/components/pages/editor/summary/content-browser.tsx (1)

3-3: LGTM: Type definition update

Successfully simplified the editorRef type by removing EditorReadOnlyRefApi, which aligns with the PR objective of consolidating editor functionality.

Also applies to: 8-8

web/core/components/pages/editor/summary/popover.tsx (1)

12-12: LGTM! Verify PageContentBrowser's null handling

The removal of EditorReadOnlyRefApi aligns with the PR objective. The change simplifies the type to just EditorRefApi | null.

Let's verify that PageContentBrowser properly handles null editorRef:

✅ Verification successful

LGTM! PageContentBrowser handles null editorRef properly

The code properly handles the null case for editorRef through:

  • Optional chaining (?.) when calling onHeadingChange and scrollSummary
  • Nullish coalescing (??) with getHeadings() defaulting to empty array
  • No direct property access without null checks
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for null checks in PageContentBrowser
ast-grep --pattern 'editorRef?.getDocumentInfo()' web/core/components/pages/editor/summary/content-browser.tsx

Length of output: 112


Script:

#!/bin/bash
# Let's first check the content of PageContentBrowser to understand how editorRef is used
cat web/core/components/pages/editor/summary/content-browser.tsx

# As a backup, let's also search for any usage of editorRef with ripgrep
rg "editorRef" web/core/components/pages/editor/summary/content-browser.tsx

Length of output: 2297

web/core/components/pages/editor/header/info-popover.tsx (1)

10-10: LGTM! Proper null handling in place

The removal of EditorReadOnlyRefApi is consistent with the PR objective. The component already handles null editorRef safely through optional chaining.

packages/editor/src/core/extensions/drop.tsx (1)

16-33: LGTM! Proper editability check added

The addition of editor.isEditable check ensures images can only be pasted when the editor is editable, which aligns with removing readonly editor functionality.

packages/editor/src/core/hooks/use-collaborative-editor.ts (1)

18-18: LGTM! Clean integration of editable prop

The changes properly integrate the editable prop through the component hierarchy while maintaining the existing functionality.

Also applies to: 79-79, 102-104

web/core/hooks/use-collaborative-page-actions.tsx (1)

67-67: LGTM! Correct dependency array update

The addition of editorRef to the dependency array is correct and necessary for proper hook functionality.

web/core/components/pages/editor/page-root.tsx (2)

142-143: LGTM! Clean handler prop assignments

The simplified handler assignments improve code readability while maintaining the same functionality.


100-100: Verify version history functionality with single editor

The version history feature now relies solely on the main editor reference. Ensure this change doesn't affect version comparison functionality.

✅ Verification successful

Version history functionality remains intact with single editor

Based on the code analysis, the version history functionality is properly maintained after removing the readonly editor:

  • The version comparison overlay (PageVersionsOverlay) uses currentVersionDescription from the main editor correctly
  • Version history state management (via URL params) and restoration flow are independent of the editor implementation
  • The version history feature is accessible through the options dropdown and works with the current editor state
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for version comparison related code
rg -A 5 "version.*comparison|compare.*version" 
# Check for version-related components that might be affected
ast-grep --pattern 'class $_ {
  $$$
  version($$$) {
    $$$
  }
  $$$
}'

Length of output: 125


Script:

#!/bin/bash
# Search for version-related functionality in the editor component
rg -A 5 "getDocument|setDocument|version" web/core/components/pages/editor/

# Check for version history related components and their usage
fd "version|history" web/core/components/ --type f --exec rg -l "editorRef|getDocument"

# Look for any tests related to version comparison
fd "test|spec" web/core/ --type f --exec rg -l "version.*history|document.*version"

Length of output: 5638

packages/editor/src/core/extensions/extensions.tsx (2)

150-152: LGTM! Proper mention handling based on editability

The conditional mention suggestions and readonly state are correctly configured based on the editor's editable state.


156-157: LGTM! Placeholder visibility control

Early return for placeholder when editor is not editable improves user experience.

web/core/components/pages/editor/header/options-dropdown.tsx (1)

18-18: LGTM! Simplified editor reference type

The removal of EditorReadOnlyRefApi aligns with the PR objective of removing the readonly editor functionality.

Also applies to: 33-33

web/core/components/pages/editor/editor-body.tsx (1)

43-44: LGTM: Props type refinement

The change to use Dispatch<SetStateAction> for state handlers improves type safety and better reflects their usage as state setters.

web/core/components/pages/modals/export-page-modal.tsx (1)

7-7: LGTM: Type simplification

The removal of EditorReadOnlyRefApi and simplification of the editorRef type is consistent with the unified editor approach.

Also applies to: 19-19

packages/editor/src/styles/editor.css (1)

114-119: LGTM: Enhanced checkbox interaction styles

The styles now properly handle checkbox interactions based on the editor's editable state:

  • Hover effects only when editable
  • Disabled pointer events when not editable
packages/editor/src/core/hooks/use-editor.ts (1)

83-118: Verify editor state preservation on editable changes

The editable prop in the dependency array will cause editor reinitialization when changed. This could lead to:

  1. Performance issues if editable changes frequently
  2. Potential loss of user input or selection state

Consider:

  1. Using editor commands to update editable state instead of reinitializing
  2. Preserving and restoring editor state during reinitialization
✅ Verification successful

Let me analyze the search results:

  1. The ast-grep search shows that the editor commands are used for various operations like text selection, image insertion, code block handling, etc., but there's no direct command to update the editable state.

  2. The rg search shows that editable is primarily used as:

  • A prop in React components for UI elements like filters and editors
  • A database field attribute in Django migrations
  • A CSS property for styling

Looking at the editor's usage in web/core/components/pages/editor/editor-body.tsx, the editable prop is passed directly to control the editor state:

editable={isContentEditable}

Based on this analysis, I can generate the final response:

Editor reinitialization is the correct approach for editable state changes

The codebase shows that editable state is a fundamental prop that should trigger editor reinitialization because:

  1. There's no editor command to toggle editable state at runtime
  2. The editable state affects multiple extensions and core editor behavior
  3. The editor preserves selection state via setSavedSelection in onTransaction

The current implementation correctly handles state preservation and the performance impact is justified for this critical state change.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for editor commands related to editable state
ast-grep --pattern 'editor.commands.$_($_)'

# Search for editable state changes in components
rg -A 3 'setEditable|editable.*=.*'

Length of output: 67674

@Palanikannan1437 Palanikannan1437 changed the title fix: removing readonly editor [PE-92] fix: removing readonly collaborative document editor Dec 17, 2024
@Palanikannan1437 Palanikannan1437 self-assigned this Dec 17, 2024
@Palanikannan1437 Palanikannan1437 marked this pull request as ready for review December 17, 2024 10:38
@pushya22 pushya22 merged commit e33bae2 into preview Dec 18, 2024
@pushya22 pushya22 deleted the fix/pages-loading-optimization branch December 18, 2024 07:28
@coderabbitai coderabbitai bot mentioned this pull request Dec 19, 2024
1 task
@coderabbitai coderabbitai bot mentioned this pull request Jan 6, 2025
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants