Skip to content

Conversation

@kevinansfield
Copy link
Member

closes https://linear.app/ghost/issue/PLG-339

  • swapped contentVisibilityAlpha flag conditionals to contentVisibility where appropriate
  • deleted code left in place to support previous beta behaviour

@coderabbitai
Copy link

coderabbitai bot commented Feb 4, 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/koenig-lexical/src/components/ui/CardWrapper.jsx

Oops! Something went wrong! :(

ESLint: 8.57.0

ESLint couldn't find the config "react-app" to extend from. Please check that the name of the config is correct.

The config "react-app" was referenced from the config file in "/packages/koenig-lexical/.eslintrc.cjs".

If you still have problems, please stop by https://eslint.org/chat/help to chat with the team.

packages/koenig-lexical/src/components/KoenigCardWrapper.jsx

Oops! Something went wrong! :(

ESLint: 8.57.0

ESLint couldn't find the config "react-app" to extend from. Please check that the name of the config is correct.

The config "react-app" was referenced from the config file in "/packages/koenig-lexical/.eslintrc.cjs".

If you still have problems, please stop by https://eslint.org/chat/help to chat with the team.

packages/koenig-lexical/src/nodes/HtmlNodeComponent.jsx

Oops! Something went wrong! :(

ESLint: 8.57.0

ESLint couldn't find the config "react-app" to extend from. Please check that the name of the config is correct.

The config "react-app" was referenced from the config file in "/packages/koenig-lexical/.eslintrc.cjs".

If you still have problems, please stop by https://eslint.org/chat/help to chat with the team.

  • 6 others

Walkthrough

This pull request refactors how visibility is managed in various components. The changes replace the specific check for contentVisibilityAlpha with a general contentVisibility flag, simplifying conditional rendering logic. Visibility settings are now dynamically generated via a streamlined toggle system, and legacy visibility messaging—including functions and tests—has been removed. The overall control flow remains, but the components now use simplified and unified visibility logic.

Changes

File(s) Change Summary
packages/koenig-lexical/src/components/{KoenigCardWrapper.jsx,ui/CardWrapper.jsx,nodes/HtmlNodeComponent.jsx} Replaced checks for contentVisibilityAlpha with generic contentVisibility; simplified conditional rendering for visibility indicators and settings.
packages/koenig-lexical/src/components/ui/{VisibilitySettings.jsx,cards/HtmlCard.jsx} Refactored VisibilitySettings to dynamically render toggles, removed dropdown functionality, and eliminated legacy visibility messaging and associated props from HtmlCard.
packages/koenig-lexical/src/{hooks/useVisibilityToggle.js,utils/visibility.js} Removed legacy variables and functions (e.g., generateVisibilityMessage) to simplify toggle logic and content visibility handling.
packages/koenig-lexical/test/{e2e/content-visibility.test.js,unit/hooks/useVisibilityToggle.test.js} Deleted multiple test cases related to legacy visibility messaging and updated test initialization reflecting the removal of contentVisibilityAlpha.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Card
    participant Config
    User->>Card: Render card
    Card->>Config: Check cardConfig.feature.visibility
    alt Visibility Active
        Card->>Card: Render VisibilityIndicator
    else
        Card->>Card: Render default IndicatorIcon
    end
Loading
sequenceDiagram
    participant User
    participant VisibilitySettings
    participant ToggleHandler
    User->>VisibilitySettings: Click toggle button
    VisibilitySettings->>ToggleHandler: Invoke toggleVisibility
    ToggleHandler-->>VisibilitySettings: State updated
    VisibilitySettings->>User: Rerender toggle state
Loading

Possibly related PRs

Suggested reviewers

  • ronaldlangeveld

Poem

I'm a hare with a clever twist,
Hopping through code with a joyful list.
Visibility checks now swift and bright,
Toggling toggles with pure delight.
With each small leap, bugs take flight—
Code carrots abound in our sight!
🥕 Happy coding, day and night!

Tip

🌐 Web search-backed reviews and chat
  • We have enabled web search-based reviews and chat for all users. This feature allows CodeRabbit to access the latest documentation and information on the web.
  • You can disable this feature by setting web_search: false in the knowledge_base settings.
  • Please share any feedback in the Discord discussion.
✨ 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.

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

🔭 Outside diff range comments (1)
packages/koenig-lexical/src/nodes/HtmlNodeComponent.jsx (1)

48-53: Remove unused onBlur prop and handler.

The TODO comment indicates that the onBlur prop is not used by the HtmlCard component. This dead code should be removed.

Apply this diff to remove the unused code:

-    // TODO: this isn't used? <HtmlCard> does not have a prop for `onBlur`
-    const onBlur = (event) => {
-        if (event?.relatedTarget?.className !== 'kg-prose') {
-            editor.dispatchCommand(DESELECT_CARD_COMMAND, {cardKey: nodeKey});
-        }
-    };

Also remove the onBlur prop from the HtmlCard component usage:

     <HtmlCard
         darkMode={darkMode}
         html={html}
         isEditing={cardContext.isEditing}
         updateHtml={updateHtml}
-        onBlur={onBlur}
     />
🧹 Nitpick comments (1)
packages/koenig-lexical/src/hooks/useVisibilityToggle.js (1)

15-28: Prevent potential undefined references.

If group or toggle is not found during .find(...), this code could raise an error. Consider adding a check or fallback to handle the scenario of unknown group or toggle keys gracefully.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 939f01d and 869d970.

📒 Files selected for processing (9)
  • packages/koenig-lexical/src/components/KoenigCardWrapper.jsx (1 hunks)
  • packages/koenig-lexical/src/components/ui/CardWrapper.jsx (1 hunks)
  • packages/koenig-lexical/src/components/ui/VisibilitySettings.jsx (1 hunks)
  • packages/koenig-lexical/src/components/ui/cards/HtmlCard.jsx (2 hunks)
  • packages/koenig-lexical/src/hooks/useVisibilityToggle.js (1 hunks)
  • packages/koenig-lexical/src/nodes/HtmlNodeComponent.jsx (3 hunks)
  • packages/koenig-lexical/src/utils/visibility.js (0 hunks)
  • packages/koenig-lexical/test/e2e/content-visibility.test.js (1 hunks)
  • packages/koenig-lexical/test/unit/hooks/useVisibilityToggle.test.js (0 hunks)
💤 Files with no reviewable changes (2)
  • packages/koenig-lexical/src/utils/visibility.js
  • packages/koenig-lexical/test/unit/hooks/useVisibilityToggle.test.js
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Node 20.11.1
🔇 Additional comments (7)
packages/koenig-lexical/src/components/ui/VisibilitySettings.jsx (1)

1-30: The new function-based approach is clear and maintainable.

Implementation is well-structured. The code neatly maps each group and its toggles, provides unique keys, and correctly checks the index when deciding to render the divider. Overall, this streamlined design should be easy to maintain and extend.

packages/koenig-lexical/src/hooks/useVisibilityToggle.js (1)

2-2: Good usage of specialized helpers.

Relying on getVisibilityOptions, parseVisibilityToToggles, and serializeOptionsToVisibility keeps the code DRY and consistent.

packages/koenig-lexical/src/components/ui/cards/HtmlCard.jsx (1)

7-43: Refactored prop structure is simpler.

Removing the visibility messaging props reduces complexity. Passing darkMode through to the HtmlEditor is clean and consistent with the rest of the code.

🧰 Tools
🪛 Biome (1.9.4)

[error] 32-32: Avoid passing content using the dangerouslySetInnerHTML prop.

Setting content using code can expose users to cross-site scripting (XSS) attacks

(lint/security/noDangerouslySetInnerHtml)

packages/koenig-lexical/src/components/ui/CardWrapper.jsx (1)

60-60: LGTM! Simplified visibility indicator logic.

The visibility indicator logic has been streamlined to only depend on isVisibilityActive, which aligns with the transition from alpha to beta.

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

21-29: LGTM! Clean transition to beta visibility settings.

The visibility settings implementation has been simplified by:

  1. Using the standard VisibilitySettings component
  2. Streamlining the useVisibilityToggle hook usage
  3. Removing alpha-specific code
packages/koenig-lexical/test/e2e/content-visibility.test.js (1)

15-117: Verify test coverage for beta visibility features.

While the removal of alpha-specific tests is appropriate, please ensure that the remaining tests cover all critical beta visibility features:

  1. Basic visibility toggle functionality
  2. Visibility indicator behavior
  3. Settings panel interactions
  4. Stripe integration checks

The current test suite covers these aspects, but consider adding tests for any new beta-specific behaviors.

packages/koenig-lexical/src/components/KoenigCardWrapper.jsx (1)

148-153: LGTM! Clean transition to beta feature flag.

The feature flag check has been updated from contentVisibilityAlpha to contentVisibility while maintaining the same visibility checking logic.

closes https://linear.app/ghost/issue/PLG-339

- swapped `contentVisibilityAlpha` flag conditionals to `contentVisibility` where appropriate
- deleted code left in place to support previous beta behaviour
- added `ignoreCardSettings` option to our `assertHTML` test util and updated paste behaviour test so it's not dependent on changes that have no impact on what's being tested
@kevinansfield kevinansfield force-pushed the move-web-visibility-out-of-alpha branch from 869d970 to 8d90486 Compare February 4, 2025 11:39
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

🔭 Outside diff range comments (1)
packages/koenig-lexical/src/nodes/HtmlNodeComponent.jsx (1)

48-53: Remove unused onBlur prop and handler.

The TODO comment correctly identifies that the onBlur handler is unused. Since the HtmlCard component doesn't accept an onBlur prop, this code can be safely removed.

Apply this diff to remove the unused code:

-    // TODO: this isn't used? <HtmlCard> does not have a prop for `onBlur`
-    const onBlur = (event) => {
-        if (event?.relatedTarget?.className !== 'kg-prose') {
-            editor.dispatchCommand(DESELECT_CARD_COMMAND, {cardKey: nodeKey});
-        }
-    };

And remove it from the HtmlCard props:

             <HtmlCard
                 darkMode={darkMode}
                 html={html}
                 isEditing={cardContext.isEditing}
                 updateHtml={updateHtml}
-                onBlur={onBlur}
             />

Also applies to: 62-62

🧹 Nitpick comments (1)
packages/koenig-lexical/test/e2e/content-visibility.test.js (1)

15-28: Consider adding more test coverage.

While the current tests cover basic functionality, consider adding tests for:

  • Edge cases when toggling multiple visibility options
  • Persistence of visibility settings after card reload
  • Interaction with other card settings

I can help generate additional test cases if you'd like.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 869d970 and 8d90486.

📒 Files selected for processing (11)
  • packages/koenig-lexical/src/components/KoenigCardWrapper.jsx (1 hunks)
  • packages/koenig-lexical/src/components/ui/CardWrapper.jsx (1 hunks)
  • packages/koenig-lexical/src/components/ui/VisibilitySettings.jsx (1 hunks)
  • packages/koenig-lexical/src/components/ui/cards/HtmlCard.jsx (2 hunks)
  • packages/koenig-lexical/src/hooks/useVisibilityToggle.js (1 hunks)
  • packages/koenig-lexical/src/nodes/HtmlNodeComponent.jsx (3 hunks)
  • packages/koenig-lexical/src/utils/visibility.js (0 hunks)
  • packages/koenig-lexical/test/e2e/content-visibility.test.js (1 hunks)
  • packages/koenig-lexical/test/e2e/paste-behaviour.test.js (1 hunks)
  • packages/koenig-lexical/test/unit/hooks/useVisibilityToggle.test.js (0 hunks)
  • packages/koenig-lexical/test/utils/e2e.js (5 hunks)
💤 Files with no reviewable changes (2)
  • packages/koenig-lexical/src/utils/visibility.js
  • packages/koenig-lexical/test/unit/hooks/useVisibilityToggle.test.js
🚧 Files skipped from review as they are similar to previous changes (3)
  • packages/koenig-lexical/src/components/KoenigCardWrapper.jsx
  • packages/koenig-lexical/src/components/ui/CardWrapper.jsx
  • packages/koenig-lexical/src/hooks/useVisibilityToggle.js
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Node 20.11.1
🔇 Additional comments (10)
packages/koenig-lexical/src/components/ui/VisibilitySettings.jsx (1)

3-29: Clean and efficient implementation!

The refactored VisibilitySettings component is well-structured with:

  • Clear prop interface
  • Efficient use of map functions
  • Proper key usage in iterations
  • Semantic class names
packages/koenig-lexical/src/components/ui/cards/HtmlCard.jsx (2)

7-7: Successfully removed visibility message functionality.

The component interface has been simplified by removing visibility-related props, aligning with the PR objectives.

Also applies to: 39-44


20-23: Consider removing or documenting the empty z-index layer.

The empty div with z-50 appears to serve no purpose in the current implementation.

Could you clarify the purpose of this empty div with absolute positioning and z-index? If it's no longer needed, consider removing it:

-                    <div className="absolute inset-0 z-50 mt-0"></div>
✅ Verification successful

I'll run a script to extract and review the relevant snippet from the file in question for more context.


Clarify or Remove the Redundant Overlay Element

Based on the context provided from the file at packages/koenig-lexical/src/components/ui/cards/HtmlCard.jsx, the empty <div className="absolute inset-0 z-50 mt-0"></div> does not appear to have any active role (e.g. no event handling or visible content). If it was intended for a feature like an overlay or interaction blocker, its purpose should be clearly documented. Otherwise, it would be safe to remove it to simplify the code.

🏁 Scripts executed

The following scripts were executed for the analysis:

Error: No shell scripts or web queries found


Script:

#!/bin/bash
# Display lines 15 to 40 of the file to see the context around the empty div.
sed -n '15,40p' packages/koenig-lexical/src/components/ui/cards/HtmlCard.jsx

Length of output: 765

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

21-29: Successfully simplified visibility management.

The code cleanly handles visibility settings without alpha feature checks.

packages/koenig-lexical/test/e2e/content-visibility.test.js (1)

85-86: Test updated to reflect new visibility behavior.

The comment and test assertion correctly document the removal of visibility messages as part of the beta changes.

packages/koenig-lexical/test/utils/e2e.js (3)

73-73: LGTM! Parameter addition follows existing pattern.

The new ignoreCardSettings parameter is consistent with other ignore flags and aligns with the PR objectives.


126-142: LGTM! Well-structured changes with clear documentation.

The changes are well-documented and follow the existing patterns:

  • Clear comment explaining the order of operations
  • Consistent use of data-testid selectors

150-160: LGTM! Logical reordering of operations.

The reordering ensures that class and data-testid selectors are available for card-related replacements before being removed.

packages/koenig-lexical/test/e2e/paste-behaviour.test.js (2)

554-554: LGTM! Card UI enhancement.

Added draggable div follows card UI requirements.


558-558: LGTM! Test adaptation for visibility settings.

Added ignoreCardSettings: true aligns with the PR objectives to move HTML card web visibility settings to beta.

@kevinansfield kevinansfield merged commit 1f835cc into TryGhost:main Feb 4, 2025
2 checks passed
@kevinansfield kevinansfield deleted the move-web-visibility-out-of-alpha branch February 4, 2025 11:46
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