Skip to content

Conversation

@zombieJ
Copy link
Member

@zombieJ zombieJ commented Oct 22, 2025

Summary by CodeRabbit

发布说明

  • 重构

    • 优化了样式和类名配置在组件中的应用方式
  • 测试

    • 新增语义自定义功能的测试覆盖,验证样式和类名配置在单选和多选模式下的有效性

@vercel
Copy link

vercel bot commented Oct 22, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
tree-select Error Error Oct 22, 2025 9:55am

@gemini-code-assist
Copy link

Summary of Changes

Hello @zombieJ, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refactors the TreeSelect component to fully leverage the semantic styling capabilities provided by the underlying @rc-component/select library. By aligning the SemanticName type and simplifying the passing of classNames and styles props, the component now offers more comprehensive and flexible customization of its various internal elements. This enhancement is thoroughly validated by newly added unit tests covering both single and multiple selection scenarios, ensuring robust and predictable styling behavior.

Highlights

  • Enhanced Semantic Styling: The TreeSelect component now supports a wider range of semantic classNames and styles for its internal components, allowing for more granular customization.
  • Type Alignment: The internal SemanticName type has been updated to directly use BaseSelectSemanticName from @rc-component/select, ensuring consistency and broader coverage of styling options.
  • Simplified Prop Passing: The classNames and styles props are now passed directly to the underlying BaseSelect component, streamlining the implementation and reducing boilerplate.
  • New Test Coverage: A new test file (tests/Select.semantic.spec.tsx) has been added to thoroughly validate the new semantic styling capabilities in both single and multiple selection modes.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@coderabbitai
Copy link

coderabbitai bot commented Oct 22, 2025

Walkthrough

TreeSelect组件中修改了类型签名和参数传递机制,将SemanticName从具体类型别名改为BaseSelectSemanticName,并将classNames和styles的逐字段映射改为直接传递完整对象给底层BaseSelect组件。新增语义化定制测试套件验证。

Changes

文件集合 变更摘要
类型和参数传递更新
src/TreeSelect.tsx
导入BaseSelectSemanticName类型;将SemanticName导出类型从具体联合类型('input' | 'prefix' | 'suffix')改为BaseSelectSemanticName;在BaseSelect渲染路径中用完整的treeSelectClassNames和styles对象替代逐字段的className和style映射
语义化定制测试
tests/Select.semantic.spec.tsx
新增测试套件,包含createSingleSelect和createMultipleSelect两个辅助函数;验证TreeSelect在单选和多选模式下对prefix、suffix、input、clear、placeholder、content等语义部分的classNames和styles定制支持;多选模式额外验证items、itemContent、itemRemove元素的样式应用

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Poem

🐰 ✨
样式配置简化了,
完整对象直接传,
语义映射更通畅,
类型宽泛又包容,
TreeSelect更灵活~

Pre-merge checks and finishing touches

❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Title Check ❓ Inconclusive PR 标题 "chore: pass rc-select semantic" 与变更集的内容相关,两者都涉及向 TreeSelect 组件添加 rc-select 的语义功能支持。然而,标题中使用了"pass"这个相对模糊且不够具体的表述,没有清楚地阐明具体的变更内容,比如是在添加类型支持、重构样式映射还是实现新功能。标题过于宽泛,不够具体,难以让团队成员通过扫描历史快速理解主要变化的具体性质。 建议将标题改为更具体和清晰的描述,例如"refactor: standardize TreeSelect styling with BaseSelectSemanticName"或"feat: add semantic customization support to TreeSelect",这样能更准确地反映核心变更(类型更新、样式映射重构以及语义测试的添加),帮助团队成员更快速地理解 PR 的主要目的。
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch semantic

📜 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 d65883d and 9696629.

📒 Files selected for processing (2)
  • src/TreeSelect.tsx (3 hunks)
  • tests/Select.semantic.spec.tsx (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
tests/Select.semantic.spec.tsx (1)
src/index.tsx (1)
  • TreeNode (6-6)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Socket Security: Pull Request Alerts
  • GitHub Check: Socket Security: Project Report
🔇 Additional comments (6)
src/TreeSelect.tsx (3)

2-2: LGTM!导入语句正确。

导入 BaseSelectSemanticName 类型以支持下面的类型别名更改,这是必要的。


40-40: 类型扩展提升了 API 灵活性。

SemanticName 从具体的联合类型改为 BaseSelectSemanticName 是一个积极的改进。这允许 TreeSelect 支持 BaseSelect 的所有语义化命名(如 'clear'、'placeholder'、'content'、'item' 等),提供了更好的类型一致性和更强的定制能力。


740-741: 简化的属性传递更加清晰。

直接将 treeSelectClassNamesstyles 对象传递给 BaseSelect 组件,而不是逐字段映射,使代码更简洁、更易维护。这种方式自动支持 BaseSelect 的所有语义化名称,与第 40 行的类型更改保持一致。

tests/Select.semantic.spec.tsx (3)

6-24: 测试辅助函数设计合理。

createSingleSelectcreateMultipleSelect 辅助函数很好地减少了代码重复,并提供了清晰的树形结构用于测试。接受 props 参数的设计使得测试用例更加灵活。


26-76: 单选模式的测试覆盖完整。

测试验证了单选模式下所有语义化部分(prefix、suffix、input、clear、placeholder、content)的 classNamesstyles 应用,覆盖全面且断言准确。


78-150: 多选模式的测试覆盖全面且严谨。

测试不仅验证了通用的语义化部分,还特别覆盖了多选模式特有的 itemitemContentitemRemove 语义化名称。使用 querySelectorAllforEach 确保所有元素都应用了正确的样式,验证逻辑严谨。


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link

codecov bot commented Oct 22, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.83%. Comparing base (d65883d) to head (9696629).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #651   +/-   ##
=======================================
  Coverage   99.83%   99.83%           
=======================================
  Files          17       17           
  Lines         619      619           
  Branches      177      190   +13     
=======================================
  Hits          618      618           
  Misses          1        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

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

The pull request refactors the TreeSelect component to utilize the BaseSelectSemanticName type from @rc-component/select/lib/BaseSelect for semantic class names, simplifying the component's props and improving maintainability. Additionally, a new test file Select.semantic.spec.tsx is added to verify the correct application of semantic class names and styles in both single and multiple modes.

LegacyDataNode,
} from './interface';
import useSearchConfig from './hooks/useSearchConfig';

Choose a reason for hiding this comment

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

medium

This change updates the SemanticName type to use BaseSelectSemanticName from @rc-component/select. This ensures that the TreeSelect component's semantic names are consistent with the base select component, promoting code reuse and reducing the risk of inconsistencies. This is a good change that improves maintainability and reduces redundancy.

Consider adding a comment explaining why this change was made, and where BaseSelectSemanticName is defined.

Comment on lines +1 to +151
import React from 'react';
import { render } from '@testing-library/react';
import TreeSelect, { TreeNode } from '../src';

describe('TreeSelect.semantic', () => {
const createSingleSelect = (props = {}) => (
<TreeSelect {...props}>
<TreeNode value="0" title="Node 0" key="0">
<TreeNode value="0-0" title="Node 0-0" key="0-0" />
<TreeNode value="0-1" title="Node 0-1" key="0-1" />
</TreeNode>
<TreeNode value="1" title="Node 1" key="1" />
</TreeSelect>
);

const createMultipleSelect = (props = {}) => (
<TreeSelect multiple {...props}>
<TreeNode value="0" title="Node 0" key="0">
<TreeNode value="0-0" title="Node 0-0" key="0-0" />
<TreeNode value="0-1" title="Node 0-1" key="0-1" />
</TreeNode>
<TreeNode value="1" title="Node 1" key="1" />
</TreeSelect>
);

it('should support semantic classNames and styles in single mode', () => {
const classNames = {
prefix: 'custom-prefix',
suffix: 'custom-suffix',
input: 'custom-input',
clear: 'custom-clear',
placeholder: 'custom-placeholder',
content: 'custom-content',
};

const styles = {
prefix: { color: 'red' },
suffix: { color: 'blue' },
input: { backgroundColor: 'yellow' },
clear: { fontSize: '14px' },
placeholder: { fontStyle: 'italic' },
content: { fontWeight: 'bold' },
};

const { container } = render(
createSingleSelect({
value: '0',
prefix: <span>Prefix</span>,
suffix: <span>Suffix</span>,
allowClear: true,
placeholder: 'Please select',
classNames,
styles,
}),
);

// Test prefix
const prefixElement = container.querySelector(`.${classNames.prefix}`);
expect(prefixElement).toBeTruthy();
expect(prefixElement).toHaveStyle(styles.prefix);

// Test suffix
const suffixElement = container.querySelector(`.${classNames.suffix}`);
expect(suffixElement).toBeTruthy();
expect(suffixElement).toHaveStyle(styles.suffix);

// Test content
const contentElement = container.querySelector(`.${classNames.content}`);
expect(contentElement).toBeTruthy();
expect(contentElement).toHaveStyle(styles.content);

// Test clear
const clearElement = container.querySelector(`.${classNames.clear}`);
expect(clearElement).toBeTruthy();
expect(clearElement).toHaveStyle(styles.clear);
});

it('should support semantic classNames and styles in multiple mode', () => {
const classNames = {
prefix: 'custom-prefix',
suffix: 'custom-suffix',
content: 'custom-content',
clear: 'custom-clear',
item: 'custom-item',
itemContent: 'custom-item-content',
itemRemove: 'custom-item-remove',
};

const styles = {
prefix: { color: 'red' },
suffix: { color: 'blue' },
content: { fontWeight: 'bold' },
clear: { fontSize: '14px' },
item: { border: '1px solid green' },
itemContent: { padding: '4px' },
itemRemove: { color: 'orange' },
};

const { container } = render(
createMultipleSelect({
value: ['0', '1'],
prefix: <span>Prefix</span>,
suffix: <span>Suffix</span>,
allowClear: true,
classNames,
styles,
}),
);

// Test prefix
const prefixElement = container.querySelector(`.${classNames.prefix}`);
expect(prefixElement).toBeTruthy();
expect(prefixElement).toHaveStyle(styles.prefix);

// Test suffix
const suffixElement = container.querySelector(`.${classNames.suffix}`);
expect(suffixElement).toBeTruthy();
expect(suffixElement).toHaveStyle(styles.suffix);

// Test content
const contentElement = container.querySelector(`.${classNames.content}`);
expect(contentElement).toBeTruthy();
expect(contentElement).toHaveStyle(styles.content);

// Test clear
const clearElement = container.querySelector(`.${classNames.clear}`);
expect(clearElement).toBeTruthy();
expect(clearElement).toHaveStyle(styles.clear);

// Test items (multiple mode specific)
const items = container.querySelectorAll(`.${classNames.item}`);
expect(items.length).toBeGreaterThan(0);
items.forEach(item => {
expect(item).toHaveStyle(styles.item);
});

// Test item contents (multiple mode specific)
const itemContents = container.querySelectorAll(`.${classNames.itemContent}`);
expect(itemContents.length).toBeGreaterThan(0);
itemContents.forEach(content => {
expect(content).toHaveStyle(styles.itemContent);
});

// Test item remove buttons (multiple mode specific)
const removeButtons = container.querySelectorAll(`.${classNames.itemRemove}`);
expect(removeButtons.length).toBeGreaterThan(0);
removeButtons.forEach(button => {
expect(button).toHaveStyle(styles.itemRemove);
});
});
});

Choose a reason for hiding this comment

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

medium

The addition of Select.semantic.spec.tsx provides valuable tests for ensuring the correct application of semantic class names and styles. The tests cover both single and multiple select modes, which is comprehensive. However, consider adding more test cases to cover edge cases and different scenarios, such as when certain class names or styles are not provided.

@zombieJ zombieJ merged commit e6e1e41 into master Oct 22, 2025
12 of 13 checks passed
@zombieJ zombieJ deleted the semantic branch October 22, 2025 14:43
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