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

Integrated CTA Node Component into Koenig-Lexical #1413

Merged
merged 9 commits into from
Jan 22, 2025

Conversation

ronaldlangeveld
Copy link
Member

@ronaldlangeveld ronaldlangeveld commented Jan 21, 2025

ref PLG-310 PLG-311

  • Started integrating the CTA node into Koenig Lexical
  • Wired up the initial UI component to access the new call-to-action card from the koenig selector.
  • Added the visibility of the CTA card behind a flag.

Copy link

coderabbitai bot commented Jan 22, 2025

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 eslint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

packages/kg-default-nodes/lib/nodes/call-to-action/CallToActionNode.js

Oops! Something went wrong! :(

ESLint: 8.57.0

Error: Failed to load parser '@babel/eslint-parser' declared in 'packages/kg-default-nodes/.eslintrc.js': Cannot find module '@babel/eslint-parser'
Require stack:

  • /packages/kg-default-nodes/.eslintrc.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1248:15)
    at Function.resolve (node:internal/modules/helpers:145:19)
    at Object.resolve (/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2346:46)
    at ConfigArrayFactory._loadParser (/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3325:39)
    at ConfigArrayFactory._normalizeObjectConfigDataBody (/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3099:43)
    at _normalizeObjectConfigDataBody.next ()
    at ConfigArrayFactory._normalizeObjectConfigData (/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3040:20)
    at _normalizeObjectConfigData.next ()
    at ConfigArrayFactory.loadInDirectory (/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2886:28)
    at CascadingConfigArrayFactory._loadConfigInAncestors (/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3871:46)

Walkthrough

The pull request introduces a comprehensive implementation of a Call To Action (CTA) feature across multiple packages. The changes include creating a new CallToActionNode, adding a plugin for CTA insertion, updating test suites, and modifying configuration files to support the new node type. The implementation adds new properties like buttonColor and adjusts default values for existing properties, enhancing the flexibility of CTA card styling and configuration.

Changes

File Change Summary
packages/kg-default-nodes/lib/nodes/call-to-action/CallToActionNode.js Added buttonColor property, changed backgroundColor default to none
packages/kg-default-nodes/test/nodes/call-to-action.test.js Updated tests to include buttonColor, modified backgroundColor test cases
packages/koenig-lexical/demo/DemoApp.jsx Added contentVisibilityAlpha feature flag
packages/koenig-lexical/src/components/ui/cards/CtaCard.jsx Added comment markers to prop declarations
packages/koenig-lexical/src/index.js Imported and exported CallToActionPlugin
packages/koenig-lexical/src/nodes/CallToActionNode.jsx Created new CallToActionNode class with related functions
packages/koenig-lexical/src/nodes/CallToActionNodeComponent.jsx Implemented new CallToActionNodeComponent
packages/koenig-lexical/src/nodes/DefaultNodes.js Added CallToActionNode to default nodes
packages/koenig-lexical/src/plugins/AllDefaultPlugins.jsx Integrated CallToActionPlugin
packages/koenig-lexical/src/plugins/CallToActionPlugin.jsx Created new CallToActionPlugin
packages/koenig-lexical/test/e2e/cards/cta-card.test.js Added end-to-end test suite for CTA card

Sequence Diagram

sequenceDiagram
    participant Editor
    participant CallToActionPlugin
    participant CallToActionNode
    participant CallToActionNodeComponent

    Editor->>CallToActionPlugin: Trigger INSERT_CTA_COMMAND
    CallToActionPlugin->>CallToActionNode: Create new node
    CallToActionNode-->>CallToActionNodeComponent: Instantiate component
    CallToActionNodeComponent->>Editor: Render CTA Card
Loading

Possibly related PRs

Poem

🐰 A Rabbit's Ode to Call-to-Action

With buttons bright and colors clear,
Our CTA card leaps without fear!
From none to red, from code to art,
A lexical journey, a brand new start! 🚀
Hop along, dear developer friend! 🐇

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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

@ronaldlangeveld ronaldlangeveld marked this pull request as ready for review January 22, 2025 09:55
@ronaldlangeveld ronaldlangeveld changed the title Integrated CTA Node into Koenig-Lexical Integrated CTA Node Component into Koenig-Lexical Jan 22, 2025
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: 2

🧹 Nitpick comments (11)
packages/koenig-lexical/src/nodes/CallToActionNode.jsx (4)

14-14: Address the TODO: Improve the menu item description

There's a TODO comment indicating that the description ("copy") of the menu item needs improvement. Enhancing this description can help users understand the purpose of the Call To Action card more clearly.

Would you like assistance in refining the menu item description to make it more engaging and informative?


18-18: Replace the placeholder icon in the menu with the correct icon

A TODO comment indicates that the correct icon needs to be set for the Call To Action card in the menu. Using the appropriate icon enhances user recognition and improves the UI consistency.

Do you need help in selecting or integrating the correct icon for the menu item?


23-25: Simplify the isHidden logic for better readability

The isHidden function currently returns the negation of a boolean expression:

return !(config?.feature?.contentVisibilityAlpha === true);

This can be simplified for readability:

return config?.feature?.contentVisibilityAlpha !== true;

Applying this change makes the intent of the condition clearer.


33-33: Replace the placeholder icon in getIcon method

There's a TODO comment indicating that the method getIcon should return the correct icon for the Call To Action card.

Would you like assistance in updating the getIcon method with the appropriate icon?

packages/koenig-lexical/test/e2e/cards/cta-card.test.js (1)

19-30: Enhance test coverage by adding interaction tests

The current test verifies that the Call To Action card renders correctly. Consider adding tests that cover user interactions, such as:

  • Editing the content of the card
  • Changing card settings (e.g., button text, URL, colors)
  • Verifying default values and state changes
  • Ensuring the card saves and persists data correctly

Adding these tests will improve confidence in the functionality and help catch regression issues in the future.

packages/koenig-lexical/src/plugins/CallToActionPlugin.jsx (3)

12-15: Ensure CallToActionNode is registered before plugin initialization

The check for editor.hasNodes([CallToActionNode]) is crucial. However, consider providing guidance or a fallback if the node is not registered, as simply logging an error may not be sufficient.

For example, you could throw an error or provide instructions on how to register the node, ensuring that the plugin fails gracefully.


13-13: Avoid suppressing ESLint rules inline

The inline ESLint suppression // eslint-disable-line no-console is generally discouraged. It may be better to handle logging through a dedicated logging utility or to allow console statements in development environments only.

Consider removing the suppression or configuring ESLint appropriately.


19-24: Remove unnecessary async keyword from the command handler

The command handler function is marked as async, but there are no await expressions inside it. Removing the async keyword avoids unnecessary promise creation and improves performance.

Apply this diff:

-                async (dataset) => {
+                (dataset) => {
packages/kg-default-nodes/lib/nodes/call-to-action/CallToActionNode.js (1)

11-11: Consider using consistent default values.

The buttonColor property uses an empty string as default while backgroundColor uses 'none'. Consider using 'none' as the default for buttonColor to maintain consistency in color property defaults.

-        {name: 'buttonColor', default: ''},
+        {name: 'buttonColor', default: 'none'},
packages/koenig-lexical/src/nodes/CallToActionNodeComponent.jsx (1)

24-24: Remove commented out code.

The commented out useLexicalComposerContext line should be removed if it's not needed. If it will be needed in the future, add a TODO comment explaining the intended usage.

-    // const [editor] = useLexicalComposerContext();
packages/koenig-lexical/demo/DemoApp.jsx (1)

53-54: Consider documenting the relationship between contentVisibility flags.

It would be helpful to add a comment explaining the relationship between contentVisibility and contentVisibilityAlpha flags, and when to use each one.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 885a303 and f86fa2b.

📒 Files selected for processing (11)
  • packages/kg-default-nodes/lib/nodes/call-to-action/CallToActionNode.js (3 hunks)
  • packages/kg-default-nodes/test/nodes/call-to-action.test.js (3 hunks)
  • packages/koenig-lexical/demo/DemoApp.jsx (1 hunks)
  • packages/koenig-lexical/src/components/ui/cards/CtaCard.jsx (1 hunks)
  • packages/koenig-lexical/src/index.js (2 hunks)
  • packages/koenig-lexical/src/nodes/CallToActionNode.jsx (1 hunks)
  • packages/koenig-lexical/src/nodes/CallToActionNodeComponent.jsx (1 hunks)
  • packages/koenig-lexical/src/nodes/DefaultNodes.js (2 hunks)
  • packages/koenig-lexical/src/plugins/AllDefaultPlugins.jsx (2 hunks)
  • packages/koenig-lexical/src/plugins/CallToActionPlugin.jsx (1 hunks)
  • packages/koenig-lexical/test/e2e/cards/cta-card.test.js (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • packages/koenig-lexical/src/components/ui/cards/CtaCard.jsx
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Node 20.11.1
🔇 Additional comments (11)
packages/koenig-lexical/src/nodes/CallToActionNode.jsx (1)

45-45: Review the default HTML content in populateNestedEditor

The default HTML content includes:

<p>Hey <code>{first_name, "there"}</code>,</p>

Ensure that the syntax {first_name, "there"} aligns with your templating system for personalization tokens and that it renders correctly in the editor.

Do you need assistance in confirming the correct rendering of the default content or updating it to match your personalization syntax?

✅ Verification successful

Templating syntax {first_name, "there"} is correctly implemented

The syntax is verified to be the standard format used throughout the codebase, with dedicated test coverage and formatting support. The implementation in CallToActionNode follows the established pattern used in other components.

🏁 Scripts executed

The following scripts were executed for the analysis:

Error: No shell scripts found


Script:

#!/bin/bash
# Search for similar first_name token patterns
rg -g '!*.{lock,min.js}' '{first_name' -A 2 -B 2

# Search for documentation about templating
fd -e md -e txt . | xargs rg -l -i 'templat.*syntax|personalization.*token'

# Search for test files related to CTA or templating
fd -e test.js -e spec.js -e test.jsx -e spec.jsx . | xargs rg -l 'first_name|template|personalization'

Length of output: 655


Script:

#!/bin/bash
# Search with escaped curly braces
rg -g '!*.{lock,min.js}' '\{first_name' -A 2 -B 2

# Check email card test content
cat packages/koenig-lexical/test/e2e/cards/email-card.test.js

# Look for config files in koenig-lexical
fd -e js -e json . packages/koenig-lexical/src/config packages/koenig-lexical/config 2>/dev/null || echo "No config directory found"

Length of output: 15804

packages/kg-default-nodes/lib/nodes/call-to-action/CallToActionNode.js (1)

39-39: LGTM! Consistent default values in constructor.

The constructor properly initializes both color properties with 'none' as the default value, maintaining consistency.

Also applies to: 42-42

packages/koenig-lexical/src/nodes/DefaultNodes.js (1)

18-18: LGTM! Clean integration of CallToActionNode.

The CallToActionNode is properly imported and integrated into the DEFAULT_NODES array.

Also applies to: 64-64

packages/koenig-lexical/src/plugins/AllDefaultPlugins.jsx (1)

2-2: LGTM! Clean integration of CallToActionPlugin.

The CallToActionPlugin is properly imported and integrated into the plugins list.

Also applies to: 67-67

packages/koenig-lexical/src/nodes/CallToActionNodeComponent.jsx (2)

28-32: LGTM! Proper event handling.

The handleToolbarEdit function correctly prevents event propagation and handles the editing state.


35-58: Verify error handling for CTA card properties.

The CtaCard component receives multiple properties that affect its appearance and behavior. Consider adding error boundaries or prop validation to handle cases where these properties might be undefined or invalid.

packages/koenig-lexical/src/index.js (1)

11-11: LGTM! Clean integration of CallToActionPlugin.

The import and export of CallToActionPlugin follow the established pattern and maintain alphabetical ordering.

Also applies to: 69-69

packages/kg-default-nodes/test/nodes/call-to-action.test.js (3)

36-36: LGTM! Proper initialization of new properties.

The new buttonColor and updated backgroundColor properties are correctly initialized with default values in the test dataset.

Also applies to: 39-39


93-95: LGTM! Comprehensive test coverage for buttonColor.

The test properly verifies both the default value and setter functionality for the new buttonColor property.


103-103: LGTM! Updated backgroundColor test.

The test correctly reflects the new default value for backgroundColor and verifies its setter functionality.

packages/koenig-lexical/demo/DemoApp.jsx (1)

53-54: LGTM! Clean addition of contentVisibilityAlpha feature flag.

The new feature flag is properly integrated alongside the existing contentVisibility flag and follows the established pattern.

import {assertHTML, focusEditor, html, initialize, insertCard} from '../../utils/e2e';
import {test} from '@playwright/test';

test.describe('Call To Action Card', async () => {
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Remove async from test.describe callback

The test.describe function expects a synchronous callback function. Using an asynchronous function may lead to unexpected behavior.

Apply this diff to fix the issue:

-test.describe('Call To Action Card', async () => {
+test.describe('Call To Action Card', () => {
📝 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
test.describe('Call To Action Card', async () => {
test.describe('Call To Action Card', () => {

Comment on lines +40 to +42
handleButtonColor={() => {}}
handleColorChange={() => {}}
hasBackground={hasBackground}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Implement missing handler functions.

Several handler functions are passed as empty arrow functions. These need to be implemented to provide the expected functionality:

  • handleButtonColor
  • handleColorChange
  • updateButtonText
  • updateButtonUrl
  • updateHasSponsorLabel
  • updateLayout
  • updateShowButton

Also applies to: 53-57

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant