From 26f88b72577fd1d8a0fc427b3c41fbecd1b1bb82 Mon Sep 17 00:00:00 2001 From: Michael Bromley Date: Wed, 6 Sep 2023 12:30:27 +0200 Subject: [PATCH] refactor(admin-ui): Remove usage of deprecated ComponentFactoryResolver --- .../core/src/providers/modal/modal.service.ts | 11 +++-------- .../dialog-component-outlet.component.ts | 19 +++---------------- .../customer-history-entry-host.component.ts | 9 ++------- .../dashboard-widget.component.ts | 8 +------- .../order-history-entry-host.component.ts | 9 ++------- 5 files changed, 11 insertions(+), 45 deletions(-) diff --git a/packages/admin-ui/src/lib/core/src/providers/modal/modal.service.ts b/packages/admin-ui/src/lib/core/src/providers/modal/modal.service.ts index d66ea163b7..1dbe5cf73b 100644 --- a/packages/admin-ui/src/lib/core/src/providers/modal/modal.service.ts +++ b/packages/admin-ui/src/lib/core/src/providers/modal/modal.service.ts @@ -1,4 +1,4 @@ -import { ComponentFactoryResolver, Injectable } from '@angular/core'; +import { Injectable } from '@angular/core'; import { Type } from '@vendure/common/lib/shared-types'; import { from, Observable } from 'rxjs'; import { mergeMap } from 'rxjs/operators'; @@ -22,10 +22,7 @@ import { Dialog, DialogConfig, ModalOptions } from './modal.types'; providedIn: 'root', }) export class ModalService { - constructor( - private componentFactoryResolver: ComponentFactoryResolver, - private overlayHostService: OverlayHostService, - ) {} + constructor(private overlayHostService: OverlayHostService) {} /** * @description @@ -72,11 +69,9 @@ export class ModalService { component: Type & Type>, options?: ModalOptions, ): Observable { - const modalFactory = this.componentFactoryResolver.resolveComponentFactory(ModalDialogComponent); - return from(this.overlayHostService.getHostView()).pipe( mergeMap(hostView => { - const modalComponentRef = hostView.createComponent(modalFactory); + const modalComponentRef = hostView.createComponent(ModalDialogComponent); const modalInstance: ModalDialogComponent = modalComponentRef.instance; modalInstance.childComponentType = component; modalInstance.options = options; diff --git a/packages/admin-ui/src/lib/core/src/shared/components/modal-dialog/dialog-component-outlet.component.ts b/packages/admin-ui/src/lib/core/src/shared/components/modal-dialog/dialog-component-outlet.component.ts index 57c076d293..3b0f66afe6 100644 --- a/packages/admin-ui/src/lib/core/src/shared/components/modal-dialog/dialog-component-outlet.component.ts +++ b/packages/admin-ui/src/lib/core/src/shared/components/modal-dialog/dialog-component-outlet.component.ts @@ -1,13 +1,4 @@ -import { - Component, - ComponentFactoryResolver, - EventEmitter, - Input, - OnInit, - Output, - Type, - ViewContainerRef, -} from '@angular/core'; +import { Component, EventEmitter, Input, OnInit, Output, Type, ViewContainerRef } from '@angular/core'; /** * A helper component used to embed a component instance into the {@link ModalDialogComponent} @@ -20,14 +11,10 @@ export class DialogComponentOutletComponent implements OnInit { @Input() component: Type; @Output() create = new EventEmitter(); - constructor( - private viewContainerRef: ViewContainerRef, - private componentFactoryResolver: ComponentFactoryResolver, - ) {} + constructor(private viewContainerRef: ViewContainerRef) {} ngOnInit() { - const factory = this.componentFactoryResolver.resolveComponentFactory(this.component); - const componentRef = this.viewContainerRef.createComponent(factory); + const componentRef = this.viewContainerRef.createComponent(this.component); this.create.emit(componentRef.instance); } } diff --git a/packages/admin-ui/src/lib/customer/src/components/customer-history/customer-history-entry-host.component.ts b/packages/admin-ui/src/lib/customer/src/components/customer-history/customer-history-entry-host.component.ts index be7f083426..4f136a513d 100644 --- a/packages/admin-ui/src/lib/customer/src/components/customer-history/customer-history-entry-host.component.ts +++ b/packages/admin-ui/src/lib/customer/src/components/customer-history/customer-history-entry-host.component.ts @@ -1,6 +1,5 @@ import { Component, - ComponentFactoryResolver, ComponentRef, EventEmitter, Input, @@ -42,18 +41,14 @@ export class CustomerHistoryEntryHostComponent implements OnInit, OnDestroy { instance: CustomerHistoryEntryComponent; private componentRef: ComponentRef; - constructor( - private componentFactoryResolver: ComponentFactoryResolver, - private historyEntryComponentService: HistoryEntryComponentService, - ) {} + constructor(private historyEntryComponentService: HistoryEntryComponentService) {} ngOnInit(): void { const componentType = this.historyEntryComponentService.getComponent( this.entry.type, ) as Type; - const factory = this.componentFactoryResolver.resolveComponentFactory(componentType); - const componentRef = this.portalRef.createComponent(factory); + const componentRef = this.portalRef.createComponent(componentType); componentRef.instance.entry = this.entry; componentRef.instance.customer = this.customer; this.instance = componentRef.instance; diff --git a/packages/admin-ui/src/lib/dashboard/src/components/dashboard-widget/dashboard-widget.component.ts b/packages/admin-ui/src/lib/dashboard/src/components/dashboard-widget/dashboard-widget.component.ts index 1435ba0f17..9bcb85a7db 100644 --- a/packages/admin-ui/src/lib/dashboard/src/components/dashboard-widget/dashboard-widget.component.ts +++ b/packages/admin-ui/src/lib/dashboard/src/components/dashboard-widget/dashboard-widget.component.ts @@ -2,11 +2,9 @@ import { AfterViewInit, ChangeDetectionStrategy, Component, - ComponentFactoryResolver, ComponentRef, Input, OnDestroy, - OnInit, ViewChild, ViewContainerRef, } from '@angular/core'; @@ -26,8 +24,6 @@ export class DashboardWidgetComponent implements AfterViewInit, OnDestroy { private componentRef: ComponentRef; - constructor(private componentFactoryResolver: ComponentFactoryResolver) {} - ngAfterViewInit(): void { this.loadWidget(); } @@ -36,9 +32,7 @@ export class DashboardWidgetComponent implements AfterViewInit, OnDestroy { const loadComponentResult = this.widgetConfig.loadComponent(); const componentType = loadComponentResult instanceof Promise ? await loadComponentResult : loadComponentResult; - this.componentRef = this.portal.createComponent( - this.componentFactoryResolver.resolveComponentFactory(componentType), - ); + this.componentRef = this.portal.createComponent(componentType); this.componentRef.changeDetectorRef.detectChanges(); } diff --git a/packages/admin-ui/src/lib/order/src/components/order-history/order-history-entry-host.component.ts b/packages/admin-ui/src/lib/order/src/components/order-history/order-history-entry-host.component.ts index 04043c6e6f..43e082db93 100644 --- a/packages/admin-ui/src/lib/order/src/components/order-history/order-history-entry-host.component.ts +++ b/packages/admin-ui/src/lib/order/src/components/order-history/order-history-entry-host.component.ts @@ -1,6 +1,5 @@ import { Component, - ComponentFactoryResolver, ComponentRef, EventEmitter, Input, @@ -42,18 +41,14 @@ export class OrderHistoryEntryHostComponent implements OnInit, OnDestroy { instance: OrderHistoryEntryComponent; private componentRef: ComponentRef; - constructor( - private componentFactoryResolver: ComponentFactoryResolver, - private historyEntryComponentService: HistoryEntryComponentService, - ) {} + constructor(private historyEntryComponentService: HistoryEntryComponentService) {} ngOnInit(): void { const componentType = this.historyEntryComponentService.getComponent( this.entry.type, ) as Type; - const factory = this.componentFactoryResolver.resolveComponentFactory(componentType); - const componentRef = this.portalRef.createComponent(factory); + const componentRef = this.portalRef.createComponent(componentType); componentRef.instance.entry = this.entry; componentRef.instance.order = this.order; this.instance = componentRef.instance;