RED-7116, change redirect so it wouldnt cause a loop, prevent double navigations.

This commit is contained in:
George 2023-07-18 11:25:27 +03:00
parent d3ac14497d
commit 66662a0314

View File

@ -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<Class extends IListable<PrimaryKey>, PrimaryK
private _lastScrolledIndex = 0;
private _multiSelectActive$ = new BehaviorSubject(false);
readonly #navigationEvents = new BehaviorSubject<string>('');
readonly #tenantsService = inject(TenantsService);
readonly #router = inject(Router);
#navigationInProgress = false;
constructor(
@Inject(forwardRef(() => ListingComponent)) readonly listingComponent: ListingComponent<Class>,
@ -48,16 +47,6 @@ export class TableContentComponent<Class extends IListable<PrimaryKey>, 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<Class extends IListable<PrimaryKey>, 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;
}
}