Explorar o código

feat(admin-ui): Implement bulk actions for StockLocations

Michael Bromley %!s(int64=2) %!d(string=hai) anos
pai
achega
650aff3475

+ 9 - 0
packages/admin-ui/src/lib/catalog/src/catalog.module.ts

@@ -62,6 +62,11 @@ import { ProductVariantQuickJumpComponent } from './components/product-variant-q
 import { ProductVariantsEditorComponent } from './components/product-variants-editor/product-variants-editor.component';
 import { ProductVariantsTableComponent } from './components/product-variants-table/product-variants-table.component';
 import { StockLocationDetailComponent } from './components/stock-location-detail/stock-location-detail.component';
+import {
+    assignStockLocationsToChannelBulkAction,
+    deleteStockLocationsBulkAction,
+    removeStockLocationsFromChannelBulkAction,
+} from './components/stock-location-list/stock-location-list-bulk-actions';
 import { StockLocationListComponent } from './components/stock-location-list/stock-location-list.component';
 import { UpdateProductOptionDialogComponent } from './components/update-product-option-dialog/update-product-option-dialog.component';
 import { VariantPriceDetailComponent } from './components/variant-price-detail/variant-price-detail.component';
@@ -134,6 +139,10 @@ export class CatalogModule {
         bulkActionRegistryService.registerBulkAction(removeCollectionsFromChannelBulkAction);
         bulkActionRegistryService.registerBulkAction(deleteCollectionsBulkAction);
 
+        bulkActionRegistryService.registerBulkAction(assignStockLocationsToChannelBulkAction);
+        bulkActionRegistryService.registerBulkAction(removeStockLocationsFromChannelBulkAction);
+        bulkActionRegistryService.registerBulkAction(deleteStockLocationsBulkAction);
+
         pageService.registerPageTab({
             location: 'product-list',
             tab: _('catalog.products'),

+ 96 - 0
packages/admin-ui/src/lib/catalog/src/components/stock-location-list/stock-location-list-bulk-actions.ts

@@ -0,0 +1,96 @@
+import {
+    AssignStockLocationsToChannelDocument,
+    createBulkAssignToChannelAction,
+    createBulkDeleteAction,
+    createBulkRemoveFromChannelAction,
+    DeleteStockLocationsDocument,
+    DeletionResult,
+    GetStockLocationListQuery,
+    ItemOf,
+    Permission,
+    RemoveStockLocationsFromChannelDocument,
+} from '@vendure/admin-ui/core';
+import { gql } from 'apollo-angular';
+import { map } from 'rxjs/operators';
+
+const DELETE_STOCK_LOCATIONS = gql`
+    mutation DeleteStockLocations($input: [DeleteStockLocationInput!]!) {
+        deleteStockLocations(input: $input) {
+            result
+            message
+        }
+    }
+`;
+
+const ASSIGN_STOCK_LOCATIONS_TO_CHANNEL = gql`
+    mutation AssignStockLocationsToChannel($input: AssignStockLocationsToChannelInput!) {
+        assignStockLocationsToChannel(input: $input) {
+            id
+            name
+        }
+    }
+`;
+
+const REMOVE_STOCK_LOCATIONS_FROM_CHANNEL = gql`
+    mutation RemoveStockLocationsFromChannel($input: RemoveStockLocationsFromChannelInput!) {
+        removeStockLocationsFromChannel(input: $input) {
+            id
+            name
+        }
+    }
+`;
+
+export const deleteStockLocationsBulkAction = createBulkDeleteAction<
+    ItemOf<GetStockLocationListQuery, 'stockLocations'>
+>({
+    location: 'stock-location-list',
+    requiresPermission: userPermissions =>
+        userPermissions.includes(Permission.DeleteStockLocation) ||
+        userPermissions.includes(Permission.DeleteCatalog),
+    getItemName: item => item.name,
+    bulkDelete: (dataService, ids) =>
+        dataService
+            .mutate(DeleteStockLocationsDocument, {
+                input: ids.map(id => ({ id })),
+            })
+            .pipe(map(res => res.deleteStockLocations)),
+    shouldRetryItem: response => response.result === DeletionResult.NOT_DELETED,
+});
+
+export const assignStockLocationsToChannelBulkAction = createBulkAssignToChannelAction<
+    ItemOf<GetStockLocationListQuery, 'stockLocations'>
+>({
+    location: 'stock-location-list',
+    requiresPermission: userPermissions =>
+        userPermissions.includes(Permission.UpdateCatalog) ||
+        userPermissions.includes(Permission.UpdateStockLocation),
+    getItemName: item => item.name,
+    bulkAssignToChannel: (dataService, stockLocationIds, channelId) =>
+        dataService
+            .mutate(AssignStockLocationsToChannelDocument, {
+                input: {
+                    channelId,
+                    stockLocationIds,
+                },
+            })
+            .pipe(map(res => res.assignStockLocationsToChannel)),
+});
+
+export const removeStockLocationsFromChannelBulkAction = createBulkRemoveFromChannelAction<
+    ItemOf<GetStockLocationListQuery, 'stockLocations'>
+>({
+    location: 'stock-location-list',
+    requiresPermission: userPermissions =>
+        userPermissions.includes(Permission.DeleteCatalog) ||
+        userPermissions.includes(Permission.DeleteStockLocation),
+    getItemName: item => item.name,
+    bulkRemoveFromChannel: (dataService, stockLocationIds, channelId) =>
+        dataService
+            .mutate(RemoveStockLocationsFromChannelDocument, {
+                input: {
+                    channelId,
+                    stockLocationIds,
+                },
+            })
+            .pipe(map(res => res.removeStockLocationsFromChannel)),
+});

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 27 - 1
packages/admin-ui/src/lib/core/src/common/generated-types.ts


+ 19 - 12
packages/admin-ui/src/lib/core/src/common/utilities/bulk-action-utils.ts

@@ -144,20 +144,27 @@ export function createBulkDeleteAction<ItemType>(config: CreateBulkDeleteActionC
                         }
                     }),
                 )
-                .subscribe(deletedCount => {
-                    if (deletedCount) {
+                .subscribe({
+                    next: deletedCount => {
+                        if (deletedCount) {
+                            hostComponent.refresh();
+                            clearSelection();
+                            notificationService.success(_('common.notify-delete-success-with-count'), {
+                                count: deletedCount,
+                            });
+                        }
+                        const notDeletedCount = selection.length - deletedCount;
+                        if (0 < notDeletedCount && notDeletedCount < selection.length) {
+                            notificationService.error(_('common.notify-delete-error-with-count'), {
+                                count: notDeletedCount,
+                            });
+                        }
                         hostComponent.refresh();
                         clearSelection();
-                        notificationService.success(_('common.notify-delete-success-with-count'), {
-                            count: deletedCount,
-                        });
-                    }
-                    const notDeletedCount = selection.length - deletedCount;
-                    if (0 < notDeletedCount && notDeletedCount < selection.length) {
-                        notificationService.error(_('common.notify-delete-error-with-count'), {
-                            count: notDeletedCount,
-                        });
-                    }
+                    },
+                    error: err => {
+                        notificationService.error(_('common.notify-delete-error'));
+                    },
                 });
         },
     };

+ 3 - 0
packages/admin-ui/src/lib/core/src/shared/components/chart/tooltip-plugin.ts

@@ -90,6 +90,9 @@ export function tooltipPlugin(userOptions?: any) {
 
         on('mousemove', undefined, (event: MouseEvent) => {
             const closestPoint = getClosestPoint(event.clientX);
+            if (!closestPoint) {
+                return;
+            }
             points.forEach(point => point.event.element.removeClass('ct-tooltip-hover'));
             closestPoint.element.addClass('ct-tooltip-hover');
 

Algúns arquivos non se mostraron porque demasiados arquivos cambiaron neste cambio