Skip to content

Commit

Permalink
fix(module:upload): remove unnecessary checks (#1039)
Browse files Browse the repository at this point in the history
close #1038
  • Loading branch information
cipchk authored and vthinkxie committed Feb 22, 2018
1 parent 6035c27 commit df9f3e5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
10 changes: 2 additions & 8 deletions src/components/upload/nz-upload.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ export class NzUploadComponent implements OnInit, OnChanges, OnDestroy {
onRemove = (file: UploadFile): void => {
this.upload.abort(file);
file.status = 'removed';
(this.nzRemove ? this.nzRemove instanceof Observable ? this.nzRemove : of(this.nzRemove(file)) : of(true))
((this.nzRemove ? this.nzRemove instanceof Observable ? this.nzRemove : of(this.nzRemove(file)) : of(true)) as Observable<any>)
.pipe(filter((res: boolean) => res))
.subscribe(res => {
const removedFileList = this.removeFileItem(file, this.nzFileList);
Expand Down Expand Up @@ -411,13 +411,7 @@ export class NzUploadComponent implements OnInit, OnChanges, OnDestroy {
}

ngOnChanges(changes: { [P in keyof this]?: SimpleChange } & SimpleChanges): void {
if (changes.nzFileList) {
(this.nzFileList || []).forEach(file => file.message = this.genErr(file));
if (!changes.nzFileList.firstChange) return;
}
if (this.inited) {
if (changes.nzPreview || changes.nzCustomRequest || changes.nzBeforeUpload || changes.nzRemove) return;
}
if (changes.nzFileList) (this.nzFileList || []).forEach(file => file.message = this.genErr(file));
this.zipOptions()._setClassMap();
}

Expand Down
19 changes: 18 additions & 1 deletion src/components/upload/nz-upload.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,30 @@ describe('NzUpload', () => {
it('should create an instance', () => {
expect(instance).toBeTruthy();
});

it('recreate bug https://github.com/NG-ZORRO/ng-zorro-antd/issues/1038', () => {
expect(instance.ref._btnOptions.disabled).toBe(false);
instance.fileList = [{
uid: -1,
name: 'xxx.png',
status: 'done',
url: 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png',
}];
fixture.detectChanges();
expect(instance.ref._btnOptions.disabled).toBe(true);
});
});

@Component({
template: `<nz-upload #ref [nzShowUploadList]="false">Upload</nz-upload>`
template: `<nz-upload #ref
[(nzFileList)]="fileList"
[nzDisabled]="fileList.length >= 1"
[nzShowUploadList]="false">Upload</nz-upload>`
})
class TestComponent {

@ViewChild('ref') ref: NzUploadComponent;

fileList = [];

}

0 comments on commit df9f3e5

Please sign in to comment.