Skip to content

Commit

Permalink
fix(core/reports): fix FROM_REPS function
Browse files Browse the repository at this point in the history
  • Loading branch information
robzan8 committed Jan 26, 2024
1 parent a464783 commit 992f9cf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
4 changes: 2 additions & 2 deletions projects/core/models/src/utils/expression-utils.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ The form's fields can be used inside expression.
Returns a clone of forms, where the specified fields are replaced by the corresponding labels,
as defined by the choice origins in schema.

`FROM_REPS(forms, expression)`
Returns the array obtained by evaluating expression for every repetition of form.
`FROM_REPS(form | forms, expression)`
Returns the array obtained by evaluating expression for every repetition of every input form.

`GET_LABELS(schema, values)`
Given an array of values, returns the corresponding array of labels,
Expand Down
15 changes: 12 additions & 3 deletions projects/core/models/src/utils/expression-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2020,15 +2020,24 @@ export function JOIN_REPEATING_SLIDES(
* Returns the array obtained by evaluating expression for every repetition of form.
*
* @export
* @param {MainForm} form
* @param {MainForm | MainForm[]} forms
* @param {string} expression
* @return {*} {any[]}
*/
export function FROM_REPS(form: MainForm, expression: Func | string): any[] {
export function FROM_REPS(forms: MainForm | MainForm[], expression: Func | string): any[] {
if (typeof expression === 'string') {
expression = createFunction(expression);
}
return allReps(form || {}).map(rep => (expression as Func)({...form, ...rep}));
if (forms == null) {
forms = [];
}
if (!Array.isArray(forms)) {
forms = [forms];
}
const func = expression;
return forms.map(
form => allReps(form || {}).map(rep => func({...form, ...rep}))
).flat();
}

/**
Expand Down

0 comments on commit 992f9cf

Please sign in to comment.