Browse Source

feat(admin-ui): Display shipping calculator metadata

Relates to #136
Michael Bromley 6 years ago
parent
commit
4e5bce59bd

+ 13 - 10
admin-ui/src/app/common/generated-types.ts

@@ -3065,6 +3065,7 @@ export type ShippingMethodQuote = {
   price: Scalars['Int'],
   priceWithTax: Scalars['Int'],
   description: Scalars['String'],
+  metadata?: Maybe<Scalars['JSON']>,
 };
 
 export type ShippingMethodSortParameter = {
@@ -3075,12 +3076,6 @@ export type ShippingMethodSortParameter = {
   description?: Maybe<SortOrder>,
 };
 
-export type ShippingPrice = {
-  __typename?: 'ShippingPrice',
-  price: Scalars['Int'],
-  priceWithTax: Scalars['Int'],
-};
-
 /** The price value where the result has a single price */
 export type SinglePrice = {
   __typename?: 'SinglePrice',
@@ -3221,10 +3216,18 @@ export type TestShippingMethodOrderLineInput = {
   quantity: Scalars['Int'],
 };
 
+export type TestShippingMethodQuote = {
+  __typename?: 'TestShippingMethodQuote',
+  price: Scalars['Int'],
+  priceWithTax: Scalars['Int'],
+  description: Scalars['String'],
+  metadata?: Maybe<Scalars['JSON']>,
+};
+
 export type TestShippingMethodResult = {
   __typename?: 'TestShippingMethodResult',
   eligible: Scalars['Boolean'],
-  price?: Maybe<ShippingPrice>,
+  quote?: Maybe<TestShippingMethodQuote>,
 };
 
 export type UiState = {
@@ -4289,14 +4292,14 @@ export type TestShippingMethodQueryVariables = {
 };
 
 
-export type TestShippingMethodQuery = ({ __typename?: 'Query' } & { testShippingMethod: ({ __typename?: 'TestShippingMethodResult' } & Pick<TestShippingMethodResult, 'eligible'> & { price: Maybe<({ __typename?: 'ShippingPrice' } & Pick<ShippingPrice, 'price' | 'priceWithTax'>)> }) });
+export type TestShippingMethodQuery = ({ __typename?: 'Query' } & { testShippingMethod: ({ __typename?: 'TestShippingMethodResult' } & Pick<TestShippingMethodResult, 'eligible'> & { quote: Maybe<({ __typename?: 'TestShippingMethodQuote' } & Pick<TestShippingMethodQuote, 'price' | 'priceWithTax' | 'metadata'>)> }) });
 
 export type TestEligibleShippingMethodsQueryVariables = {
   input: TestEligibleShippingMethodsInput
 };
 
 
-export type TestEligibleShippingMethodsQuery = ({ __typename?: 'Query' } & { testEligibleShippingMethods: Array<({ __typename?: 'ShippingMethodQuote' } & Pick<ShippingMethodQuote, 'id' | 'description' | 'price' | 'priceWithTax'>)> });
+export type TestEligibleShippingMethodsQuery = ({ __typename?: 'Query' } & { testEligibleShippingMethods: Array<({ __typename?: 'ShippingMethodQuote' } & Pick<ShippingMethodQuote, 'id' | 'description' | 'price' | 'priceWithTax' | 'metadata'>)> });
 type DiscriminateUnion<T, U> = T extends U ? T : never;
 
 type RequireField<T, TNames extends string> = T & { [P in TNames]: (T & { [name: string]: never })[P] };
@@ -5261,7 +5264,7 @@ export namespace TestShippingMethod {
   export type Variables = TestShippingMethodQueryVariables;
   export type Query = TestShippingMethodQuery;
   export type TestShippingMethod = TestShippingMethodQuery['testShippingMethod'];
-  export type Price = (NonNullable<TestShippingMethodQuery['testShippingMethod']['price']>);
+  export type Quote = (NonNullable<TestShippingMethodQuery['testShippingMethod']['quote']>);
 }
 
 export namespace TestEligibleShippingMethods {

+ 3 - 1
admin-ui/src/app/data/definitions/shipping-definitions.ts

@@ -83,9 +83,10 @@ export const TEST_SHIPPING_METHOD = gql`
     query TestShippingMethod($input: TestShippingMethodInput!) {
         testShippingMethod(input: $input) {
             eligible
-            price {
+            quote {
                 price
                 priceWithTax
+                metadata
             }
         }
     }
@@ -98,6 +99,7 @@ export const TEST_ELIGIBLE_SHIPPING_METHODS = gql`
             description
             price
             priceWithTax
+            metadata
         }
     }
 `;

+ 1 - 0
admin-ui/src/app/settings/components/shipping-eligibility-test-result/shipping-eligibility-test-result.component.html

@@ -15,6 +15,7 @@
                     {{ quote.priceWithTax / 100 | currency: currencyCode }}
                 </vdr-labeled-data>
             </div>
+            <vdr-object-tree *ngIf="quote.metadata" [value]="quote.metadata"></vdr-object-tree>
         </div>
     </div>
     <div class="card-block" *ngIf="testResult?.length === 0">

+ 8 - 4
admin-ui/src/app/settings/components/shipping-method-test-result/shipping-method-test-result.component.html

@@ -30,17 +30,21 @@
             <div class="price-row">
                 <vdr-labeled-data
                     [label]="'common.price' | translate"
-                    *ngIf="testResult?.price?.price != null"
+                    *ngIf="testResult?.quote?.price != null"
                 >
-                    {{ testResult.price.price / 100 | currency: currencyCode }}
+                    {{ testResult.quote.price / 100 | currency: currencyCode }}
                 </vdr-labeled-data>
                 <vdr-labeled-data
                     [label]="'common.price-with-tax' | translate"
-                    *ngIf="testResult?.price?.priceWithTax != null"
+                    *ngIf="testResult?.quote?.priceWithTax != null"
                 >
-                    {{ testResult.price.priceWithTax / 100 | currency: currencyCode }}
+                    {{ testResult.quote.priceWithTax / 100 | currency: currencyCode }}
                 </vdr-labeled-data>
             </div>
+            <vdr-object-tree
+                *ngIf="testResult?.quote?.metadata"
+                [value]="testResult?.quote?.metadata"
+            ></vdr-object-tree>
         </div>
     </div>
     <div class="card-footer">

+ 1 - 1
admin-ui/src/app/settings/components/test-order-builder/test-order-builder.component.html

@@ -25,7 +25,7 @@
             <td class="align-middle quantity">
                 <input
                     [(ngModel)]="line.quantity"
-                    (change)="orderLinesChange.emit(lines)"
+                    (change)="updateQuantity()"
                     type="number"
                     max="9999"
                     min="1"

+ 11 - 6
admin-ui/src/app/settings/components/test-order-builder/test-order-builder.component.ts

@@ -66,12 +66,6 @@ export class TestOrderBuilderComponent implements OnInit {
         }
     }
 
-    removeLine(line: TestOrderLine) {
-        this.lines = this.lines.filter(l => l.id !== line.id);
-        this.persistToLocalStorage();
-        this.orderLinesChange.emit(this.lines);
-    }
-
     private addToLines(result: SearchForTestOrder.Items) {
         if (!this.lines.find(l => l.id === result.productVariantId)) {
             this.lines.push({
@@ -87,6 +81,17 @@ export class TestOrderBuilderComponent implements OnInit {
         }
     }
 
+    private updateQuantity() {
+        this.persistToLocalStorage();
+        this.orderLinesChange.emit(this.lines);
+    }
+
+    removeLine(line: TestOrderLine) {
+        this.lines = this.lines.filter(l => l.id !== line.id);
+        this.persistToLocalStorage();
+        this.orderLinesChange.emit(this.lines);
+    }
+
     private initSearchResults() {
         const searchItems$ = this.searchInput$.pipe(
             debounceTime(200),