Browse Source

Merge pull request #23458 from SecTex/angular-dynamic-layout

Fix DynamicLayoutComponent Initialization for Remote Environment Configurations and Remove Non-Null Assertion
pull/23690/head
sumeyye 1 year ago
committed by GitHub
parent
commit
c7750f6c91
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 34
      npm/ng-packs/packages/core/src/lib/components/dynamic-layout.component.ts

34
npm/ng-packs/packages/core/src/lib/components/dynamic-layout.component.ts

@ -1,4 +1,4 @@
import { Component, inject, isDevMode, OnInit, Type } from '@angular/core'; import { Component, inject, isDevMode, Type } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router'; import { ActivatedRoute, Router } from '@angular/router';
import { eLayoutType } from '../enums/common'; import { eLayoutType } from '../enums/common';
import { ABP } from '../models'; import { ABP } from '../models';
@ -13,6 +13,7 @@ import { TreeNode } from '../utils/tree-utils';
import { DYNAMIC_LAYOUTS_TOKEN } from '../tokens/dynamic-layout.token'; import { DYNAMIC_LAYOUTS_TOKEN } from '../tokens/dynamic-layout.token';
import { EnvironmentService } from '../services'; import { EnvironmentService } from '../services';
import { NgComponentOutlet } from '@angular/common'; import { NgComponentOutlet } from '@angular/common';
import { filter, take } from 'rxjs';
@Component({ @Component({
selector: 'abp-dynamic-layout', selector: 'abp-dynamic-layout',
@ -24,7 +25,7 @@ import { NgComponentOutlet } from '@angular/common';
providers: [SubscriptionService], providers: [SubscriptionService],
imports: [NgComponentOutlet], imports: [NgComponentOutlet],
}) })
export class DynamicLayoutComponent implements OnInit { export class DynamicLayoutComponent {
layout?: Type<any>; layout?: Type<any>;
layoutKey?: eLayoutType; layoutKey?: eLayoutType;
readonly layouts = inject(DYNAMIC_LAYOUTS_TOKEN); readonly layouts = inject(DYNAMIC_LAYOUTS_TOKEN);
@ -40,7 +41,7 @@ export class DynamicLayoutComponent implements OnInit {
protected readonly environment = inject(EnvironmentService); protected readonly environment = inject(EnvironmentService);
constructor() { constructor() {
const dynamicLayoutComponent = inject(DynamicLayoutComponent, { optional: true, skipSelf: true })!; const dynamicLayoutComponent = inject(DynamicLayoutComponent, { optional: true, skipSelf: true });
if (dynamicLayoutComponent) { if (dynamicLayoutComponent) {
if (isDevMode()) console.warn('DynamicLayoutComponent must be used only in AppComponent.'); if (isDevMode()) console.warn('DynamicLayoutComponent must be used only in AppComponent.');
@ -48,17 +49,7 @@ export class DynamicLayoutComponent implements OnInit {
} }
this.checkLayoutOnNavigationEnd(); this.checkLayoutOnNavigationEnd();
this.listenToLanguageChange(); this.listenToLanguageChange();
} this.listenToEnvironmentChange();
ngOnInit(): void {
if (this.layout) {
return;
}
const { oAuthConfig } = this.environment.getEnvironment();
if (oAuthConfig.responseType === 'code') {
this.getLayout();
}
} }
private checkLayoutOnNavigationEnd() { private checkLayoutOnNavigationEnd() {
@ -120,4 +111,19 @@ export class DynamicLayoutComponent implements OnInit {
private getComponent(key: string): ReplaceableComponents.ReplaceableComponent | undefined { private getComponent(key: string): ReplaceableComponents.ReplaceableComponent | undefined {
return this.replaceableComponents.get(key); return this.replaceableComponents.get(key);
} }
private listenToEnvironmentChange() {
this.environment
.createOnUpdateStream(x => x.oAuthConfig)
.pipe(
take(1),
filter(config => config.responseType === 'code'),
)
.subscribe(() => {
if (this.layout) {
return;
}
this.getLayout();
});
}
} }

Loading…
Cancel
Save