From 66662a0314add0e9a2cff154e1370488f858d0d6 Mon Sep 17 00:00:00 2001 From: George Date: Tue, 18 Jul 2023 11:25:27 +0300 Subject: [PATCH] RED-7116, change redirect so it wouldnt cause a loop, prevent double navigations. --- .../table-content/table-content.component.ts | 23 ++++++------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/src/lib/listing/table-content/table-content.component.ts b/src/lib/listing/table-content/table-content.component.ts index 1a2b110..d938179 100644 --- a/src/lib/listing/table-content/table-content.component.ts +++ b/src/lib/listing/table-content/table-content.component.ts @@ -1,14 +1,13 @@ /* eslint-disable @angular-eslint/prefer-on-push-component-change-detection */ import { AfterViewInit, Component, forwardRef, HostListener, inject, Inject, Input, OnDestroy, Optional, ViewChild } from '@angular/core'; import { CdkVirtualScrollViewport } from '@angular/cdk/scrolling'; -import { delay, filter, switchMap, tap, throttleTime } from 'rxjs/operators'; +import { delay, tap } from 'rxjs/operators'; import { AutoUnsubscribe, trackByFactory } from '../../utils'; import { Id, IListable } from '../models'; import { ListingComponent, ListingService } from '../index'; import { BehaviorSubject } from 'rxjs'; import { HelpModeService } from '../../help-mode'; import { HasScrollbarDirective } from '../../directives'; -import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; import { TenantsService } from '../../tenants'; import { Router } from '@angular/router'; @@ -33,9 +32,9 @@ export class TableContentComponent, PrimaryK private _lastScrolledIndex = 0; private _multiSelectActive$ = new BehaviorSubject(false); - readonly #navigationEvents = new BehaviorSubject(''); readonly #tenantsService = inject(TenantsService); readonly #router = inject(Router); + #navigationInProgress = false; constructor( @Inject(forwardRef(() => ListingComponent)) readonly listingComponent: ListingComponent, @@ -48,16 +47,6 @@ export class TableContentComponent, PrimaryK this.scrollViewport?.checkViewportSize(); }, 0); }); - this.#navigationEvents - .asObservable() - .pipe( - filter(Boolean), - throttleTime(1000), - switchMap(route => this.#router.navigateByUrl(route)), - takeUntilDestroyed(), - ) - // eslint-disable-next-line rxjs/no-ignored-subscription - .subscribe(); } multiSelect(entity: Class, $event: MouseEvent): void { @@ -110,8 +99,10 @@ export class TableContentComponent, PrimaryK this._multiSelectActive$.next(false); } - initiateNavigation(routerLink: string | undefined) { - if (!routerLink) return; - this.#navigationEvents.next('/' + this.#tenantsService.activeTenantId + routerLink); + async initiateNavigation(routerLink: string | undefined) { + if (!routerLink || this.#navigationInProgress) return; + this.#navigationInProgress = true; + await this.#router.navigateByUrl('/' + this.#tenantsService.activeTenantId + routerLink); + this.#navigationInProgress = false; } }