Skip to content

Conversation

@sanne-san
Copy link
Contributor

@sanne-san sanne-san commented Mar 25, 2025

ref https://linear.app/ghost/issue/PLG-307/change-trigger-for-visibility-panel-on-html-card

  • We're changing the way the visibility panel is triggered on the html card; instead of opening upon inserting the card, it can now be triggered via an icon in the toolbar.

  • Added visibility toggle to HTML card toolbar in HtmlNodeComponent.jsx:

    • Introduced a new ToolbarMenuItem with dataTestId="show-visibility" and icon="visibility" to trigger visibility settings.
    • Wired it to the toggleVisibilitySettings function for controlled panel display.
  • Implemented new visibility settings panel toggle behaviour in HtmlNodeComponent.jsx:

    • Updated conditional rendering of SettingsPanel to depend on showVisibilitySettings state rather than just isEditing or isSelected.
    • Added React.useEffect to reset setShowVisibilitySettings(false) when isSelected becomes false, ensuring panel closure on deselection.
  • Updated KoenigCardWrapper.jsx to handle visibility settings without entering edit mode:

    • Replaced toggleEditMode with toggleVisibilitySettings for the onIndicatorClick prop on CardWrapper.
    • Modified CLICK_COMMAND listener to avoid triggering EDIT_CARD_COMMAND when clicking settings-related elements (e.g., clickedSettingsPanel check).
    • Removed DESELECT_CARD_COMMAND usage, relying on SELECT_CARD_COMMAND for selection without edit mode.
  • Created useVisibilitySettingsToggle.js hook for managing visibility panel state:

    • Added a new hook that uses React.useCallback to toggle showVisibilitySettings state via setShowVisibilitySettings.
    • Dispatches SELECT_CARD_COMMAND when the card isn’t selected, ensuring focus without edit mode transition.
  • Modified HtmlNodeComponent.jsx to show visibility settings only when explicitly toggled:

    • Changed SettingsPanel rendering condition to isContentVisibilityEnabled && showVisibilitySettings && cardContext.isSelected and removed the cardContext.isEditing condition.
    • Added onMouseDown event handler to prevent event propagation and maintain selection state.
  • Added context state for visibility settings in KoenigSelectedCardContext.jsx:

    • Extended context with showVisibilitySettings and setShowVisibilitySettings using React.useState(false).
  • Updated E2E tests in html-card.test.js and content-visibility.test.js to verify visibility toggle behavior:

    • Added test in html-card.test.js to confirm visibility panel isn’t shown by default in edit mode (expect.not.toBeVisible for tab-contents-visibility).
    • Enhanced content-visibility.test.js.
    • Verified data-kg-card-editing="false" attribute persists when toggling visibility settings.
  • Ensured visibility settings panel resets when card is deselected in HtmlNodeComponent.jsx:

    • Used React.useEffect to monitor isSelected and call setShowVisibilitySettings(false) on deselection.
  • Added visibility indicator toggle functionality in KoenigCardWrapper.jsx and content-visibility.test.js:

    • Linked toggleVisibilitySettings to the visibility indicator’s onIndicatorClick event.
    • Added E2E test to confirm clicking the indicator toggles the settings panel without entering edit mode.

Ref https://linear.app/ghost/issue/PLG-307/change-trigger-for-visibility-panel-on-html-card
- We're changing the way the visibility panel is triggered on the html card; instead of opening upon inserting the card, it can now be triggered via an icon in the toolbar.
@coderabbitai
Copy link

coderabbitai bot commented Mar 25, 2025

Walkthrough

The pull request introduces a new context hook, useKoenigSelectedCardContext, to manage the state related to the selected card within the HtmlNodeComponent. A new state variable, showVisibilitySettings, is added along with its setter, setShowVisibilitySettings. A React.useEffect hook resets showVisibilitySettings to false when the component is no longer selected. The toggleVisibilitySettings function is defined using the useVisibilitySettingsToggle hook and is invoked in the ToolbarMenuItem labeled "Visibility." The rendering condition for the SettingsPanel is modified to depend on both isContentVisibilityEnabled and showVisibilitySettings. Additionally, new test cases are added to verify the behavior of the visibility panel in different editing states.

Possibly related PRs

  • Added visibility rendering to Call to Action card #1436: The changes in the main PR are related to the retrieved PR that enhances visibility rendering for the Call to Action card, as both involve modifications to visibility handling logic and the introduction of new functions for managing visibility states.
  • Expanded visibility controls to cover web segments #1424: The changes in the main PR are related to the retrieved PR as both involve modifications to visibility management logic, specifically through the introduction of new structures and functions for handling visibility settings in the HTML node context.
  • Wired up visibility settings for CTA card #1440: The changes in the main PR are related to those in the retrieved PR as both involve the management and toggling of visibility settings within components, specifically focusing on the HtmlNodeComponent and CtaCard, respectively.

Suggested reviewers

  • ronaldlangeveld

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/test/e2e/cards/html-card.test.js

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.

packages/koenig-lexical/demo/DemoApp.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.

  • 1 others

📜 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 342233d and b83268c.

📒 Files selected for processing (4)
  • packages/koenig-lexical/demo/DemoApp.jsx (1 hunks)
  • packages/koenig-lexical/src/nodes/HtmlNodeComponent.jsx (5 hunks)
  • packages/koenig-lexical/test/e2e/cards/call-to-action-card.test.js (7 hunks)
  • packages/koenig-lexical/test/e2e/cards/html-card.test.js (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/koenig-lexical/test/e2e/cards/call-to-action-card.test.js
🧰 Additional context used
🧬 Code Definitions (2)
packages/koenig-lexical/src/nodes/HtmlNodeComponent.jsx (4)
packages/koenig-lexical/src/context/KoenigSelectedCardContext.jsx (4)
  • useKoenigSelectedCardContext (35-35)
  • useKoenigSelectedCardContext (35-35)
  • selectedCardKey (6-6)
  • showVisibilitySettings (9-9)
packages/koenig-lexical/src/components/ui/SettingsPanel.jsx (2)
  • React (96-96)
  • SettingsPanel (17-47)
packages/koenig-lexical/src/hooks/useVisibilitySettingsToggle.js (1)
  • useVisibilitySettingsToggle (6-31)
packages/koenig-lexical/src/components/ui/ToolbarMenu.jsx (1)
  • ToolbarMenuItem (54-76)
packages/koenig-lexical/test/e2e/cards/html-card.test.js (1)
packages/koenig-lexical/test/utils/e2e.js (2)
  • focusEditor (58-61)
  • initialize (10-48)
⏰ 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/koenig-lexical/demo/DemoApp.jsx (1)

53-53: Updated default configuration to disable content visibility

The default value for contentVisibility has been changed from true to false, which aligns with the PR objective of changing how the visibility panel is triggered. This ensures that by default, users must explicitly activate the visibility panel through the toolbar icon rather than having it appear automatically.

packages/koenig-lexical/test/e2e/cards/html-card.test.js (4)

178-189: Test confirms absence of visibility icon when feature is disabled

This test effectively verifies that the visibility icon doesn't appear in the toolbar when the content visibility feature is disabled by default. The test follows best practices by:

  1. Creating the HTML card
  2. Checking for the visibility of the toolbar
  3. Asserting that the visibility icon is not present

This aligns well with the PR's objective of making the visibility panel trigger manual.


192-206: Well-structured test setup for content visibility feature

The test suite properly isolates tests for the enabled content visibility feature by:

  1. Creating a separate describe block
  2. Using the appropriate URI parameters to enable the feature (&labs=contentVisibility)
  3. Following test best practices with proper setup and teardown

This organization makes the test intentions clear and keeps the test cases focused.


207-221: Complete test coverage for visibility icon functionality

This test thoroughly validates the visibility icon's behavior when the content visibility feature is enabled:

  1. Verifies that the visibility icon appears in the toolbar
  2. Confirms that clicking the icon opens the visibility settings panel

The test covers the complete interaction flow, providing confidence in the feature's implementation.


223-229: Test ensures visibility panel doesn't show automatically

This test correctly verifies that the visibility settings panel doesn't appear automatically when entering edit mode, which confirms the intended change in behavior. This ensures that users must explicitly click the visibility icon to see these settings.

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

12-12: Added context hook for selected card state

The import of useKoenigSelectedCardContext is appropriate for accessing the selected card state, which is necessary for managing the visibility settings panel.


14-14: Added visibility settings toggle hook

The import of useVisibilitySettingsToggle properly separates the toggle logic into a reusable hook, promoting code reusability and separation of concerns.


23-26: Correctly accessing selected card context

The destructuring of context values and creation of the isSelected variable provides a clean way to check if the current card is selected, which is essential for managing the visibility settings panel state.


28-32: Added effect to reset visibility settings when unselected

This useEffect hook ensures that the visibility settings panel is closed when the card loses selection, preventing it from remaining open when the user moves to another card. This is a critical improvement for the user experience.


69-76: Implemented visibility settings toggle

The toggleVisibilitySettings function is properly implemented using the hook with all the necessary parameters:

  • editor
  • nodeKey
  • isSelected state
  • visibility settings state
  • setter function
  • editing state

This encapsulates all the logic needed for toggling the visibility settings panel.


107-118: Added conditional toolbar menu item for visibility

The visibility icon is correctly wrapped in a conditional block that only renders it when the content visibility feature is enabled. The menu item has:

  • Proper test ID for easy testing
  • Appropriate icon
  • Active state tied to the visibility settings state
  • Clear label
  • Correctly wired onClick handler

This implements the core UI change required for the PR objective.


131-131: Updated condition for rendering settings panel

The condition now correctly checks both the feature flag and the showVisibilitySettings state before rendering the panel, ensuring it only appears when explicitly triggered by the user.


136-139: Improved event handling for settings panel

The onMouseDown handler now includes e.stopPropagation() to prevent event bubbling, which helps avoid unintended interactions when interacting with the settings panel. This improves the user experience by ensuring events don't propagate unexpectedly.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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: 1

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 02d257a and cf36f82.

📒 Files selected for processing (1)
  • packages/koenig-lexical/src/nodes/HtmlNodeComponent.jsx (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Node 22.13.1
  • GitHub Check: Node 20.11.1

ref https://linear.app/ghost/issue/PLG-307/change-trigger-for-visibility-panel-on-html-card

- added an additional state in the HTML Node Component that would handle
  the state of the visibility panel.
- added comprehensive tests to ensure the state remains consistant with
  the behaviour
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 (2)
packages/koenig-lexical/test/e2e/cards/html-card.test.js (2)

201-201: Remove extra comment slash

There's a double comment marker on this line that should be cleaned up.

- // // Click the visibility button to show the panel
+ // Click the visibility button to show the panel

214-214: Incomplete comment at end of file

This comment appears to be incomplete and should either be completed or removed.

- // we need t
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between cf36f82 and 7466a60.

📒 Files selected for processing (2)
  • packages/koenig-lexical/src/nodes/HtmlNodeComponent.jsx (3 hunks)
  • packages/koenig-lexical/test/e2e/cards/html-card.test.js (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/koenig-lexical/src/nodes/HtmlNodeComponent.jsx
🧰 Additional context used
🧬 Code Definitions (1)
packages/koenig-lexical/test/e2e/cards/html-card.test.js (1)
packages/koenig-lexical/test/utils/e2e.js (1)
  • focusEditor (58-61)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Node 22.13.1
  • GitHub Check: Node 20.11.1
🔇 Additional comments (2)
packages/koenig-lexical/test/e2e/cards/html-card.test.js (2)

178-186: Clean and clear test for visibility panel default state

This test correctly verifies that the visibility panel is not displayed by default when an HTML card is in edit mode, which aligns with the PR objective to change the trigger mechanism for the visibility panel.


188-212: Well-structured behavior test for visibility panel state management

This test thoroughly verifies the behavior of the visibility panel when toggling between editing states. It confirms that:

  1. The panel is not visible by default in edit mode
  2. The panel becomes visible when the visibility button is clicked
  3. The panel is automatically hidden when editing is turned off
  4. The panel becomes visible again when clicking on the card after editing is disabled

The test captures all the key scenarios for the new visibility toggle feature.

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

🧹 Nitpick comments (1)
packages/koenig-lexical/src/context/KoenigSelectedCardContext.jsx (1)

9-9: Consider a more descriptive variable name for clarity.
showVisibilitySettings could optionally be renamed to something like isVisibilityPanelOpen to provide an immediate understanding of its boolean nature, making the code more self-explanatory.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 7466a60 and fb2e845.

📒 Files selected for processing (5)
  • packages/koenig-lexical/src/components/KoenigCardWrapper.jsx (3 hunks)
  • packages/koenig-lexical/src/context/KoenigSelectedCardContext.jsx (1 hunks)
  • packages/koenig-lexical/src/nodes/HtmlNodeComponent.jsx (5 hunks)
  • packages/koenig-lexical/test/e2e/cards/html-card.test.js (1 hunks)
  • packages/koenig-lexical/test/e2e/content-visibility.test.js (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/koenig-lexical/test/e2e/cards/html-card.test.js
🧰 Additional context used
🧬 Code Definitions (1)
packages/koenig-lexical/src/nodes/HtmlNodeComponent.jsx (7)
packages/koenig-lexical/src/context/KoenigSelectedCardContext.jsx (2)
  • useKoenigSelectedCardContext (35-35)
  • useKoenigSelectedCardContext (35-35)
packages/koenig-lexical/src/components/ui/ActionToolbar.jsx (1)
  • useKoenigSelectedCardContext (5-5)
packages/koenig-lexical/src/components/ui/SettingsPanel.jsx (1)
  • React (100-100)
packages/koenig-lexical/src/nodes/CodeBlockNodeComponent.jsx (1)
  • React (13-13)
packages/koenig-lexical/src/nodes/EmailNodeComponent.jsx (2)
  • cardContext (13-13)
  • cardContext (15-15)
packages/koenig-lexical/src/nodes/ToggleNodeComponent.jsx (2)
  • cardContext (13-13)
  • cardContext (15-15)
packages/koenig-lexical/src/components/ui/ToolbarMenu.jsx (1)
  • ToolbarMenuItem (54-76)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Node 22.13.1
  • GitHub Check: Node 20.11.1
🔇 Additional comments (18)
packages/koenig-lexical/src/context/KoenigSelectedCardContext.jsx (1)

17-19: State additions look correct and consistent.
The inclusion of showVisibilitySettings and setShowVisibilitySettings in the context value is properly handled. The memo dependencies are correctly updated to ensure the context re-renders only when these states change.

Also applies to: 27-29

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

38-42: Test name aligns with the new behavior of hiding settings panel by default.
This clarifies expectations for the user interaction, ensuring that the visibility panel no longer appears automatically when the edit button is clicked. The assertion checking not.toBeVisible() is correct.


54-55: Toolbar interactions updated as intended.
Clicking the newly introduced "show-visibility" icon, followed by "tab-visibility", correctly reflects the new workflow for toggling the visibility settings panel.


93-94: Visibility toggling tested thoroughly.
Ensuring that clicking "show-visibility" and "tab-visibility" transitions to the correct panel and states is good for reliable UI coverage.


107-107: Further testing ensures consistent visibility interactions.
Indicating that Stripe is disabled and verifying the correct toggles are hidden helps maintain coverage for membership scenarios.


111-111: Verifies toggles remain hidden under correct conditions.
Nice job ensuring separate code paths for Stripe being disabled, preventing paid member toggles from incorrectly showing up.


118-131: New test "visibility indicator can toggle visibility settings panel" is comprehensive.
It checks multiple transitions—opening the panel, toggling members, focusing away, then re-opening from the indicator—for thorough coverage of the new display logic.

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

12-12: Context import is appropriate.
Using useKoenigSelectedCardContext inside this component clearly indicates it will manage or consume card-specific states, keeping the design consistent with other Koenig context usage.


22-29: Resetting showVisibilitySettings when editing ends is beneficial.
This useEffect reliably guards against leaving the panel open when the card is deselected. Including setShowVisibilitySettings in the dependency array ensures correct and timely updates.


66-69: Toggle function is concise.
toggleVisibilitySettings neatly handles the open/close logic. Ensure that external triggers also consistently set the same state, preserving a single source of truth for the panel's visibility.


91-106: Visibility icon usage in the toolbar is well-implemented.
The added ToolbarMenuItem with dataTestId="show-visibility" and a distinct icon fosters clarity in the UI. The onClick logic is straightforward, making it easy to maintain.


119-130: Conditional settings panel rendering is well-structured.
Conditionally rendering SettingsPanel only if isContentVisibilityEnabled and showVisibilitySettings are both true prevents accidental or unwanted display. Great approach to controlling UI complexity.

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

20-20: Good addition of the visibility settings context.

The addition of setShowVisibilitySettings to the destructured values from useKoenigSelectedCardContext is appropriate for managing the visibility settings state in this component.


25-40: Well-implemented toggle function with clear responsibilities.

The renaming from what appears to have been toggleEditMode to toggleVisibilitySettings better reflects this function's purpose. The implementation correctly manages both the visibility settings state and the edit mode dispatch commands.


33-33: Appropriate visibility settings activation.

Setting showVisibilitySettings to true when entering edit mode aligns with the expected behavior when a user wants to modify visibility settings.


36-36: Properly resetting visibility settings.

Resetting showVisibilitySettings to false when exiting edit mode ensures the visibility panel is hidden appropriately.


40-40: Correct dependency array update.

The addition of setShowVisibilitySettings to the dependency array is necessary to ensure the callback is recreated if this function reference changes.


180-180: Consistent prop update with function rename.

The update to use toggleVisibilitySettings for the onIndicatorClick prop maintains consistency with the function's new name and purpose.

Comment on lines 69 to 70
// await card.getByTestId('edit-html').click();
await card.getByTestId('show-visibility').click();
Copy link

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Commented-out edit button interaction is acceptable if no longer needed.
Ensure no references to the old edit-html workflow remain if the show-visibility button fully replaces its functionality for changing visibility settings.


🏁 Script executed:

#!/bin/bash
# Confirm there are no stale references to 'edit-html' across the test suite
rg 'edit-html' -A 2

Length of output: 1641


Action Required: Remove Legacy 'edit-html' Workflow References

The commented-out edit button interaction in the snippet is acceptable if the legacy edit workflow is deprecated. However, the regex search revealed that active references to the edit-html identifier still exist in both tests and production code:

  • In packages/koenig-lexical/src/nodes/HtmlNodeComponent.jsx, the element is rendered with dataTestId="edit-html".
  • In packages/koenig-lexical/test/e2e/content-visibility.test.js, several test steps verify the presence and interaction for edit-html.

Please confirm that the new show-visibility functionality fully replaces the old edit workflow. If so, update or remove these remaining references to ensure consistency in the codebase.

- since the html card now loads without the settings / visibility panel
  pre loaded, we don't expect the element to be in the test
@codecov-commenter
Copy link

codecov-commenter commented Mar 27, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.95%. Comparing base (6ccedee) to head (9b18548).
Report is 19 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1491      +/-   ##
==========================================
+ Coverage   90.92%   90.95%   +0.03%     
==========================================
  Files         187      189       +2     
  Lines       17589    17683      +94     
  Branches     1974     1998      +24     
==========================================
+ Hits        15992    16083      +91     
- Misses       1588     1590       +2     
- Partials        9       10       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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/hooks/useVisibilitySettingsToggle.js (1)

14-15: Simplify the boolean toggle.

Instead of the ternary expression, consider using the logical NOT operator for a cleaner approach:

- setShowVisibilitySettings(showVisibilitySettings ? false : true);
+ setShowVisibilitySettings(!showVisibilitySettings);
🧰 Tools
🪛 Biome (1.9.4)

[error] 15-15: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with

(lint/complexity/noUselessTernary)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 66c53a7 and 9b18548.

📒 Files selected for processing (4)
  • packages/koenig-lexical/src/components/KoenigCardWrapper.jsx (4 hunks)
  • packages/koenig-lexical/src/hooks/useVisibilitySettingsToggle.js (1 hunks)
  • packages/koenig-lexical/src/nodes/HtmlNodeComponent.jsx (5 hunks)
  • packages/koenig-lexical/test/e2e/content-visibility.test.js (4 hunks)
🧰 Additional context used
🧬 Code Definitions (3)
packages/koenig-lexical/test/e2e/content-visibility.test.js (1)
packages/koenig-lexical/test/utils/e2e.js (1)
  • initialize (10-48)
packages/koenig-lexical/src/hooks/useVisibilitySettingsToggle.js (2)
packages/koenig-lexical/src/nodes/HtmlNodeComponent.jsx (3)
  • editor (18-18)
  • isSelected (25-25)
  • React (20-20)
packages/koenig-lexical/src/components/KoenigCardWrapper.jsx (3)
  • editor (14-14)
  • isSelected (23-23)
  • React (13-13)
packages/koenig-lexical/src/nodes/HtmlNodeComponent.jsx (2)
packages/koenig-lexical/src/context/KoenigSelectedCardContext.jsx (4)
  • useKoenigSelectedCardContext (35-35)
  • useKoenigSelectedCardContext (35-35)
  • selectedCardKey (6-6)
  • showVisibilitySettings (9-9)
packages/koenig-lexical/src/hooks/useVisibilitySettingsToggle.js (1)
  • useVisibilitySettingsToggle (5-24)
🪛 Biome (1.9.4)
packages/koenig-lexical/src/hooks/useVisibilitySettingsToggle.js

[error] 15-15: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with

(lint/complexity/noUselessTernary)

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Node 22.13.1
  • GitHub Check: Node 20.11.1
🔇 Additional comments (18)
packages/koenig-lexical/test/e2e/content-visibility.test.js (5)

38-41: Confirm desired default behavior.

The test ensures the settings panel remains hidden when the edit button is clicked. Verify that this is the intended UX, as previously opening settings automatically could be a feature. If this is correct, then no changes needed.

Do you want me to run or generate any script-based checks on user workflow consistency?


53-55: Visibility tab usage looks good.

Using show-visibility and tab-visibility is consistent with your updated approach. No issues found.


69-70: Remove or update legacy references to “edit-html”.

There's a commented-out call to edit-html. A previous review mentioned removing all references to the old "edit-html" workflow if they're no longer needed. Consider removing these lines if they are truly obsolete.

#!/bin/bash
# Search for 'edit-html' usage that may still exist in the codebase
rg 'edit-html' -A 2

93-94: Consistent with standard toggling pattern.

Clicking show-visibility and switching tabs ensures you remain in edit mode. This is aligned with the new design. No issues identified.


112-145: Tests thoroughly cover new visibility indicator interactions.

These additions provide comprehensive coverage for toggling visibility settings and confirm that edit mode remains unaffected. Great job ensuring test clarity and covering multiple user flows.

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

6-6: Imports look correct.

These plugin commands are used appropriately for selecting and editing cards. No concerns here.


10-10: Hook import is properly introduced.

useVisibilitySettingsToggle is now available, aligning well with the new visibility settings logic.


21-21: Successfully retrieving visibility states.

Destructuring showVisibilitySettings and its setter from context is a clean approach, making the component’s intent clear.


26-32: Hook usage is consistent.

Attaching the useVisibilitySettingsToggle hook to manage the card’s visibility settings is straightforward and maintains separation of concerns. Good practice for reusability.


80-80: Trailing comma is acceptable.

Retaining a trailing comma helps minimize diffs if more parameters are added. No issues found.


172-172: Indicator click callback redefined.

Replacing onIndicatorClick with toggleVisibilitySettings correctly directs the user flow towards controlling visibility instead of toggling edit mode.

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

12-12: New context hook import looks good.

This addition allows the component to properly consume the Koenig selected card context.


14-14: Importing the custom visibility toggle hook is appropriate.

Ensures clean separation of toggling logic into a reusable hook.


23-25: Context state destructuring is well implemented.

Using {selectedCardKey, showVisibilitySettings, setShowVisibilitySettings} makes it straightforward to manage and track the card’s visibility settings in a unified manner.


27-32: useEffect cleanup logic is clear and effective.

Resetting showVisibilitySettings to false whenever the card is no longer selected prevents the visibility panel from persisting when the focus shifts away.


69-76: Visibility toggle hook usage is correctly integrated.

The component properly updates the editor state and toggles the visibility panel, ensuring consistent behavior with card selection.


106-113: New toolbar item for manual visibility control is well-structured.

Providing an explicit onClick handler and icon improves user discoverability and aligns with the planned UX for toggling visibility settings.


126-126: Conditional rendering of SettingsPanel aligns with feature flags and selection state.

Combining isContentVisibilityEnabled, showVisibilitySettings, and cardContext.isSelected ensures the panel only appears under the intended circumstances.

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/hooks/useVisibilitySettingsToggle.js (1)

6-31: Simplify the boolean toggle expression.

The hook effectively manages visibility settings for different card types, but the boolean toggle can be simplified.

-                setShowVisibilitySettings(showVisibilitySettings ? false : true);
+                setShowVisibilitySettings(!showVisibilitySettings);
🧰 Tools
🪛 Biome (1.9.4)

[error] 18-18: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with

(lint/complexity/noUselessTernary)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 403cd15 and 342233d.

📒 Files selected for processing (4)
  • packages/koenig-lexical/src/components/KoenigCardWrapper.jsx (5 hunks)
  • packages/koenig-lexical/src/hooks/useVisibilitySettingsToggle.js (1 hunks)
  • packages/koenig-lexical/src/nodes/HtmlNodeComponent.jsx (5 hunks)
  • packages/koenig-lexical/test/e2e/cards/call-to-action-card.test.js (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/koenig-lexical/src/components/KoenigCardWrapper.jsx
🧰 Additional context used
🧬 Code Definitions (1)
packages/koenig-lexical/src/nodes/HtmlNodeComponent.jsx (4)
packages/koenig-lexical/src/context/KoenigSelectedCardContext.jsx (4)
  • useKoenigSelectedCardContext (35-35)
  • useKoenigSelectedCardContext (35-35)
  • selectedCardKey (6-6)
  • showVisibilitySettings (9-9)
packages/koenig-lexical/src/components/ui/SettingsPanel.jsx (2)
  • React (96-96)
  • SettingsPanel (17-47)
packages/koenig-lexical/src/hooks/useVisibilitySettingsToggle.js (1)
  • useVisibilitySettingsToggle (6-31)
packages/koenig-lexical/src/components/ui/ToolbarMenu.jsx (1)
  • ToolbarMenuItem (54-76)
🪛 Biome (1.9.4)
packages/koenig-lexical/src/hooks/useVisibilitySettingsToggle.js

[error] 18-18: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with

(lint/complexity/noUselessTernary)

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Node 22.13.1
  • GitHub Check: Node 20.11.1
🔇 Additional comments (7)
packages/koenig-lexical/test/e2e/cards/call-to-action-card.test.js (1)

568-582: Well-structured test for the visibility toggle feature.

This test effectively validates the behavior described in the PR objectives, showing that the visibility panel can now be triggered through the visibility indicator in the toolbar rather than automatically opening upon card insertion.

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

1-5: LGTM - Clean import structure.

The imports are appropriate for the hook's functionality.

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

12-14: LGTM - Appropriate imports for the new functionality.

These imports provide access to the required context and hook for managing visibility settings.


23-32: LGTM - Effective state management for visibility settings.

The effect hook properly resets the visibility settings when the card loses selection, ensuring a clean UI experience.


69-76: LGTM - Well-structured hook implementation.

The hook is properly configured with all necessary parameters.


107-114: LGTM - Well-implemented visibility toggle button.

The toolbar menu item now provides a manual way to toggle visibility settings as described in the PR objectives.


127-141: LGTM - Enhanced conditional rendering of the settings panel.

The settings panel is now only rendered when visibility settings are toggled on, and the event propagation is properly handled.

Comment on lines +14 to +21
// If the card is an html card, we toggle the visibility settings differently
// because we want to show the visibility settings panel while in selected mode
// instead of entering edit mode
if ($isHtmlNode(cardNode)) {
setShowVisibilitySettings(showVisibilitySettings ? false : true);
if (!isSelected) {
editor.dispatchCommand(SELECT_CARD_COMMAND, {cardKey: nodeKey, focusEditor: true});
}
Copy link
Member

Choose a reason for hiding this comment

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

This feels like a code smell that's indicative of a pattern not being quite right. A "generic" hook should not typically have any specific knowledge of what is calling it or what it's acting upon.

If we stick with a hook approach then it would be better if cardNode exposed something that allows the hook to enter this conditional path, similar to the code below where it switches between edit/select based on cardNode exposing whether it has an edit mode.

const cardNode = $getNodeByKey(nodeKey);
const clickedDifferentEditor = !cardNode;
const clickedToolbar = event.target.closest('[data-kg-allow-clickthrough="false"]');
const clickedSettingsPanel = event.target.closest('[data-testid="settings-panel"]');
Copy link
Member

Choose a reason for hiding this comment

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

Ideally we would not use testid's in any non-test code, there's no guarantee they'll always be present - e.g. the test id's in our Admin app get stripped out in production builds to save some bytes in the build output - and it creates some potentially invisible coupling as there's usually no expectation that test-specific code would be in use elsewhere.

Better to add our own attributes for selecting anything in app code, similar to the existing data-kg-slash-menu, data-kg-card-menu-item, data-kg-allow-clickthrough etc

Copy link
Member

@kevinansfield kevinansfield left a comment

Choose a reason for hiding this comment

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

Merging as-is because it's all working well 🙌

However, I do wonder if a different approach where we add something like a new EDIT_CARD_VISIBILITY_COMMAND that the button click events could dispatch 🤔 That would potentially make things more re-usable as it keeps logic centralised and lets Lexical code also dispatch the same command in case we wanted to attach it to keyboard shortcuts etc. The command handler should read some data from the cardNode to determine which type of behaviour to follow (e.g. select-only settings panel vs edit-mode settings panel). I think that approach would also give us a path towards the "open visibility tab when clicking visibility icon" improvement.

- turned off `contentVisibility` flag being on by default in demo app so we can effectively test both off and on states
- added test for visibility icon not showing without flag
- added test for working visibility icon with flag
@kevinansfield kevinansfield merged commit 5a75ec9 into main Apr 1, 2025
3 checks passed
@kevinansfield kevinansfield deleted the html-visibility-trigger branch April 1, 2025 19:48
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.

4 participants