From 5ad41bf40364c8fdb42ce686e5ae2f7a75ce39fc Mon Sep 17 00:00:00 2001 From: Michael Bromley Date: Fri, 9 Feb 2024 10:47:20 +0100 Subject: [PATCH] feat(admin-ui): Add bulk facet value editing to product variant list --- .../src/lib/catalog/src/catalog.module.ts | 2 + .../product-list/product-list-bulk-actions.ts | 1 - .../product-variant-list-bulk-actions.ts | 40 ++++++++++++++++++- 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/packages/admin-ui/src/lib/catalog/src/catalog.module.ts b/packages/admin-ui/src/lib/catalog/src/catalog.module.ts index b1b75829f8..dcefad4fd6 100644 --- a/packages/admin-ui/src/lib/catalog/src/catalog.module.ts +++ b/packages/admin-ui/src/lib/catalog/src/catalog.module.ts @@ -59,6 +59,7 @@ import { ProductListComponent } from './components/product-list/product-list.com import { ProductOptionsEditorComponent } from './components/product-options-editor/product-options-editor.component'; import { ProductVariantDetailComponent } from './components/product-variant-detail/product-variant-detail.component'; import { + assignFacetValuesToProductVariantsBulkAction, assignProductVariantsToChannelBulkAction, deleteProductVariantsBulkAction, removeProductVariantsFromChannelBulkAction, @@ -133,6 +134,7 @@ export class CatalogModule { bulkActionRegistryService.registerBulkAction(removeProductVariantsFromChannelBulkAction); bulkActionRegistryService.registerBulkAction(deleteProductsBulkAction); bulkActionRegistryService.registerBulkAction(deleteProductVariantsBulkAction); + bulkActionRegistryService.registerBulkAction(assignFacetValuesToProductVariantsBulkAction); bulkActionRegistryService.registerBulkAction(assignFacetsToChannelBulkAction); bulkActionRegistryService.registerBulkAction(removeFacetsFromChannelBulkAction); diff --git a/packages/admin-ui/src/lib/catalog/src/components/product-list/product-list-bulk-actions.ts b/packages/admin-ui/src/lib/catalog/src/components/product-list/product-list-bulk-actions.ts index 21a431cc1f..31bab50913 100644 --- a/packages/admin-ui/src/lib/catalog/src/components/product-list/product-list-bulk-actions.ts +++ b/packages/admin-ui/src/lib/catalog/src/components/product-list/product-list-bulk-actions.ts @@ -133,7 +133,6 @@ export const assignFacetValuesToProductsBulkAction: BulkAction< userPermissions.includes(Permission.UpdateProduct), onClick: ({ injector, selection, hostComponent, clearSelection }) => { const modalService = injector.get(ModalService); - const dataService = injector.get(DataService); const notificationService = injector.get(NotificationService); const mode = 'product'; const ids = unique(selection.map(p => p.id)); diff --git a/packages/admin-ui/src/lib/catalog/src/components/product-variant-list/product-variant-list-bulk-actions.ts b/packages/admin-ui/src/lib/catalog/src/components/product-variant-list/product-variant-list-bulk-actions.ts index e95a0c0aad..7c860f9c02 100644 --- a/packages/admin-ui/src/lib/catalog/src/components/product-variant-list/product-variant-list-bulk-actions.ts +++ b/packages/admin-ui/src/lib/catalog/src/components/product-variant-list/product-variant-list-bulk-actions.ts @@ -1,21 +1,22 @@ import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker'; import { BulkAction, + createBulkRemoveFromChannelAction, DataService, DeletionResult, GetProductVariantListQuery, + isMultiChannel, ItemOf, ModalService, NotificationService, Permission, - createBulkRemoveFromChannelAction, - isMultiChannel, ProductVariant, } from '@vendure/admin-ui/core'; import { unique } from '@vendure/common/lib/unique'; import { EMPTY } from 'rxjs'; import { map, switchMap } from 'rxjs/operators'; import { AssignProductsToChannelDialogComponent } from '../assign-products-to-channel-dialog/assign-products-to-channel-dialog.component'; +import { BulkAddFacetValuesDialogComponent } from '../bulk-add-facet-values-dialog/bulk-add-facet-values-dialog.component'; import { ProductVariantListComponent } from './product-variant-list.component'; export const assignProductVariantsToChannelBulkAction: BulkAction< @@ -117,3 +118,38 @@ export const deleteProductVariantsBulkAction: BulkAction, + ProductVariantListComponent +> = { + location: 'product-variant-list', + label: _('catalog.edit-facet-values'), + icon: 'tag', + requiresPermission: userPermissions => + userPermissions.includes(Permission.UpdateCatalog) || + userPermissions.includes(Permission.UpdateProduct), + onClick: ({ injector, selection, clearSelection }) => { + const modalService = injector.get(ModalService); + const notificationService = injector.get(NotificationService); + const mode = 'variant'; + const ids = unique(selection.map(p => p.id)); + return modalService + .fromComponent(BulkAddFacetValuesDialogComponent, { + size: 'xl', + locals: { + mode, + ids, + }, + }) + .subscribe(result => { + if (result) { + notificationService.success(_('common.notify-bulk-update-success'), { + count: selection.length, + entity: mode === 'variant' ? 'Products' : 'ProductVariants', + }); + clearSelection(); + } + }); + }, +};