-
-
Notifications
You must be signed in to change notification settings - Fork 68
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
Conversation
ref PLG-310 - Started integrating the CTA node into Koenig Lexical
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
packages/kg-default-nodes/lib/nodes/call-to-action/CallToActionNode.jsOops! 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'
WalkthroughThe pull request introduces a comprehensive implementation of a Call To Action (CTA) feature across multiple packages. The changes include creating a new Changes
Sequence DiagramsequenceDiagram
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
Possibly related PRs
Poem
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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 descriptionThere'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 iconA 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 theisHidden
logic for better readabilityThe
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 ingetIcon
methodThere'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 testsThe 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
: EnsureCallToActionNode
is registered before plugin initializationThe 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 inlineThe 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 unnecessaryasync
keyword from the command handlerThe command handler function is marked as
async
, but there are noawait
expressions inside it. Removing theasync
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 whilebackgroundColor
uses 'none'. Consider using 'none' as the default forbuttonColor
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
andcontentVisibilityAlpha
flags, and when to use each one.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 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 inpopulateNestedEditor
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 implementedThe 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 updatedbackgroundColor
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 () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
test.describe('Call To Action Card', async () => { | |
test.describe('Call To Action Card', () => { |
handleButtonColor={() => {}} | ||
handleColorChange={() => {}} | ||
hasBackground={hasBackground} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
ref PLG-310 PLG-311
call-to-action
card from the koenig selector.