Skip to content

Commit cebbe23

Browse files
authored
fix: Upload item removed should keep status className (ant-design#36439)
* fix: Upload item removed should keep status className * add test case * test: fix act warning * revert act test * test: update snapshot
1 parent 1d0ae57 commit cebbe23

File tree

6 files changed

+17
-16
lines changed

6 files changed

+17
-16
lines changed

components/upload/Upload.tsx

+1-8
Original file line numberDiff line numberDiff line change
@@ -262,15 +262,8 @@ const InternalUpload: React.ForwardRefRenderFunction<unknown, UploadProps> = (pr
262262
const removedFileList = removeFileItem(file, mergedFileList);
263263

264264
if (removedFileList) {
265-
currentFile = { ...file, status: 'removed' };
266-
mergedFileList?.forEach(item => {
267-
const matchKey = currentFile.uid !== undefined ? 'uid' : 'name';
268-
if (item[matchKey] === currentFile[matchKey] && !Object.isFrozen(item)) {
269-
item.status = 'removed';
270-
}
271-
});
265+
currentFile = { ...file };
272266
upload.current?.abort(currentFile);
273-
274267
onInternalChange(currentFile, removedFileList);
275268
}
276269
});

components/upload/__tests__/__snapshots__/uploadlist.test.js.snap

+2-2
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ exports[`Upload List itemRender 1`] = `
118118
class="custom-item-render"
119119
>
120120
<span>
121-
uid:-1 name: xxx.png status: removed url: https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png 1/2
121+
uid:-1 name: xxx.png status: done url: https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png 1/2
122122
</span>
123123
<span
124124
class="custom-item-render-action-remove"
@@ -144,7 +144,7 @@ exports[`Upload List itemRender 1`] = `
144144
class="custom-item-render"
145145
>
146146
<span>
147-
uid:-2 name: yyy.png status: removed url: https://zos.alipayobjects.com/rmsportal/IQKRngzUuFzJzGzRJXUs.png 2/2
147+
uid:-2 name: yyy.png status: done url: https://zos.alipayobjects.com/rmsportal/IQKRngzUuFzJzGzRJXUs.png 2/2
148148
</span>
149149
<span
150150
class="custom-item-render-action-remove"

components/upload/__tests__/upload.test.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,9 @@ describe('Upload', () => {
505505
<Upload fileList={[file]} onChange={onChange} onRemove={onRemove} />,
506506
);
507507
fireEvent.click(container.querySelector('div.ant-upload-list-item .anticon-delete'));
508+
expect(container.querySelector('.ant-upload-list-item').className).toContain(
509+
'ant-upload-list-item-uploading',
510+
);
508511

509512
// uploadStart is a batch work which we need wait for react act
510513
await act(async () => {
@@ -517,8 +520,13 @@ describe('Upload', () => {
517520
await removePromise(true);
518521
});
519522

523+
// https://github.com/ant-design/ant-design/issues/36286
524+
expect(container.querySelector('.ant-upload-list-item').className).toContain(
525+
'ant-upload-list-item-uploading',
526+
);
527+
520528
expect(onChange).toHaveBeenCalled();
521-
expect(file.status).toBe('removed');
529+
expect(file.status).toBe('uploading');
522530
});
523531

524532
it('should not stop download when return use onDownload', done => {

components/upload/index.en-US.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ Extends File with additional props.
5757
| crossOrigin | CORS settings attributes | `'anonymous'` \| `'use-credentials'` \| `''` | - | 4.20.0 |
5858
| name | File name | string | - | - |
5959
| percent | Upload progress percent | number | - | - |
60-
| status | Upload status. Show different style when configured | `error` \| `success` \| `done` \| `uploading` \| `removed` | - | - |
60+
| status | Upload status. Show different style when configured | `error` \| `success` \| `done` \| `uploading` | - | - |
6161
| thumbUrl | Thumb image url | string | - | - |
6262
| uid | unique id. Will auto generate when not provided | string | - | - |
6363
| url | Download url | string | - | - |
@@ -82,7 +82,7 @@ When uploading state change, it returns:
8282
{
8383
uid: 'uid', // unique identifier, negative is recommend, to prevent interference with internal generated id
8484
name: 'xx.png', // file name
85-
status: 'done', // options:uploading, done, error, removed. Intercepted file by beforeUpload don't have status field.
85+
status: 'done', // options:uploading, done, error. Intercepted file by beforeUpload don't have status field.
8686
response: '{"status": "success"}', // response from server
8787
linkProps: '{"download": "image"}', // additional html props of file link
8888
xhr: 'XMLHttpRequest{ ... }', // XMLHttpRequest Header

components/upload/index.zh-CN.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ cover: https://gw.alipayobjects.com/zos/alicdn/QaeBt_ZMg/Upload.svg
5858
| crossOrigin | CORS 属性设置 | `'anonymous'` \| `'use-credentials'` \| `''` | - | 4.20.0 |
5959
| name | 文件名 | string | - | - |
6060
| percent | 上传进度 | number | - | - |
61-
| status | 上传状态,不同状态展示颜色也会有所不同 | `error` \| `success` \| `done` \| `uploading` \| `removed` | - | - |
61+
| status | 上传状态,不同状态展示颜色也会有所不同 | `error` \| `success` \| `done` \| `uploading` | - | - |
6262
| thumbUrl | 缩略图地址 | string | - | - |
6363
| uid | 唯一标识符,不设置时会自动生成 | string | - | - |
6464
| url | 下载地址 | string | - | - |
@@ -83,7 +83,7 @@ cover: https://gw.alipayobjects.com/zos/alicdn/QaeBt_ZMg/Upload.svg
8383
{
8484
uid: 'uid', // 文件唯一标识,建议设置为负数,防止和内部产生的 id 冲突
8585
name: 'xx.png' // 文件名
86-
status: 'done', // 状态有:uploading done error removed,被 beforeUpload 拦截的文件没有 status 属性
86+
status: 'done', // 状态有:uploading done errorbeforeUpload 拦截的文件没有 status 属性
8787
response: '{"status": "success"}', // 服务端响应内容
8888
linkProps: '{"download": "image"}', // 下载链接额外的 HTML 属性
8989
}

components/upload/interface.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export interface RcFile extends OriRcFile {
1010
readonly lastModifiedDate: Date;
1111
}
1212

13-
export type UploadFileStatus = 'error' | 'success' | 'done' | 'uploading' | 'removed';
13+
export type UploadFileStatus = 'error' | 'success' | 'done' | 'uploading';
1414

1515
export interface HttpRequestHeader {
1616
[key: string]: string;

0 commit comments

Comments
 (0)