Koenig
Koenig copied to clipboard
Added visibility toggle to html card toolbar
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
ToolbarMenuItemwithdataTestId="show-visibility"andicon="visibility"to trigger visibility settings. - Wired it to the
toggleVisibilitySettingsfunction for controlled panel display.
- Introduced a new
-
Implemented new visibility settings panel toggle behaviour in
HtmlNodeComponent.jsx:- Updated conditional rendering of
SettingsPanelto depend onshowVisibilitySettingsstate rather than justisEditingorisSelected. - Added
React.useEffectto resetsetShowVisibilitySettings(false)whenisSelectedbecomes false, ensuring panel closure on deselection.
- Updated conditional rendering of
-
Updated
KoenigCardWrapper.jsxto handle visibility settings without entering edit mode:- Replaced
toggleEditModewithtoggleVisibilitySettingsfor theonIndicatorClickprop onCardWrapper. - Modified
CLICK_COMMANDlistener to avoid triggeringEDIT_CARD_COMMANDwhen clicking settings-related elements (e.g.,clickedSettingsPanelcheck). - Removed
DESELECT_CARD_COMMANDusage, relying onSELECT_CARD_COMMANDfor selection without edit mode.
- Replaced
-
Created
useVisibilitySettingsToggle.jshook for managing visibility panel state:- Added a new hook that uses
React.useCallbackto toggleshowVisibilitySettingsstate viasetShowVisibilitySettings. - Dispatches
SELECT_CARD_COMMANDwhen the card isn’t selected, ensuring focus without edit mode transition.
- Added a new hook that uses
-
Modified
HtmlNodeComponent.jsxto show visibility settings only when explicitly toggled:- Changed
SettingsPanelrendering condition toisContentVisibilityEnabled && showVisibilitySettings && cardContext.isSelectedand removed thecardContext.isEditingcondition. - Added
onMouseDownevent handler to prevent event propagation and maintain selection state.
- Changed
-
Added context state for visibility settings in
KoenigSelectedCardContext.jsx:- Extended context with
showVisibilitySettingsandsetShowVisibilitySettingsusingReact.useState(false).
- Extended context with
-
Updated E2E tests in
html-card.test.jsandcontent-visibility.test.jsto verify visibility toggle behavior:- Added test in
html-card.test.jsto confirm visibility panel isn’t shown by default in edit mode (expect.not.toBeVisiblefortab-contents-visibility). - Enhanced
content-visibility.test.js. - Verified
data-kg-card-editing="false"attribute persists when toggling visibility settings.
- Added test in
-
Ensured visibility settings panel resets when card is deselected in
HtmlNodeComponent.jsx:- Used
React.useEffectto monitorisSelectedand callsetShowVisibilitySettings(false)on deselection.
- Used
-
Added visibility indicator toggle functionality in
KoenigCardWrapper.jsxandcontent-visibility.test.js:- Linked
toggleVisibilitySettingsto the visibility indicator’sonIndicatorClickevent. - Added E2E test to confirm clicking the indicator toggles the settings panel without entering edit mode.
- Linked
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
- TryGhost/Koenig#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.
- TryGhost/Koenig#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.
- TryGhost/Koenig#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
HtmlNodeComponentandCtaCard, 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 342233d9adf6a1aeaaea934c2505a2607e53ea4a and b83268c33e6a35b96bec487681410f3a6c5c6758.
📒 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 visibilityThe default value for
contentVisibilityhas been changed fromtruetofalse, 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 disabledThis 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:
- Creating the HTML card
- Checking for the visibility of the toolbar
- 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 featureThe test suite properly isolates tests for the enabled content visibility feature by:
- Creating a separate describe block
- Using the appropriate URI parameters to enable the feature (
&labs=contentVisibility)- 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 functionalityThis test thoroughly validates the visibility icon's behavior when the content visibility feature is enabled:
- Verifies that the visibility icon appears in the toolbar
- 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 automaticallyThis 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 stateThe import of
useKoenigSelectedCardContextis appropriate for accessing the selected card state, which is necessary for managing the visibility settings panel.
14-14: Added visibility settings toggle hookThe import of
useVisibilitySettingsToggleproperly separates the toggle logic into a reusable hook, promoting code reusability and separation of concerns.
23-26: Correctly accessing selected card contextThe destructuring of context values and creation of the
isSelectedvariable 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 unselectedThis 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 toggleThe
toggleVisibilitySettingsfunction 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 visibilityThe 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 panelThe condition now correctly checks both the feature flag and the
showVisibilitySettingsstate before rendering the panel, ensuring it only appears when explicitly triggered by the user.
136-139: Improved event handling for settings panelThe
onMouseDownhandler now includese.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
@coderabbitaiin 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
@coderabbitaiin 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 pauseto pause the reviews on a PR.@coderabbitai resumeto resume the paused reviews.@coderabbitai reviewto trigger an incremental review. This is useful when automatic reviews are disabled for the repository.@coderabbitai full reviewto do a full review from scratch and review all the files again.@coderabbitai summaryto regenerate the summary of the PR.@coderabbitai generate docstringsto generate docstrings for this PR.@coderabbitai resolveresolve all the CodeRabbit review comments.@coderabbitai planto trigger planning for file edits and PR creation.@coderabbitai configurationto show the current CodeRabbit configuration for the repository.@coderabbitai helpto get help.
Other keywords and placeholders
- Add
@coderabbitai ignoreanywhere in the PR description to prevent this PR from being reviewed. - Add
@coderabbitai summaryto generate the high-level summary at a specific location in the PR description. - Add
@coderabbitaianywhere in the PR title to generate the title automatically.
CodeRabbit Configuration File (.coderabbit.yaml)
- You can programmatically configure CodeRabbit by adding a
.coderabbit.yamlfile 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.
Codecov Report
All modified and coverable lines are covered by tests :white_check_mark:
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
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
:rocket: New features to boost your workflow:
- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
- :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.