Fix #478 - Add new trigger status check 'onDependencyChange'

- add trigger to email select action
This commit is contained in:
Jack Anderson 2024-09-18 08:09:57 +01:00 committed by y.yerli
parent 3adb99624d
commit 39881bceb6
3 changed files with 27 additions and 9 deletions

View file

@ -146,17 +146,18 @@ export class BaseFieldComponent implements FieldComponentInterface, OnInit, OnDe
if (this.field.valueChanges$ && ((this.dependentFields && Object.keys(this.dependentFields).length) || this.dependentAttributes.length)) {
this.subs.push(this.field.valueChanges$.pipe(debounceTime(500)).subscribe((data) => {
Object.keys(this.dependentFields).forEach(fieldKey => {
const dependentField = this.dependentFields[fieldKey];
const dependentFieldKey = this.dependentFields[fieldKey];
const field = this.record.fields[fieldKey] || null;
const dependentField = this.record.fields[dependentFieldKey.field] || null;
if (!field) {
return;
}
if (this.field.previousValue != data.value) {
const types = dependentField.type ?? [];
const types = dependentFieldKey.type ?? [];
if (types.includes('logic')) {
this.logic.runLogic(field, this.originalMode as ViewMode, this.record, 'onValueChange');
this.logic.runLogic(field, this.originalMode as ViewMode, this.record, 'onDependencyChange', dependentField);
}
if (types.includes('displayLogic')) {

View file

@ -76,4 +76,9 @@ export class EmailPrimarySelectAction extends FieldLogicActionHandler {
emailField.formControl.updateValueAndValidity({onlySelf: true, emitEvent: true});
}
}
getTriggeringStatus(): string[] {
return ['onFieldInitialize'];
}
}

View file

@ -84,15 +84,16 @@ export class FieldLogicManager extends BaseActionManager<FieldLogicActionData> {
* @param {object} mode
* @param {object} record
* @param triggeringStatus
* @param dependentField
*/
runLogic(field: Field, mode: ViewMode, record: Record, triggeringStatus: string = ''): void {
runLogic(field: Field, mode: ViewMode, record: Record, triggeringStatus: string = '', dependentField: Field = {} as Field): void {
if (!field.logic) {
return;
}
const actions = Object.keys(field.logic).map(key => field.logic[key]);
const modeActions = this.parseModeActions(actions, mode, triggeringStatus);
const modeActions = this.parseModeActions(actions, mode, triggeringStatus, dependentField);
const context = {
record,
field,
@ -147,7 +148,7 @@ export class FieldLogicManager extends BaseActionManager<FieldLogicActionData> {
* @param mode
* @param triggeringStatus
*/
protected parseModeActions(declaredActions: Action[], mode: ViewMode, triggeringStatus: string) {
protected parseModeActions(declaredActions: Action[], mode: ViewMode, triggeringStatus: string, fieldDependent: Field) {
if (!declaredActions) {
return [];
}
@ -181,13 +182,24 @@ export class FieldLogicManager extends BaseActionManager<FieldLogicActionData> {
availableActions[mode].forEach(action => {
const dependentFieldsKeys = Object.keys(action?.params?.activeOnFields ?? {});
const frontendActionTriggeringStatus = this?.actions[mode][action.key]?.getTriggeringStatus() ?? null;
const actionTriggeringStatus = action?.triggeringStatus ?? frontendActionTriggeringStatus ?? defaultTriggeringStatus;
let actionTriggeringStatus = action?.triggeringStatus ?? frontendActionTriggeringStatus ?? defaultTriggeringStatus;
if (triggeringStatus && !actionTriggeringStatus.includes(triggeringStatus)) {
return;
}
if (actionTriggeringStatus.includes('onValueChange')) {
actionTriggeringStatus = ['onAnyLogic'];
}
if (actionTriggeringStatus.includes('onDependencyChange') && !dependentFieldsKeys?.includes(fieldDependent.name)) {
return;
}
actions.push(action);
});