libs/pfe-connector/src/lib/pfe-runtime-facade.ts

Extends

PFEFacade

Relationships

Used by

No results matching.

Depends on

Index

Properties
Methods

Constructor

constructor(buildingBlock: BuildingBlockInterface, pfeBusinessService: PfeBusinessService, buildingBlockMetaService: BuildingBlockMetaService, frameNavigationService: TalyFrameNavigationService, pfeResourcesService: TalyResourcesService, businessEventService: TalyBusinessEventService, aclService: AclService, pfeTrackingService: PfeTrackingService | null, talyValidationService: TalyValidationService, runtimeConfigService: PfeRuntimeConfigService, navigationService: PfeNavigationService, injector: Injector)
Parameters :
Name Type Optional
buildingBlock BuildingBlockInterface No
pfeBusinessService PfeBusinessService No
buildingBlockMetaService BuildingBlockMetaService No
frameNavigationService TalyFrameNavigationService No
pfeResourcesService TalyResourcesService No
businessEventService TalyBusinessEventService No
aclService AclService No
pfeTrackingService PfeTrackingService | null No
talyValidationService TalyValidationService No
runtimeConfigService PfeRuntimeConfigService No
navigationService PfeNavigationService No
injector Injector No

Properties

stateChangesObservable
Type : Observable<unknown>
Inherited from PFEFacade
_isConnected
Type : unknown
Default value : false
connected$
Type : unknown
Default value : new Subject<void>()
disconnected$
Type : unknown
Default value : new Subject<void>()

Methods

connect
connect()
Returns : void
cleanupValidationHandling
cleanupValidationHandling(form: UntypedFormGroup)
Parameters :
Name Type Optional
form UntypedFormGroup No
Returns : void
disconnect
disconnect()
Returns : void
Static create
create(block: BuildingBlockInterface)
Parameters :
Name Type Optional
block BuildingBlockInterface No
markFormGroupAsTouched
markFormGroupAsTouched()
Returns : void
import { PfeBusinessService, PfeNavigationService } from '@allianz/ngx-pfe';
import { PfeTrackingService } from '@allianz/ngx-pfe/tracking';
import { AclService } from '@allianz/taly-acl/angular';
import { TalyValidationService, TalyBusinessEventService } from '@allianz/taly-core';
import {
  BuildingBlockInterface,
  BuildingBlockMetaService,
  TalyResourcesService
} from '@allianz/taly-core/building-blocks';
import { trackForm } from '@allianz/taly-core/form-tracking';
import { TalyFrameNavigationService } from '@allianz/taly-core/frame';
import { isDynamicFormBbConfig } from '@allianz/taly-core/schemas';
import { computed, Injector, Signal } from '@angular/core';
import { toObservable } from '@angular/core/rxjs-interop';
import { filter, skip, takeUntil } from 'rxjs';
import { PFEFacade } from './pfe-facade';
import { PfeRuntimeConfigService } from './runtime-utils/pfe-runtime-config/pfe-runtime-config.service';

export class PFERuntimeFacade extends PFEFacade {
  constructor(
    buildingBlock: BuildingBlockInterface,
    pfeBusinessService: PfeBusinessService,
    buildingBlockMetaService: BuildingBlockMetaService,
    frameNavigationService: TalyFrameNavigationService,
    pfeResourcesService: TalyResourcesService,
    businessEventService: TalyBusinessEventService,
    aclService: AclService,
    pfeTrackingService: PfeTrackingService | null,
    talyValidationService: TalyValidationService,
    private runtimeConfigService: PfeRuntimeConfigService,
    private navigationService: PfeNavigationService,
    private injector: Injector
  ) {
    super(
      buildingBlock,
      pfeBusinessService,
      buildingBlockMetaService,
      frameNavigationService,
      pfeResourcesService,
      businessEventService,
      aclService,
      pfeTrackingService,
      talyValidationService
    );
  }

  override connect() {
    const dynamicFormBbRawResources = this.getDynamicFormBbRawResources();
    // If not a Dynamic Form Building Block, connect through PFEFacade instead
    if (!dynamicFormBbRawResources()) {
      super.connect();
      return;
    }

    console.log(`✅ PFE Runtime Facade connecting Building Block '${this.buildingBlock.id}'`);

    const form = this.buildingBlock.getForm();
    if (form && this.pfeTrackingService) {
      trackForm(
        form,
        this.buildingBlock.id,
        this.disconnected$,
        this.pfeTrackingService.pushEvent.bind(this.pfeTrackingService)
      );
    }

    this.buildingBlock.setRawResources(dynamicFormBbRawResources());
    this.handleStateAndConnect();

    toObservable(dynamicFormBbRawResources, { injector: this.injector })
      .pipe(
        skip(1),
        filter((resources) => Boolean(resources)),
        takeUntil(this.disconnected$)
      )
      .subscribe((resources) => this.buildingBlock.setRawResources(resources));
  }

  private getDynamicFormBbRawResources(): Signal<Record<string, unknown> | undefined> {
    return computed(() => {
      const pagesConfig = this.runtimeConfigService.pagesConfig();
      const pageId = this.navigationService.currentPageId$.value;
      const currentPageConfig = pagesConfig.pages?.find((page) => page.id === pageId);
      const sidebarBlocks = (pagesConfig.frame?.globalSidebar?.tabs ?? []).flatMap(
        (tab) => tab.blocks ?? []
      );
      const blockConfig = [...(currentPageConfig?.blocks ?? []), ...sidebarBlocks].find(
        (block) => block.id === this.buildingBlock.id
      );

      if (!isDynamicFormBbConfig(blockConfig)) {
        return undefined;
      }

      return {
        talyDynamicFormConfig: blockConfig.form
      };
    });
  }
}

results matching ""

    No results matching ""