Skip to content

Commit

Permalink
fix(admin-ui): Trigger navigation confirm if assets have been changed
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbromley committed Sep 16, 2019
1 parent 528eb3c commit 6e751b0
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
4 changes: 4 additions & 0 deletions packages/admin-ui/src/app/common/base-detail.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down

0 comments on commit 6e751b0

Please sign in to comment.