Skip to content

Conversation

@myNameIsDu
Copy link
Member

No description provided.

@codesandbox
Copy link

codesandbox bot commented May 20, 2025

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

@vercel
Copy link

vercel bot commented May 20, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
rsuite-nextjs ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 21, 2025 2:37am
rsuite-storybook ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 21, 2025 2:37am

@myNameIsDu myNameIsDu marked this pull request as draft May 20, 2025 09:15
@codesandbox-ci
Copy link

codesandbox-ci bot commented May 20, 2025

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces an onCascadeChange callback to CheckTreePicker, allowing consumers to receive leaf-node values when selections cascade.

  • Added onCascadeChange to the component props and invocation points
  • Implemented a recursive transformer to extract leaf values and wired it into selection logic
  • Expanded test coverage and updated both English and Chinese documentation

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
src/CheckTreePicker/CheckTreePicker.tsx Added onCascadeChange prop, cascade-change handler, and value-to-leaf transformation
src/CheckTreePicker/test/CheckTreePickerSpec.tsx New tests verifying onCascadeChange behavior
docs/pages/components/check-tree-picker/zh-CN/index.md Added onCascadeChange entry in Chinese docs
docs/pages/components/check-tree-picker/en-US/index.md Added onCascadeChange entry in English docs
Comments suppressed due to low confidence (3)

src/CheckTreePicker/CheckTreePicker.tsx:220

  • [nitpick] The function name handleTransValue2Children is ambiguous. Consider renaming it to something more descriptive like transformToLeafNodes or getLeafNodesFromSelection.
const handleTransValue2Children = useEventCallback((nextSelectedNodes: TreeNode[]) => {

src/CheckTreePicker/test/CheckTreePickerSpec.tsx:256

  • No test covers the case when the cascade prop is explicitly enabled or disabled. Consider adding a test that passes cascade={true} to ensure the correct branch of handleChangeCascade is executed.
  it('Should call `onCascadeChange` with values of children', () => {

src/CheckTreePicker/CheckTreePicker.tsx:228

  • The variables disabledItemValues and uncheckableItemValues are used here but are not explicitly destructured from props, which can lead to undefined at runtime. Please destructure them from propsWithDefaults or reference them via rest.
              !disabledItemValues.includes(childValue) &&

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request adds support for the onCascadeChange prop in the CheckTreePicker component. It includes new tests to verify the callback behavior when cascade changes occur, integrates the callback into the component’s change handling logic, and updates both Chinese and English documentation.

  • Adds tests for onCascadeChange behavior with different conditions (all children, without disabled, without uncheckable values).
  • Integrates onCascadeChange in the CheckTreePicker component, handling both cascade and non-cascade cases.
  • Updates documentation for the new prop in both zh-CN and en-US locales.

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
src/CheckTreePicker/test/CheckTreePickerSpec.tsx Adds tests to verify onCascadeChange behavior under different scenarios.
src/CheckTreePicker/CheckTreePicker.tsx Introduces the onCascadeChange prop and integrates its callback logic.
docs/pages/components/check-tree-picker/zh-CN/index.md Updates documentation with the onCascadeChange prop description.
docs/pages/components/check-tree-picker/en-US/index.md Updates documentation with the onCascadeChange prop description.

) => React.ReactNode;

/**
* In the cascade case, the leaf node's value change callbacks
Copy link

Copilot AI May 21, 2025

Choose a reason for hiding this comment

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

The JSDoc comment for onCascadeChange appears truncated; please update it to clearly describe that the callback is triggered when the value of leaf nodes changes in cascade mode.

Copilot uses AI. Check for mistakes.
Comment on lines +221 to +236
return nextSelectedNodes
.map((node: TreeNode) => {
const currentNode = node.refKey ? flattenedNodes[node.refKey] : null;
if (currentNode && currentNode[childrenKey] && currentNode[childrenKey].length) {
const childNodes = currentNode[childrenKey].filter((child: TreeNode) => {
const childValue = child[valueKey];
return (
!disabledItemValues.includes(childValue) &&
!uncheckableItemValues.includes(childValue)
);
});
return handleTransValue2Children(childNodes);
}
return node;
})
.flat();
Copy link

Copilot AI May 21, 2025

Choose a reason for hiding this comment

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

[nitpick] Consider refactoring the mapping and flattening logic using Array.flatMap() for improved readability and potential performance benefits.

Suggested change
return nextSelectedNodes
.map((node: TreeNode) => {
const currentNode = node.refKey ? flattenedNodes[node.refKey] : null;
if (currentNode && currentNode[childrenKey] && currentNode[childrenKey].length) {
const childNodes = currentNode[childrenKey].filter((child: TreeNode) => {
const childValue = child[valueKey];
return (
!disabledItemValues.includes(childValue) &&
!uncheckableItemValues.includes(childValue)
);
});
return handleTransValue2Children(childNodes);
}
return node;
})
.flat();
return nextSelectedNodes.flatMap((node: TreeNode) => {
const currentNode = node.refKey ? flattenedNodes[node.refKey] : null;
if (currentNode && currentNode[childrenKey] && currentNode[childrenKey].length) {
const childNodes = currentNode[childrenKey].filter((child: TreeNode) => {
const childValue = child[valueKey];
return (
!disabledItemValues.includes(childValue) &&
!uncheckableItemValues.includes(childValue)
);
});
return handleTransValue2Children(childNodes);
}
return [node];
});

Copilot uses AI. Check for mistakes.
@simonguo simonguo requested a review from Copilot May 21, 2025 06:02
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds support for an onCascadeChange prop to the CheckTreePicker component. It updates the component’s TypeScript interface and implementation to handle cascade change behavior, introduces new tests to verify the callback functionality (including handling disabled and uncheckable values), and updates both Chinese and English documentation.

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
src/CheckTreePicker/test/CheckTreePickerSpec.tsx Added tests to verify that onCascadeChange is called correctly in various scenarios
src/CheckTreePicker/CheckTreePicker.tsx Integrated the onCascadeChange prop into the component’s logic and added helper functions for cascade processing
docs/pages/components/check-tree-picker/zh-CN/index.md Updated to document the new onCascadeChange callback
docs/pages/components/check-tree-picker/en-US/index.md Updated to document the new onCascadeChange callback
Comments suppressed due to low confidence (1)

src/CheckTreePicker/CheckTreePicker.tsx:82

  • Consider updating the comment for 'onCascadeChange' to provide a complete and clear description of its behavior. For example, explain that the callback receives either the direct value or, in cascade mode, an array of leaf node values.
/** In the cascade case, the leaf node's value change callbacks

/**
* In the cascade case, the leaf node's value change callbacks
*/
onCascadeChange?: (v: ValueType, event: React.SyntheticEvent) => void;
Copy link

Copilot AI May 21, 2025

Choose a reason for hiding this comment

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

Ensure that the type for 'onCascadeChange' is consistent with its documentation. If the callback is intended to always receive an array of values (as indicated in the docs), consider updating the type to reflect that or clarifying the expected behavior when cascade is false.

Copilot uses AI. Check for mistakes.
@simonguo simonguo merged commit 48c5a9b into rsuite:main May 23, 2025
14 checks passed
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.

2 participants