Skip to content

Commit

Permalink
fix(admin-ui): Prevent module constructor side effects from repeating
Browse files Browse the repository at this point in the history
Closes #2455
  • Loading branch information
michaelbromley committed Nov 14, 2023
1 parent b44cc88 commit a684b59
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 8 deletions.
6 changes: 6 additions & 0 deletions packages/admin-ui/src/lib/catalog/src/catalog.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -259,5 +264,6 @@ export class CatalogModule {
],
}),
});
CatalogModule.hasRegisteredTabsAndBulkActions = true;
}
}
11 changes: 7 additions & 4 deletions packages/admin-ui/src/lib/customer/src/customer.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -122,5 +124,6 @@ export class CustomerModule {
],
}),
});
CustomerModule.hasRegisteredTabsAndBulkActions = true;
}
}
8 changes: 7 additions & 1 deletion packages/admin-ui/src/lib/marketing/src/marketing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -61,5 +66,6 @@ export class MarketingModule {
],
}),
});
MarketingModule.hasRegisteredTabsAndBulkActions = true;
}
}
8 changes: 7 additions & 1 deletion packages/admin-ui/src/lib/order/src/order.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -160,5 +165,6 @@ export class OrderModule {
],
}),
});
OrderModule.hasRegisteredTabsAndBulkActions = true;
}
}
8 changes: 7 additions & 1 deletion packages/admin-ui/src/lib/settings/src/settings.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -451,5 +456,6 @@ export class SettingsModule {
],
}),
});
SettingsModule.hasRegisteredTabsAndBulkActions = true;
}
}
1 change: 0 additions & 1 deletion packages/admin-ui/src/lib/system/src/system.module.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down

0 comments on commit a684b59

Please sign in to comment.