Skip to content

Commit

Permalink
fix(ui): put wizard showing in AfterViewInit to prevent undefined err…
Browse files Browse the repository at this point in the history
…or (#203)
  • Loading branch information
kosmoz authored Dec 20, 2024
1 parent c889d0c commit 3176dae
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {GlobalPositionStrategy} from '@angular/cdk/overlay';
import {AsyncPipe} from '@angular/common';
import {Component, inject, OnInit, TemplateRef, ViewChild} from '@angular/core';
import {AfterViewInit, Component, inject, OnInit, TemplateRef, ViewChild} from '@angular/core';
import {FaIconComponent} from '@fortawesome/angular-fontawesome';
import {faPlus} from '@fortawesome/free-solid-svg-icons';
import {combineLatest, first} from 'rxjs';
Expand Down Expand Up @@ -33,7 +33,7 @@ import {UsersService} from '../../services/users.service';
],
templateUrl: './dashboard-placeholder.component.html',
})
export class DashboardPlaceholderComponent implements OnInit {
export class DashboardPlaceholderComponent implements AfterViewInit {
private overlay = inject(OverlayService);
private readonly deploymentTargets = inject(DeploymentTargetsService);
public readonly deploymentTargets$ = this.deploymentTargets.list();
Expand All @@ -49,7 +49,7 @@ export class DashboardPlaceholderComponent implements OnInit {

protected readonly faPlus = faPlus;

ngOnInit() {
ngAfterViewInit() {
combineLatest([this.applications$])
.pipe(first())
.subscribe(([apps]) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {GlobalPositionStrategy} from '@angular/cdk/overlay';
import {AsyncPipe, DatePipe, NgOptimizedImage} from '@angular/common';
import {Component, inject, Input, OnDestroy, OnInit, TemplateRef, ViewChild} from '@angular/core';
import {AfterViewInit, Component, inject, Input, OnDestroy, OnInit, TemplateRef, ViewChild} from '@angular/core';
import {FormControl, FormGroup, FormsModule, ReactiveFormsModule, Validators} from '@angular/forms';
import {FaIconComponent} from '@fortawesome/angular-fontawesome';
import {faMagnifyingGlass, faPen, faPlus, faShip, faTrash, faXmark} from '@fortawesome/free-solid-svg-icons';
Expand Down Expand Up @@ -43,7 +43,7 @@ import {filteredByFormControl} from '../../util/filter';
standalone: true,
animations: [modalFlyInOut, drawerFlyInOut],
})
export class DeploymentTargetsComponent implements OnInit, OnDestroy {
export class DeploymentTargetsComponent implements AfterViewInit, OnDestroy {
public readonly auth = inject(AuthService);
private readonly toast = inject(ToastService);
@Input('fullVersion') fullVersion = false;
Expand Down Expand Up @@ -95,14 +95,13 @@ export class DeploymentTargetsComponent implements OnInit, OnDestroy {
}),
});

ngOnInit() {
ngAfterViewInit() {
if (this.fullVersion) {
const always = false;
const isCustomer = this.auth.getClaims().role === 'customer';
combineLatest([this.applications$, this.deploymentTargets$])
.pipe(first())
.subscribe(([apps, dts]) => {
if (always || (isCustomer && apps.length > 0 && dts.length === 0)) {
if (always || (this.auth.hasRole('customer') && apps.length > 0 && dts.length === 0)) {
this.openWizard();
}
});
Expand Down
2 changes: 2 additions & 0 deletions frontend/cloud-ui/src/app/services/overlay.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ export class OverlayService {
new TemplatePortal(templateRefOrComponentType, this.viewContainerRef, injector)
);
dialogRef.closed().subscribe(() => embeddedViewRef.destroy());
} else if (!templateRefOrComponentType) {
throw new Error('templateRefOrComponentType is ' + templateRefOrComponentType);
} else {
const componentRef = overlayRef.attach(new ComponentPortal(templateRefOrComponentType, null, injector));
dialogRef.closed().subscribe(() => componentRef.destroy());
Expand Down

0 comments on commit 3176dae

Please sign in to comment.