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

[WEB-2127] dev: editor extensions configuration #5279

Merged
merged 1 commit into from
Aug 7, 2024

Conversation

aaryan610
Copy link
Collaborator

@aaryan610 aaryan610 commented Jul 31, 2024

Plane issue: WEB-2127

Summary by CodeRabbit

  • New Features

    • Added functionality to manage disabled extensions in document and rich text editors for enhanced user control.
    • Introduced a new hook, useEditorFlagging, to manage the state of disabled extensions across different editors.
    • Expanded command options in the editor by adding "issue-embed".
  • Bug Fixes

    • Streamlined the handling of issue embed properties within the editor, improving performance and clarity.
  • Documentation

    • Enhanced type safety with the introduction of new types for better clarity and functionality.

Copy link
Contributor

coderabbitai bot commented Jul 31, 2024

Walkthrough

The recent changes enhance the type safety and functionality of the document and rich text editors. New optional properties for disabling extensions were introduced, improving control over editor behavior. Functions were streamlined, unnecessary code removed, and a new hook was added for managing disabled states across different editors. Overall, these updates promote a more flexible and user-friendly editing experience while ensuring clarity and efficiency in the codebase.

Changes

File Path Change Summary
packages/editor/src/ce/extensions/... Added disabledExtensions prop to DocumentEditorAdditionalExtensions, enhancing flexibility.
packages/editor/src/core/components/... Updated IDocumentEditor and DocumentEditor to handle disabledExtensions for better control.
packages/editor/src/core/components/... Simplified getExtensions in RichTextEditor by removing comments and streamlining logic.
packages/editor/src/core/hooks/... Enhanced useDocumentEditor to manage disabledExtensions, improving its functionality.
packages/editor/src/core/types/extensions.ts Introduced TExtensions type for improved type safety regarding extensions.
packages/editor/src/core/types/index.ts Re-exported types from extensions.ts for better accessibility.
packages/editor/src/core/types/... Expanded TEditorCommands with a new command option "issue-embed" for enhanced capabilities.
web/ce/hooks/... Created useEditorFlagging hook to manage disabled extensions in editors.
web/ce/hooks/use-issue-embed.tsx Simplified useIssueEmbed by removing unnecessary properties, improving clarity.
web/core/components/pages/editor/... Integrated useEditorFlagging into PageEditorBody, enhancing editor state management.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant PageEditorBody
    participant useEditorFlagging
    participant DocumentEditor

    User->>PageEditorBody: Interact with editor
    PageEditorBody->>useEditorFlagging: Fetch disabled extensions
    useEditorFlagging-->>PageEditorBody: Return disabled extensions
    PageEditorBody->>DocumentEditor: Render editor with disabled extensions
Loading

🐇 In a meadow so bright and fair,
We’ve made changes with utmost care.
Extensions disabled, oh what a sight,
Editing now feels just right!
With clarity and flow, we cheer and play,
Hopping to code’s new, joyful day! 🌼


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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
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: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between dd3df20 and bb52b69.

Files selected for processing (10)
  • packages/editor/src/ce/extensions/document-extensions.tsx (1 hunks)
  • packages/editor/src/core/components/editors/document/editor.tsx (3 hunks)
  • packages/editor/src/core/components/editors/rich-text/editor.tsx (1 hunks)
  • packages/editor/src/core/hooks/use-document-editor.ts (4 hunks)
  • packages/editor/src/core/types/extensions.ts (1 hunks)
  • packages/editor/src/core/types/index.ts (1 hunks)
  • packages/editor/src/core/types/slash-commands-suggestion.ts (1 hunks)
  • web/ce/hooks/use-editor-flagging.ts (1 hunks)
  • web/ce/hooks/use-issue-embed.tsx (2 hunks)
  • web/core/components/pages/editor/editor-body.tsx (4 hunks)
Files skipped from review due to trivial changes (3)
  • packages/editor/src/core/components/editors/rich-text/editor.tsx
  • packages/editor/src/core/types/extensions.ts
  • web/ce/hooks/use-issue-embed.tsx
Additional comments not posted (15)
packages/editor/src/core/types/index.ts (1)

3-3: LGTM! The new export statement enhances module accessibility.

The addition of export * from "./extensions"; is straightforward and ensures that functionalities from the extensions module are accessible.

packages/editor/src/ce/extensions/document-extensions.tsx (2)

1-1: LGTM! The type safety improvements are beneficial.

The addition of the optional disabledExtensions property and the explicit type declaration for extensions enhance type safety and control over active extensions.


11-11: Verify the usage of the new disabledExtensions property.

Ensure that the new disabledExtensions property is correctly utilized throughout the codebase.

Verification successful

The disabledExtensions property is correctly utilized throughout the codebase.

The property is integrated into the document editor's configuration and functionality, appearing in type definitions, component props, and hooks.

  • DocumentEditor component
  • useDocumentEditor hook
  • Type definitions for DocumentEditorProps and IDocumentEditor
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of the new `disabledExtensions` property.

# Test: Search for the usage of the `disabledExtensions` property. Expect: Occurrences of the property being used.
rg --type tsx --type ts 'disabledExtensions'

Length of output: 72


Script:

#!/bin/bash
# Description: Verify the usage of the new `disabledExtensions` property.

# Find all .tsx and .ts files and search for the usage of the `disabledExtensions` property within those files.
fd -e tsx -e ts -x rg 'disabledExtensions' {}

Length of output: 311


Script:

#!/bin/bash
# Description: Extract context around the usage of the `disabledExtensions` property.

# Find all .tsx and .ts files and search for the usage of the `disabledExtensions` property within those files, including 5 lines of context before and after each match.
fd -e tsx -e ts -x rg 'disabledExtensions' -C 5 {}

Length of output: 2480

packages/editor/src/core/types/slash-commands-suggestion.ts (1)

23-24: New command added to editor commands.

The new command "issue-embed" has been correctly added to the TEditorCommands type definition. This enhances the functionality by providing additional command options.

packages/editor/src/core/components/editors/document/editor.tsx (3)

16-16: New property added to IDocumentEditor interface.

The new optional property disabledExtensions of type TExtensions[] has been added to the IDocumentEditor interface. This enhances the configurability of the DocumentEditor component.


36-36: New property destructured in DocumentEditor component.

The disabledExtensions property has been correctly destructured from the props object in the DocumentEditor component. This ensures that the new property is utilized within the component.


59-59: New property passed to useDocumentEditor hook.

The disabledExtensions property is correctly passed to the useDocumentEditor hook, ensuring that the hook can manage the disabled extensions as intended.

packages/editor/src/core/hooks/use-document-editor.ts (4)

19-19: New property added to DocumentEditorProps type.

The new optional property disabledExtensions of type TExtensions[] has been added to the DocumentEditorProps type. This enhances the configurability of the useDocumentEditor hook.


40-40: New property destructured in useDocumentEditor function.

The disabledExtensions property has been correctly destructured from the props object in the useDocumentEditor function. This ensures that the new property is utilized within the hook.


107-107: New property passed to DocumentEditorAdditionalExtensions function.

The disabledExtensions property is correctly passed to the DocumentEditorAdditionalExtensions function, ensuring that the disabled extensions are managed as intended.


117-120: Enhanced return statement in useDocumentEditor function.

The return statement of the useDocumentEditor function has been updated to include both editor and isIndexedDbSynced. This improves the clarity of the return values without altering existing functionality.

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

22-23: New imports for editor flagging and issue embed.

The new hooks useEditorFlagging and useIssueEmbed are imported. Ensure these hooks are necessary and used effectively within the file.


83-84: Integration of useEditorFlagging hook.

The useEditorFlagging hook is used to obtain documentEditor, which is then used to manage disabled extensions within the editor. This integration appears correct and enhances control over the editor's behavior.


151-151: Passing documentEditor to DocumentEditorWithRef.

The documentEditor object is correctly passed as disabledExtensions to the DocumentEditorWithRef component, ensuring that extensions can be dynamically disabled based on the flagging state.


165-167: Refactoring of issueEmbedProps.

The issueEmbedProps are now used directly in the DocumentReadOnlyEditorWithRef component, simplifying the code and potentially enhancing performance.

Comment on lines +1 to +20
// editor
import { TExtensions } from "@plane/editor";

/**
* @description extensions disabled in various editors
* @returns
* ```ts
* {
* documentEditor: TExtensions[]
* richTextEditor: TExtensions[]
* }
* ```
*/
export const useEditorFlagging = (): {
documentEditor: TExtensions[];
richTextEditor: TExtensions[];
} => ({
documentEditor: [],
richTextEditor: [],
});
Copy link
Contributor

Choose a reason for hiding this comment

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

LGTM! Consider adding customization options.

The new hook useEditorFlagging is well-documented and straightforward. However, consider adding customization options to allow dynamic configuration of disabled extensions.

export const useEditorFlagging = (initialFlags = { documentEditor: [], richTextEditor: [] }): {
  documentEditor: TExtensions[];
  richTextEditor: TExtensions[];
} => ({
  documentEditor: initialFlags.documentEditor,
  richTextEditor: initialFlags.richTextEditor,
});
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// editor
import { TExtensions } from "@plane/editor";
/**
* @description extensions disabled in various editors
* @returns
* ```ts
* {
* documentEditor: TExtensions[]
* richTextEditor: TExtensions[]
* }
* ```
*/
export const useEditorFlagging = (): {
documentEditor: TExtensions[];
richTextEditor: TExtensions[];
} => ({
documentEditor: [],
richTextEditor: [],
});
// editor
import { TExtensions } from "@plane/editor";
/**
* @description extensions disabled in various editors
* @returns
* ```ts
* {
* documentEditor: TExtensions[]
* richTextEditor: TExtensions[]
* }
* ```
*/
export const useEditorFlagging = (initialFlags = { documentEditor: [], richTextEditor: [] }): {
documentEditor: TExtensions[];
richTextEditor: TExtensions[];
} => ({
documentEditor: initialFlags.documentEditor,
richTextEditor: initialFlags.richTextEditor,
});

Copy link
Contributor

@SatishGandham SatishGandham left a comment

Choose a reason for hiding this comment

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

Think about if disabled extensions is the right approach.

@SatishGandham SatishGandham merged commit 943dd59 into preview Aug 7, 2024
13 of 14 checks passed
@SatishGandham SatishGandham deleted the dev/editor-flagging branch August 7, 2024 14:36
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.

2 participants