Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replaced visibility message with indicator icon #1429

Merged
merged 1 commit into from
Jan 30, 2025

Conversation

kevinansfield
Copy link
Member

ref https://linear.app/ghost/issue/PLG-330/

  • removed visibility text when content visibility is active
  • added replacement of card type indicator icon with visibility icon when visibility settings are active
    • clicking toggles card in/out of edit mode for context-driven access to visibility settings

Copy link

coderabbitai bot commented Jan 30, 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/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/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/ui/cards/HtmlCard.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.

  • 4 others

Walkthrough

The pull request introduces enhancements to the content visibility management in the Koenig Lexical editor. The changes focus on refactoring how card visibility is handled, particularly around the contentVisibilityAlpha feature. Modifications span multiple components and utilities, updating the logic for displaying visibility indicators, managing card editing states, and simplifying visibility message generation. New props and state variables are introduced to enhance the functionality and interactivity of the card components.

Changes

File Change Summary
packages/koenig-lexical/src/components/KoenigCardWrapper.jsx Added KoenigComposerContext import, introduced isVisibilityActive state, added toggleEditMode function, updated CardWrapper props
packages/koenig-lexical/src/components/ui/CardWrapper.jsx Added VisibilityIndicator import, modified rendering logic for indicator icon based on new props
packages/koenig-lexical/src/components/ui/cards/HtmlCard.jsx Updated content visibility determination, added contentVisibility prop type
packages/koenig-lexical/src/hooks/useVisibilityToggle.js Simplified visibility message generation logic
packages/koenig-lexical/src/nodes/HtmlNode.jsx Added isVisibilityActive property to decorate method
packages/koenig-lexical/src/utils/visibility.js Removed generateVisibilityMessageAlpha function
packages/koenig-lexical/test/e2e/content-visibility.test.js Renamed and modified tests for visibility settings and toggles
packages/koenig-lexical/test/unit/hooks/useVisibilityToggle.test.js Updated expected outcomes for visibility messages
packages/koenig-lexical/test/unit/utils/visibility.test.js Removed test suite for generateVisibilityMessageAlpha function

Sequence Diagram

sequenceDiagram
    participant User
    participant CardWrapper
    participant KoenigCardWrapper
    participant VisibilityIndicator

    User->>CardWrapper: Click visibility indicator
    CardWrapper->>KoenigCardWrapper: Trigger toggleEditMode
    KoenigCardWrapper->>KoenigCardWrapper: Determine edit state
    alt Edit mode on
        KoenigCardWrapper->>CardWrapper: Show EDIT_CARD_COMMAND
    else Edit mode off
        KoenigCardWrapper->>CardWrapper: Show DESELECT_CARD_COMMAND
    end
    CardWrapper->>VisibilityIndicator: Update visibility state
Loading

Possibly related PRs

  • Updated CTA card cardwrapper behavior #1414: The changes in this PR update the CardWrapper component to include new props (feature and isVisibilityActive), which are directly related to the modifications made in the main PR to enhance the KoenigCardWrapper component's functionality.
  • Wired up button toggle to CTA Card #1415: This PR involves wiring up button toggle functionality in the CtaCard, which is relevant as the main PR also introduces new props and functionality related to editing and visibility management in the card components.
  • Expanded visibility controls to cover web segments #1424: Expanded visibility controls for web segments are relevant as they enhance the visibility management features introduced in the main PR.

Poem

🐰 A Rabbit's Ode to Visibility

In cards of code, where shadows dance,
Visibility gets a clever glance.
Toggles flip, and icons shine bright,
Revealing content's hidden might.
A lexical leap of rabbit delight! 🎉

✨ 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 (2)
packages/koenig-lexical/src/components/ui/cards/HtmlCard.jsx (1)

Line range hint 48-48: Fix incorrect PropType for contentVisibility.

The contentVisibility prop is defined as PropTypes.element but based on usage it should be PropTypes.bool.

-    contentVisibility: PropTypes.element,
+    contentVisibility: PropTypes.bool,
packages/koenig-lexical/src/components/ui/CardWrapper.jsx (1)

Line range hint 109-119: Add PropTypes for new props.

Several new props are being used but not declared in PropTypes:

  • feature
  • isVisibilityActive
  • onIndicatorClick
 CardWrapper.propTypes = {
     isSelected: PropTypes.bool,
     isEditing: PropTypes.bool,
     cardWidth: PropTypes.oneOf(['regular', 'wide', 'full']),
     icon: PropTypes.string,
     indicatorPosition: PropTypes.shape({
         left: PropTypes.string,
         top: PropTypes.string
-    })
+    }),
+    feature: PropTypes.shape({
+        contentVisibilityAlpha: PropTypes.bool,
+        contentVisibility: PropTypes.bool
+    }),
+    isVisibilityActive: PropTypes.bool,
+    onIndicatorClick: PropTypes.func
 };
🧹 Nitpick comments (2)
packages/koenig-lexical/src/components/KoenigCardWrapper.jsx (2)

25-38: LGTM! Consider memoizing the editor.update callback.

The toggleEditMode implementation is clean and handles both edit and deselect cases correctly.

Consider memoizing the editor.update callback to prevent unnecessary re-renders:

 const toggleEditMode = React.useCallback((event) => {
     event.preventDefault();
     event.stopPropagation();
 
+    const updateCallback = React.useCallback(() => {
+        const cardNode = $getNodeByKey(nodeKey);
+
+        if (cardNode?.hasEditMode?.() && !isEditing) {
+            editor.dispatchCommand(EDIT_CARD_COMMAND, {cardKey: nodeKey, focusEditor: true});
+        } else if (isEditing) {
+            editor.dispatchCommand(DESELECT_CARD_COMMAND, {cardKey: nodeKey, focusEditor: true});
+        }
+    }, [nodeKey, isEditing]);
+
-    editor.update(() => {
-        const cardNode = $getNodeByKey(nodeKey);
-
-        if (cardNode?.hasEditMode?.() && !isEditing) {
-            editor.dispatchCommand(EDIT_CARD_COMMAND, {cardKey: nodeKey, focusEditor: true});
-        } else if (isEditing) {
-            editor.dispatchCommand(DESELECT_CARD_COMMAND, {cardKey: nodeKey, focusEditor: true});
-        }
-    });
+    editor.update(updateCallback);
 }, [editor, isEditing, nodeKey]);

147-153: Move isVisibilityActive computation to a useMemo hook.

The visibility state computation should be memoized to prevent unnecessary recalculations on re-renders.

-    let isVisibilityActive = false;
-    if (cardConfig?.feature?.contentVisibilityAlpha) {
-        editor.getEditorState().read(() => {
-            const cardNode = $getNodeByKey(nodeKey);
-            isVisibilityActive = cardNode?.getIsVisibilityActive?.();
-        });
-    }
+    const isVisibilityActive = React.useMemo(() => {
+        if (!cardConfig?.feature?.contentVisibilityAlpha) {
+            return false;
+        }
+        
+        let isActive = false;
+        editor.getEditorState().read(() => {
+            const cardNode = $getNodeByKey(nodeKey);
+            isActive = cardNode?.getIsVisibilityActive?.();
+        });
+        return isActive;
+    }, [editor, nodeKey, cardConfig?.feature?.contentVisibilityAlpha]);
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 58489e6 and 7db2938.

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

2-2: LGTM! Clean import statement.

The removal of generateVisibilityMessageAlpha import aligns with the PR's objective to replace visibility messages with indicator icons.


21-22: LGTM! Visibility message logic update.

The condition !isContentVisibilityAlphaEnabled correctly ensures that visibility messages are only shown when the alpha feature is disabled, aligning with the PR's objective to use indicator icons instead.

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

108-109: LGTM! Test case updated to match new behavior.

The test case correctly verifies that visibility messages are removed when contentVisibilityAlpha is enabled. The added comment provides clear documentation of the intentional change.

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

34-34: Verify the implementation of getIsVisibilityActive().

The code calls this.getIsVisibilityActive() but this method is not visible in the current file. Please ensure that this method is properly implemented, either in this class or in the parent BaseHtmlNode class.

✅ Verification successful

Implementation of getIsVisibilityActive() is verified and correct

The method is properly implemented through the decorator node generator and inherited by the HtmlNode class. The implementation includes proper visibility property handling and is well-tested.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for the implementation of getIsVisibilityActive
ast-grep --pattern 'getIsVisibilityActive() {
  $$$
}'

# Also check the base class implementation
rg -A 5 "getIsVisibilityActive" 

Length of output: 4577


Script:

#!/bin/bash
# Check HtmlNode's class definition and inheritance
ast-grep --pattern 'class HtmlNode extends $_ {
  $$$
}'

# Search for BaseHtmlNode or related class definitions
rg -A 5 "class.*HtmlNode"

Length of output: 6972

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

11-14: LGTM! Clean implementation of feature flags.

The extraction of feature flags and the logic for displayVisibilityMessage is clear and well-structured.

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

59-89: LGTM! Clean implementation of conditional indicator rendering.

The logic for rendering either the visibility indicator or the card type indicator is well-structured and maintains consistent styling.

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

192-204: Well-structured test coverage for default visibility settings!

The test comprehensively verifies the default state of all visibility toggles, ensuring content is visible across all platforms and member types by default.


205-224: Comprehensive test coverage for visibility toggles!

The test methodically verifies each visibility toggle's functionality, and correctly documents the intentional removal of the visibility message as part of the new design.


226-241: Excellent test coverage for the new visibility indicator feature!

The test effectively verifies both the visibility indicator's appearance conditions and its interactive behavior for toggling edit mode, aligning perfectly with the PR's objective of replacing the visibility message with an interactive indicator icon.


Line range hint 244-253: Good test coverage for Stripe-dependent visibility settings!

The test effectively verifies that paid member visibility options are properly hidden when Stripe is not enabled, maintaining a consistent user experience.

ref https://linear.app/ghost/issue/PLG-330/

- removed visibility text when content visibility is active
- added replacement of card type indicator icon with visibility icon when visibility settings are active
  - clicking toggles card in/out of edit mode for context-driven access to visibility settings
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 (3)
packages/koenig-lexical/src/components/KoenigCardWrapper.jsx (1)

147-153: Consider memoizing the visibility state calculation.

The visibility state is recalculated on every render. Consider memoizing this value using useMemo to optimize performance, especially since it involves a state read operation.

-    let isVisibilityActive = false;
-    if (cardConfig?.feature?.contentVisibilityAlpha) {
-        editor.getEditorState().read(() => {
-            const cardNode = $getNodeByKey(nodeKey);
-            isVisibilityActive = cardNode?.getIsVisibilityActive?.();
-        });
-    }
+    const isVisibilityActive = React.useMemo(() => {
+        if (!cardConfig?.feature?.contentVisibilityAlpha) {
+            return false;
+        }
+        let isActive = false;
+        editor.getEditorState().read(() => {
+            const cardNode = $getNodeByKey(nodeKey);
+            isActive = cardNode?.getIsVisibilityActive?.();
+        });
+        return isActive;
+    }, [cardConfig?.feature?.contentVisibilityAlpha, editor, nodeKey]);
packages/koenig-lexical/test/e2e/content-visibility.test.js (2)

205-224: Consider adding error states testing.

While the test covers the basic toggle functionality well, consider adding tests for error states and edge cases, such as:

  • Rapid toggle clicks
  • Toggle during card state transitions
  • Network latency simulation

Line range hint 244-253: Consider adding more Stripe integration test cases.

While the test verifies that paid member settings are hidden when Stripe is disabled, consider adding tests for:

  • Stripe initialization failures
  • Mid-session Stripe disconnection
  • Stripe feature flag changes
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 7db2938 and 5d54605.

📒 Files selected for processing (9)
  • packages/koenig-lexical/src/components/KoenigCardWrapper.jsx (4 hunks)
  • packages/koenig-lexical/src/components/ui/CardWrapper.jsx (3 hunks)
  • packages/koenig-lexical/src/components/ui/cards/HtmlCard.jsx (2 hunks)
  • packages/koenig-lexical/src/hooks/useVisibilityToggle.js (2 hunks)
  • packages/koenig-lexical/src/nodes/HtmlNode.jsx (1 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 (1 hunks)
  • packages/koenig-lexical/test/unit/utils/visibility.test.js (0 hunks)
💤 Files with no reviewable changes (2)
  • packages/koenig-lexical/src/utils/visibility.js
  • packages/koenig-lexical/test/unit/utils/visibility.test.js
🚧 Files skipped from review as they are similar to previous changes (5)
  • packages/koenig-lexical/test/unit/hooks/useVisibilityToggle.test.js
  • packages/koenig-lexical/src/nodes/HtmlNode.jsx
  • packages/koenig-lexical/src/hooks/useVisibilityToggle.js
  • packages/koenig-lexical/src/components/ui/cards/HtmlCard.jsx
  • packages/koenig-lexical/src/components/ui/CardWrapper.jsx
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Node 20.11.1
🔇 Additional comments (5)
packages/koenig-lexical/src/components/KoenigCardWrapper.jsx (3)

2-2: LGTM! Import statements are correctly structured.

The new imports for KoenigComposerContext and DESELECT_CARD_COMMAND are properly organized and align with the component's enhanced functionality.

Also applies to: 6-6


25-38: LGTM! Well-implemented toggle functionality.

The toggleEditMode function is well-structured with proper event handling and clear logic for toggling between edit modes. Good use of React's useCallback for optimization.


171-171: LGTM! Props are properly passed to CardWrapper.

The new props (feature, isVisibilityActive, onIndicatorClick) are correctly passed to the CardWrapper component, maintaining a clean props interface.

Also applies to: 176-176, 178-178

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

192-203: LGTM! Comprehensive default visibility test.

The test thoroughly verifies all default visibility states for different member types and platforms.


226-241: LGTM! Well-structured visibility icon interaction test.

The test effectively verifies both the visibility icon's appearance conditions and its edit mode toggle functionality.

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