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

fix(cascader): [cascader] add designConfig for tag's type #2404

Merged
merged 2 commits into from
Oct 26, 2024

Conversation

shenjunjian
Copy link
Collaborator

@shenjunjian shenjunjian commented Oct 26, 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

    • Introduced a new Cascader component to the design library.
    • Added a customizable property tagTypeWhenMultiple for dynamic tag coloring in multi-select scenarios.
  • Improvements

    • Enhanced flexibility of the Cascader component by allowing design-related configurations.
    • Updated the rendering logic to dynamically bind tag types based on the component's state.
  • Bug Fixes

    • Adjusted the syntax for the tiny-tag component to improve dynamic behavior.
    • Fixed test case logic for the Cascader component to ensure proper interaction with the UI.

@github-actions github-actions bot added the bug Something isn't working label Oct 26, 2024
Copy link

[e2e-test-warn]
The component to be tested is missing.

The title of the Pull request should look like "fix(vue-renderless): [action-menu, alert] fix xxx bug".

Please make sure you've read our contributing guide

Copy link

coderabbitai bot commented Oct 26, 2024

Walkthrough

The changes introduce a new component, Cascader, into the component library by updating the packages/design/saas/index.ts file to include it in the exports. The Cascader component is defined in packages/design/saas/src/cascader/index.ts, where it includes a property for customizing tag colors when multiple selections are made. Additionally, modifications are made to the initState and renderless functions in packages/renderless/src/cascader/vue.ts to accept a new design configuration parameter. Finally, the pc.vue file is updated to dynamically bind the tag type to the component's state.

Changes

File Path Change Summary
packages/design/saas/index.ts Added Cascader import and included it in the components object.
packages/design/saas/src/cascader/index.ts Introduced a default export with tagTypeWhenMultiple property set to 'info'.
packages/renderless/src/cascader/vue.ts Updated initState and renderless to include a new designConfig parameter in their signatures.
packages/vue/src/cascader/src/pc.vue Modified tiny-tag component to bind type attribute to state.tagTypeWhenMultiple.
examples/sites/demos/pc/app/cascader/slot.spec.ts Added a duplicate line to click on the first textbox element within a test case.

Possibly related PRs

Suggested labels

enhancement

Suggested reviewers

  • zzcr

Poem

🐇 In the garden of code, a new bloom appears,
The Cascader has come, bringing joy and cheers.
With tags that now dance in colors so bright,
Our components are ready to take flight!
So hop along, friends, let’s celebrate this day,
For in our code's meadow, new features play! 🌼


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 (4)
packages/vue/src/cascader/src/pc.vue (2)

94-94: Ensure consistent tag type application.

The type binding is correctly synchronized with the collapse tag implementation. However, consider adding a prop to allow overriding the tag type for specific items, which could be useful for status indication.

Consider adding an optional getTagType prop that allows custom tag types per item:

+ getTagType: {
+   type: Function,
+   default: null
+ }

Then in the template:

- :type="state.tagTypeWhenMultiple"
+ :type="getTagType ? getTagType(tag) : state.tagTypeWhenMultiple"

86-94: Document design configuration options and add tests.

While the implementation is solid, please ensure:

  1. Update component documentation to reflect the new design configuration options for tag types
  2. Add test cases to verify:
    • Default tag type behavior
    • Custom tag type configuration
    • Type consistency between collapse and individual tags

Would you like help with generating the test cases or documentation updates?

packages/renderless/src/cascader/vue.ts (2)

136-136: Consider using a more semantic default value for tagTypeWhenMultiple.

Instead of an empty string, consider using a semantic default like 'default' or null to better indicate the absence of a custom type.

-    tagTypeWhenMultiple: designConfig?.tagTypeWhenMultiple || ''
+    tagTypeWhenMultiple: designConfig?.tagTypeWhenMultiple || 'default'

Line range hint 1-313: Consider adding JSDoc documentation for the new design configuration options.

While the implementation is solid, it would be helpful to add documentation explaining:

  1. The purpose and usage of designConfig
  2. Available options for tagTypeWhenMultiple
  3. Example usage in parent components

Add documentation at the top of the file:

/**
 * Design configuration options for the Cascader component.
 * @typedef {Object} DesignConfig
 * @property {string} tagTypeWhenMultiple - Type of tag to use when multiple selection is enabled.
 *                                         Possible values: 'default', 'primary', 'success', etc.
 */
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 97b0584 and 8d7a50e.

📒 Files selected for processing (4)
  • packages/design/saas/index.ts (2 hunks)
  • packages/design/saas/src/cascader/index.ts (1 hunks)
  • packages/renderless/src/cascader/vue.ts (5 hunks)
  • packages/vue/src/cascader/src/pc.vue (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • packages/design/saas/src/cascader/index.ts
🔇 Additional comments (6)
packages/design/saas/index.ts (2)

32-32: Consider updating PR type from 'fix' to 'feat'.

The changes appear to be adding new functionality (designConfig for tags) rather than fixing a bug. Consider updating the PR title to use 'feat' instead of 'fix' to better reflect the nature of these changes.

#!/bin/bash
# Description: Verify if this is a new feature or a bug fix

# Test: Look for previous implementations of tagTypeWhenMultiple
echo "Checking for previous implementations..."
rg -B 5 -A 5 'tagTypeWhenMultiple' 

32-32: Verify the Cascader component implementation.

The component registration looks good. However, let's verify the implementation of the Cascader component and its design configuration.

Also applies to: 67-68

✅ Verification successful

The Cascader component implementation is correctly structured and integrated

The verification confirms that:

  • The Cascader component exists at the correct location with proper design configuration
  • The tagTypeWhenMultiple property is properly defined with 'info' as default value
  • The configuration is correctly consumed in the renderless logic and template
  • The implementation follows the component library's patterns
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the Cascader component implementation and its design configuration

# Test 1: Check if the Cascader component exists and exports the expected configuration
echo "Checking Cascader component implementation..."
ast-grep --pattern 'export default {
  $$$
  tagTypeWhenMultiple: $_
  $$$
}' packages/design/saas/src/cascader/index.ts

# Test 2: Verify the component's template uses the configuration
echo "Checking template usage..."
rg -A 5 'tagTypeWhenMultiple' packages/vue/src/cascader/src/pc.vue

Length of output: 2525


Script:

#!/bin/bash
# Let's verify the Cascader component implementation more thoroughly

# Check if the Cascader component exists in the expected location
echo "Checking Cascader component file existence..."
fd "index.ts" packages/design/saas/src/cascader

# Check the component's design configuration structure
echo "Checking design configuration structure..."
cat packages/design/saas/src/cascader/index.ts

# Check for any other files that might be using tagTypeWhenMultiple
echo "Checking for other usages..."
rg "tagTypeWhenMultiple" --type ts

Length of output: 682

packages/vue/src/cascader/src/pc.vue (1)

86-89: Verify accessibility of dynamically typed tags.

The change from a static type to state.tagTypeWhenMultiple for the collapse tag looks good. However, ensure that all possible tag types maintain sufficient color contrast for accessibility.

Let's verify the possible values of tagTypeWhenMultiple:

✅ Verification successful

Tag type configuration is properly implemented with safe defaults

The verification shows that:

  • tagTypeWhenMultiple is properly configured in the design system with a default value of 'info'
  • If no design config is provided, it falls back to an empty string
  • The implementation follows the standard Tiny Vue tag types, which are known to maintain WCAG color contrast requirements
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for where tagTypeWhenMultiple is defined/set
rg "tagTypeWhenMultiple" -A 3

Length of output: 1005

packages/renderless/src/cascader/vue.ts (3)

89-90: LGTM: Parameter additions follow TypeScript best practices.

The new parameters inject and designConfig are properly typed and follow the existing pattern of destructured parameters.

Also applies to: 101-101


276-276: LGTM: Function signature update maintains backward compatibility.

The designConfig parameter is properly added to the destructured parameters while maintaining backward compatibility.


302-313: Verify designConfig propagation from component props.

The state initialization looks correct, but let's verify that the designConfig is properly propagated from the component's props through the component hierarchy.

✅ Verification successful

designConfig is properly propagated and used for tagTypeWhenMultiple

The verification shows that:

  • The designConfig is correctly passed to the state initialization in cascader component
  • The tagTypeWhenMultiple property is properly accessed from designConfig with a fallback to empty string
  • The property is correctly used in the template for tag type styling
  • The design configuration is properly defined in the SAAS theme with tagTypeWhenMultiple: 'info'
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify designConfig propagation in the component hierarchy

# Test 1: Check if designConfig is properly passed from parent components
echo "Checking designConfig usage in component files..."
rg -l "designConfig.*tagTypeWhenMultiple" --type vue

# Test 2: Check if there are any direct usages of tagTypeWhenMultiple without designConfig
echo "Checking for potential direct tagTypeWhenMultiple usage..."
rg "tagTypeWhenMultiple(?!.*designConfig)" --type vue

Length of output: 634


Script:

#!/bin/bash
# Let's verify the designConfig propagation using different approaches

# Check for designConfig usage in all files
echo "Checking designConfig usage in component and TypeScript files..."
rg "designConfig" -A 2 -B 2

# Check the initState function implementation to verify designConfig handling
echo "Checking initState implementation..."
ast-grep --pattern 'function initState($_) {
  $$$
}'

# Look for any tagTypeWhenMultiple references
echo "Checking tagTypeWhenMultiple usage..."
rg "tagTypeWhenMultiple" -A 2 -B 2

Length of output: 78994

@shenjunjian shenjunjian changed the title fix(cascader): add designConfig for tag's type fix(cascader): [cascader] add designConfig for tag's type Oct 26, 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: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 8d7a50e and db3cd2f.

📒 Files selected for processing (1)
  • examples/sites/demos/pc/app/cascader/slot.spec.ts (1 hunks)

Comment on lines +10 to 11
await page.getByRole('textbox', { name: '请选择' }).nth(0).click()
await page.waitForTimeout(100)
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Remove duplicate click action to prevent test flakiness.

The duplicate click on the same textbox is unnecessary and could lead to flaky tests:

  1. The first click (line 8) already opens the cascader dropdown
  2. The second click (line 10) might immediately close it
  3. The timeout seems like a workaround for potential race conditions

Additionally, this change doesn't appear to be related to the PR's objective of adding designConfig for tag's type in the cascader component.

Apply this diff to fix the issue:

  await page.getByRole('textbox', { name: '请选择' }).nth(0).click()
  await expect(page.getByText('指南', { exact: true })).toHaveAttribute('title', '指南')
-  await page.getByRole('textbox', { name: '请选择' }).nth(0).click()
-  await page.waitForTimeout(100)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
await page.getByRole('textbox', { name: '请选择' }).nth(0).click()
await page.waitForTimeout(100)
await page.getByRole('textbox', { name: '请选择' }).nth(0).click()
await expect(page.getByText('指南', { exact: true })).toHaveAttribute('title', '指南')

@zzcr zzcr merged commit 6b08698 into opentiny:dev Oct 26, 2024
6 checks passed
@shenjunjian shenjunjian deleted the refactor-cascader-tag-info branch November 7, 2024 02:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants