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(#19132): fix component tree defaultExpandAll does not work when u… #19148
Conversation
…ork when using treeData
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please add tests to make sure this change works as expected?
Deploy preview for ant-design ready! Built with commit 959ffba |
Could you fix lint and add a test case? |
…ork when using treeData
…ork when using treeData
…ork when using treeData
Codecov Report
@@ Coverage Diff @@
## master #19148 +/- ##
==========================================
- Coverage 97.32% 97.28% -0.04%
==========================================
Files 282 282
Lines 7548 7557 +9
Branches 2067 2102 +35
==========================================
+ Hits 7346 7352 +6
- Misses 201 204 +3
Partials 1 1
Continue to review full report at Codecov.
|
ok, I will |
expandedKeysByChildren.length === 0 | ||
) { | ||
this.state.expandedKeys = getFullKeyListByTreeData(props.treeData); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change to:
if (treeData) {
this.state.expandedKeys = ...
} else {
this.state.expandedKeys = ...
}
treeData
priority should be higher than children.
components/tree/util.ts
Outdated
@@ -101,3 +101,12 @@ export function convertDirectoryKeysToNodes( | |||
}); | |||
return nodes; | |||
} | |||
|
|||
export function getFullKeyListByTreeData(treeData: any[]): any { | |||
for (let i = 0; i < treeData.length; i++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(treeData || []).forEach
or (treeData || []).reduce
instead.
}, | ||
]; | ||
|
||
const keys = getFullKeyListByTreeData(treeData); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should test Tree component behavior instead of testing inner function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am sorry, this is my first contribution for ant-design, I have see documents but I still don't understand how to write this test, can you help me ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should I white test case in directory.test.js ? like this:
it('defaultExpandAll when use treeData', () => {
const treeData = [
{
key: '0-0-0',
title: 'Folder',
children: [
{
title: 'Folder2',
key: '0-0-1',
children: [
{
title: 'File',
key: '0-0-2',
isLeaf: true,
},
],
},
],
},
{
key: '0-0-3',
title: 'Folder',
children: [
{
title: 'File',
key: '0-0-4',
isLeaf: true,
},
{
title: 'File',
key: '0-0-5',
isLeaf: true,
},
{
title: 'File',
key: '0-0-6',
isLeaf: true,
},
],
},
];
const wrapper = render(createTree({ defaultExpandAll: true, treeData }));
expect(wrapper).toMatchSnapshot();
});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just simulate the exact problem in test case, like test case in https://github.com/ant-design/ant-design/blob/master/components/tree/__tests__/directory.test.js or
it('inlineCollapsed should works well when specify a not existed default openKeys', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so this is right ? I don't sure...
it('DirectoryTree should expend all when use treeData and defaultExpandAll is true', () => {
const treeData = [
{
key: '0-0-0',
title: 'Folder',
children: [
{
title: 'Folder2',
key: '0-0-1',
children: [
{
title: 'File',
key: '0-0-2',
isLeaf: true,
},
],
},
],
},
];
const wrapper = render(createTree({ defaultExpandAll: true, treeData }));
expect(wrapper).toMatchSnapshot();
});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this test case can reflect the problem you meet, then it is right.
…sing treeData
🤔 This is a ...
🔗 Related issue link
💡 Background and solution
📝 Changelog
☑️ Self Check before Merge