Skip to content

Commit

Permalink
feat(admin-ui): Display error messages on failed Asset uploads
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbromley committed Oct 7, 2020
1 parent 177a14f commit 5aebcd6
Showing 1 changed file with 28 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<GetAssetList.Query, GetAssetList.Items>
export class AssetListComponent
extends BaseListComponent<GetAssetList.Query, GetAssetList.Items>
implements OnInit {
searchTerm = new FormControl('');
uploading = false;
Expand All @@ -37,7 +38,7 @@ export class AssetListComponent extends BaseListComponent<GetAssetList.Query, Ge
super(router, route);
super.setQueryFn(
(...args: any[]) => this.dataService.product.getAssetList(...args),
(data) => data.assets,
data => data.assets,
(skip, take) => ({
options: {
skip,
Expand Down Expand Up @@ -71,26 +72,39 @@ export class AssetListComponent extends BaseListComponent<GetAssetList.Query, Ge
this.dataService.product
.createAssets(files)
.pipe(finalize(() => (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));
}
}),
)
Expand All @@ -101,7 +115,7 @@ export class AssetListComponent extends BaseListComponent<GetAssetList.Query, Ge
});
this.refresh();
},
(err) => {
err => {
this.notificationService.error(_('common.notify-delete-error'), {
entity: 'Assets',
});
Expand All @@ -123,10 +137,8 @@ export class AssetListComponent extends BaseListComponent<GetAssetList.Query, Ge
],
})
.pipe(
switchMap((res) =>
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),
);
}
}

0 comments on commit 5aebcd6

Please sign in to comment.