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)) { 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) => { this.subs.push(this.field.valueChanges$.pipe(debounceTime(500)).subscribe((data) => {
Object.keys(this.dependentFields).forEach(fieldKey => { Object.keys(this.dependentFields).forEach(fieldKey => {
const dependentField = this.dependentFields[fieldKey]; const dependentFieldKey = this.dependentFields[fieldKey];
const field = this.record.fields[fieldKey] || null; const field = this.record.fields[fieldKey] || null;
const dependentField = this.record.fields[dependentFieldKey.field] || null;
if (!field) { if (!field) {
return; return;
} }
if (this.field.previousValue != data.value) { if (this.field.previousValue != data.value) {
const types = dependentField.type ?? []; const types = dependentFieldKey.type ?? [];
if (types.includes('logic')) { 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')) { if (types.includes('displayLogic')) {

View file

@ -76,4 +76,9 @@ export class EmailPrimarySelectAction extends FieldLogicActionHandler {
emailField.formControl.updateValueAndValidity({onlySelf: true, emitEvent: true}); 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} mode
* @param {object} record * @param {object} record
* @param triggeringStatus * @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) { if (!field.logic) {
return; return;
} }
const actions = Object.keys(field.logic).map(key => field.logic[key]); 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 = { const context = {
record, record,
field, field,
@ -147,7 +148,7 @@ export class FieldLogicManager extends BaseActionManager<FieldLogicActionData> {
* @param mode * @param mode
* @param triggeringStatus * @param triggeringStatus
*/ */
protected parseModeActions(declaredActions: Action[], mode: ViewMode, triggeringStatus: string) { protected parseModeActions(declaredActions: Action[], mode: ViewMode, triggeringStatus: string, fieldDependent: Field) {
if (!declaredActions) { if (!declaredActions) {
return []; return [];
} }
@ -181,10 +182,21 @@ export class FieldLogicManager extends BaseActionManager<FieldLogicActionData> {
availableActions[mode].forEach(action => { availableActions[mode].forEach(action => {
const frontendActionTriggeringStatus = this?.actions[mode][action.key]?.getTriggeringStatus() ?? null; const dependentFieldsKeys = Object.keys(action?.params?.activeOnFields ?? {});
const actionTriggeringStatus = action?.triggeringStatus ?? frontendActionTriggeringStatus ?? defaultTriggeringStatus;
if(triggeringStatus && !actionTriggeringStatus.includes(triggeringStatus)) { const frontendActionTriggeringStatus = this?.actions[mode][action.key]?.getTriggeringStatus() ?? null;
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; return;
} }