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

feat(web): plugin playground presets extension to extension messenger #1367

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

OpeDada
Copy link
Contributor

@OpeDada OpeDada commented Jan 22, 2025

Overview

Created an extension to extension messenger plugin based on these requirements:

  • Post message between extensions. Two different widgets with same UI each, that includes:
    • an input
    • a send button
    • a div to show received data

What I've done

Screenshot 2025-01-23 at 2 44 53 PM

What I haven't done

How I tested

Locally

Which point I want you to review particularly

Memo

Summary by CodeRabbit

  • New Features
    • Added a new communication plugin with two messaging widgets (Extension 1 and Extension 2)
    • Enhanced messaging functionality between the widgets and the extension
    • Improved widget data structure with unique identifiers and additional metadata
    • Expanded plugin communication capabilities by integrating multiple plugins in the communication category
    • Enhanced event handling for extension events within the plugin API

Copy link

coderabbitai bot commented Jan 22, 2025

Walkthrough

This pull request introduces a new messaging extension plugin called extensionExtensionMessenger to the Plugin Playground. The plugin defines two widgets, Extension 1 and Extension 2, which can send and receive messages using the postMessage API. The changes include adding a new TypeScript file for the plugin, updating the presetPlugins array in the index file to include this new communication plugin alongside the existing uiExtensionMessenger, and enhancing the widget data structure for better identification and metadata.

Changes

File Change Summary
web/src/beta/features/PluginPlayground/Plugins/presets/communication/extensionExtensionMessenger.ts Added new plugin with YAML file and two messenger widgets (Extension 1 and Extension 2); introduced variables for YAML and widget files; exported extensionExtensionMessenger
web/src/beta/features/PluginPlayground/Plugins/presets/index.ts Updated presetPlugins to include extensionExtensionMessenger in the communication category, replacing the previous single entry of uiExtensionMessenger
web/src/beta/features/PluginPlayground/Code/hook.ts Updated widget object structure to include unique IDs and additional metadata properties
web/src/beta/features/Visualizer/Crust/Plugins/Plugin/hooks/usePluginAPI.ts Introduced extensionEvents reference for handling extension events within the plugin API
web/src/beta/features/PluginPlayground/Plugins/presets/communication/uiExtensionMessenger.ts Enhanced UI with new styles and HTML structure for toggling information display; added event listener for the toggle button

Possibly related PRs

Suggested reviewers

  • mkumbobeaty
  • airslice
  • ZTongci
  • mulengawilfred

Poem

🐰 Messengers dance, widgets unite,
Plugins conversing with pure delight!
Extensions whisper, messages flow,
A rabbit's code puts on a show! 📨
Communication's magic takes flight! 🚀

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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.

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

netlify bot commented Jan 22, 2025

Deploy Preview for reearth-web ready!

Name Link
🔨 Latest commit ebc1e20
🔍 Latest deploy log https://app.netlify.com/sites/reearth-web/deploys/6791d66921f2bb00081bdaaa
😎 Deploy Preview https://deploy-preview-1367--reearth-web.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

codecov bot commented Jan 22, 2025

Codecov Report

Attention: Patch coverage is 0% with 257 lines in your changes missing coverage. Please review.

Project coverage is 22.60%. Comparing base (2d1d0ac) to head (cef7e7f).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...esets/communication/extensionExtensionMessenger.ts 0.00% 254 Missing ⚠️
...features/PluginPlayground/Plugins/presets/index.ts 0.00% 3 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1367      +/-   ##
==========================================
- Coverage   22.74%   22.60%   -0.15%     
==========================================
  Files        1047     1054       +7     
  Lines      109304   110058     +754     
  Branches      669      676       +7     
==========================================
+ Hits        24865    24877      +12     
- Misses      83178    83920     +742     
  Partials     1261     1261              
Flag Coverage Δ
server 31.47% <ø> (ø)
web 17.64% <0.00%> (-0.18%) ⬇️
web-beta 17.64% <0.00%> (-0.18%) ⬇️
web-classic 17.64% <0.00%> (-0.18%) ⬇️
web-utils 17.64% <0.00%> (-0.18%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...gins/presets/communication/uiExtensionMessenger.ts 0.00% <ø> (ø)
...features/PluginPlayground/Plugins/presets/index.ts 0.00% <0.00%> (ø)
...esets/communication/extensionExtensionMessenger.ts 0.00% <0.00%> (ø)

... and 10 files with indirect coverage changes

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

🧹 Nitpick comments (1)
web/src/beta/features/PluginPlayground/Plugins/presets/communication/extensionExtensionMessenger.ts (1)

80-90: Improve accessibility support.

The UI components lack proper accessibility attributes and keyboard navigation support.

Add accessibility improvements:

 <div id="wrapper">
-  <h2>Messenger 1</h2>
+  <h2 id="messenger-title">Messenger 1</h2>
   <div class="flex-center">
     <input id="messageInput" type="text" 
+      aria-label="Message input"
+      aria-describedby="messenger-title"
       placeholder="Enter message"/>
-    <button id="sendButton">Send</button>
+    <button id="sendButton"
+      aria-label="Send message"
+      role="button"
+      tabindex="0">Send</button>
   </div>
-  <h3>Received Messages</h3>
+  <h3 id="received-title">Received Messages</h3>
   <div class="received">
-    <div id="messagesContainer" class="messages-container"></div>
+    <div id="messagesContainer" 
+      class="messages-container"
+      role="log"
+      aria-labelledby="received-title"></div>
   </div>
 </div>

Also applies to: 182-192

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b282bb6 and cef7e7f.

📒 Files selected for processing (2)
  • web/src/beta/features/PluginPlayground/Plugins/presets/communication/extensionExtensionMessenger.ts (1 hunks)
  • web/src/beta/features/PluginPlayground/Plugins/presets/index.ts (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: ci-server / ci-server-lint
  • GitHub Check: ci-web / ci
  • GitHub Check: ci-server / ci-server-test
  • GitHub Check: Redirect rules - reearth-web
  • GitHub Check: Header rules - reearth-web
  • GitHub Check: Pages changed - reearth-web
🔇 Additional comments (2)
web/src/beta/features/PluginPlayground/Plugins/presets/index.ts (1)

3-4: LGTM! Clean integration of the new extension messenger.

The changes properly integrate the new extension messenger while maintaining the existing UI messenger functionality.

Also applies to: 39-39

web/src/beta/features/PluginPlayground/Plugins/presets/communication/extensionExtensionMessenger.ts (1)

4-33: LGTM! Well-structured YAML configuration.

The YAML configuration properly defines two widget extensions with appropriate metadata and layout settings.

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

♻️ Duplicate comments (2)
web/src/beta/features/PluginPlayground/Plugins/presets/communication/extensionExtensionMessenger.ts (2)

84-92: ⚠️ Potential issue

Add security measures for message handling.

The current implementation lacks several security measures:

  1. No origin validation in postMessage
  2. No input validation or sanitization
  3. No message size limits

Also applies to: 185-192


109-117: ⚠️ Potential issue

Add error handling for extension communication.

The current implementation lacks error handling for extension operations and message posting.

Also applies to: 208-216

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cef7e7f and d097912.

📒 Files selected for processing (3)
  • web/src/beta/features/PluginPlayground/Code/hook.ts (2 hunks)
  • web/src/beta/features/PluginPlayground/Plugins/presets/communication/extensionExtensionMessenger.ts (1 hunks)
  • web/src/beta/features/Visualizer/Crust/Plugins/Plugin/hooks/usePluginAPI.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: Redirect rules - reearth-web
  • GitHub Check: ci-web / ci
  • GitHub Check: Header rules - reearth-web
  • GitHub Check: ci-server / ci-server-lint
  • GitHub Check: Pages changed - reearth-web
  • GitHub Check: ci-server / ci-server-test
🔇 Additional comments (4)
web/src/beta/features/PluginPlayground/Code/hook.ts (1)

125-128: LGTM! Enhanced widget identification.

The changes improve widget identification and traceability by:

  • Using UUID v4 for unique widget IDs
  • Adding descriptive metadata (name, extensionId, pluginId)
web/src/beta/features/Visualizer/Crust/Plugins/Plugin/hooks/usePluginAPI.ts (1)

119-119: LGTM! Proper extension event handling.

The addition of extensionEvents properly integrates extension-specific event handling with initialization and cleanup.

web/src/beta/features/PluginPlayground/Plugins/presets/communication/extensionExtensionMessenger.ts (2)

29-68: Reduce code duplication in styles.

The CSS styles are duplicated between both messengers. Consider extracting them to a shared constant.

Also applies to: 131-170


240-244: LGTM! Well-structured plugin definition.

The plugin is well-organized with clear separation of concerns between YAML configuration and widget implementations.

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

🧹 Nitpick comments (3)
web/src/beta/features/PluginPlayground/Plugins/presets/communication/uiExtensionMessenger.ts (2)

83-91: Enhance accessibility with ARIA attributes.

The info section should include ARIA attributes to improve accessibility for screen readers.

-        <button id="info-toggle">Show Info</button>
-        <div id="info-content" style="display: none;">
+        <button id="info-toggle" aria-expanded="false" aria-controls="info-content">Show Info</button>
+        <div id="info-content" style="display: none;" role="region" aria-labelledby="info-toggle">

126-132: Update ARIA attributes with toggle state.

The toggle functionality should update ARIA attributes to maintain accessibility.

 document.getElementById("info-toggle").addEventListener("click", () => {
   const infoContent = document.getElementById("info-content");
   const isHidden = infoContent.style.display === "none";
   infoContent.style.display = isHidden ? "block" : "none";
-  document.getElementById("info-toggle").textContent = isHidden ? "Hide Info" : "Show Info";
+  const toggleButton = document.getElementById("info-toggle");
+  toggleButton.textContent = isHidden ? "Hide Info" : "Show Info";
+  toggleButton.setAttribute("aria-expanded", isHidden ? "true" : "false");
 });
web/src/beta/features/PluginPlayground/Plugins/presets/communication/extensionExtensionMessenger.ts (1)

207-209: Enhance implementation documentation.

While the note about Re:Earth visualizer requirements is helpful, consider adding more comprehensive documentation:

  • Add JSDoc comments for each function
  • Document the message format and types
  • Include examples of valid messages
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d097912 and ebc1e20.

📒 Files selected for processing (3)
  • web/src/beta/features/PluginPlayground/Plugins/presets/communication/extensionExtensionMessenger.ts (1 hunks)
  • web/src/beta/features/PluginPlayground/Plugins/presets/communication/uiExtensionMessenger.ts (2 hunks)
  • web/src/beta/features/PluginPlayground/Plugins/presets/index.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • web/src/beta/features/PluginPlayground/Plugins/presets/index.ts
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: Redirect rules - reearth-web
  • GitHub Check: ci-web / ci
  • GitHub Check: Header rules - reearth-web
  • GitHub Check: ci-server / ci-server-lint
  • GitHub Check: Pages changed - reearth-web
  • GitHub Check: ci-server / ci-server-test
🔇 Additional comments (4)
web/src/beta/features/PluginPlayground/Plugins/presets/communication/uiExtensionMessenger.ts (1)

56-78: LGTM! Well-structured CSS additions.

The new CSS styles for the info section are well-organized and follow consistent styling patterns.

web/src/beta/features/PluginPlayground/Plugins/presets/communication/extensionExtensionMessenger.ts (3)

84-92: Add security measures for message handling.

The implementation needs security measures for safe message handling.

Also applies to: 95-104


109-125: Add error handling for extension communication.

The extension communication logic needs proper error handling.


29-68: Reduce code duplication in styles.

The CSS styles are duplicated between both extensions.

Also applies to: 132-170


// YAML File Definition
const yamlFile: FileType = {
id: "extension-extension-messenger-reearth-yml",
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can call this extension-to-extension-messenger-reearth-yml

name: Extension Extension Messenger
version: 1.0.0
extensions:
- id: extension1
Copy link
Contributor

Choose a reason for hiding this comment

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

extension-1

@@ -89,6 +122,14 @@ const widgetFile: FileType = {
alt: 1000 // Fixed camera height for better viewing
}, "*");
});
// Toggle info section
document.getElementById("info-toggle").addEventListener("click", () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

When I click the show info button in the ui-extension-messenger plugin, the widget disappears for me. Does the same happen for you @OpeDada ?

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess it's still the iframe auto resize bug. We could fix that in another PR i think.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No , it just extends downwards for me. Maybe you can show me?

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