Skip to content

Commit

Permalink
refactor(admin-ui): Remove usage of deprecated ComponentFactoryResolver
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbromley committed Sep 6, 2023
1 parent 5f26a1e commit 26f88b7
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 45 deletions.
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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}
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {
Component,
ComponentFactoryResolver,
ComponentRef,
EventEmitter,
Input,
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ import {
AfterViewInit,
ChangeDetectionStrategy,
Component,
ComponentFactoryResolver,
ComponentRef,
Input,
OnDestroy,
OnInit,
ViewChild,
ViewContainerRef,
} from '@angular/core';
Expand All @@ -26,8 +24,6 @@ export class DashboardWidgetComponent implements AfterViewInit, OnDestroy {

private componentRef: ComponentRef<any>;

constructor(private componentFactoryResolver: ComponentFactoryResolver) {}

ngAfterViewInit(): void {
this.loadWidget();
}
Expand All @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {
Component,
ComponentFactoryResolver,
ComponentRef,
EventEmitter,
Input,
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 26f88b7

Please sign in to comment.