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(#19132): fix component tree defaultExpandAll does not work when u… #19148

Merged
merged 9 commits into from Oct 12, 2019

Conversation

kavience
Copy link

@kavience kavience commented Oct 10, 2019

…sing treeData

🤔 This is a ...

  • New feature
  • Bug fix
  • Site / document update
  • Component style update
  • TypeScript definition update
  • Refactoring
  • Code style optimization
  • Test Case
  • Branch merge
  • Other (about what?)

🔗 Related issue link

💡 Background and solution

📝 Changelog

Language Changelog
🇺🇸 English
🇨🇳 Chinese 修复 DirectoryTree 组件, 该 bug 导致当传入属性 treeData 导致时, defaultExpandAll 不生效

☑️ Self Check before Merge

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • TypeScript definition is updated/provided or not needed
  • Changelog is provided or not needed

Copy link

@tests-checker tests-checker bot left a 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?

@netlify
Copy link

netlify bot commented Oct 10, 2019

Deploy preview for ant-design ready!

Built with commit 959ffba

https://deploy-preview-19148--ant-design.netlify.com

@afc163
Copy link
Member

afc163 commented Oct 10, 2019

Could you fix lint and add a test case?

@codecov
Copy link

codecov bot commented Oct 10, 2019

Codecov Report

Merging #19148 into master will decrease coverage by 0.03%.
The diff coverage is 100%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
components/tree/util.ts 96.15% <100%> (+0.59%) ⬆️
components/tree/DirectoryTree.tsx 97.84% <100%> (+0.04%) ⬆️
components/carousel/index.tsx 91.37% <0%> (-5.18%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d582ba3...959ffba. Read the comment docs.

@kavience
Copy link
Author

Could you fix lint and add a test case?

ok, I will

expandedKeysByChildren.length === 0
) {
this.state.expandedKeys = getFullKeyListByTreeData(props.treeData);
}
Copy link
Member

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.

@@ -101,3 +101,12 @@ export function convertDirectoryKeysToNodes(
});
return nodes;
}

export function getFullKeyListByTreeData(treeData: any[]): any {
for (let i = 0; i < treeData.length; i++) {
Copy link
Member

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);
Copy link
Member

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.

Copy link
Author

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 ?

Copy link
Author

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();
  });

Copy link
Member

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', () => {

Copy link
Author

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();
  });

Copy link
Member

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.

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.

None yet

3 participants