From 0e98cb55c7e9f3ac49a0f2b9c1511b497ec612b9 Mon Sep 17 00:00:00 2001 From: Michael Bromley Date: Mon, 11 Jan 2021 11:18:17 +0100 Subject: [PATCH] feat(admin-ui): Auto update ProductVariant name with ProductOption name Relates to #600 --- packages/admin-ui/i18n-coverage.json | 28 +++---- .../product-detail.component.ts | 35 +++++---- .../product-variants-list.component.ts | 2 +- ...pdate-product-option-dialog.component.html | 10 ++- .../update-product-option-dialog.component.ts | 10 ++- .../src/providers/product-detail.service.ts | 74 +++++++++++++++---- .../src/lib/static/i18n-messages/cs.json | 1 + .../src/lib/static/i18n-messages/de.json | 1 + .../src/lib/static/i18n-messages/en.json | 1 + .../src/lib/static/i18n-messages/es.json | 1 + .../src/lib/static/i18n-messages/fr.json | 1 + .../src/lib/static/i18n-messages/pl.json | 1 + .../src/lib/static/i18n-messages/pt_BR.json | 1 + .../src/lib/static/i18n-messages/zh_Hans.json | 1 + .../src/lib/static/i18n-messages/zh_Hant.json | 1 + 15 files changed, 118 insertions(+), 50 deletions(-) diff --git a/packages/admin-ui/i18n-coverage.json b/packages/admin-ui/i18n-coverage.json index 865085bf30..3ad84c9aef 100644 --- a/packages/admin-ui/i18n-coverage.json +++ b/packages/admin-ui/i18n-coverage.json @@ -1,49 +1,49 @@ { - "generatedOn": "2021-01-11T09:10:41.279Z", - "lastCommit": "12c46425e453d3e160a27aed41f14bd23120c9f2", + "generatedOn": "2021-01-11T10:15:44.646Z", + "lastCommit": "b1b363d91d14b3484a30d889db74491e8813c5f0", "translationStatus": { "cs": { - "tokenCount": 750, + "tokenCount": 751, "translatedCount": 687, - "percentage": 92 + "percentage": 91 }, "de": { - "tokenCount": 750, + "tokenCount": 751, "translatedCount": 596, "percentage": 79 }, "en": { - "tokenCount": 750, - "translatedCount": 749, + "tokenCount": 751, + "translatedCount": 750, "percentage": 100 }, "es": { - "tokenCount": 750, + "tokenCount": 751, "translatedCount": 458, "percentage": 61 }, "fr": { - "tokenCount": 750, + "tokenCount": 751, "translatedCount": 692, "percentage": 92 }, "pl": { - "tokenCount": 750, + "tokenCount": 751, "translatedCount": 551, "percentage": 73 }, "pt_BR": { - "tokenCount": 750, + "tokenCount": 751, "translatedCount": 642, - "percentage": 86 + "percentage": 85 }, "zh_Hans": { - "tokenCount": 750, + "tokenCount": 751, "translatedCount": 533, "percentage": 71 }, "zh_Hant": { - "tokenCount": 750, + "tokenCount": 751, "translatedCount": 533, "percentage": 71 } diff --git a/packages/admin-ui/src/lib/catalog/src/components/product-detail/product-detail.component.ts b/packages/admin-ui/src/lib/catalog/src/components/product-detail/product-detail.component.ts index 757c0f3d49..5fb29bf765 100644 --- a/packages/admin-ui/src/lib/catalog/src/components/product-detail/product-detail.component.ts +++ b/packages/admin-ui/src/lib/catalog/src/components/product-detail/product-detail.component.ts @@ -29,7 +29,7 @@ import { normalizeString } from '@vendure/common/lib/normalize-string'; import { DEFAULT_CHANNEL_CODE } from '@vendure/common/lib/shared-constants'; import { notNullOrUndefined } from '@vendure/common/lib/shared-utils'; import { unique } from '@vendure/common/lib/unique'; -import { combineLatest, EMPTY, merge, Observable } from 'rxjs'; +import { combineLatest, EMPTY, merge, Observable, of } from 'rxjs'; import { debounceTime, distinctUntilChanged, @@ -347,19 +347,26 @@ export class ProductDetailComponent }); } - updateProductOption(input: UpdateProductOptionInput) { - this.productDetailService.updateProductOption(input).subscribe( - () => { - this.notificationService.success(_('common.notify-update-success'), { - entity: 'ProductOption', - }); - }, - err => { - this.notificationService.error(_('common.notify-update-error'), { - entity: 'ProductOption', - }); - }, - ); + updateProductOption(input: UpdateProductOptionInput & { autoUpdate: boolean }) { + combineLatest(this.product$, this.languageCode$) + .pipe( + take(1), + mergeMap(([product, languageCode]) => + this.productDetailService.updateProductOption(input, product, languageCode), + ), + ) + .subscribe( + () => { + this.notificationService.success(_('common.notify-update-success'), { + entity: 'ProductOption', + }); + }, + err => { + this.notificationService.error(_('common.notify-update-error'), { + entity: 'ProductOption', + }); + }, + ); } removeProductFacetValue(facetValueId: string) { diff --git a/packages/admin-ui/src/lib/catalog/src/components/product-variants-list/product-variants-list.component.ts b/packages/admin-ui/src/lib/catalog/src/components/product-variants-list/product-variants-list.component.ts index 19583a80ed..cf056eed66 100644 --- a/packages/admin-ui/src/lib/catalog/src/components/product-variants-list/product-variants-list.component.ts +++ b/packages/admin-ui/src/lib/catalog/src/components/product-variants-list/product-variants-list.component.ts @@ -64,7 +64,7 @@ export class ProductVariantsListComponent implements OnChanges, OnInit, OnDestro @Output() assetChange = new EventEmitter(); @Output() selectionChange = new EventEmitter(); @Output() selectFacetValueClick = new EventEmitter(); - @Output() updateProductOption = new EventEmitter(); + @Output() updateProductOption = new EventEmitter(); selectedVariantIds: string[] = []; pagination: PaginationInstance = { currentPage: 1, diff --git a/packages/admin-ui/src/lib/catalog/src/components/update-product-option-dialog/update-product-option-dialog.component.html b/packages/admin-ui/src/lib/catalog/src/components/update-product-option-dialog/update-product-option-dialog.component.html index 53f1af00a3..ea1b73f029 100644 --- a/packages/admin-ui/src/lib/catalog/src/components/update-product-option-dialog/update-product-option-dialog.component.html +++ b/packages/admin-ui/src/lib/catalog/src/components/update-product-option-dialog/update-product-option-dialog.component.html @@ -12,6 +12,10 @@ + + + +
@@ -30,7 +34,11 @@