Răsfoiți Sursa

feat(admin-ui): Add channel operations for ShippingMethod & PaymentMethod

Michael Bromley 2 ani în urmă
părinte
comite
12749d2dde

Fișier diff suprimat deoarece este prea mare
+ 90 - 0
packages/admin-ui/src/lib/core/src/common/generated-types.ts


+ 64 - 2
packages/admin-ui/src/lib/marketing/src/components/promotion-list/promotion-list-bulk-actions.ts

@@ -1,12 +1,74 @@
-import { createBulkDeleteAction, GetPromotionListQuery, ItemOf, Permission } from '@vendure/admin-ui/core';
+import {
+    AssignPromotionsToChannelDocument,
+    createBulkAssignToChannelAction,
+    createBulkDeleteAction,
+    createBulkRemoveFromChannelAction,
+    GetPromotionListQuery,
+    ItemOf,
+    Permission,
+    RemovePromotionsFromChannelDocument,
+} from '@vendure/admin-ui/core';
+import { gql } from 'apollo-angular';
 import { map } from 'rxjs/operators';
 
+const ASSIGN_PROMOTIONS_TO_CHANNEL = gql`
+    mutation AssignPromotionsToChannel($input: AssignPromotionsToChannelInput!) {
+        assignPromotionsToChannel(input: $input) {
+            id
+            name
+        }
+    }
+`;
+
+const REMOVE_PROMOTIONS_FROM_CHANNEL = gql`
+    mutation RemovePromotionsFromChannel($input: RemovePromotionsFromChannelInput!) {
+        removePromotionsFromChannel(input: $input) {
+            id
+            name
+        }
+    }
+`;
+
 export const deletePromotionsBulkAction = createBulkDeleteAction<ItemOf<GetPromotionListQuery, 'promotions'>>(
     {
         location: 'promotion-list',
-        requiresPermission: userPermissions => userPermissions.includes(Permission.DeletePromotion),
+        requiresPermission: Permission.DeletePromotion,
         getItemName: item => item.name,
         bulkDelete: (dataService, ids) =>
             dataService.promotion.deletePromotions(ids).pipe(map(res => res.deletePromotions)),
     },
 );
+
+export const assignPromotionsToChannelBulkAction = createBulkAssignToChannelAction<
+    ItemOf<GetPromotionListQuery, 'promotions'>
+>({
+    location: 'promotion-list',
+    requiresPermission: Permission.UpdatePromotion,
+    getItemName: item => item.name,
+    bulkAssignToChannel: (dataService, promotionIds, channelId) =>
+        dataService
+            .mutate(AssignPromotionsToChannelDocument, {
+                input: {
+                    channelId,
+                    promotionIds,
+                },
+            })
+            .pipe(map(res => res.assignPromotionsToChannel)),
+});
+
+export const removePromotionsFromChannelBulkAction = createBulkRemoveFromChannelAction<
+    ItemOf<GetPromotionListQuery, 'promotions'>
+>({
+    location: 'promotion-list',
+    requiresPermission: Permission.DeleteCatalog,
+    getItemName: item => item.name,
+    bulkRemoveFromChannel: (dataService, promotionIds, channelId) =>
+        dataService
+            .mutate(RemovePromotionsFromChannelDocument, {
+                input: {
+                    channelId,
+                    promotionIds,
+                },
+            })
+            .pipe(map(res => res.removePromotionsFromChannel)),
+});

+ 7 - 1
packages/admin-ui/src/lib/marketing/src/marketing.module.ts

@@ -11,7 +11,11 @@ import {
 } from '@vendure/admin-ui/core';
 
 import { PromotionDetailComponent } from './components/promotion-detail/promotion-detail.component';
-import { deletePromotionsBulkAction } from './components/promotion-list/promotion-list-bulk-actions';
+import {
+    assignPromotionsToChannelBulkAction,
+    deletePromotionsBulkAction,
+    removePromotionsFromChannelBulkAction,
+} from './components/promotion-list/promotion-list-bulk-actions';
 import { PromotionListComponent } from './components/promotion-list/promotion-list.component';
 import { createRoutes } from './marketing.routes';
 
@@ -29,6 +33,8 @@ import { createRoutes } from './marketing.routes';
 })
 export class MarketingModule {
     constructor(private bulkActionRegistryService: BulkActionRegistryService, pageService: PageService) {
+        bulkActionRegistryService.registerBulkAction(assignPromotionsToChannelBulkAction);
+        bulkActionRegistryService.registerBulkAction(removePromotionsFromChannelBulkAction);
         bulkActionRegistryService.registerBulkAction(deletePromotionsBulkAction);
 
         pageService.registerPageTab({

+ 1 - 1
packages/admin-ui/src/lib/settings/src/components/payment-method-detail/payment-method-detail.component.html

@@ -14,7 +14,7 @@
             <button
                 class="btn btn-primary"
                 *ngIf="isNew$ | async; else updateButton"
-                [disabled]="detailForm.pristine || detailForm.invalid"
+                [disabled]="detailForm.pristine || detailForm.invalid || !selectedHandler"
                 (click)="create()"
             >
                 {{ 'common.create' | translate }}

+ 61 - 1
packages/admin-ui/src/lib/settings/src/components/payment-method-list/payment-method-list-bulk-actions.ts

@@ -1,12 +1,17 @@
 import {
+    createBulkAssignToChannelAction,
+    AssignPaymentMethodsToChannelDocument,
+    RemovePaymentMethodsFromChannelDocument,
     createBulkDeleteAction,
+    createBulkRemoveFromChannelAction,
     GetPaymentMethodListQuery,
     ItemOf,
     Permission,
 } from '@vendure/admin-ui/core';
+import { gql } from 'apollo-angular';
 import { map } from 'rxjs/operators';
 
-export const deleteFacetsBulkAction = createBulkDeleteAction<
+export const deletePaymentMethodsBulkAction = createBulkDeleteAction<
     ItemOf<GetPaymentMethodListQuery, 'paymentMethods'>
 >({
     location: 'payment-method-list',
@@ -18,3 +23,58 @@ export const deleteFacetsBulkAction = createBulkDeleteAction<
     bulkDelete: (dataService, ids, retrying) =>
         dataService.settings.deletePaymentMethods(ids, retrying).pipe(map(res => res.deletePaymentMethods)),
 });
+
+const ASSIGN_PAYMENT_METHODS_TO_CHANNEL = gql`
+    mutation AssignPaymentMethodsToChannel($input: AssignPaymentMethodsToChannelInput!) {
+        assignPaymentMethodsToChannel(input: $input) {
+            id
+            name
+        }
+    }
+`;
+
+const REMOVE_PAYMENT_METHODS_FROM_CHANNEL = gql`
+    mutation RemovePaymentMethodsFromChannel($input: RemovePaymentMethodsFromChannelInput!) {
+        removePaymentMethodsFromChannel(input: $input) {
+            id
+            name
+        }
+    }
+`;
+export const assignPaymentMethodsToChannelBulkAction = createBulkAssignToChannelAction<
+    ItemOf<GetPaymentMethodListQuery, 'paymentMethods'>
+>({
+    location: 'payment-method-list',
+    requiresPermission: userPermissions =>
+        userPermissions.includes(Permission.UpdatePaymentMethod) ||
+        userPermissions.includes(Permission.UpdateSettings),
+    getItemName: item => item.name,
+    bulkAssignToChannel: (dataService, paymentMethodIds, channelId) =>
+        dataService
+            .mutate(AssignPaymentMethodsToChannelDocument, {
+                input: {
+                    channelId,
+                    paymentMethodIds,
+                },
+            })
+            .pipe(map(res => res.assignPaymentMethodsToChannel)),
+});
+
+export const removePaymentMethodsFromChannelBulkAction = createBulkRemoveFromChannelAction<
+    ItemOf<GetPaymentMethodListQuery, 'paymentMethods'>
+>({
+    location: 'payment-method-list',
+    requiresPermission: userPermissions =>
+        userPermissions.includes(Permission.DeletePaymentMethod) ||
+        userPermissions.includes(Permission.DeleteSettings),
+    getItemName: item => item.name,
+    bulkRemoveFromChannel: (dataService, paymentMethodIds, channelId) =>
+        dataService
+            .mutate(RemovePaymentMethodsFromChannelDocument, {
+                input: {
+                    channelId,
+                    paymentMethodIds,
+                },
+            })
+            .pipe(map(res => res.removePaymentMethodsFromChannel)),
+});

+ 1 - 1
packages/admin-ui/src/lib/settings/src/components/payment-method-list/payment-method-list.component.html

@@ -30,7 +30,7 @@
     (itemsPerPageChange)="setItemsPerPage($event)"
 >
     <vdr-bulk-action-menu
-        locationId="paymentMethod-list"
+        locationId="payment-method-list"
         [hostComponent]="this"
         [selectionManager]="selectionManager"
     ></vdr-bulk-action-menu>

+ 61 - 1
packages/admin-ui/src/lib/settings/src/components/shipping-method-list/shipping-method-list-bulk-actions.ts

@@ -1,10 +1,15 @@
 import {
+    createBulkAssignToChannelAction,
     createBulkDeleteAction,
-    GetRolesQuery,
+    createBulkRemoveFromChannelAction,
     GetShippingMethodListQuery,
+    GetRolesQuery,
     ItemOf,
     Permission,
+    AssignShippingMethodsToChannelDocument,
+    RemoveShippingMethodsFromChannelDocument,
 } from '@vendure/admin-ui/core';
+import { gql } from 'apollo-angular';
 import { map } from 'rxjs/operators';
 
 export const deleteShippingMethodsBulkAction = createBulkDeleteAction<
@@ -16,3 +21,58 @@ export const deleteShippingMethodsBulkAction = createBulkDeleteAction<
     bulkDelete: (dataService, ids) =>
         dataService.shippingMethod.deleteShippingMethods(ids).pipe(map(res => res.deleteShippingMethods)),
 });
+
+const ASSIGN_SHIPPING_METHODS_TO_CHANNEL = gql`
+    mutation AssignShippingMethodsToChannel($input: AssignShippingMethodsToChannelInput!) {
+        assignShippingMethodsToChannel(input: $input) {
+            id
+            name
+        }
+    }
+`;
+
+const REMOVE_SHIPPING_METHODS_FROM_CHANNEL = gql`
+    mutation RemoveShippingMethodsFromChannel($input: RemoveShippingMethodsFromChannelInput!) {
+        removeShippingMethodsFromChannel(input: $input) {
+            id
+            name
+        }
+    }
+`;
+export const assignShippingMethodsToChannelBulkAction = createBulkAssignToChannelAction<
+    ItemOf<GetShippingMethodListQuery, 'shippingMethods'>
+>({
+    location: 'shipping-method-list',
+    requiresPermission: userPermissions =>
+        userPermissions.includes(Permission.UpdateShippingMethod) ||
+        userPermissions.includes(Permission.UpdateSettings),
+    getItemName: item => item.name,
+    bulkAssignToChannel: (dataService, shippingMethodIds, channelId) =>
+        dataService
+            .mutate(AssignShippingMethodsToChannelDocument, {
+                input: {
+                    channelId,
+                    shippingMethodIds,
+                },
+            })
+            .pipe(map(res => res.assignShippingMethodsToChannel)),
+});
+
+export const removeShippingMethodsFromChannelBulkAction = createBulkRemoveFromChannelAction<
+    ItemOf<GetShippingMethodListQuery, 'shippingMethods'>
+>({
+    location: 'shipping-method-list',
+    requiresPermission: userPermissions =>
+        userPermissions.includes(Permission.DeleteShippingMethod) ||
+        userPermissions.includes(Permission.DeleteSettings),
+    getItemName: item => item.name,
+    bulkRemoveFromChannel: (dataService, shippingMethodIds, channelId) =>
+        dataService
+            .mutate(RemoveShippingMethodsFromChannelDocument, {
+                input: {
+                    channelId,
+                    shippingMethodIds,
+                },
+            })
+            .pipe(map(res => res.removeShippingMethodsFromChannel)),
+});

+ 25 - 1
packages/admin-ui/src/lib/settings/src/settings.module.ts

@@ -31,6 +31,11 @@ import { deleteCountriesBulkAction } from './components/country-list/country-lis
 import { CountryListComponent } from './components/country-list/country-list.component';
 import { GlobalSettingsComponent } from './components/global-settings/global-settings.component';
 import { PaymentMethodDetailComponent } from './components/payment-method-detail/payment-method-detail.component';
+import {
+    assignPaymentMethodsToChannelBulkAction,
+    deletePaymentMethodsBulkAction,
+    removePaymentMethodsFromChannelBulkAction,
+} from './components/payment-method-list/payment-method-list-bulk-actions';
 import { PaymentMethodListComponent } from './components/payment-method-list/payment-method-list.component';
 import { PermissionGridComponent } from './components/permission-grid/permission-grid.component';
 import { ProfileComponent } from './components/profile/profile.component';
@@ -42,7 +47,11 @@ import { deleteSellersBulkAction } from './components/seller-list/seller-list-bu
 import { SellerListComponent } from './components/seller-list/seller-list.component';
 import { ShippingEligibilityTestResultComponent } from './components/shipping-eligibility-test-result/shipping-eligibility-test-result.component';
 import { ShippingMethodDetailComponent } from './components/shipping-method-detail/shipping-method-detail.component';
-import { deleteShippingMethodsBulkAction } from './components/shipping-method-list/shipping-method-list-bulk-actions';
+import {
+    assignShippingMethodsToChannelBulkAction,
+    deleteShippingMethodsBulkAction,
+    removeShippingMethodsFromChannelBulkAction,
+} from './components/shipping-method-list/shipping-method-list-bulk-actions';
 import { ShippingMethodListComponent } from './components/shipping-method-list/shipping-method-list.component';
 import { ShippingMethodTestResultComponent } from './components/shipping-method-test-result/shipping-method-test-result.component';
 import { TaxCategoryDetailComponent } from './components/tax-category-detail/tax-category-detail.component';
@@ -111,14 +120,29 @@ import { createRoutes } from './settings.routes';
 export class SettingsModule {
     constructor(private bulkActionRegistryService: BulkActionRegistryService, pageService: PageService) {
         bulkActionRegistryService.registerBulkAction(deleteSellersBulkAction);
+
         bulkActionRegistryService.registerBulkAction(deleteChannelsBulkAction);
+
         bulkActionRegistryService.registerBulkAction(deleteAdministratorsBulkAction);
+
         bulkActionRegistryService.registerBulkAction(deleteRolesBulkAction);
+
+        bulkActionRegistryService.registerBulkAction(assignShippingMethodsToChannelBulkAction);
+        bulkActionRegistryService.registerBulkAction(removeShippingMethodsFromChannelBulkAction);
         bulkActionRegistryService.registerBulkAction(deleteShippingMethodsBulkAction);
+
+        bulkActionRegistryService.registerBulkAction(assignPaymentMethodsToChannelBulkAction);
+        bulkActionRegistryService.registerBulkAction(removePaymentMethodsFromChannelBulkAction);
+        bulkActionRegistryService.registerBulkAction(deletePaymentMethodsBulkAction);
+
         bulkActionRegistryService.registerBulkAction(deleteTaxCategoriesBulkAction);
+
         bulkActionRegistryService.registerBulkAction(deleteTaxRatesBulkAction);
+
         bulkActionRegistryService.registerBulkAction(deleteCountriesBulkAction);
+
         bulkActionRegistryService.registerBulkAction(deleteZonesBulkAction);
+
         bulkActionRegistryService.registerBulkAction(removeZoneMembersBulkAction);
 
         pageService.registerPageTab({

Unele fișiere nu au fost afișate deoarece prea multe fișiere au fost modificate în acest diff