Skip to content

Commit

Permalink
fix(admin-ui): Preserve asset changes between product list/table view
Browse files Browse the repository at this point in the history
Relates to #632
  • Loading branch information
michaelbromley committed Jan 15, 2021
1 parent 90a1176 commit c83e511
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ <h4>{{ 'catalog.product-variants' | translate }}</h4>
[optionGroups]="product.optionGroups"
[channelPriceIncludesTax]="channelPriceIncludesTax$ | async"
[productVariantsFormArray]="detailForm.get('variants')"
[pendingAssetChanges]="variantAssetChanges"
></vdr-product-variants-table>
<vdr-product-variants-list
*ngIf="variantDisplayMode === 'card'"
Expand All @@ -240,6 +241,7 @@ <h4>{{ 'catalog.product-variants' | translate }}</h4>
[customFields]="customVariantFields"
[customOptionFields]="customOptionFields"
[activeLanguage]="languageCode$ | async"
[pendingAssetChanges]="variantAssetChanges"
(assignToChannel)="assignVariantToChannel($event)"
(removeFromChannel)="removeVariantFromChannel($event)"
(assetChange)="variantAssetChange($event)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
<div class="assets">
<vdr-product-assets
[compact]="true"
[assets]="variant.assets"
[featuredAsset]="variant.featuredAsset"
[assets]="pendingAssetChanges[variant.id]?.assets || variant.assets"
[featuredAsset]="pendingAssetChanges[variant.id]?.featuredAsset || variant.featuredAsset"
(change)="onAssetChange(variant.id, $event)"
></vdr-product-assets>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export class ProductVariantsListComponent implements OnChanges, OnInit, OnDestro
@Input() customFields: CustomFieldConfig[];
@Input() customOptionFields: CustomFieldConfig[];
@Input() activeLanguage: LanguageCode;
@Input() pendingAssetChanges: { [variantId: string]: SelectedAssets };
@Output() assignToChannel = new EventEmitter<ProductWithVariants.Variants>();
@Output() removeFromChannel = new EventEmitter<{
channelId: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@
<div class="card-img">
<div class="featured-asset">
<img
*ngIf="variant.featuredAsset"
[src]="variant.featuredAsset | assetPreview:'tiny'"
*ngIf="getFeaturedAsset(variant) as featuredAsset; else placeholder"
[src]="featuredAsset | assetPreview: 'tiny'"
/>
<div class="placeholder" *ngIf="!variant.featuredAsset">
<clr-icon shape="image" size="48"></clr-icon>
</div>
<ng-template #placeholder>
<div class="placeholder">
<clr-icon shape="image" size="48"></clr-icon>
</div>
</ng-template>
</div>
</div>
</td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import { flattenFacetValues, ProductWithVariants } from '@vendure/admin-ui/core'
import { Subscription } from 'rxjs';
import { debounceTime, distinctUntilChanged, map } from 'rxjs/operators';

import { SelectedAssets } from '../product-detail/product-detail.component';

@Component({
selector: 'vdr-product-variants-table',
templateUrl: './product-variants-table.component.html',
Expand All @@ -24,6 +26,7 @@ export class ProductVariantsTableComponent implements OnInit, OnChanges, OnDestr
@Input() variants: ProductWithVariants.Variants[];
@Input() channelPriceIncludesTax: boolean;
@Input() optionGroups: ProductWithVariants.OptionGroups[];
@Input() pendingAssetChanges: { [variantId: string]: SelectedAssets };
formGroupMap = new Map<string, FormGroup>();
variantListPrice: { [variantId: string]: number } = {};
private subscription: Subscription;
Expand Down Expand Up @@ -61,6 +64,10 @@ export class ProductVariantsTableComponent implements OnInit, OnChanges, OnDestr
}
}

getFeaturedAsset(variant: ProductWithVariants.Variants) {
return this.pendingAssetChanges[variant.id]?.featuredAsset || variant.featuredAsset;
}

optionGroupName(optionGroupId: string): string | undefined {
const group = this.optionGroups.find(g => g.id === optionGroupId);
return group && group.name;
Expand Down

0 comments on commit c83e511

Please sign in to comment.