Skip to content

Commit

Permalink
fix: componentType can be undefined (onecx#208)
Browse files Browse the repository at this point in the history
* fix: ocxSrc directive with external image url, ocx slots

* fix: loading remote component

* fix: lint issues

* fix: componentType may be undefined

---------

Co-authored-by: kim.tran <[email protected]>
  • Loading branch information
KimFFVII and kim.tran authored Apr 8, 2024
1 parent eb5294d commit eb80995
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ export class SlotComponent implements OnInit, OnDestroy {

subscription: Subscription | undefined
components$:
| Observable<{ componentType: Type<unknown>; remoteComponent: RemoteComponentInfo; permissions: string[] }[]>
| Observable<
{ componentType: Type<unknown> | undefined; remoteComponent: RemoteComponentInfo; permissions: string[] }[]
>
| undefined

constructor(@Inject(SLOT_SERVICE) private slotService: SlotService) {}
Expand All @@ -40,16 +42,18 @@ export class SlotComponent implements OnInit, OnDestroy {
([viewContainers, components]) => {
if (viewContainers && viewContainers.length === components.length) {
components.forEach((componentInfo, i) => {
const componentRef = viewContainers.get(i)?.createComponent<any>(componentInfo.componentType)
if (componentRef && 'ocxInitRemoteComponent' in componentRef.instance) {
;(componentRef.instance as ocxRemoteComponent).ocxInitRemoteComponent({
appId: componentInfo.remoteComponent.appId,
productName: componentInfo.remoteComponent.productName,
baseUrl: componentInfo.remoteComponent.baseUrl,
permissions: componentInfo.permissions,
})
if (componentInfo.componentType) {
const componentRef = viewContainers.get(i)?.createComponent<any>(componentInfo.componentType)
if (componentRef && 'ocxInitRemoteComponent' in componentRef.instance) {
;(componentRef.instance as ocxRemoteComponent).ocxInitRemoteComponent({
appId: componentInfo.remoteComponent.appId,
productName: componentInfo.remoteComponent.productName,
baseUrl: componentInfo.remoteComponent.baseUrl,
permissions: componentInfo.permissions,
})
}
componentRef?.changeDetectorRef.detectChanges()
}
componentRef?.changeDetectorRef.detectChanges()
})
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@ export interface SlotService {
init(): Promise<void>
getComponentsForSlot(
slotName: string
): Observable<{ componentType: Type<unknown>; remoteComponent: RemoteComponentInfo; permissions: string[] }[]>
): Observable<
{ componentType: Type<unknown> | undefined; remoteComponent: RemoteComponentInfo; permissions: string[] }[]
>
}

0 comments on commit eb80995

Please sign in to comment.