libs/core/devtools/src/lib/debugger/dynamic-form-debugger/dynamic-form-debugger.service.ts
No results matching.
Methods |
| getActions | ||||||
getActions(buildingBlock: AbstractBuildingBlock<DynamicFormBbState | DynamicFormBbResources>)
|
||||||
|
Parameters :
Returns :
Signal<Array<DynamicFormDebuggerAction>>
|
| registerAction | ||||||
registerAction(action: DynamicFormDebuggerAction)
|
||||||
|
Parameters :
Returns :
void
|
import { AbstractBuildingBlock } from '@allianz/taly-core/building-blocks';
import { computed, Injectable, Signal, signal } from '@angular/core';
// TODO Use DynamicFormBbResources and DynamicFormBbState from dynamic-form-bb.model.ts
// once https://github.developer.allianz.io/ilt/taly-workspace/issues/3211 is implemented
// replace the any with DynamicFormConfiguration as well
export interface DynamicFormBbResources {
talyDynamicFormConfig?: any;
}
export type DynamicFormBbState = Record<string, unknown> | undefined;
export type DfDebuggerContext = 'pageBlock' | 'globalSidebar';
export type DynamicFormDebuggerAction = {
/**
* Unique identifier for the action
*/
id: string;
/**
* Label to display in the button
*/
label: string;
/**
* Callback to execute when the action is triggered
* @param buildingBlock
* @param context where the building block is rendered
*/
callback: (
buildingBlock: AbstractBuildingBlock<DynamicFormBbState, DynamicFormBbResources>,
context: DfDebuggerContext
) => void;
};
@Injectable()
export class DynamicFormDebuggerService {
private actions = signal<Array<DynamicFormDebuggerAction>>([]);
getActions(
buildingBlock: AbstractBuildingBlock<DynamicFormBbState, DynamicFormBbResources>
): Signal<Array<DynamicFormDebuggerAction>> {
return computed(() =>
this.actions().filter(() => !!buildingBlock.resources?.talyDynamicFormConfig)
);
}
registerAction(action: DynamicFormDebuggerAction) {
if (this.actions().some((registeredAction) => registeredAction.id === action.id)) {
return;
}
this.actions.update((actions) => actions.concat(action));
}
}