Explorar o código

feat(admin-ui): Enable deletion of shipping methods

Michael Bromley %!s(int64=6) %!d(string=hai) anos
pai
achega
00329786f9

+ 34 - 14
admin-ui/src/app/common/generated-types.ts

@@ -1738,6 +1738,8 @@ export type Mutation = {
   createShippingMethod: ShippingMethod,
   /** Update an existing ShippingMethod */
   updateShippingMethod: ShippingMethod,
+  /** Delete a ShippingMethod */
+  deleteShippingMethod: DeletionResponse,
   /** Create a new TaxCategory */
   createTaxCategory: TaxCategory,
   /** Update an existing TaxCategory */
@@ -2065,6 +2067,11 @@ export type MutationUpdateShippingMethodArgs = {
 };
 
 
+export type MutationDeleteShippingMethodArgs = {
+  id: Scalars['ID']
+};
+
+
 export type MutationCreateTaxCategoryArgs = {
   input: CreateTaxCategoryInput
 };
@@ -4220,13 +4227,6 @@ export type SearchForTestOrderQueryVariables = {
 
 export type SearchForTestOrderQuery = ({ __typename?: 'Query' } & { search: ({ __typename?: 'SearchResponse' } & { items: Array<({ __typename?: 'SearchResult' } & Pick<SearchResult, 'productVariantId' | 'productVariantName' | 'productPreview' | 'sku'> & { price: ({ __typename?: 'SinglePrice' } & Pick<SinglePrice, 'value'>), priceWithTax: ({ __typename?: 'SinglePrice' } & Pick<SinglePrice, 'value'>) })> }) });
 
-export type TestShippingMethodQueryVariables = {
-  input: TestShippingMethodInput
-};
-
-
-export type TestShippingMethodQuery = ({ __typename?: 'Query' } & { testShippingMethod: ({ __typename?: 'TestShippingMethodResult' } & Pick<TestShippingMethodResult, 'eligible'> & { price: Maybe<({ __typename?: 'ShippingPrice' } & Pick<ShippingPrice, 'price' | 'priceWithTax'>)> }) });
-
 export type ConfigurableOperationFragment = ({ __typename?: 'ConfigurableOperation' } & Pick<ConfigurableOperation, 'code'> & { args: Array<({ __typename?: 'ConfigArg' } & Pick<ConfigArg, 'name' | 'type' | 'value'>)> });
 
 export type ConfigurableOperationDefFragment = ({ __typename?: 'ConfigurableOperationDefinition' } & Pick<ConfigurableOperationDefinition, 'code' | 'description'> & { args: Array<({ __typename?: 'ConfigArgDefinition' } & Pick<ConfigArgDefinition, 'name' | 'type' | 'config'>)> });
@@ -4265,6 +4265,20 @@ export type UpdateShippingMethodMutationVariables = {
 
 
 export type UpdateShippingMethodMutation = ({ __typename?: 'Mutation' } & { updateShippingMethod: ({ __typename?: 'ShippingMethod' } & ShippingMethodFragment) });
+
+export type DeleteShippingMethodMutationVariables = {
+  id: Scalars['ID']
+};
+
+
+export type DeleteShippingMethodMutation = ({ __typename?: 'Mutation' } & { deleteShippingMethod: ({ __typename?: 'DeletionResponse' } & Pick<DeletionResponse, 'result' | 'message'>) });
+
+export type TestShippingMethodQueryVariables = {
+  input: TestShippingMethodInput
+};
+
+
+export type TestShippingMethodQuery = ({ __typename?: 'Query' } & { testShippingMethod: ({ __typename?: 'TestShippingMethodResult' } & Pick<TestShippingMethodResult, 'eligible'> & { price: Maybe<({ __typename?: 'ShippingPrice' } & Pick<ShippingPrice, 'price' | 'priceWithTax'>)> }) });
 type DiscriminateUnion<T, U> = T extends U ? T : never;
 
 type RequireField<T, TNames extends string> = T & { [P in TNames]: (T & { [name: string]: never })[P] };
@@ -5171,13 +5185,6 @@ export namespace SearchForTestOrder {
   export type _SinglePriceInlineFragment = (DiscriminateUnion<RequireField<(NonNullable<SearchForTestOrderQuery['search']['items'][0]>)['priceWithTax'], '__typename'>, { __typename: 'SinglePrice' }>);
 }
 
-export namespace TestShippingMethod {
-  export type Variables = TestShippingMethodQueryVariables;
-  export type Query = TestShippingMethodQuery;
-  export type TestShippingMethod = TestShippingMethodQuery['testShippingMethod'];
-  export type Price = (NonNullable<TestShippingMethodQuery['testShippingMethod']['price']>);
-}
-
 export namespace ConfigurableOperation {
   export type Fragment = ConfigurableOperationFragment;
   export type Args = (NonNullable<ConfigurableOperationFragment['args'][0]>);
@@ -5225,3 +5232,16 @@ export namespace UpdateShippingMethod {
   export type Mutation = UpdateShippingMethodMutation;
   export type UpdateShippingMethod = ShippingMethodFragment;
 }
+
+export namespace DeleteShippingMethod {
+  export type Variables = DeleteShippingMethodMutationVariables;
+  export type Mutation = DeleteShippingMethodMutation;
+  export type DeleteShippingMethod = DeleteShippingMethodMutation['deleteShippingMethod'];
+}
+
+export namespace TestShippingMethod {
+  export type Variables = TestShippingMethodQueryVariables;
+  export type Query = TestShippingMethodQuery;
+  export type TestShippingMethod = TestShippingMethodQuery['testShippingMethod'];
+  export type Price = (NonNullable<TestShippingMethodQuery['testShippingMethod']['price']>);
+}

+ 9 - 0
admin-ui/src/app/data/definitions/shipping-definitions.ts

@@ -70,6 +70,15 @@ export const UPDATE_SHIPPING_METHOD = gql`
     ${SHIPPING_METHOD_FRAGMENT}
 `;
 
+export const DELETE_SHIPPING_METHOD = gql`
+    mutation DeleteShippingMethod($id: ID!) {
+        deleteShippingMethod(id: $id) {
+            result
+            message
+        }
+    }
+`;
+
 export const TEST_SHIPPING_METHOD = gql`
     query TestShippingMethod($input: TestShippingMethodInput!) {
         testShippingMethod(input: $input) {

+ 11 - 0
admin-ui/src/app/data/providers/shipping-method-data.service.ts

@@ -1,6 +1,7 @@
 import {
     CreateShippingMethod,
     CreateShippingMethodInput,
+    DeleteShippingMethod,
     GetShippingMethod,
     GetShippingMethodList,
     GetShippingMethodOperations,
@@ -11,6 +12,7 @@ import {
 } from '../../common/generated-types';
 import {
     CREATE_SHIPPING_METHOD,
+    DELETE_SHIPPING_METHOD,
     GET_SHIPPING_METHOD,
     GET_SHIPPING_METHOD_LIST,
     GET_SHIPPING_METHOD_OPERATIONS,
@@ -66,6 +68,15 @@ export class ShippingMethodDataService {
         );
     }
 
+    deleteShippingMethod(id: string) {
+        return this.baseDataService.mutate<DeleteShippingMethod.Mutation, DeleteShippingMethod.Variables>(
+            DELETE_SHIPPING_METHOD,
+            {
+                id,
+            },
+        );
+    }
+
     testShippingMethod(input: TestShippingMethodInput) {
         return this.baseDataService.query<TestShippingMethod.Query, TestShippingMethod.Variables>(
             TEST_SHIPPING_METHOD,

+ 20 - 0
admin-ui/src/app/settings/components/shipping-method-list/shipping-method-list.component.html

@@ -18,6 +18,7 @@
     <vdr-dt-column>{{ 'common.code' | translate }}</vdr-dt-column>
     <vdr-dt-column>{{ 'common.description' | translate }}</vdr-dt-column>
     <vdr-dt-column></vdr-dt-column>
+    <vdr-dt-column></vdr-dt-column>
     <ng-template let-shippingMethod="item">
         <td class="left align-middle">{{ shippingMethod.code }}</td>
         <td class="left align-middle">{{ shippingMethod.description }}</td>
@@ -28,5 +29,24 @@
                 [linkTo]="['./', shippingMethod.id]"
             ></vdr-table-row-action>
         </td>
+        <td class="right align-middle">
+            <vdr-dropdown>
+                <button type="button" class="btn btn-link btn-sm" vdrDropdownTrigger>
+                    {{ 'common.actions' | translate }}
+                    <clr-icon shape="caret down"></clr-icon>
+                </button>
+                <vdr-dropdown-menu vdrPosition="bottom-right">
+                    <button
+                        type="button"
+                        class="delete-button"
+                        (click)="deleteShippingMethod(shippingMethod.id)"
+                        vdrDropdownItem
+                    >
+                        <clr-icon shape="trash" class="is-danger"></clr-icon>
+                        {{ 'common.delete' | translate }}
+                    </button>
+                </vdr-dropdown-menu>
+            </vdr-dropdown>
+        </td>
     </ng-template>
 </vdr-data-table>

+ 41 - 1
admin-ui/src/app/settings/components/shipping-method-list/shipping-method-list.component.ts

@@ -1,9 +1,14 @@
 import { ChangeDetectionStrategy, Component } from '@angular/core';
 import { ActivatedRoute, Router } from '@angular/router';
+import { EMPTY } from 'rxjs';
+import { switchMap } from 'rxjs/operators';
 
 import { BaseListComponent } from '../../../common/base-list.component';
 import { GetShippingMethodList } from '../../../common/generated-types';
+import { _ } from '../../../core/providers/i18n/mark-for-extraction';
+import { NotificationService } from '../../../core/providers/notification/notification.service';
 import { DataService } from '../../../data/providers/data.service';
+import { ModalService } from '../../../shared/providers/modal/modal.service';
 
 @Component({
     selector: 'vdr-shipping-method-list',
@@ -15,11 +20,46 @@ export class ShippingMethodListComponent extends BaseListComponent<
     GetShippingMethodList.Query,
     GetShippingMethodList.Items
 > {
-    constructor(private dataService: DataService, router: Router, route: ActivatedRoute) {
+    constructor(
+        private modalService: ModalService,
+        private notificationService: NotificationService,
+        private dataService: DataService,
+        router: Router,
+        route: ActivatedRoute,
+    ) {
         super(router, route);
         super.setQueryFn(
             (...args: any[]) => this.dataService.shippingMethod.getShippingMethods(...args),
             data => data.shippingMethods,
         );
     }
+
+    deleteShippingMethod(id: string) {
+        this.modalService
+            .dialog({
+                title: _('catalog.confirm-delete-shipping-method'),
+                buttons: [
+                    { type: 'seconday', label: _('common.cancel') },
+                    { type: 'danger', label: _('common.delete'), returnValue: true },
+                ],
+            })
+            .pipe(
+                switchMap(response =>
+                    response ? this.dataService.shippingMethod.deleteShippingMethod(id) : EMPTY,
+                ),
+            )
+            .subscribe(
+                () => {
+                    this.notificationService.success(_('common.notify-delete-success'), {
+                        entity: 'ShippingMethod',
+                    });
+                    this.refresh();
+                },
+                err => {
+                    this.notificationService.error(_('common.notify-delete-error'), {
+                        entity: 'ShippingMethod',
+                    });
+                },
+            );
+    }
 }