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

refactor(theme): [toggle-menu] refactor toggle-menu theme vars #2248

Merged
merged 4 commits into from
Oct 15, 2024

Conversation

zzcr
Copy link
Member

@zzcr zzcr commented Oct 12, 2024

PR

PR Checklist

Please check if your PR fulfills the following requirements:

  • The commit message follows our Commit Message Guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Summary by CodeRabbit

  • New Features

    • Updated styling for the toggle menu component with a new naming convention for CSS variables.
    • Enhanced visual consistency through updated colors, sizes, and dimensions for various toggle menu elements.
  • Bug Fixes

    • Resolved inconsistencies in variable references, ensuring accurate styling across different states of the toggle menu.
  • Refactor

    • Renamed CSS variable methods and updated their declarations for clarity and consistency.
    • Simplified test cases for drag-and-drop functionality and filtering within the toggle menu.

@github-actions github-actions bot added the refactoring Refactoring (重构) label Oct 12, 2024
Copy link

coderabbitai bot commented Oct 12, 2024

Walkthrough

The pull request introduces a comprehensive update to the CSS variable naming conventions for the toggle menu component. It transitions variable prefixes from ti- to tv-, modifies the method for injecting CSS variables, and updates various properties such as width, color, font size, and background colors to align with the new naming scheme. Additionally, test cases for the toggle menu have been updated to reflect changes in the interaction flow and improve code clarity. This change ensures consistency in styling across the toggle menu component.

Changes

File Path Change Summary
packages/theme/src/toggle-menu/index.less Updated CSS variable references from --ti- to --tv-, changed injection method, and modified various properties.
packages/theme/src/toggle-menu/vars.less Refactored CSS variable declarations to use the tv- prefix, including width, font size, colors, and heights.
examples/sites/demos/pc/app/toggle-menu/automatic-filtering.spec.ts Modified test case to update assertions regarding visibility of tree items after filtering.
examples/sites/demos/pc/app/toggle-menu/drag-events.spec.ts Simplified logic for obtaining the bounding box of a drag node by removing unnecessary locator chaining.
examples/sites/demos/pc/app/toggle-menu/draggable.spec.ts Streamlined test case for drag-and-drop functionality by simplifying node location and expectation checks.

Possibly related PRs

🐰 In the meadow, colors bright,
Variables change, a joyful sight.
From ti- to tv-, we hop along,
Styling our toggle, where we belong.
With each new prefix, we dance and play,
A whimsical update, hip-hip-hooray! 🌼


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 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 and nitpick comments (3)
packages/theme/src/toggle-menu/vars.less (3)

15-21: Improved variable naming and value consistency.

The changes to the variable names and values enhance consistency and maintainability:

  1. The prefix change from --ti- to --tv- aligns with the new naming convention.
  2. Capitalizing the component name in variables (e.g., ToggleMenu) improves readability.
  3. Using references to other CSS variables (e.g., var(--tv-font-size-md)) promotes theme-wide consistency.

Consider using relative units (e.g., rem or em) for --tv-ToggleMenu-width and --tv-ToggleMenu-tree-node-height to improve flexibility and responsiveness across different screen sizes and user preferences.


23-27: Consistent updates to search-related variables.

The changes to the search-related variables improve consistency and maintainability:

  1. The naming convention aligns with the new standard.
  2. Using var(--tv-icon-size) for the search icon size promotes theme-wide consistency.

Consider using a relative unit or referencing another theme variable for --tv-ToggleMenu-filter-search-size to improve flexibility and consistency with other form elements in the theme.


13-37: Overall improvement in theme consistency and maintainability.

The refactoring of the ToggleMenu variables has significantly enhanced the theme's consistency and maintainability:

  1. The new naming convention (--tv-ToggleMenu-*) is more consistent and easier to understand.
  2. Extensive use of referenced variables (e.g., var(--tv-color-icon)) promotes theme-wide consistency and easier updates.
  3. The use of semantic color variables improves code readability and maintainability.

These changes will make it easier to manage and update the theme in the future, as well as ensure a consistent look and feel across the application.

For further improvement, consider:

  1. Using relative units (e.g., rem or em) for fixed pixel values to enhance responsiveness and flexibility.
  2. Ensuring all component-specific variables are derived from global theme variables where appropriate, to maintain consistency across different components.
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 98246dd and d808ed9.

📒 Files selected for processing (2)
  • packages/theme/src/toggle-menu/index.less (8 hunks)
  • packages/theme/src/toggle-menu/vars.less (1 hunks)
🧰 Additional context used
🔇 Additional comments (12)
packages/theme/src/toggle-menu/vars.less (2)

13-13: Improved method naming convention.

The change from .component-css-vars-toggle-menu() to .inject-ToggleMenu-vars() enhances clarity and consistency. It accurately reflects the method's purpose of injecting variables for the ToggleMenu component.


29-37: Improved consistency and semantics in toggle-related variables.

The updates to the toggle-related variables enhance the overall theme consistency and maintainability:

  1. The naming convention aligns with the new standard.
  2. Referencing other CSS variables (e.g., var(--tv-color-icon), var(--tv-color-bg-hover)) promotes theme-wide consistency.
  3. The use of semantic color variables improves maintainability and makes it easier to understand the purpose of each color.

These changes will make it easier to manage and update the theme in the future.

packages/theme/src/toggle-menu/index.less (10)

56-58: LGTM! Consistent naming for filter search properties.

The changes to the CSS variable names for filter search properties (e.g., --ti-toggle-menu-filter-search-size to --tv-ToggleMenu-filter-search-size) are consistent with the new naming convention. Using the same variable for width, height, and line-height ensures square proportions.


66-67: LGTM! Consistent naming for icon properties.

The changes to the CSS variable names for icon properties (color and size) are consistent with the new naming convention while maintaining their specific purposes.


126-126: LGTM! Consistent naming for toggle font weight.

The change to the CSS variable name for toggle font weight is consistent with the new naming convention while maintaining its specific purpose.


137-138: LGTM! Consistent naming for hover state properties.

The changes to the CSS variable names for hover state properties (background color and font weight) are consistent with the new naming convention while maintaining their specific purposes.


179-179: LGTM! Consistent naming for font size.

The change to the CSS variable name for font size is consistent with the new naming convention and matches the earlier change on line 42, ensuring consistency throughout the file.


188-190: LGTM! Consistent naming for tree node properties.

The changes to the CSS variable names for tree node properties (height, line-height, and font size) are consistent with the new naming convention while maintaining their specific purposes. The font size variable remains consistent with its usage elsewhere in the file.


25-25: LGTM! Verify new CSS variable definitions.

The changes to CSS variable names (e.g., --ti-toggle-menu-width to --tv-ToggleMenu-width) are consistent with the new naming convention. This refactoring improves overall consistency.

Please ensure that these new CSS variables are properly defined in the theme. Run the following script to verify:

#!/bin/bash
# Search for the definitions of the new CSS variables
rg --type less "(--tv-ToggleMenu-width|--tv-ToggleMenu-name-text-color|--tv-ToggleMenu-font-size)" packages/theme/src

Also applies to: 41-42


Line range hint 1-193: Overall LGTM! Comprehensive refactoring of CSS variable names.

The changes in this file consistently update CSS variable names from the ti- prefix to the tv- prefix, improving overall consistency and following a clear naming convention. No functional changes were made to the styles themselves, which reduces the risk of introducing bugs.

However, to ensure the refactoring doesn't cause any styling issues:

  1. Verify that all new CSS variables are correctly defined in the theme files.
  2. Conduct a thorough visual test of the ToggleMenu component in various states (default, hover, active) to confirm that the styling remains intact.
  3. Check for any potential impact on responsive designs or different viewport sizes.

Please run the following script to ensure all new CSS variables are defined:

#!/bin/bash
# Search for all new CSS variable definitions
rg --type less "^\s*--tv-ToggleMenu-" packages/theme/src

77-79: LGTM! Consistent naming for toggle properties.

The changes to the CSS variable names for toggle properties (height, line-height, background color, icon color, and hover icon color) are consistent with the new naming convention while maintaining their specific purposes.

Please ensure that these new CSS variables for toggle properties are properly defined in the theme. Run the following script to verify:

#!/bin/bash
# Search for the definitions of the new CSS variables for toggle properties
rg --type less "(--tv-ToggleMenu-filter-search-size|--tv-ToggleMenu-toggle-bg-color|--tv-ToggleMenu-toggle-icon-color|--tv-ToggleMenu-toggle-icon-color-hover)" packages/theme/src

Also applies to: 84-84, 88-88


23-23: LGTM! Verify the new mixin definition.

The change from .component-css-vars-toggle-menu() to .inject-ToggleMenu-vars() improves clarity and consistency in naming. This appears to be part of a larger refactoring effort.

Please ensure that the .inject-ToggleMenu-vars() mixin is properly defined elsewhere in the codebase. Run the following script to verify:

✅ Verification successful

Mixin .inject-ToggleMenu-vars() Definition Verified

The .inject-ToggleMenu-vars() mixin is properly defined in packages/theme/src/toggle-menu/vars.less and correctly used in index.less.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for the definition of the new mixin
rg --type less "\.inject-ToggleMenu-vars\s*\(\)" packages/theme/src

Length of output: 1521


Script:

#!/bin/bash
# Search for the definition of the new mixin without parentheses
rg --type less "\.inject-ToggleMenu-vars" packages/theme/src

Length of output: 202

kagol
kagol previously approved these changes Oct 14, 2024
kagol
kagol previously approved these changes Oct 15, 2024
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 and nitpick comments (3)
examples/sites/demos/pc/app/toggle-menu/automatic-filtering.spec.ts (2)

10-10: Good improvement in test logic!

Changing from a click action to a visibility check is more appropriate for testing the filtering behavior. It correctly verifies that the item becomes visible again after clearing the filter.

For improved clarity, consider adding a comment explaining that this check is performed after clearing the filter. For example:

// Verify that the item is visible again after clearing the filter
await expect(page.getByRole('treeitem', { name: '引入组件' })).toBeVisible()

Line range hint 1-11: Consider enhancing test structure and readability

The changes have significantly improved the test coverage for the filtering functionality. To further enhance the test's structure and readability, consider the following suggestions:

  1. Add descriptive comments for each step of the test to improve readability.
  2. Consider breaking down the test into smaller, more focused test cases (e.g., one for applying the filter and one for clearing it).
  3. Use test hooks (like test.beforeEach()) to set up common test conditions.

Here's an example of how you might restructure the test:

import { test, expect } from '@playwright/test'

test.describe('Toggle Menu Automatic Filtering', () => {
  test.beforeEach(async ({ page }) => {
    page.on('pageerror', (exception) => expect(exception).toBeNull())
    await page.goto('toggle-menu#automatic-filtering')
  })

  test('hides non-matching items when filter is applied', async ({ page }) => {
    // Apply filter
    await page.getByRole('textbox', { name: '请输入过滤值' }).fill('组件')

    // Verify item is hidden
    await expect(page.getByRole('treeitem', { name: '引入组件' })).not.toBeVisible()
  })

  test('shows all items when filter is cleared', async ({ page }) => {
    // Apply and then clear filter
    await page.getByRole('textbox', { name: '请输入过滤值' }).fill('组件')
    await page.locator('.tiny-toggle-menu__filter-search > .tiny-svg').click()

    // Verify item is visible again
    await expect(page.getByRole('treeitem', { name: '引入组件' })).toBeVisible()
  })
})

This structure improves readability and makes it easier to add more specific test cases in the future.

examples/sites/demos/pc/app/toggle-menu/draggable.spec.ts (1)

17-17: Improved assertion with consistent element selection!

The simplification of the assertion is a great improvement:

  1. It maintains consistency with the earlier getByRole usage.
  2. The code is more readable and direct.

Consider if the exact match using a regular expression is necessary. If a precise match isn't required, you could simplify further:

await expect(page.getByRole('treeitem', { name: '其他组件', exact: true })).toHaveText('其他组件')

This would be slightly more lenient (allowing for potential whitespace differences) while still ensuring the correct text is present.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 786fe84 and a6e90ff.

📒 Files selected for processing (3)
  • examples/sites/demos/pc/app/toggle-menu/automatic-filtering.spec.ts (1 hunks)
  • examples/sites/demos/pc/app/toggle-menu/drag-events.spec.ts (1 hunks)
  • examples/sites/demos/pc/app/toggle-menu/draggable.spec.ts (2 hunks)
🧰 Additional context used
🔇 Additional comments (3)
examples/sites/demos/pc/app/toggle-menu/automatic-filtering.spec.ts (1)

8-8: Excellent addition to improve test coverage!

This new assertion verifies that the tree item '引入组件' is not visible after applying the filter. It's a crucial check to ensure the filtering functionality is working correctly by hiding non-matching items.

examples/sites/demos/pc/app/toggle-menu/drag-events.spec.ts (1)

7-7: Approve simplification of drag node selection, but verify test behavior.

The change simplifies the selection of the drag node by directly using the bounding box of the treeitem instead of a specific child element. This approach is more robust and less prone to breaking if the internal structure of the treeitem changes.

However, please ensure that this modification doesn't alter the intended behavior of the drag operation in the test. The starting point of the drag might be slightly different now, which could potentially affect the test results.

To verify that this change doesn't negatively impact the test, please run the following script:

examples/sites/demos/pc/app/toggle-menu/draggable.spec.ts (1)

6-8: Excellent refactoring of element selection!

The changes to lines 7-8 significantly improve the code:

  1. Enhanced readability and conciseness.
  2. Improved maintainability by using getByRole instead of text-based filtering.
  3. Promotes accessibility by leveraging ARIA roles.
  4. Potentially better performance compared to the previous locator and filter combination.

This refactoring aligns well with best practices for writing robust and accessible tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactoring Refactoring (重构)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants