libs/pfe-connector/src/lib/runtime-utils/dynamic-building-block-meta-service/dynamic-building-block-meta-service.ts
This is a dynamic version of the BuildingBlockMetaService. It enables the Runtime Mode to trigger events out of Dynamic Forms.
See the original BuildingBlockMetaService implementation for more details on the functionality.
| providedIn | any |
No results matching.
Methods |
| getBusinessEvents | ||||||
getBusinessEvents(buildingBlockId: string)
|
||||||
|
Parameters :
Returns :
any
|
| getData | ||||||
getData(buildingBlockId: string)
|
||||||
|
Parameters :
Returns :
any
|
| getNavigationData | ||||||
getNavigationData(buildingBlockId: string)
|
||||||
|
Parameters :
Returns :
{}
|
| getResources | ||||||
getResources(buildingBlockId: string)
|
||||||
|
Parameters :
Returns :
undefined
|
| hasData | |||||||||
hasData(buildingBlockId: string, key: string | number | symbol)
|
|||||||||
|
Parameters :
Returns :
boolean
|
| hasMetaData | ||||||
hasMetaData(id: string)
|
||||||
|
Parameters :
Returns :
boolean
|
| hasResources | ||||||
hasResources(id: string)
|
||||||
|
Parameters :
Returns :
boolean
|
import { PfeNavigationService } from '@allianz/ngx-pfe';
import {
type BuildingBlockMetaData,
type BuildingBlockMetaServiceInterface
} from '@allianz/taly-core/building-blocks';
import { type BusinessEventConfig } from '@allianz/taly-core';
import { isDynamicFormBbConfig } from '@allianz/taly-core/schemas';
import { inject, Injectable } from '@angular/core';
import { PfeRuntimeConfigService } from '../pfe-runtime-config/pfe-runtime-config.service';
/**
* This is a dynamic version of the BuildingBlockMetaService.
* It enables the Runtime Mode to trigger events out of Dynamic Forms.
*
* See the original BuildingBlockMetaService implementation for more details on the functionality.
*/
@Injectable({
providedIn: 'any'
})
export class DynamicBuildingBlockMetaService implements BuildingBlockMetaServiceInterface {
private pfeNavigationService = inject(PfeNavigationService);
private runtimeConfigService = inject(PfeRuntimeConfigService);
getData(buildingBlockId: string) {
const currentPageConfig = this.runtimeConfigService
.pagesConfig()
.pages?.find((page) => page.id === this.pfeNavigationService.currentPageId$.value);
const blockConfig = currentPageConfig?.blocks?.find((block) => block.id === buildingBlockId);
if (blockConfig) {
return blockConfig;
} else {
throw new Error(
`Could not find block with id ${buildingBlockId} in current page configuration`
);
}
}
hasData(buildingBlockId: string, key: keyof BuildingBlockMetaData) {
return false;
}
getResources(buildingBlockId: string) {
return undefined;
}
getBusinessEvents(buildingBlockId: string) {
const block = this.getData(buildingBlockId);
if (isDynamicFormBbConfig(block)) {
const businessEvents = block.form.fields.reduce(
(acc: Record<string, BusinessEventConfig>, fieldConfig) => {
/**
* The implementation must be synced with the libs/sdk/src/lib/journey/transform/transform.ts
*/
let configWithMaybeEventConfig;
if (fieldConfig.type === 'CUSTOM_COMPONENT') {
configWithMaybeEventConfig = fieldConfig.config;
if (!configWithMaybeEventConfig) return acc;
} else {
configWithMaybeEventConfig = fieldConfig;
}
Object.entries(configWithMaybeEventConfig).forEach(
([maybeEventName, maybeEventConfig]) => {
if (!isBusinessEventConfigType(maybeEventConfig)) return;
const businessEventId = `${fieldConfig.id}.${maybeEventName}`;
acc[businessEventId] = maybeEventConfig;
}
);
return acc;
},
{}
);
return businessEvents;
}
return {};
}
getNavigationData(buildingBlockId: string) {
return {};
}
hasResources(id: string) {
return false;
}
hasMetaData(id: string) {
return false;
}
}
function isBusinessEventConfigType(config: unknown): config is BusinessEventConfig {
return Boolean(config && typeof config === 'object' && 'handlerType' in config);
}