File

libs/pfe-connector/src/lib/frame/pfe-frame-top-area.service.ts

Extends

TalyFrameTopAreaService

Index

Properties
Methods

Constructor

constructor(pfeBusinessService: PfeBusinessService, pfeConditionsService: PfeConditionsService, pfeStateService: PfeStateService)
Parameters :
Name Type Optional
pfeBusinessService PfeBusinessService No
pfeConditionsService PfeConditionsService No
pfeStateService PfeStateService No

Methods

Public getNotificationVisibility$
getNotificationVisibility$(visibleIf: string | undefined)
Inherited from TalyFrameTopAreaService
Parameters :
Name Type Optional
visibleIf string | undefined No
Returns : Observable<boolean>
Public getObservableForStateKey$
getObservableForStateKey$(stateKey: string)
Inherited from TalyFrameTopAreaService
Parameters :
Name Type Optional
stateKey string No
Returns : Observable<any>

Properties

networkErrorMessage$
Default value : this._networkErrorMessage$.asObservable()
Inherited from TalyFrameTopAreaService
import {
  ExpressionCondition,
  JSON_PATH_REGEX,
  PfeBusinessService,
  PfeConditionsService,
  PfeStateService
} from '@allianz/ngx-pfe';
import { TalyFrameTopAreaService } from '@allianz/taly-common/frame';
import { Injectable } from '@angular/core';
import { Observable, merge, of } from 'rxjs';
import { map, tap } from 'rxjs/operators';

@Injectable()
export class PfeFrameTopAreaService extends TalyFrameTopAreaService {
  constructor(
    private pfeBusinessService: PfeBusinessService,
    private pfeConditionsService: PfeConditionsService,
    private pfeStateService: PfeStateService
  ) {
    super();

    this.pfeBusinessService.errorMessage$
      .pipe(
        tap((message) => {
          this._networkErrorMessage$.next(message);
        })
      )
      .subscribe();
  }

  public getNotificationVisibility$(visibleIf: string | undefined): Observable<boolean> {
    if (!visibleIf) {
      return of(true);
    } else if (JSON_PATH_REGEX.test(visibleIf)) {
      return this.getObservableForResolvedPfeExpressionCondition(visibleIf);
    } else {
      return this.getObservableForStateKey$(visibleIf).pipe(map(Boolean));
    }
  }

  // eslint-disable-next-line @typescript-eslint/no-explicit-any
  public getObservableForStateKey$(stateKey: string): Observable<any> {
    return this.pfeBusinessService.getObservableForExpressionKey(stateKey, true);
  }

  private getObservableForResolvedPfeExpressionCondition(
    expressionCondition: string
  ): Observable<boolean> {
    const condition: ExpressionCondition[] = [{ expression: expressionCondition }];
    // get all property keys which are in curly brackets (e.g. "{$.key1} == {$.key2}" => ["$.key1", "$.key2"])
    const propertyKeys =
      expressionCondition.match(JSON_PATH_REGEX)?.map((match) => match.slice(1, -1)) || [];

    return merge(
      ...propertyKeys.map((key) => this.pfeBusinessService.getObservableForExpressionKey(key, true))
    ).pipe(
      map(() =>
        this.pfeConditionsService.evaluateConditions(condition, this.pfeStateService.getFullState())
      )
    );
  }
}

results matching ""

    No results matching ""