Skip to content

Commit

Permalink
feat(admin-ui): Add bulk facet value editing to product variant list
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbromley committed Feb 9, 2024
1 parent 639097e commit 5ad41bf
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
2 changes: 2 additions & 0 deletions packages/admin-ui/src/lib/catalog/src/catalog.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
@@ -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<
Expand Down Expand Up @@ -117,3 +118,38 @@ export const deleteProductVariantsBulkAction: BulkAction<ProductVariant, Product
});
},
};

export const assignFacetValuesToProductVariantsBulkAction: BulkAction<
ItemOf<GetProductVariantListQuery, 'productVariants'>,
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();
}
});
},
};

0 comments on commit 5ad41bf

Please sign in to comment.