Browse Source

fix(admin-ui): Prevent module constructor side effects from repeating

Closes #2455
Michael Bromley 2 years ago
parent
commit
a684b59b6b

+ 6 - 0
packages/admin-ui/src/lib/catalog/src/catalog.module.ts

@@ -117,7 +117,12 @@ const CATALOG_COMPONENTS = [
     ],
 })
 export class CatalogModule {
+    private static hasRegisteredTabsAndBulkActions = false;
+
     constructor(bulkActionRegistryService: BulkActionRegistryService, pageService: PageService) {
+        if (CatalogModule.hasRegisteredTabsAndBulkActions) {
+            return;
+        }
         bulkActionRegistryService.registerBulkAction(assignFacetValuesToProductsBulkAction);
         bulkActionRegistryService.registerBulkAction(assignProductsToChannelBulkAction);
         bulkActionRegistryService.registerBulkAction(assignProductVariantsToChannelBulkAction);
@@ -259,5 +264,6 @@ export class CatalogModule {
                 ],
             }),
         });
+        CatalogModule.hasRegisteredTabsAndBulkActions = true;
     }
 }

+ 7 - 4
packages/admin-ui/src/lib/customer/src/customer.module.ts

@@ -57,10 +57,12 @@ import { CustomerGroupDetailComponent } from './components/customer-group-detail
     exports: [AddressCardComponent],
 })
 export class CustomerModule {
-    constructor(
-        private bulkActionRegistryService: BulkActionRegistryService,
-        private pageService: PageService,
-    ) {
+    private static hasRegisteredTabsAndBulkActions = false;
+
+    constructor(bulkActionRegistryService: BulkActionRegistryService, pageService: PageService) {
+        if (CustomerModule.hasRegisteredTabsAndBulkActions) {
+            return;
+        }
         bulkActionRegistryService.registerBulkAction(deleteCustomersBulkAction);
         bulkActionRegistryService.registerBulkAction(deleteCustomerGroupsBulkAction);
         bulkActionRegistryService.registerBulkAction(removeCustomerGroupMembersBulkAction);
@@ -122,5 +124,6 @@ export class CustomerModule {
                 ],
             }),
         });
+        CustomerModule.hasRegisteredTabsAndBulkActions = true;
     }
 }

+ 7 - 1
packages/admin-ui/src/lib/marketing/src/marketing.module.ts

@@ -32,7 +32,12 @@ import { createRoutes } from './marketing.routes';
     declarations: [PromotionListComponent, PromotionDetailComponent],
 })
 export class MarketingModule {
-    constructor(private bulkActionRegistryService: BulkActionRegistryService, pageService: PageService) {
+    private static hasRegisteredTabsAndBulkActions = false;
+
+    constructor(bulkActionRegistryService: BulkActionRegistryService, pageService: PageService) {
+        if (MarketingModule.hasRegisteredTabsAndBulkActions) {
+            return;
+        }
         bulkActionRegistryService.registerBulkAction(assignPromotionsToChannelBulkAction);
         bulkActionRegistryService.registerBulkAction(removePromotionsFromChannelBulkAction);
         bulkActionRegistryService.registerBulkAction(deletePromotionsBulkAction);
@@ -61,5 +66,6 @@ export class MarketingModule {
                 ],
             }),
         });
+        MarketingModule.hasRegisteredTabsAndBulkActions = true;
     }
 }

+ 7 - 1
packages/admin-ui/src/lib/order/src/order.module.ts

@@ -102,7 +102,12 @@ import { OrderDataTableComponent } from './components/order-data-table/order-dat
     exports: [OrderCustomFieldsCardComponent],
 })
 export class OrderModule {
-    constructor(private pageService: PageService) {
+    private static hasRegisteredTabsAndBulkActions = false;
+
+    constructor(pageService: PageService) {
+        if (OrderModule.hasRegisteredTabsAndBulkActions) {
+            return;
+        }
         pageService.registerPageTab({
             priority: 0,
             location: 'order-list',
@@ -160,5 +165,6 @@ export class OrderModule {
                 ],
             }),
         });
+        OrderModule.hasRegisteredTabsAndBulkActions = true;
     }
 }

+ 7 - 1
packages/admin-ui/src/lib/settings/src/settings.module.ts

@@ -128,7 +128,12 @@ import { createRoutes } from './settings.routes';
     ],
 })
 export class SettingsModule {
-    constructor(private bulkActionRegistryService: BulkActionRegistryService, pageService: PageService) {
+    private static hasRegisteredTabsAndBulkActions = false;
+
+    constructor(bulkActionRegistryService: BulkActionRegistryService, pageService: PageService) {
+        if (SettingsModule.hasRegisteredTabsAndBulkActions) {
+            return;
+        }
         bulkActionRegistryService.registerBulkAction(deleteSellersBulkAction);
 
         bulkActionRegistryService.registerBulkAction(deleteChannelsBulkAction);
@@ -451,5 +456,6 @@ export class SettingsModule {
                 ],
             }),
         });
+        SettingsModule.hasRegisteredTabsAndBulkActions = true;
     }
 }

+ 0 - 1
packages/admin-ui/src/lib/system/src/system.module.ts

@@ -1,4 +1,3 @@
-import { CommonModule } from '@angular/common';
 import { NgModule } from '@angular/core';
 import { RouterModule } from '@angular/router';
 import { SharedModule } from '@vendure/admin-ui/core';