Skip to content

gcoai-stream-to-paragraph-field.js: Fixed duplicate code and an issue with snippet not working. #1047

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

Merged
merged 1 commit into from
Mar 22, 2025

Conversation

SebastianWiz
Copy link
Contributor

Context

⛑️ Ticket(s): https://secure.helpscout.net/conversation/2853989407/78340?viewId=8172236

Summary

If the Response field is set to a plain text Paragraph field and there are rich text enabled Paragraph fields elsewhere on the form, the gcoai-stream-to-paragraph-field snippet fails to copy OpenAI's output to the Response field. This happens because the code checks if TinyMCE is globally available, not whether the specific Response field has TinyMCE enabled.

This PR fixes this by modifying the TinyMCE detection to specifically check if the target Response field has TinyMCE enabled, rather than just checking if TinyMCE exists globally.

Additionally, this PR removes duplicate code at the end of the snippet.

…ue where output wouldn't copy to a plain text Paragraph field if any rich text Paragraph fields existed on the form.
Copy link

coderabbitai bot commented Mar 13, 2025

Walkthrough

The pull request refactors the logic in the TinyMCE handling of the gc-openai/gcoai-stream-to-paragraph-field.js file. The new implementation uses a variable tiny to verify both the existence of window.tinyMCE and the TinyMCE instance for a specific field before retrieving and setting HTML content. Additionally, redundant code related to checking for the WordPress editor container and inserting a button has been removed, and comments have been updated to provide clearer descriptions.

Changes

File(s) Change Summary
gc-openai/.../gcoai-stream-to-paragraph-field.js Refactored the TinyMCE check by assigning the result of window.tinyMCE and instance availability to a variable tiny. Simplified the content setting logic and removed redundant checks for the WordPress editor container.

Sequence Diagram(s)

sequenceDiagram
    participant JS as JavaScript
    participant T as TinyMCE Instance

    JS->>JS: Check if window.tinyMCE exists and get TinyMCE instance (assign to `tiny`)
    alt TinyMCE available
        JS->>T: Call setContent(html)
    else Not available
        JS->>JS: Skip setting content
    end
Loading

Suggested reviewers

  • saifsultanc

Tip

⚡🧪 Multi-step agentic review comment chat (experimental)
  • We're introducing multi-step agentic chat in review comments. This experimental feature enhances review discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments.
    - To enable this feature, set early_access to true under in the settings.

📜 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 6b9e42a and b2eadb4.

📒 Files selected for processing (1)
  • gc-openai/gcoai-stream-to-paragraph-field.js (1 hunks)
🔇 Additional comments (4)
gc-openai/gcoai-stream-to-paragraph-field.js (4)

30-31: Improved TinyMCE detection logic

This change properly checks if TinyMCE is available for the specific response field, rather than just checking for global TinyMCE availability. This will fix the issue where the snippet failed when the Response field was configured as a plain text Paragraph field while other fields had rich text enabled.


33-36: Clearer code organization with improved comments

The updated comment and restructured logic make it easier to understand the conditional flow. The code now first checks for TinyMCE availability and then performs the appropriate action based on that check.


38-38: Simplified TinyMCE content setting

The code has been simplified by removing redundant checks. Since tiny is already verified in the conditional statement, there's no need for a nested check before calling setContent().


45-56: Verify if duplicate code was removed

According to the PR description, duplicate code was removed from the end of the snippet. However, this section dealing with button placement and WordPress editor container detection still appears to be present. Consider verifying if any actual duplicate code was removed as claimed in the PR description.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
  • @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.

@saifsultanc saifsultanc changed the title gcoai-stream-to-paragraph-field.js: Fixed duplicate code and an iss… gcoai-stream-to-paragraph-field.js: Fixed duplicate code and an issue with snippet not working. Mar 21, 2025
Copy link
Contributor

@saifsultanc saifsultanc left a comment

Choose a reason for hiding this comment

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

LGTM!

Thanks for getting rid of the duplicate code. It was my mistake 😭

@saifsultanc saifsultanc merged commit ff20239 into gravitywiz:master Mar 22, 2025
1 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants