From d29f9a22fd2f5f8fc3fad2f2913c3bf34ac6c937 Mon Sep 17 00:00:00 2001 From: tom Date: Tue, 29 Oct 2024 11:06:25 +1100 Subject: [PATCH] * Fix #563 - rewrote runAll() of FieldLogicDisplayManager class - use ['params']['targetDisplayType'] of display logic for setting targetDisplay - handle the case where there are multiple display logics in terms of deciding targetDisplay value for field.display eventually. --- .../field-logic-display.manager.ts | 55 +++++++------------ 1 file changed, 21 insertions(+), 34 deletions(-) diff --git a/core/app/core/src/lib/fields/field-logic-display/field-logic-display.manager.ts b/core/app/core/src/lib/fields/field-logic-display/field-logic-display.manager.ts index 49b6639d30..e6090d8edc 100644 --- a/core/app/core/src/lib/fields/field-logic-display/field-logic-display.manager.ts +++ b/core/app/core/src/lib/fields/field-logic-display/field-logic-display.manager.ts @@ -43,55 +43,42 @@ export class FieldLogicDisplayManager extends BaseActionManager { + // 1. Set default display + const defaultDisplay: DisplayType = (field.defaultDisplay ?? "show") as DisplayType; + + // 2. Set target display + let targetDisplay: DisplayType = null; + + // 2-1. Get valid mode logics - only the mode logics relevant to the current 'mode' + const validModeLogics = Object.values(field.displayLogic).filter(logic => { const allowedModes = logic['modes'] ?? []; return !!(allowedModes.length && allowedModes.includes(mode)); }); - - if (!validModeLogic || !validModeLogic.length) { - field.display = toDisplay; + if (validModeLogics.length === 0) { return; } - let defaultDisplay = field.defaultDisplay ?? 'show'; - - let targetDisplay: DisplayType = 'none'; - - if (defaultDisplay === 'none') { - targetDisplay = 'show'; - } - + // 2-2. Set target display by applying the valid mode logics const context = { record, field, module: record.module - } as ActionContext; - - - const isActive = validModeLogic.some(logic => { - const data: FieldLogicDisplayActionData = this.buildActionData(logic, context); - return this.actions[mode][logic.key].run(data, logic); - }); - - if (isActive) { - defaultDisplay = targetDisplay; - + } as ActionContext; + for (const modeLogic of validModeLogics) { + const data: FieldLogicDisplayActionData = this.buildActionData(modeLogic, context); + const isModeLogicActive: boolean = Boolean(this.actions[mode][modeLogic.key].run(data, modeLogic)); + // Take targetDisplayType of the last mode logic by overwriting targetDisplay in case there are multiple active mode logics + if (isModeLogicActive) { + targetDisplay = modeLogic['params']['targetDisplayType']; + } } - toDisplay = defaultDisplay as DisplayType; - - if (defaultDisplay === 'show') { - toDisplay = 'show'; - } - - field.display = toDisplay; - + // 3. Set field display + field.display = targetDisplay === null ? defaultDisplay : targetDisplay; } protected buildActionData(action: Action, context?: ActionContext): FieldLogicDisplayActionData {