From 5aebcd6092bafd944ffb2a9027133ac8a3b00b6e Mon Sep 17 00:00:00 2001 From: Michael Bromley Date: Tue, 6 Oct 2020 21:20:13 +0200 Subject: [PATCH] feat(admin-ui): Display error messages on failed Asset uploads --- .../asset-list/asset-list.component.ts | 44 ++++++++++++------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/packages/admin-ui/src/lib/catalog/src/components/asset-list/asset-list.component.ts b/packages/admin-ui/src/lib/catalog/src/components/asset-list/asset-list.component.ts index d9fa988c93..011ec99f1c 100644 --- a/packages/admin-ui/src/lib/catalog/src/components/asset-list/asset-list.component.ts +++ b/packages/admin-ui/src/lib/catalog/src/components/asset-list/asset-list.component.ts @@ -21,7 +21,8 @@ import { debounceTime, finalize, map, switchMap, takeUntil } from 'rxjs/operator templateUrl: './asset-list.component.html', styleUrls: ['./asset-list.component.scss'], }) -export class AssetListComponent extends BaseListComponent +export class AssetListComponent + extends BaseListComponent implements OnInit { searchTerm = new FormControl(''); uploading = false; @@ -37,7 +38,7 @@ export class AssetListComponent extends BaseListComponent this.dataService.product.getAssetList(...args), - (data) => data.assets, + data => data.assets, (skip, take) => ({ options: { skip, @@ -71,26 +72,39 @@ export class AssetListComponent extends BaseListComponent (this.uploading = false))) - .subscribe((res) => { - super.refresh(); - this.notificationService.success(_('asset.notify-create-assets-success'), { - count: files.length, - }); + .subscribe(({ createAssets }) => { + let successCount = 0; + for (const result of createAssets) { + switch (result.__typename) { + case 'Asset': + successCount++; + break; + case 'MimeTypeError': + this.notificationService.error(result.message); + break; + } + } + if (0 < successCount) { + super.refresh(); + this.notificationService.success(_('asset.notify-create-assets-success'), { + count: successCount, + }); + } }); } } deleteAssets(assets: Asset[]) { - this.showModalAndDelete(assets.map((a) => a.id)) + this.showModalAndDelete(assets.map(a => a.id)) .pipe( - switchMap((response) => { + switchMap(response => { if (response.result === DeletionResult.DELETED) { return [true]; } else { return this.showModalAndDelete( - assets.map((a) => a.id), + assets.map(a => a.id), response.message || '', - ).pipe(map((r) => r.result === DeletionResult.DELETED)); + ).pipe(map(r => r.result === DeletionResult.DELETED)); } }), ) @@ -101,7 +115,7 @@ export class AssetListComponent extends BaseListComponent { + err => { this.notificationService.error(_('common.notify-delete-error'), { entity: 'Assets', }); @@ -123,10 +137,8 @@ export class AssetListComponent extends BaseListComponent - res ? this.dataService.product.deleteAssets(assetIds, !!message) : EMPTY, - ), - map((res) => res.deleteAssets), + switchMap(res => (res ? this.dataService.product.deleteAssets(assetIds, !!message) : EMPTY)), + map(res => res.deleteAssets), ); } }