Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #563 - rewrote runAll() of FieldLogicDisplayManager class #564

Open
wants to merge 1 commit into
base: hotfix
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,55 +43,42 @@ export class FieldLogicDisplayManager extends BaseActionManager<FieldLogicDispla
}

runAll(field: Field, record: Record, mode: ViewMode): void {
let toDisplay: DisplayType = 'show';

if(!field.displayLogic) {
if (!field.displayLogic) {
return;
}

const validModeLogic = Object.values(field.displayLogic).filter(logic => {
// 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 {
Expand Down