Просмотр исходного кода

refactor(admin-ui): Update admin ui to new OrderLine model

Relates to #1981
Michael Bromley 3 лет назад
Родитель
Сommit
c31db79e6e
16 измененных файлов с 452 добавлено и 573 удалено
  1. 68 99
      packages/admin-ui/src/lib/core/src/common/generated-types.ts
  2. 228 308
      packages/admin-ui/src/lib/core/src/common/introspection-result.ts
  3. 41 38
      packages/admin-ui/src/lib/core/src/data/definitions/order-definitions.ts
  4. 3 3
      packages/admin-ui/src/lib/order/src/components/fulfill-order-dialog/fulfill-order-dialog.component.ts
  5. 2 3
      packages/admin-ui/src/lib/order/src/components/fulfillment-detail/fulfillment-detail.component.ts
  6. 18 13
      packages/admin-ui/src/lib/order/src/components/line-fulfillment/line-fulfillment.component.ts
  7. 17 21
      packages/admin-ui/src/lib/order/src/components/line-refunds/line-refunds.component.ts
  8. 9 20
      packages/admin-ui/src/lib/order/src/components/modification-detail/modification-detail.component.ts
  9. 5 6
      packages/admin-ui/src/lib/order/src/components/order-detail/order-detail.component.ts
  10. 1 0
      packages/admin-ui/src/lib/order/src/components/order-editor/order-editor.component.html
  11. 4 12
      packages/admin-ui/src/lib/order/src/components/order-editor/order-editor.component.ts
  12. 1 1
      packages/admin-ui/src/lib/order/src/components/order-history/order-history.component.html
  13. 15 12
      packages/admin-ui/src/lib/order/src/components/order-history/order-history.component.ts
  14. 5 1
      packages/admin-ui/src/lib/order/src/components/order-table/order-table.component.html
  15. 16 17
      packages/admin-ui/src/lib/order/src/components/refund-order-dialog/refund-order-dialog.component.ts
  16. 19 19
      scripts/codegen/generate-graphql-types.ts

Разница между файлами не показана из-за своего большого размера
+ 68 - 99
packages/admin-ui/src/lib/core/src/common/generated-types.ts


+ 228 - 308
packages/admin-ui/src/lib/core/src/common/introspection-result.ts

@@ -1,311 +1,231 @@
 // tslint:disable
 // tslint:disable
 
 
-      export interface PossibleTypesResultData {
-        possibleTypes: {
-          [key: string]: string[]
-        }
-      }
-      const result: PossibleTypesResultData = {
-  "possibleTypes": {
-    "AddFulfillmentToOrderResult": [
-      "CreateFulfillmentError",
-      "EmptyOrderLineSelectionError",
-      "Fulfillment",
-      "FulfillmentStateTransitionError",
-      "InsufficientStockOnHandError",
-      "InvalidFulfillmentHandlerError",
-      "ItemsAlreadyFulfilledError"
-    ],
-    "AddManualPaymentToOrderResult": [
-      "ManualPaymentStateError",
-      "Order"
-    ],
-    "ApplyCouponCodeResult": [
-      "CouponCodeExpiredError",
-      "CouponCodeInvalidError",
-      "CouponCodeLimitError",
-      "Order"
-    ],
-    "AuthenticationResult": [
-      "CurrentUser",
-      "InvalidCredentialsError"
-    ],
-    "CancelOrderResult": [
-      "CancelActiveOrderError",
-      "EmptyOrderLineSelectionError",
-      "MultipleOrderError",
-      "Order",
-      "OrderStateTransitionError",
-      "QuantityTooGreatError"
-    ],
-    "CancelPaymentResult": [
-      "CancelPaymentError",
-      "Payment",
-      "PaymentStateTransitionError"
-    ],
-    "CreateAssetResult": [
-      "Asset",
-      "MimeTypeError"
-    ],
-    "CreateChannelResult": [
-      "Channel",
-      "LanguageNotAvailableError"
-    ],
-    "CreateCustomerResult": [
-      "Customer",
-      "EmailAddressConflictError"
-    ],
-    "CreatePromotionResult": [
-      "MissingConditionsError",
-      "Promotion"
-    ],
-    "CustomField": [
-      "BooleanCustomFieldConfig",
-      "DateTimeCustomFieldConfig",
-      "FloatCustomFieldConfig",
-      "IntCustomFieldConfig",
-      "LocaleStringCustomFieldConfig",
-      "RelationCustomFieldConfig",
-      "StringCustomFieldConfig",
-      "TextCustomFieldConfig"
-    ],
-    "CustomFieldConfig": [
-      "BooleanCustomFieldConfig",
-      "DateTimeCustomFieldConfig",
-      "FloatCustomFieldConfig",
-      "IntCustomFieldConfig",
-      "LocaleStringCustomFieldConfig",
-      "RelationCustomFieldConfig",
-      "StringCustomFieldConfig",
-      "TextCustomFieldConfig"
-    ],
-    "ErrorResult": [
-      "AlreadyRefundedError",
-      "CancelActiveOrderError",
-      "CancelPaymentError",
-      "ChannelDefaultLanguageError",
-      "CouponCodeExpiredError",
-      "CouponCodeInvalidError",
-      "CouponCodeLimitError",
-      "CreateFulfillmentError",
-      "EmailAddressConflictError",
-      "EmptyOrderLineSelectionError",
-      "FacetInUseError",
-      "FulfillmentStateTransitionError",
-      "IneligibleShippingMethodError",
-      "InsufficientStockError",
-      "InsufficientStockOnHandError",
-      "InvalidCredentialsError",
-      "InvalidFulfillmentHandlerError",
-      "ItemsAlreadyFulfilledError",
-      "LanguageNotAvailableError",
-      "ManualPaymentStateError",
-      "MimeTypeError",
-      "MissingConditionsError",
-      "MultipleOrderError",
-      "NativeAuthStrategyError",
-      "NegativeQuantityError",
-      "NoActiveOrderError",
-      "NoChangesSpecifiedError",
-      "NothingToRefundError",
-      "OrderLimitError",
-      "OrderModificationError",
-      "OrderModificationStateError",
-      "OrderStateTransitionError",
-      "PaymentMethodMissingError",
-      "PaymentOrderMismatchError",
-      "PaymentStateTransitionError",
-      "ProductOptionInUseError",
-      "QuantityTooGreatError",
-      "RefundOrderStateError",
-      "RefundPaymentIdMissingError",
-      "RefundStateTransitionError",
-      "SettlePaymentError"
-    ],
-    "ModifyOrderResult": [
-      "CouponCodeExpiredError",
-      "CouponCodeInvalidError",
-      "CouponCodeLimitError",
-      "InsufficientStockError",
-      "NegativeQuantityError",
-      "NoChangesSpecifiedError",
-      "Order",
-      "OrderLimitError",
-      "OrderModificationStateError",
-      "PaymentMethodMissingError",
-      "RefundPaymentIdMissingError"
-    ],
-    "NativeAuthenticationResult": [
-      "CurrentUser",
-      "InvalidCredentialsError",
-      "NativeAuthStrategyError"
-    ],
-    "Node": [
-      "Address",
-      "Administrator",
-      "Allocation",
-      "Asset",
-      "AuthenticationMethod",
-      "Cancellation",
-      "Channel",
-      "Collection",
-      "Country",
-      "Customer",
-      "CustomerGroup",
-      "Facet",
-      "FacetValue",
-      "Fulfillment",
-      "HistoryEntry",
-      "Job",
-      "Order",
-      "OrderItem",
-      "OrderLine",
-      "OrderModification",
-      "Payment",
-      "PaymentMethod",
-      "Product",
-      "ProductOption",
-      "ProductOptionGroup",
-      "ProductVariant",
-      "Promotion",
-      "Refund",
-      "Release",
-      "Return",
-      "Role",
-      "Sale",
-      "Seller",
-      "ShippingMethod",
-      "StockAdjustment",
-      "Surcharge",
-      "Tag",
-      "TaxCategory",
-      "TaxRate",
-      "User",
-      "Vendor",
-      "Zone"
-    ],
-    "PaginatedList": [
-      "AdministratorList",
-      "AssetList",
-      "CollectionList",
-      "CountryList",
-      "CustomerGroupList",
-      "CustomerList",
-      "FacetList",
-      "FacetValueList",
-      "HistoryEntryList",
-      "JobList",
-      "OrderList",
-      "PaymentMethodList",
-      "ProductList",
-      "ProductVariantList",
-      "PromotionList",
-      "RoleList",
-      "SellerList",
-      "ShippingMethodList",
-      "TagList",
-      "TaxRateList",
-      "VendorList"
-    ],
-    "RefundOrderResult": [
-      "AlreadyRefundedError",
-      "MultipleOrderError",
-      "NothingToRefundError",
-      "OrderStateTransitionError",
-      "PaymentOrderMismatchError",
-      "QuantityTooGreatError",
-      "Refund",
-      "RefundOrderStateError",
-      "RefundStateTransitionError"
-    ],
-    "RemoveFacetFromChannelResult": [
-      "Facet",
-      "FacetInUseError"
-    ],
-    "RemoveOptionGroupFromProductResult": [
-      "Product",
-      "ProductOptionInUseError"
-    ],
-    "RemoveOrderItemsResult": [
-      "Order",
-      "OrderModificationError"
-    ],
-    "SearchResultPrice": [
-      "PriceRange",
-      "SinglePrice"
-    ],
-    "SetCustomerForDraftOrderResult": [
-      "EmailAddressConflictError",
-      "Order"
-    ],
-    "SetOrderShippingMethodResult": [
-      "IneligibleShippingMethodError",
-      "NoActiveOrderError",
-      "Order",
-      "OrderModificationError"
-    ],
-    "SettlePaymentResult": [
-      "OrderStateTransitionError",
-      "Payment",
-      "PaymentStateTransitionError",
-      "SettlePaymentError"
-    ],
-    "SettleRefundResult": [
-      "Refund",
-      "RefundStateTransitionError"
-    ],
-    "StockMovement": [
-      "Allocation",
-      "Cancellation",
-      "Release",
-      "Return",
-      "Sale",
-      "StockAdjustment"
-    ],
-    "StockMovementItem": [
-      "Allocation",
-      "Cancellation",
-      "Release",
-      "Return",
-      "Sale",
-      "StockAdjustment"
-    ],
-    "TransitionFulfillmentToStateResult": [
-      "Fulfillment",
-      "FulfillmentStateTransitionError"
-    ],
-    "TransitionOrderToStateResult": [
-      "Order",
-      "OrderStateTransitionError"
-    ],
-    "TransitionPaymentToStateResult": [
-      "Payment",
-      "PaymentStateTransitionError"
-    ],
-    "UpdateChannelResult": [
-      "Channel",
-      "LanguageNotAvailableError"
-    ],
-    "UpdateCustomerResult": [
-      "Customer",
-      "EmailAddressConflictError"
-    ],
-    "UpdateGlobalSettingsResult": [
-      "ChannelDefaultLanguageError",
-      "GlobalSettings"
-    ],
-    "UpdateOrderItemsResult": [
-      "InsufficientStockError",
-      "NegativeQuantityError",
-      "Order",
-      "OrderLimitError",
-      "OrderModificationError"
-    ],
-    "UpdatePromotionResult": [
-      "MissingConditionsError",
-      "Promotion"
-    ]
-  }
+export interface PossibleTypesResultData {
+    possibleTypes: {
+        [key: string]: string[];
+    };
+}
+const result: PossibleTypesResultData = {
+    possibleTypes: {
+        AddFulfillmentToOrderResult: [
+            'CreateFulfillmentError',
+            'EmptyOrderLineSelectionError',
+            'Fulfillment',
+            'FulfillmentStateTransitionError',
+            'InsufficientStockOnHandError',
+            'InvalidFulfillmentHandlerError',
+            'ItemsAlreadyFulfilledError',
+        ],
+        AddManualPaymentToOrderResult: ['ManualPaymentStateError', 'Order'],
+        ApplyCouponCodeResult: [
+            'CouponCodeExpiredError',
+            'CouponCodeInvalidError',
+            'CouponCodeLimitError',
+            'Order',
+        ],
+        AuthenticationResult: ['CurrentUser', 'InvalidCredentialsError'],
+        CancelOrderResult: [
+            'CancelActiveOrderError',
+            'EmptyOrderLineSelectionError',
+            'MultipleOrderError',
+            'Order',
+            'OrderStateTransitionError',
+            'QuantityTooGreatError',
+        ],
+        CancelPaymentResult: ['CancelPaymentError', 'Payment', 'PaymentStateTransitionError'],
+        CreateAssetResult: ['Asset', 'MimeTypeError'],
+        CreateChannelResult: ['Channel', 'LanguageNotAvailableError'],
+        CreateCustomerResult: ['Customer', 'EmailAddressConflictError'],
+        CreatePromotionResult: ['MissingConditionsError', 'Promotion'],
+        CustomField: [
+            'BooleanCustomFieldConfig',
+            'DateTimeCustomFieldConfig',
+            'FloatCustomFieldConfig',
+            'IntCustomFieldConfig',
+            'LocaleStringCustomFieldConfig',
+            'RelationCustomFieldConfig',
+            'StringCustomFieldConfig',
+            'TextCustomFieldConfig',
+        ],
+        CustomFieldConfig: [
+            'BooleanCustomFieldConfig',
+            'DateTimeCustomFieldConfig',
+            'FloatCustomFieldConfig',
+            'IntCustomFieldConfig',
+            'LocaleStringCustomFieldConfig',
+            'RelationCustomFieldConfig',
+            'StringCustomFieldConfig',
+            'TextCustomFieldConfig',
+        ],
+        ErrorResult: [
+            'AlreadyRefundedError',
+            'CancelActiveOrderError',
+            'CancelPaymentError',
+            'ChannelDefaultLanguageError',
+            'CouponCodeExpiredError',
+            'CouponCodeInvalidError',
+            'CouponCodeLimitError',
+            'CreateFulfillmentError',
+            'EmailAddressConflictError',
+            'EmptyOrderLineSelectionError',
+            'FacetInUseError',
+            'FulfillmentStateTransitionError',
+            'IneligibleShippingMethodError',
+            'InsufficientStockError',
+            'InsufficientStockOnHandError',
+            'InvalidCredentialsError',
+            'InvalidFulfillmentHandlerError',
+            'ItemsAlreadyFulfilledError',
+            'LanguageNotAvailableError',
+            'ManualPaymentStateError',
+            'MimeTypeError',
+            'MissingConditionsError',
+            'MultipleOrderError',
+            'NativeAuthStrategyError',
+            'NegativeQuantityError',
+            'NoActiveOrderError',
+            'NoChangesSpecifiedError',
+            'NothingToRefundError',
+            'OrderLimitError',
+            'OrderModificationError',
+            'OrderModificationStateError',
+            'OrderStateTransitionError',
+            'PaymentMethodMissingError',
+            'PaymentOrderMismatchError',
+            'PaymentStateTransitionError',
+            'ProductOptionInUseError',
+            'QuantityTooGreatError',
+            'RefundOrderStateError',
+            'RefundPaymentIdMissingError',
+            'RefundStateTransitionError',
+            'SettlePaymentError',
+        ],
+        ModifyOrderResult: [
+            'CouponCodeExpiredError',
+            'CouponCodeInvalidError',
+            'CouponCodeLimitError',
+            'InsufficientStockError',
+            'NegativeQuantityError',
+            'NoChangesSpecifiedError',
+            'Order',
+            'OrderLimitError',
+            'OrderModificationStateError',
+            'PaymentMethodMissingError',
+            'RefundPaymentIdMissingError',
+        ],
+        NativeAuthenticationResult: ['CurrentUser', 'InvalidCredentialsError', 'NativeAuthStrategyError'],
+        Node: [
+            'Address',
+            'Administrator',
+            'Allocation',
+            'Asset',
+            'AuthenticationMethod',
+            'Cancellation',
+            'Channel',
+            'Collection',
+            'Country',
+            'Customer',
+            'CustomerGroup',
+            'Facet',
+            'FacetValue',
+            'Fulfillment',
+            'HistoryEntry',
+            'Job',
+            'Order',
+            'OrderItem',
+            'OrderLine',
+            'OrderModification',
+            'Payment',
+            'PaymentMethod',
+            'Product',
+            'ProductOption',
+            'ProductOptionGroup',
+            'ProductVariant',
+            'Promotion',
+            'Refund',
+            'Release',
+            'Return',
+            'Role',
+            'Sale',
+            'Seller',
+            'ShippingMethod',
+            'StockAdjustment',
+            'StockLevel',
+            'StockLocation',
+            'Surcharge',
+            'Tag',
+            'TaxCategory',
+            'TaxRate',
+            'User',
+            'Zone',
+        ],
+        PaginatedList: [
+            'AdministratorList',
+            'AssetList',
+            'CollectionList',
+            'CountryList',
+            'CustomerGroupList',
+            'CustomerList',
+            'FacetList',
+            'FacetValueList',
+            'HistoryEntryList',
+            'JobList',
+            'OrderList',
+            'PaymentMethodList',
+            'ProductList',
+            'ProductVariantList',
+            'PromotionList',
+            'RoleList',
+            'SellerList',
+            'ShippingMethodList',
+            'TagList',
+            'TaxRateList',
+        ],
+        RefundOrderResult: [
+            'AlreadyRefundedError',
+            'MultipleOrderError',
+            'NothingToRefundError',
+            'OrderStateTransitionError',
+            'PaymentOrderMismatchError',
+            'QuantityTooGreatError',
+            'Refund',
+            'RefundOrderStateError',
+            'RefundStateTransitionError',
+        ],
+        RemoveFacetFromChannelResult: ['Facet', 'FacetInUseError'],
+        RemoveOptionGroupFromProductResult: ['Product', 'ProductOptionInUseError'],
+        RemoveOrderItemsResult: ['Order', 'OrderModificationError'],
+        SearchResultPrice: ['PriceRange', 'SinglePrice'],
+        SetCustomerForDraftOrderResult: ['EmailAddressConflictError', 'Order'],
+        SetOrderShippingMethodResult: [
+            'IneligibleShippingMethodError',
+            'NoActiveOrderError',
+            'Order',
+            'OrderModificationError',
+        ],
+        SettlePaymentResult: [
+            'OrderStateTransitionError',
+            'Payment',
+            'PaymentStateTransitionError',
+            'SettlePaymentError',
+        ],
+        SettleRefundResult: ['Refund', 'RefundStateTransitionError'],
+        StockMovement: ['Allocation', 'Cancellation', 'Release', 'Return', 'Sale', 'StockAdjustment'],
+        StockMovementItem: ['Allocation', 'Cancellation', 'Release', 'Return', 'Sale', 'StockAdjustment'],
+        TransitionFulfillmentToStateResult: ['Fulfillment', 'FulfillmentStateTransitionError'],
+        TransitionOrderToStateResult: ['Order', 'OrderStateTransitionError'],
+        TransitionPaymentToStateResult: ['Payment', 'PaymentStateTransitionError'],
+        UpdateChannelResult: ['Channel', 'LanguageNotAvailableError'],
+        UpdateCustomerResult: ['Customer', 'EmailAddressConflictError'],
+        UpdateGlobalSettingsResult: ['ChannelDefaultLanguageError', 'GlobalSettings'],
+        UpdateOrderItemsResult: [
+            'InsufficientStockError',
+            'NegativeQuantityError',
+            'Order',
+            'OrderLimitError',
+            'OrderModificationError',
+        ],
+        UpdatePromotionResult: ['MissingConditionsError', 'Promotion'],
+    },
 };
 };
-      export default result;
-    
+export default result;

+ 41 - 38
packages/admin-ui/src/lib/core/src/data/definitions/order-definitions.ts

@@ -84,16 +84,45 @@ export const FULFILLMENT_FRAGMENT = gql`
         createdAt
         createdAt
         updatedAt
         updatedAt
         method
         method
-        summary {
-            orderLine {
-                id
-            }
+        lines {
+            orderLineId
             quantity
             quantity
         }
         }
         trackingCode
         trackingCode
     }
     }
 `;
 `;
 
 
+export const PAYMENT_WITH_REFUNDS_FRAGMENT = gql`
+    fragment PaymentWithRefunds on Payment {
+        id
+        createdAt
+        transactionId
+        amount
+        method
+        state
+        nextStates
+        errorMessage
+        metadata
+        refunds {
+            id
+            createdAt
+            state
+            items
+            adjustment
+            total
+            paymentId
+            reason
+            transactionId
+            method
+            metadata
+            lines {
+                orderLineId
+                quantity
+            }
+        }
+    }
+`;
+
 export const ORDER_LINE_FRAGMENT = gql`
 export const ORDER_LINE_FRAGMENT = gql`
     fragment OrderLine on OrderLine {
     fragment OrderLine on OrderLine {
         id
         id
@@ -110,19 +139,15 @@ export const ORDER_LINE_FRAGMENT = gql`
         discounts {
         discounts {
             ...Discount
             ...Discount
         }
         }
-        fulfillments {
-            ...Fulfillment
+        fulfillmentLines {
+            fulfillmentId
+            quantity
         }
         }
         unitPrice
         unitPrice
         unitPriceWithTax
         unitPriceWithTax
         proratedUnitPrice
         proratedUnitPrice
         proratedUnitPriceWithTax
         proratedUnitPriceWithTax
         quantity
         quantity
-        items {
-            id
-            refundId
-            cancelled
-        }
         linePrice
         linePrice
         lineTax
         lineTax
         linePriceWithTax
         linePriceWithTax
@@ -206,31 +231,7 @@ export const ORDER_DETAIL_FRAGMENT = gql`
             ...OrderAddress
             ...OrderAddress
         }
         }
         payments {
         payments {
-            id
-            createdAt
-            transactionId
-            amount
-            method
-            state
-            nextStates
-            errorMessage
-            metadata
-            refunds {
-                id
-                createdAt
-                state
-                items
-                adjustment
-                total
-                paymentId
-                reason
-                transactionId
-                method
-                metadata
-                orderItems {
-                    id
-                }
-            }
+            ...PaymentWithRefunds
         }
         }
         fulfillments {
         fulfillments {
             ...Fulfillment
             ...Fulfillment
@@ -245,8 +246,9 @@ export const ORDER_DETAIL_FRAGMENT = gql`
                 id
                 id
                 amount
                 amount
             }
             }
-            orderItems {
-                id
+            lines {
+                orderLineId
+                quantity
             }
             }
             refund {
             refund {
                 id
                 id
@@ -262,6 +264,7 @@ export const ORDER_DETAIL_FRAGMENT = gql`
     ${ORDER_ADDRESS_FRAGMENT}
     ${ORDER_ADDRESS_FRAGMENT}
     ${FULFILLMENT_FRAGMENT}
     ${FULFILLMENT_FRAGMENT}
     ${ORDER_LINE_FRAGMENT}
     ${ORDER_LINE_FRAGMENT}
+    ${PAYMENT_WITH_REFUNDS_FRAGMENT}
 `;
 `;
 
 
 export const GET_ORDERS_LIST = gql`
 export const GET_ORDERS_LIST = gql`

+ 3 - 3
packages/admin-ui/src/lib/order/src/components/fulfill-order-dialog/fulfill-order-dialog.component.ts

@@ -68,10 +68,10 @@ export class FulfillOrderDialogComponent implements Dialog<FulfillOrderInput>, O
 
 
     getUnfulfilledCount(line: OrderDetailFragment['lines'][number]): number {
     getUnfulfilledCount(line: OrderDetailFragment['lines'][number]): number {
         const fulfilled =
         const fulfilled =
-            line.fulfillments
-                ?.map(f => f.summary)
+            this.order.fulfillments
+                ?.map(f => f.lines)
                 .flat()
                 .flat()
-                .filter(row => row.orderLine.id === line.id)
+                .filter(row => row.orderLineId === line.id)
                 .reduce((sum, row) => sum + row.quantity, 0) ?? 0;
                 .reduce((sum, row) => sum + row.quantity, 0) ?? 0;
         return line.quantity - fulfilled;
         return line.quantity - fulfilled;
     }
     }

+ 2 - 3
packages/admin-ui/src/lib/order/src/components/fulfillment-detail/fulfillment-detail.component.ts

@@ -32,11 +32,10 @@ export class FulfillmentDetailComponent implements OnInit, OnChanges {
 
 
     get items(): Array<{ name: string; quantity: number }> {
     get items(): Array<{ name: string; quantity: number }> {
         return (
         return (
-            this.fulfillment?.summary.map(row => {
+            this.fulfillment?.lines.map(row => {
                 return {
                 return {
                     name:
                     name:
-                        this.order.lines.find(line => line.id === row.orderLine.id)?.productVariant.name ??
-                        '',
+                        this.order.lines.find(line => line.id === row.orderLineId)?.productVariant.name ?? '',
                     quantity: row.quantity,
                     quantity: row.quantity,
                 };
                 };
             }) ?? []
             }) ?? []

+ 18 - 13
packages/admin-ui/src/lib/order/src/components/line-fulfillment/line-fulfillment.component.ts

@@ -1,5 +1,6 @@
 import { ChangeDetectionStrategy, Component, Input, OnChanges, SimpleChanges } from '@angular/core';
 import { ChangeDetectionStrategy, Component, Input, OnChanges, SimpleChanges } from '@angular/core';
 import { OrderDetailFragment } from '@vendure/admin-ui/core';
 import { OrderDetailFragment } from '@vendure/admin-ui/core';
+import { notNullOrUndefined } from '@vendure/common/lib/shared-utils';
 import { unique } from '@vendure/common/lib/unique';
 import { unique } from '@vendure/common/lib/unique';
 
 
 export type FulfillmentStatus = 'full' | 'partial' | 'none';
 export type FulfillmentStatus = 'full' | 'partial' | 'none';
@@ -13,6 +14,7 @@ type Fulfillment = NonNullable<OrderDetailFragment['fulfillments']>[number];
 })
 })
 export class LineFulfillmentComponent implements OnChanges {
 export class LineFulfillmentComponent implements OnChanges {
     @Input() line: OrderDetailFragment['lines'][number];
     @Input() line: OrderDetailFragment['lines'][number];
+    @Input() allOrderFulfillments: OrderDetailFragment['fulfillments'];
     @Input() orderState: string;
     @Input() orderState: string;
     fulfilledCount = 0;
     fulfilledCount = 0;
     fulfillmentStatus: FulfillmentStatus;
     fulfillmentStatus: FulfillmentStatus;
@@ -24,7 +26,7 @@ export class LineFulfillmentComponent implements OnChanges {
     ngOnChanges(changes: SimpleChanges): void {
     ngOnChanges(changes: SimpleChanges): void {
         if (this.line) {
         if (this.line) {
             this.fulfilledCount = this.getDeliveredCount(this.line);
             this.fulfilledCount = this.getDeliveredCount(this.line);
-            this.fulfillmentStatus = this.getFulfillmentStatus(this.fulfilledCount, this.line.items.length);
+            this.fulfillmentStatus = this.getFulfillmentStatus(this.fulfilledCount, this.line.quantity);
             this.fulfillments = this.getFulfillments(this.line);
             this.fulfillments = this.getFulfillments(this.line);
         }
         }
     }
     }
@@ -34,11 +36,7 @@ export class LineFulfillmentComponent implements OnChanges {
      */
      */
     private getDeliveredCount(line: OrderDetailFragment['lines'][number]): number {
     private getDeliveredCount(line: OrderDetailFragment['lines'][number]): number {
         return (
         return (
-            line.fulfillments?.reduce(
-                (sum, fulfillment) =>
-                    sum + (fulfillment.summary.find(s => s.orderLine.id === line.id)?.quantity ?? 0),
-                0,
-            ) ?? 0
+            line.fulfillmentLines?.reduce((sum, fulfillmentLine) => sum + fulfillmentLine.quantity, 0) ?? 0
         );
         );
     }
     }
 
 
@@ -56,13 +54,20 @@ export class LineFulfillmentComponent implements OnChanges {
         line: OrderDetailFragment['lines'][number],
         line: OrderDetailFragment['lines'][number],
     ): Array<{ count: number; fulfillment: NonNullable<OrderDetailFragment['fulfillments']>[number] }> {
     ): Array<{ count: number; fulfillment: NonNullable<OrderDetailFragment['fulfillments']>[number] }> {
         return (
         return (
-            line.fulfillments?.map(fulfillment => {
-                const summaryLine = fulfillment.summary.find(s => s.orderLine.id === line.id);
-                return {
-                    count: summaryLine?.quantity ?? 0,
-                    fulfillment,
-                };
-            }) ?? []
+            line.fulfillmentLines
+                ?.map(fulfillmentLine => {
+                    const fulfillment = this.allOrderFulfillments?.find(
+                        f => f.id === fulfillmentLine.fulfillmentId,
+                    );
+                    if (!fulfillment) {
+                        return;
+                    }
+                    return {
+                        count: fulfillmentLine.quantity,
+                        fulfillment,
+                    };
+                })
+                .filter(notNullOrUndefined) ?? []
         );
         );
     }
     }
 }
 }

+ 17 - 21
packages/admin-ui/src/lib/order/src/components/line-refunds/line-refunds.component.ts

@@ -1,5 +1,5 @@
 import { ChangeDetectionStrategy, Component, Input } from '@angular/core';
 import { ChangeDetectionStrategy, Component, Input } from '@angular/core';
-import { OrderDetailFragment } from '@vendure/admin-ui/core';
+import { OrderDetailFragment, PaymentWithRefundsFragment } from '@vendure/admin-ui/core';
 
 
 @Component({
 @Component({
     selector: 'vdr-line-refunds',
     selector: 'vdr-line-refunds',
@@ -9,27 +9,23 @@ import { OrderDetailFragment } from '@vendure/admin-ui/core';
 })
 })
 export class LineRefundsComponent {
 export class LineRefundsComponent {
     @Input() line: OrderDetailFragment['lines'][number];
     @Input() line: OrderDetailFragment['lines'][number];
-    @Input() payments: OrderDetailFragment['payments'];
+    @Input() payments: PaymentWithRefundsFragment[];
 
 
     getRefundedCount(): number {
     getRefundedCount(): number {
-        const refunds =
-            this.payments?.reduce(
-                (all, payment) => [...all, ...payment.refunds],
-                [] as NonNullable<OrderDetailFragment['payments']>[number]['refunds'],
-            ) ?? [];
-        return this.line.items.filter(i => {
-            if (i.refundId === null && !i.cancelled) {
-                return false;
-            }
-            if (i.refundId) {
-                const refund = refunds.find(r => r.id === i.refundId);
-                if (refund?.state === 'Failed') {
-                    return false;
-                } else {
-                    return true;
-                }
-            }
-            return false;
-        }).length;
+        const refundLines =
+            this.payments
+                ?.reduce(
+                    (all, payment) => [...all, ...payment.refunds],
+                    [] as PaymentWithRefundsFragment['refunds'],
+                )
+                .filter(refund => refund.state !== 'Failed')
+                .reduce(
+                    (all, refund) => [...all, ...refund.lines],
+                    [] as Array<{ orderLineId: string; quantity: number }>,
+                ) ?? [];
+
+        return refundLines
+            .filter(i => i.orderLineId === this.line.id)
+            .reduce((sum, i) => sum + i.quantity, 0);
     }
     }
 }
 }

+ 9 - 20
packages/admin-ui/src/lib/order/src/components/modification-detail/modification-detail.component.ts

@@ -38,28 +38,17 @@ export class ModificationDetailComponent implements OnChanges {
     private getModifiedLines() {
     private getModifiedLines() {
         const added = new Map<OrderDetailFragment['lines'][number], number>();
         const added = new Map<OrderDetailFragment['lines'][number], number>();
         const removed = new Map<OrderDetailFragment['lines'][number], number>();
         const removed = new Map<OrderDetailFragment['lines'][number], number>();
-        for (const _item of this.modification.orderItems || []) {
-            const result = this.getOrderLineAndItem(_item.id);
-            if (result) {
-                const { line, item } = result;
-                if (item.cancelled) {
-                    const count = removed.get(line) ?? 0;
-                    removed.set(line, count + 1);
-                } else {
-                    const count = added.get(line) ?? 0;
-                    added.set(line, count + 1);
-                }
+        for (const modificationLine of this.modification.lines || []) {
+            const line = this.order.lines.find(l => l.id === modificationLine.orderLineId);
+            if (!line) {
+                continue;
             }
             }
-        }
-        return { added, removed };
-    }
-
-    private getOrderLineAndItem(itemId: string) {
-        for (const line of this.order.lines) {
-            const item = line.items.find(i => i.id === itemId);
-            if (item) {
-                return { line, item };
+            if (modificationLine.quantity < 0) {
+                removed.set(line, -modificationLine.quantity);
+            } else {
+                added.set(line, modificationLine.quantity);
             }
             }
         }
         }
+        return { added, removed };
     }
     }
 }
 }

+ 5 - 6
packages/admin-ui/src/lib/order/src/components/order-detail/order-detail.component.ts

@@ -9,7 +9,6 @@ import {
     DataService,
     DataService,
     EditNoteDialogComponent,
     EditNoteDialogComponent,
     FulfillmentFragment,
     FulfillmentFragment,
-    FulfillmentLineSummary,
     GetOrderHistoryQuery,
     GetOrderHistoryQuery,
     GetOrderQuery,
     GetOrderQuery,
     HistoryEntryType,
     HistoryEntryType,
@@ -255,14 +254,14 @@ export class OrderDetailComponent
     }
     }
 
 
     canAddFulfillment(order: OrderDetailFragment): boolean {
     canAddFulfillment(order: OrderDetailFragment): boolean {
-        const allFulfillmentSummaryRows: FulfillmentFragment['summary'] = (order.fulfillments ?? []).reduce(
-            (all, fulfillment) => [...all, ...fulfillment.summary],
-            [] as FulfillmentFragment['summary'],
+        const allFulfillmentLines: FulfillmentFragment['lines'] = (order.fulfillments ?? []).reduce(
+            (all, fulfillment) => [...all, ...fulfillment.lines],
+            [] as FulfillmentFragment['lines'],
         );
         );
         let allItemsFulfilled = true;
         let allItemsFulfilled = true;
         for (const line of order.lines) {
         for (const line of order.lines) {
-            const totalFulfilledCount = allFulfillmentSummaryRows
-                .filter(row => row.orderLine.id === line.id)
+            const totalFulfilledCount = allFulfillmentLines
+                .filter(row => row.orderLineId === line.id)
                 .reduce((sum, row) => sum + row.quantity, 0);
                 .reduce((sum, row) => sum + row.quantity, 0);
             if (totalFulfilledCount < line.quantity) {
             if (totalFulfilledCount < line.quantity) {
                 allItemsFulfilled = false;
                 allItemsFulfilled = false;

+ 1 - 0
packages/admin-ui/src/lib/order/src/components/order-editor/order-editor.component.html

@@ -59,6 +59,7 @@
                             <vdr-line-refunds [line]="line" [payments]="order.payments"></vdr-line-refunds>
                             <vdr-line-refunds [line]="line" [payments]="order.payments"></vdr-line-refunds>
                             <vdr-line-fulfillment
                             <vdr-line-fulfillment
                                 [line]="line"
                                 [line]="line"
+                                [allOrderFulfillments]="order.fulfillments"
                                 [orderState]="order.state"
                                 [orderState]="order.state"
                             ></vdr-line-fulfillment>
                             ></vdr-line-fulfillment>
                         </td>
                         </td>

+ 4 - 12
packages/admin-ui/src/lib/order/src/components/order-editor/order-editor.component.ts

@@ -3,7 +3,6 @@ import { FormArray, FormControl, FormGroup, Validators } from '@angular/forms';
 import { ActivatedRoute, Router } from '@angular/router';
 import { ActivatedRoute, Router } from '@angular/router';
 import {
 import {
     AddItemInput,
     AddItemInput,
-    AdjustOrderLineInput,
     BaseDetailComponent,
     BaseDetailComponent,
     CustomFieldConfig,
     CustomFieldConfig,
     DataService,
     DataService,
@@ -16,6 +15,7 @@ import {
     NotificationService,
     NotificationService,
     OrderAddressFragment,
     OrderAddressFragment,
     OrderDetailFragment,
     OrderDetailFragment,
+    OrderLineInput,
     ProductSelectorSearchQuery,
     ProductSelectorSearchQuery,
     ServerConfigService,
     ServerConfigService,
     SortOrder,
     SortOrder,
@@ -24,16 +24,8 @@ import {
 } from '@vendure/admin-ui/core';
 } from '@vendure/admin-ui/core';
 import { assertNever, notNullOrUndefined } from '@vendure/common/lib/shared-utils';
 import { assertNever, notNullOrUndefined } from '@vendure/common/lib/shared-utils';
 import { simpleDeepClone } from '@vendure/common/lib/simple-deep-clone';
 import { simpleDeepClone } from '@vendure/common/lib/simple-deep-clone';
-import { concat, EMPTY, Observable, of, Subject } from 'rxjs';
-import {
-    distinctUntilChanged,
-    map,
-    mapTo,
-    shareReplay,
-    startWith,
-    switchMap,
-    takeUntil,
-} from 'rxjs/operators';
+import { EMPTY, Observable, of } from 'rxjs';
+import { mapTo, shareReplay, switchMap, takeUntil } from 'rxjs/operators';
 
 
 import { OrderTransitionService } from '../../providers/order-transition.service';
 import { OrderTransitionService } from '../../providers/order-transition.service';
 import {
 import {
@@ -55,7 +47,7 @@ interface AddedLine {
 
 
 type ModifyOrderData = Omit<ModifyOrderInput, 'addItems' | 'adjustOrderLines'> & {
 type ModifyOrderData = Omit<ModifyOrderInput, 'addItems' | 'adjustOrderLines'> & {
     addItems: Array<AddItemInput & { customFields?: any }>;
     addItems: Array<AddItemInput & { customFields?: any }>;
-    adjustOrderLines: Array<AdjustOrderLineInput & { customFields?: any }>;
+    adjustOrderLines: Array<OrderLineInput & { customFields?: any }>;
 };
 };
 
 
 @Component({
 @Component({

+ 1 - 1
packages/admin-ui/src/lib/order/src/components/order-history/order-history.component.html

@@ -111,7 +111,7 @@
                     <ng-container *ngSwitchCase="type.ORDER_CANCELLATION">
                     <ng-container *ngSwitchCase="type.ORDER_CANCELLATION">
                         {{
                         {{
                             'order.history-items-cancelled'
                             'order.history-items-cancelled'
-                                | translate: { count: entry.data.orderItemIds.length }
+                                | translate: { count: getCancelledQuantity(entry) }
                         }}
                         }}
                         <vdr-history-entry-detail *ngIf="getCancelledItems(entry) as items">
                         <vdr-history-entry-detail *ngIf="getCancelledItems(entry) as items">
                             <vdr-labeled-data [label]="'order.cancellation-reason' | translate">
                             <vdr-labeled-data [label]="'order.cancellation-reason' | translate">

+ 15 - 12
packages/admin-ui/src/lib/order/src/components/order-history/order-history.component.ts

@@ -110,7 +110,9 @@ export class OrderHistoryComponent {
         }
         }
     }
     }
 
 
-    getFulfillment(entry: TimelineHistoryEntry): NonNullable<OrderDetailFragment['fulfillments']>[number] | undefined {
+    getFulfillment(
+        entry: TimelineHistoryEntry,
+    ): NonNullable<OrderDetailFragment['fulfillments']>[number] | undefined {
         if (
         if (
             (entry.type === HistoryEntryType.ORDER_FULFILLMENT ||
             (entry.type === HistoryEntryType.ORDER_FULFILLMENT ||
                 entry.type === HistoryEntryType.ORDER_FULFILLMENT_TRANSITION) &&
                 entry.type === HistoryEntryType.ORDER_FULFILLMENT_TRANSITION) &&
@@ -120,25 +122,26 @@ export class OrderHistoryComponent {
         }
         }
     }
     }
 
 
-    getPayment(entry: TimelineHistoryEntry): NonNullable<OrderDetailFragment['payments']>[number] | undefined {
+    getPayment(
+        entry: TimelineHistoryEntry,
+    ): NonNullable<OrderDetailFragment['payments']>[number] | undefined {
         if (entry.type === HistoryEntryType.ORDER_PAYMENT_TRANSITION && this.order.payments) {
         if (entry.type === HistoryEntryType.ORDER_PAYMENT_TRANSITION && this.order.payments) {
             return this.order.payments.find(p => p.id === entry.data.paymentId);
             return this.order.payments.find(p => p.id === entry.data.paymentId);
         }
         }
     }
     }
 
 
+    getCancelledQuantity(entry: TimelineHistoryEntry): number {
+        return entry.data.lines.reduce((total, line) => total + line.quantity, 0);
+    }
+
     getCancelledItems(entry: TimelineHistoryEntry): Array<{ name: string; quantity: number }> {
     getCancelledItems(entry: TimelineHistoryEntry): Array<{ name: string; quantity: number }> {
         const itemMap = new Map<string, number>();
         const itemMap = new Map<string, number>();
-        const cancelledItemIds: string[] = entry.data.orderItemIds;
+        const cancellationLines: Array<{ orderLineId: string; quantity: number }> = entry.data.lines;
         for (const line of this.order.lines) {
         for (const line of this.order.lines) {
-            for (const item of line.items) {
-                if (cancelledItemIds.includes(item.id)) {
-                    const count = itemMap.get(line.productVariant.name);
-                    if (count != null) {
-                        itemMap.set(line.productVariant.name, count + 1);
-                    } else {
-                        itemMap.set(line.productVariant.name, 1);
-                    }
-                }
+            const cancellationLine = cancellationLines.find(l => l.orderLineId === line.id);
+            if (cancellationLine) {
+                const count = itemMap.get(line.productVariant.name);
+                itemMap.set(line.productVariant.name, cancellationLine.quantity);
             }
             }
         }
         }
         return Array.from(itemMap.entries()).map(([name, quantity]) => ({ name, quantity }));
         return Array.from(itemMap.entries()).map(([name, quantity]) => ({ name, quantity }));

+ 5 - 1
packages/admin-ui/src/lib/order/src/components/order-table/order-table.component.html

@@ -43,7 +43,11 @@
                         </div>
                         </div>
                     </ng-template>
                     </ng-template>
                     <vdr-line-refunds [line]="line" [payments]="order.payments"></vdr-line-refunds>
                     <vdr-line-refunds [line]="line" [payments]="order.payments"></vdr-line-refunds>
-                    <vdr-line-fulfillment [line]="line" [orderState]="order.state"></vdr-line-fulfillment>
+                    <vdr-line-fulfillment
+                        [line]="line"
+                        [orderState]="order.state"
+                        [allOrderFulfillments]="order.fulfillments"
+                    ></vdr-line-fulfillment>
                 </td>
                 </td>
                 <td class="align-middle total">
                 <td class="align-middle total">
                     {{ line.linePriceWithTax | localeCurrency: order.currencyCode }}
                     {{ line.linePriceWithTax | localeCurrency: order.currencyCode }}

+ 16 - 17
packages/admin-ui/src/lib/order/src/components/refund-order-dialog/refund-order-dialog.component.ts

@@ -7,6 +7,7 @@ import {
     I18nService,
     I18nService,
     OrderDetailFragment,
     OrderDetailFragment,
     OrderLineInput,
     OrderLineInput,
+    PaymentWithRefundsFragment,
     RefundOrderInput,
     RefundOrderInput,
 } from '@vendure/admin-ui/core';
 } from '@vendure/admin-ui/core';
 import { summate } from '@vendure/common/lib/shared-utils';
 import { summate } from '@vendure/common/lib/shared-utils';
@@ -65,23 +66,21 @@ export class RefundOrderDialogComponent
     }
     }
 
 
     lineCanBeRefundedOrCancelled(line: OrderDetailFragment['lines'][number]): boolean {
     lineCanBeRefundedOrCancelled(line: OrderDetailFragment['lines'][number]): boolean {
-        const refunds =
-            this.order.payments?.reduce(
-                (all, payment) => [...all, ...payment.refunds],
-                [] as Payment['refunds'],
-            ) ?? [];
-
-        const refundable = line.items.filter(i => {
-            if (i.cancelled) {
-                return false;
-            }
-            if (i.refundId == null) {
-                return true;
-            }
-            const refund = refunds.find(r => r.id === i.refundId);
-            return refund?.state === 'Failed';
-        });
-        return 0 < refundable.length;
+        const refundedCount =
+            this.order.payments
+                ?.reduce(
+                    (all, payment) => [...all, ...payment.refunds],
+                    [] as PaymentWithRefundsFragment['refunds'],
+                )
+                .filter(refund => refund.state !== 'Failed')
+                .reduce(
+                    (all, refund) => [...all, ...refund.lines],
+                    [] as Array<{ orderLineId: string; quantity: number }>,
+                )
+                .filter(refundLine => refundLine.orderLineId === line.id)
+                .reduce((sum, refundLine) => sum + refundLine.quantity, 0) ?? 0;
+
+        return refundedCount < line.quantity;
     }
     }
 
 
     ngOnInit() {
     ngOnInit() {

+ 19 - 19
scripts/codegen/generate-graphql-types.ts

@@ -123,25 +123,25 @@ Promise.all([
                     plugins: clientPlugins,
                     plugins: clientPlugins,
                     config: e2eConfig,
                     config: e2eConfig,
                 },
                 },
-                // [path.join(__dirname, '../../packages/admin-ui/src/lib/core/src/common/generated-types.ts')]:
-                //     {
-                //         schema: [ADMIN_SCHEMA_OUTPUT_FILE, path.join(__dirname, 'client-schema.ts')],
-                //         documents: CLIENT_QUERY_FILES,
-                //         plugins: clientPlugins,
-                //         config: {
-                //             ...config,
-                //             skipTypeNameForRoot: true,
-                //         },
-                //     },
-                // [path.join(
-                //     __dirname,
-                //     '../../packages/admin-ui/src/lib/core/src/common/introspection-result.ts',
-                // )]: {
-                //     schema: [ADMIN_SCHEMA_OUTPUT_FILE, path.join(__dirname, 'client-schema.ts')],
-                //     documents: CLIENT_QUERY_FILES,
-                //     plugins: [disableTsLintPlugin, 'fragment-matcher'],
-                //     config: { ...config, apolloClientVersion: 3 },
-                // },
+                [path.join(__dirname, '../../packages/admin-ui/src/lib/core/src/common/generated-types.ts')]:
+                    {
+                        schema: [ADMIN_SCHEMA_OUTPUT_FILE, path.join(__dirname, 'client-schema.ts')],
+                        documents: CLIENT_QUERY_FILES,
+                        plugins: clientPlugins,
+                        config: {
+                            ...config,
+                            skipTypeNameForRoot: true,
+                        },
+                    },
+                [path.join(
+                    __dirname,
+                    '../../packages/admin-ui/src/lib/core/src/common/introspection-result.ts',
+                )]: {
+                    schema: [ADMIN_SCHEMA_OUTPUT_FILE, path.join(__dirname, 'client-schema.ts')],
+                    documents: CLIENT_QUERY_FILES,
+                    plugins: [disableTsLintPlugin, 'fragment-matcher'],
+                    config: { ...config, apolloClientVersion: 3 },
+                },
                 [path.join(__dirname, '../../packages/common/src/generated-types.ts')]: {
                 [path.join(__dirname, '../../packages/common/src/generated-types.ts')]: {
                     schema: [ADMIN_SCHEMA_OUTPUT_FILE],
                     schema: [ADMIN_SCHEMA_OUTPUT_FILE],
                     plugins: commonPlugins,
                     plugins: commonPlugins,

Некоторые файлы не были показаны из-за большого количества измененных файлов