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: Upload onChange immutable #22322

Merged
merged 4 commits into from
Mar 17, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions components/tree/DirectoryTree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class DirectoryTree extends React.Component<DirectoryTreeProps, DirectoryTreeSta
const { onSelect, multiple } = this.props;
const { expandedKeys = [] } = this.state;
const { node, nativeEvent } = event;
const { eventKey = '' } = node.props;
const { key = '' } = node;

const treeData = getTreeData(this.props);
const newState: DirectoryTreeState = {};
Expand All @@ -171,24 +171,24 @@ class DirectoryTree extends React.Component<DirectoryTreeProps, DirectoryTreeSta
if (multiple && ctrlPick) {
// Control click
newSelectedKeys = keys;
this.lastSelectedKey = eventKey;
this.lastSelectedKey = key;
this.cachedSelectedKeys = newSelectedKeys;
newEvent.selectedNodes = convertDirectoryKeysToNodes(treeData, newSelectedKeys);
} else if (multiple && shiftPick) {
// Shift click
newSelectedKeys = Array.from(
new Set([
...(this.cachedSelectedKeys || []),
...calcRangeKeys(treeData, expandedKeys, eventKey, this.lastSelectedKey),
...calcRangeKeys(treeData, expandedKeys, key, this.lastSelectedKey),
]),
);
newEvent.selectedNodes = convertDirectoryKeysToNodes(treeData, newSelectedKeys);
} else {
// Single click
newSelectedKeys = [eventKey];
this.lastSelectedKey = eventKey;
newSelectedKeys = [key];
this.lastSelectedKey = key;
this.cachedSelectedKeys = newSelectedKeys;
newEvent.selectedNodes = [event.node.props.data];
newEvent.selectedNodes = convertDirectoryKeysToNodes(treeData, newSelectedKeys);
Copy link
Member

Choose a reason for hiding this comment

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

为啥改了 Tree。

}
newState.selectedKeys = newSelectedKeys;

Expand Down
5 changes: 4 additions & 1 deletion components/upload/Upload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,10 @@ class Upload extends React.Component<UploadProps, UploadState> {

const { onChange } = this.props;
if (onChange) {
onChange(info);
onChange({
...info,
fileList: [...info.fileList],
});
}
};

Expand Down
6 changes: 5 additions & 1 deletion components/upload/__tests__/uploadlist.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,18 @@ describe('Upload List', () => {

it('should be uploading when upload a file', done => {
let wrapper;
const onChange = ({ file }) => {
let latestFileList = null;
const onChange = ({ file, fileList }) => {
expect(fileList === latestFileList).toBeFalsy();
if (file.status === 'uploading') {
expect(wrapper.render()).toMatchSnapshot();
}
if (file.status === 'done') {
expect(wrapper.render()).toMatchSnapshot();
done();
}

latestFileList = fileList;
};
wrapper = mount(
<Upload
Expand Down