Browse Source

fix(admin-ui): Trigger navigation confirm if assets have been changed

Michael Bromley 6 years ago
parent
commit
6e751b0167

+ 4 - 0
packages/admin-ui/src/app/catalog/components/collection-detail/collection-detail.component.ts

@@ -202,6 +202,10 @@ export class CollectionDetailComponent extends BaseDetailComponent<Collection.Fr
             );
     }
 
+    canDeactivate(): boolean {
+        return super.canDeactivate() && !this.assetChanges.assetIds && !this.assetChanges.featuredAssetId;
+    }
+
     /**
      * Sets the values of the form on changes to the category or current language.
      */

+ 4 - 0
packages/admin-ui/src/app/catalog/components/product-detail/product-detail.component.ts

@@ -382,6 +382,10 @@ export class ProductDetailComponent extends BaseDetailComponent<ProductWithVaria
             );
     }
 
+    canDeactivate(): boolean {
+        return super.canDeactivate() && !this.assetChanges.assetIds && !this.assetChanges.featuredAssetId;
+    }
+
     /**
      * Sets the values of the form on changes to the product or current language.
      */

+ 4 - 0
packages/admin-ui/src/app/common/base-detail.component.ts

@@ -59,6 +59,10 @@ export abstract class BaseDetailComponent<Entity extends { id: string; updatedAt
         this.setQueryParam('lang', code);
     }
 
+    canDeactivate(): boolean {
+        return this.detailForm && this.detailForm.pristine;
+    }
+
     protected abstract setFormValues(entity: Entity, languageCode: LanguageCode): void;
 
     protected getCustomFieldConfig(key: Exclude<keyof CustomFields, '__typename'>): CustomFieldConfig[] {

+ 1 - 1
packages/admin-ui/src/app/shared/providers/routing/can-deactivate-detail-guard.ts

@@ -29,7 +29,7 @@ export class CanDeactivateDetailGuard implements CanDeactivate<BaseDetailCompone
                 return true;
             }
         }
-        if (component.detailForm && component.detailForm.dirty) {
+        if (!component.canDeactivate()) {
             return this.modalService
                 .dialog({
                     title: _('common.confirm-navigation'),