Browse Source

refactor(admin-ui): Remove usage of deprecated ComponentFactoryResolver

Michael Bromley 2 years ago
parent
commit
26f88b7257

+ 3 - 8
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<T> & Type<Dialog<R>>,
         options?: ModalOptions<T>,
     ): Observable<R | undefined> {
-        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<any> = modalComponentRef.instance;
                 modalInstance.childComponentType = component;
                 modalInstance.options = options;

+ 3 - 16
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<any>;
     @Output() create = new EventEmitter<any>();
 
-    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);
     }
 }

+ 2 - 7
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<CustomerHistoryEntryComponent>;
 
-    constructor(
-        private componentFactoryResolver: ComponentFactoryResolver,
-        private historyEntryComponentService: HistoryEntryComponentService,
-    ) {}
+    constructor(private historyEntryComponentService: HistoryEntryComponentService) {}
 
     ngOnInit(): void {
         const componentType = this.historyEntryComponentService.getComponent(
             this.entry.type,
         ) as Type<CustomerHistoryEntryComponent>;
 
-        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;

+ 1 - 7
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<any>;
 
-    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();
     }
 

+ 2 - 7
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<OrderHistoryEntryComponent>;
 
-    constructor(
-        private componentFactoryResolver: ComponentFactoryResolver,
-        private historyEntryComponentService: HistoryEntryComponentService,
-    ) {}
+    constructor(private historyEntryComponentService: HistoryEntryComponentService) {}
 
     ngOnInit(): void {
         const componentType = this.historyEntryComponentService.getComponent(
             this.entry.type,
         ) as Type<OrderHistoryEntryComponent>;
 
-        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;