Skip to content

Conversation

@sanne-san
Copy link
Contributor

Ref https://linear.app/ghost/issue/PROD-1628/add-setting-to-showhide-dividers

  • This supports the use case where the card is used as inline with text, and the dividers are not needed.

Ref https://linear.app/ghost/issue/PROD-1628/add-setting-to-showhide-dividers
- This supports the use case where the card is used as inline with text, and the dividers are not needed.
@coderabbitai
Copy link

coderabbitai bot commented May 1, 2025

Walkthrough

This change introduces a new boolean property, showDividers, to the CallToActionNode and its associated parsing, rendering, and UI components. The property is added with a default value of true to the node's properties array. The parser is updated to detect the presence of the kg-cta-has-dividers CSS class and set showDividers accordingly in the node payload. The renderer uses this property to conditionally add the kg-cta-no-dividers class to the HTML output for both web and email templates. In the editor UI, the CallToActionCard and related components are updated to support a toggle for dividers, which is shown when the background color is 'none'. The toggle updates the showDividers property, and the component's layout and styling adjust based on this state. PropTypes are updated to reflect the new property and its updater function. Test suites for the node and UI components are extended to cover the new property across creation, export, import, and rendering scenarios.

Possibly related PRs

  • Added CallToAction Lexical Nodes #1412: Introduces the initial implementation of the CallToActionNode class and its basic properties, which the current PR extends by adding the showDividers property and related logic.

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/calltoaction-renderer.js

Oops! Something went wrong! :(

ESLint: 8.57.1

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)

📜 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 e0c0c7b and 9c808b6.

📒 Files selected for processing (1)
  • packages/kg-default-nodes/lib/nodes/call-to-action/calltoaction-renderer.js (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/kg-default-nodes/lib/nodes/call-to-action/calltoaction-renderer.js
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Node 22.13.1
  • GitHub Check: Node 20.11.1
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

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

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate sequence diagram to generate a sequence diagram of the changes in 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.

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

🧹 Nitpick comments (1)
packages/koenig-lexical/src/components/ui/cards/CallToActionCard.jsx (1)

310-311: Consider simplifying complex conditional styling logic.

The conditional logic for padding and borders is quite complex with nested conditions that may be difficult to maintain as the component evolves.

Consider extracting these conditions into helper functions or computed values to improve readability:

+ // At the top of the component or as a separate utility
+ const shouldShowTopBorder = (color, showDividers, hasSponsorLabel, hasImmersiveImage) => {
+   return (color === 'none' && showDividers) || (hasSponsorLabel && !hasImmersiveImage);
+ };
+ 
+ const shouldShowBottomBorder = (color, showDividers) => {
+   return (color === 'none' && showDividers);
+ };
+
+ // Inside the component
+ const hasImmersiveImage = imageSrc && layout === 'immersive';

// Then in your JSX
<div className={clsx(
    'flex gap-6',
-   hasSponsorLabel && color !== 'none' && (imageSrc && layout === 'immersive') ? '' : (color === 'none' && !showDividers && !hasSponsorLabel) ? '' : 'pt-6',
-   imageSrc && !showButton ? 'pb-8' : (color === 'none' && !showDividers) ? '' : 'pb-7',
+   !hasImmersiveImage || !hasSponsorLabel || color === 'none' ? ((color === 'none' && !showDividers && !hasSponsorLabel) ? '' : 'pt-6') : '',
+   imageSrc && !showButton ? 'pb-8' : (color === 'none' && !showDividers) ? '' : 'pb-7',
    layout === 'immersive' ? 'flex-col' : 'flex-row',
-   (color === 'none' && showDividers) || (hasSponsorLabel && !(imageSrc && layout === 'immersive')) ? 'border-t border-grey-900/15 dark:border-grey-100/20' : '',
-   (color === 'none' && showDividers) ? 'border-b border-grey-900/15 dark:border-grey-100/20' : color !== 'none' ? 'mx-6' : ''
+   shouldShowTopBorder(color, showDividers, hasSponsorLabel, hasImmersiveImage) ? 'border-t border-grey-900/15 dark:border-grey-100/20' : '',
+   shouldShowBottomBorder(color, showDividers) ? 'border-b border-grey-900/15 dark:border-grey-100/20' : color !== 'none' ? 'mx-6' : ''
)}>

This approach makes the code more maintainable and the conditions more explicit.

Also applies to: 348-349, 351-352

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d07cef2 and e08870a.

📒 Files selected for processing (6)
  • packages/kg-default-nodes/lib/nodes/call-to-action/CallToActionNode.js (1 hunks)
  • packages/kg-default-nodes/lib/nodes/call-to-action/calltoaction-parser.js (2 hunks)
  • packages/kg-default-nodes/lib/nodes/call-to-action/calltoaction-renderer.js (3 hunks)
  • packages/koenig-lexical/src/components/ui/cards/CallToActionCard.jsx (7 hunks)
  • packages/koenig-lexical/src/nodes/CallToActionNode.jsx (1 hunks)
  • packages/koenig-lexical/src/nodes/CallToActionNodeComponent.jsx (4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Node 22.13.1
  • GitHub Check: Node 20.11.1
🔇 Additional comments (13)
packages/kg-default-nodes/lib/nodes/call-to-action/CallToActionNode.js (1)

14-14: Good addition of the new property.

The new showDividers property is properly defined with a default value of true, which aligns with the PR objective to add a toggle for showing/hiding dividers in the Call to Action card.

packages/koenig-lexical/src/nodes/CallToActionNode.jsx (1)

114-114: Correct prop passing to component.

The new showDividers property is correctly passed down to the CallToActionNodeComponent, which enables the divider toggle functionality in the UI.

packages/kg-default-nodes/lib/nodes/call-to-action/calltoaction-parser.js (2)

23-23: Proper detection of divider class.

Good implementation of detecting the kg-cta-has-dividers class to determine the value of the showDividers property during parsing.


51-51: Correctly added property to payload.

The showDividers property is properly added to the payload object, which ensures it will be correctly set when creating a new node instance.

packages/kg-default-nodes/lib/nodes/call-to-action/calltoaction-renderer.js (3)

28-28: Proper conditional class application.

The kg-cta-has-dividers CSS class is correctly applied conditionally based on the showDividers property, which will control the visibility of dividers in the rendered HTML.


182-182: Consistent implementation in email template.

The conditional class is also applied correctly in the email template, ensuring consistent behavior between web and email renderings.


209-209: Property correctly added to dataset.

The showDividers property is properly included in the dataset object, making it available for both rendering methods.

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

26-26: Implementation looks good!

The showDividers property is correctly added to the component props, allowing the toggle functionality to be passed through to the component.


62-67: Well-implemented toggle function.

The toggleShowDividers function follows the same pattern as other toggle functions in this file, maintaining consistency in the codebase.


187-187: Correct prop passing implementation.

The showDividers prop and its update function are correctly passed to the CallToActionCard component, completing the integration of the new feature.

Also applies to: 199-199

packages/koenig-lexical/src/components/ui/cards/CallToActionCard.jsx (3)

102-102: Props correctly defined with sensible defaults.

The showDividers prop defaults to true, which maintains backward compatibility with existing content, and the updateShowDividers function has a sensible empty function default.

Also applies to: 116-116


254-261: Good conditional rendering of the dividers toggle.

The dividers toggle is correctly shown only when the background color is 'none', which is the only scenario where dividers are relevant. The implementation follows the same pattern as other toggle settings in this component.


449-449: Props properly defined in PropTypes.

Good job adding the new showDividers and updateShowDividers properties to the PropTypes definition, ensuring proper type checking and documentation.

Also applies to: 457-457

@sanne-san sanne-san requested a review from kevinansfield May 6, 2025 12:13
Ref https://linear.app/ghost/issue/PROD-1628/add-setting-to-showhide-dividers
- Changed classname from kg-cta-has-dividers to kg-cta-no-dividers to ensure backwards compatibility
@sanne-san sanne-san merged commit 0f5d70d into main May 7, 2025
3 checks passed
@sanne-san sanne-san deleted the calltoaction-dividers branch May 7, 2025 14:28
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