Преглед на файлове

feat(admin-ui): Display hint if deleting Collection with descendants

Michael Bromley преди 6 години
родител
ревизия
27b708013f

+ 16 - 9
packages/admin-ui/src/app/catalog/components/collection-list/collection-list.component.ts

@@ -1,7 +1,7 @@
 import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core';
 import { ActivatedRoute, Router } from '@angular/router';
 import { combineLatest, EMPTY, Observable } from 'rxjs';
-import { distinctUntilChanged, map, switchMap } from 'rxjs/operators';
+import { distinctUntilChanged, map, switchMap, take } from 'rxjs/operators';
 
 import { Collection, GetCollectionList } from '../../../common/generated-types';
 import { _ } from '../../../core/providers/i18n/mark-for-extraction';
@@ -63,15 +63,22 @@ export class CollectionListComponent implements OnInit {
     }
 
     deleteCollection(id: string) {
-        this.modalService
-            .dialog({
-                title: _('catalog.confirm-delete-collection'),
-                buttons: [
-                    { type: 'seconday', label: _('common.cancel') },
-                    { type: 'danger', label: _('common.delete'), returnValue: true },
-                ],
-            })
+        this.items$
             .pipe(
+                take(1),
+                map(items => -1 < items.findIndex(i => i.parent && i.parent.id === id)),
+                switchMap(hasChildren => {
+                    return this.modalService.dialog({
+                        title: _('catalog.confirm-delete-collection'),
+                        body: hasChildren
+                            ? _('catalog.confirm-delete-collection-and-children-body')
+                            : undefined,
+                        buttons: [
+                            { type: 'seconday', label: _('common.cancel') },
+                            { type: 'danger', label: _('common.delete'), returnValue: true },
+                        ],
+                    });
+                }),
                 switchMap(response => (response ? this.dataService.collection.deleteCollection(id) : EMPTY)),
             )
             .subscribe(

+ 1 - 0
packages/admin-ui/src/i18n-messages/en.json

@@ -33,6 +33,7 @@
     "confirm-adding-options-delete-default-body": "Adding options to this product will cause the existing default variant to be deleted. Do you wish to proceed?",
     "confirm-adding-options-delete-default-title": "Delete default variant?",
     "confirm-delete-collection": "Delete collection?",
+    "confirm-delete-collection-and-children-body": "Deleting this collection will also delete all child collections",
     "confirm-delete-country": "Delete country?",
     "confirm-delete-facet": "Delete facet?",
     "confirm-delete-facet-value": "Delete facet value?",