Skip to content
This repository has been archived by the owner on Sep 26, 2024. It is now read-only.

MOC-204: chat, pass dom to extension via messaging #170

Merged
merged 6 commits into from
Sep 9, 2024
Merged

Conversation

fitzk
Copy link
Contributor

@fitzk fitzk commented Sep 4, 2024

Let's get these merged so Jon can merge in his PR's and I will follow with one more PR to add chat history to the UI

https://github.com/Mocksi/nest/pull/45

To trigger the chat message you just have to edit a demo, then click the chat icon on the toolbar, from there you should see the message from the service worker in the console.

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features
    • Introduced a new utility function to convert HTML content into a structured JSON format.
    • Enhanced iframe styling with updated display settings for improved visibility during the "DEMO_ACTIVE" state.
    • Improved communication capabilities by adding support for new chat-related message types, allowing for better interactivity and data handling.

Copy link

linear bot commented Sep 4, 2024

Copy link

coderabbitai bot commented Sep 4, 2024

Walkthrough

Walkthrough

The changes involve modifications to the getIframeStyles function, replacing the "MINIMIZED" case with a new "DEMO_ACTIVE" case that alters iframe display properties. Additionally, a new utility function, innerHTMLToJson, has been introduced to convert HTML strings into JSON format by parsing the document structure. New message handling logic has also been added to respond to "CHAT" and "CHAT_NEW_MESSAGE" messages, enhancing communication capabilities within the extension.

Changes

File Path Change Summary
apps/mocksi-lite-next/src/pages/content/mocksi-extension.tsx Modified getIframeStyles function to replace "MINIMIZED" with "DEMO_ACTIVE", added innerHTMLToJson function for HTML to JSON conversion, and updated message handling for "CHAT" and "CHAT_NEW_MESSAGE".

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Iframe
    participant Document

    User->>Iframe: Send "CHAT" message
    Iframe->>Document: Parse current HTML
    Document-->>Iframe: Return parsed HTML
    Iframe->>User: Send JSON representation
    User->>Iframe: Send "CHAT_NEW_MESSAGE"
    Iframe->>User: Acknowledge with "ok"
Loading

Possibly related PRs

Poem

🐇
In the meadow where the changes bloom,
A new style dances, dispelling gloom.
With JSON magic, we weave and play,
Transforming HTML in a wondrous way.
Hooray for updates, let joy take flight,
For every hop brings a new delight!
🌼


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 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 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.

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 29f4a63 and f3c594d.

Files selected for processing (1)
  • apps/mocksi-lite-next/src/pages/content/mocksi-extension.tsx (5 hunks)
Additional comments not posted (4)
apps/mocksi-lite-next/src/pages/content/mocksi-extension.tsx (4)

43-49: LGTM!

The changes to the getIframeStyles function look good. The new "DEMO_ACTIVE" case handles the iframe display properties appropriately for what seems to be a demo mode.

Also applies to: 65-69


75-110: LGTM!

The new innerHTMLToJson function looks great! It provides a handy utility for converting HTML strings to JSON format. The recursive approach ensures that the entire document structure is captured accurately. The use of DOMParser is appropriate, and the function follows a clear and logical structure.


154-160: LGTM!

The changes to the message listener for handling the "CHAT" message look good. When a "CHAT" message is received, it appropriately converts the current document's body into JSON format using the innerHTMLToJson function and sends the data back in the response. This functionality aligns with the goal of passing the DOM to the extension via messaging.


122-122: LGTM!

The addition of the flags parameter to the findReplaceAll function is a good enhancement. It allows for specifying flags or options for the find and replace operation, providing more flexibility and customization. The flags parameter is correctly included in the content property of the modification object, ensuring that the flags are passed along with the find and replace patterns.

Also applies to: 171-171

Copy link
Contributor

@elg0nz elg0nz left a comment

Choose a reason for hiding this comment

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

Just a question for @jonathankap

default:
return {};
}
}

export const innerHTMLToJson = (innerHTML: string): string => {
Copy link
Contributor

Choose a reason for hiding this comment

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

@jonathankap I kinda feel this should be part of Reactor. Thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

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

We're all thinking the same thing! 🤣 It's already there:

exportDOM(element: null | HTMLElement = null): DomJsonExportNode[] {

@fitzk please update to use the reactor call instead

Copy link
Contributor

@jonathankap jonathankap left a comment

Choose a reason for hiding this comment

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

Update to use reactor to create the JSON

default:
return {};
}
}

export const innerHTMLToJson = (innerHTML: string): string => {
Copy link
Contributor

Choose a reason for hiding this comment

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

We're all thinking the same thing! 🤣 It's already there:

exportDOM(element: null | HTMLElement = null): DomJsonExportNode[] {

@fitzk please update to use the reactor call instead

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between f3c594d and 66854a0.

Files selected for processing (1)
  • apps/mocksi-lite-next/src/pages/content/mocksi-extension.tsx (1 hunks)
Additional comments not posted (1)
apps/mocksi-lite-next/src/pages/content/mocksi-extension.tsx (1)

118-130: LGTM!

The new message handling logic for "CHAT" and "CHAT_NEW_MESSAGE" messages looks good. The changes are consistent with the PR objective of passing DOM to the extension via messaging.

For the "CHAT" message, the response correctly includes the current DOM state exported by reactor.exportDOM(), allowing the DOM to be passed to the extension. The "CHAT_NEW_MESSAGE" message handling also looks fine.

Overall, the code changes in this segment are approved.

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 66854a0 and 201c6e8.

Files selected for processing (1)
  • apps/mocksi-lite-next/src/pages/content/mocksi-extension.tsx (3 hunks)
Additional comments not posted (3)
apps/mocksi-lite-next/src/pages/content/mocksi-extension.tsx (3)

42-51: LGTM!

The code changes are approved.


127-132: LGTM!

The code changes are approved.


162-169: LGTM!

The code changes are approved.

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 201c6e8 and a0d45c2.

Files selected for processing (1)
  • apps/mocksi-lite-next/src/pages/content/mocksi-extension.tsx (5 hunks)
Files skipped from review as they are similar to previous changes (1)
  • apps/mocksi-lite-next/src/pages/content/mocksi-extension.tsx

@fitzk fitzk marked this pull request as ready for review September 9, 2024 19:26
@fitzk fitzk requested review from jonathankap and elg0nz September 9, 2024 19:38
Copy link
Contributor

@elg0nz elg0nz left a comment

Choose a reason for hiding this comment

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

Nice!

@fitzk fitzk merged commit 9ea957d into main Sep 9, 2024
6 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants