Skip to content

Commit

Permalink
feat(admin-ui): Implement bulk delete for all regular lists
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbromley committed May 3, 2023
1 parent 2f5e096 commit ad1a82c
Show file tree
Hide file tree
Showing 63 changed files with 866 additions and 655 deletions.
72 changes: 36 additions & 36 deletions packages/admin-ui/i18n-coverage.json
Original file line number Diff line number Diff line change
@@ -1,71 +1,71 @@
{
"generatedOn": "2023-04-28T12:40:43.278Z",
"lastCommit": "f29aae9781b79ffa3c257d93639b844bf32fe6fa",
"generatedOn": "2023-05-01T20:16:42.501Z",
"lastCommit": "58dce8e9c84ba5e9050ad8aaed0c66bc256ad2d7",
"translationStatus": {
"cs": {
"tokenCount": 710,
"translatedCount": 584,
"tokenCount": 712,
"translatedCount": 581,
"percentage": 82
},
"de": {
"tokenCount": 710,
"translatedCount": 567,
"percentage": 80
"tokenCount": 712,
"translatedCount": 564,
"percentage": 79
},
"en": {
"tokenCount": 710,
"translatedCount": 702,
"tokenCount": 712,
"translatedCount": 707,
"percentage": 99
},
"es": {
"tokenCount": 710,
"translatedCount": 613,
"tokenCount": 712,
"translatedCount": 610,
"percentage": 86
},
"fr": {
"tokenCount": 710,
"translatedCount": 605,
"tokenCount": 712,
"translatedCount": 602,
"percentage": 85
},
"it": {
"tokenCount": 710,
"translatedCount": 611,
"percentage": 86
"tokenCount": 712,
"translatedCount": 608,
"percentage": 85
},
"pl": {
"tokenCount": 710,
"translatedCount": 407,
"tokenCount": 712,
"translatedCount": 404,
"percentage": 57
},
"pt_BR": {
"tokenCount": 710,
"translatedCount": 582,
"percentage": 82
"tokenCount": 712,
"translatedCount": 579,
"percentage": 81
},
"pt_PT": {
"tokenCount": 710,
"translatedCount": 624,
"percentage": 88
"tokenCount": 712,
"translatedCount": 621,
"percentage": 87
},
"ru": {
"tokenCount": 710,
"translatedCount": 610,
"percentage": 86
"tokenCount": 712,
"translatedCount": 607,
"percentage": 85
},
"uk": {
"tokenCount": 710,
"translatedCount": 610,
"percentage": 86
"tokenCount": 712,
"translatedCount": 607,
"percentage": 85
},
"zh_Hans": {
"tokenCount": 710,
"translatedCount": 552,
"percentage": 78
"tokenCount": 712,
"translatedCount": 549,
"percentage": 77
},
"zh_Hant": {
"tokenCount": 710,
"translatedCount": 387,
"percentage": 55
"tokenCount": 712,
"translatedCount": 384,
"percentage": 54
}
}
}
1 change: 1 addition & 0 deletions packages/admin-ui/src/lib/catalog/src/catalog.module.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { NgModule } from '@angular/core';
import { RouterModule } from '@angular/router';
import { BulkActionRegistryService, SharedModule } from '@vendure/admin-ui/core';
import { deleteCustomersBulkAction } from '../../customer/src/components/customer-list/customer-list-bulk-actions';

import { catalogRoutes } from './catalog.routes';
import { ApplyFacetDialogComponent } from './components/apply-facet-dialog/apply-facet-dialog.component';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
import {
BulkAction,
createBulkDeleteAction,
currentChannelIsNotDefault,
DataService,
DeletionResult,
getChannelCodeFromUserStatus,
GetFacetListQuery,
isMultiChannel,
Expand All @@ -20,89 +20,16 @@ import { AssignToChannelDialogComponent } from '../assign-to-channel-dialog/assi

import { FacetListComponent } from './facet-list.component';

export const deleteFacetsBulkAction: BulkAction<ItemOf<GetFacetListQuery, 'facets'>, FacetListComponent> = {
export const deleteFacetsBulkAction = createBulkDeleteAction<ItemOf<GetFacetListQuery, 'facets'>>({
location: 'facet-list',
label: _('common.delete'),
icon: 'trash',
iconClass: 'is-danger',
requiresPermission: userPermissions =>
userPermissions.includes(Permission.DeleteFacet) ||
userPermissions.includes(Permission.DeleteCatalog),
onClick: ({ injector, selection, hostComponent, clearSelection }) => {
const modalService = injector.get(ModalService);
const dataService = injector.get(DataService);
const notificationService = injector.get(NotificationService);

function showModalAndDelete(facetIds: string[], message?: string) {
return modalService
.dialog({
title: _('catalog.confirm-bulk-delete-facets'),
translationVars: {
count: selection.length,
},
size: message ? 'lg' : 'md',
body: message,
buttons: [
{ type: 'secondary', label: _('common.cancel') },
{
type: 'danger',
label: message ? _('common.force-delete') : _('common.delete'),
returnValue: true,
},
],
})
.pipe(
switchMap(res =>
res
? dataService.facet
.deleteFacets(facetIds, !!message)
.pipe(map(res2 => res2.deleteFacets))
: of([]),
),
);
}

showModalAndDelete(unique(selection.map(f => f.id)))
.pipe(
switchMap(result => {
let deletedCount = 0;
const errors: string[] = [];
const errorIds: string[] = [];
let i = 0;
for (const item of result) {
if (item.result === DeletionResult.DELETED) {
deletedCount++;
} else if (item.message) {
errors.push(item.message);
errorIds.push(selection[i]?.id);
}
i++;
}
if (0 < errorIds.length) {
return showModalAndDelete(errorIds, errors.join('\n')).pipe(
map(result2 => {
const deletedCount2 = result2.filter(
r => r.result === DeletionResult.DELETED,
).length;
return deletedCount + deletedCount2;
}),
);
} else {
return of(deletedCount);
}
}),
)
.subscribe(deletedCount => {
if (deletedCount) {
hostComponent.refresh();
clearSelection();
notificationService.success(_('catalog.notify-bulk-delete-facets-success'), {
count: deletedCount,
});
}
});
},
};
getItemName: item => item.name,
shouldRetryItem: (response, item) => !!response.message,
bulkDelete: (dataService, ids, retrying) =>
dataService.facet.deleteFacets(ids, retrying).pipe(map(res => res.deleteFacets)),
});

export const assignFacetsToChannelBulkAction: BulkAction<
ItemOf<GetFacetListQuery, 'facets'>,
Expand Down
Loading

0 comments on commit ad1a82c

Please sign in to comment.