- added try-catch, wrapped for getTokens;
This commit is contained in:
@@ -574,12 +574,17 @@ const BandoApplication = () => {
|
|||||||
const formula = head(o.settings.filter(o => o.name === 'formula'));
|
const formula = head(o.settings.filter(o => o.name === 'formula'));
|
||||||
|
|
||||||
if (formula && !isEmpty(formula.value)) {
|
if (formula && !isEmpty(formula.value)) {
|
||||||
|
try {
|
||||||
context = getTokens(formula.value)
|
context = getTokens(formula.value)
|
||||||
.filter(v => !['false', 'null', 'true'].includes(v))
|
.filter(v => !['false', 'null', 'true'].includes(v))
|
||||||
.reduce((acc, cur) => {
|
.reduce((acc, cur) => {
|
||||||
acc[cur] = isNil(context[cur]) ? 0 : parseCommaDecimal(context[cur]);
|
acc[cur] = isNil(context[cur]) ? 0 : parseCommaDecimal(context[cur]);
|
||||||
return acc;
|
return acc;
|
||||||
}, context);
|
}, context);
|
||||||
|
} catch {
|
||||||
|
console.error('Error in formula', formula)
|
||||||
|
context = {}
|
||||||
|
}
|
||||||
|
|
||||||
const mathFormula = renderWithDataVars(formula.value, context);
|
const mathFormula = renderWithDataVars(formula.value, context);
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -288,12 +288,17 @@ const BandoApplicationPreview = () => {
|
|||||||
const formula = head(o.settings.filter(o => o.name === 'formula'));
|
const formula = head(o.settings.filter(o => o.name === 'formula'));
|
||||||
|
|
||||||
if (formula && !isEmpty(formula.value)) {
|
if (formula && !isEmpty(formula.value)) {
|
||||||
|
try {
|
||||||
context = getTokens(formula.value)
|
context = getTokens(formula.value)
|
||||||
.filter(v => !['false', 'null', 'true'].includes(v))
|
.filter(v => !['false', 'null', 'true'].includes(v))
|
||||||
.reduce((acc, cur) => {
|
.reduce((acc, cur) => {
|
||||||
acc[cur] = isNil(context[cur]) ? 0 : parseCommaDecimal(context[cur]);
|
acc[cur] = isNil(context[cur]) ? 0 : parseCommaDecimal(context[cur]);
|
||||||
return acc;
|
return acc;
|
||||||
}, context);
|
}, context);
|
||||||
|
} catch {
|
||||||
|
console.error('Error in formula', formula)
|
||||||
|
context = {}
|
||||||
|
}
|
||||||
const mathFormula = renderWithDataVars(formula.value, context);
|
const mathFormula = renderWithDataVars(formula.value, context);
|
||||||
try {
|
try {
|
||||||
updatedFormValues[o.id] = evaluate(mathFormula);
|
updatedFormValues[o.id] = evaluate(mathFormula);
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import ElementSettingTableColumnsForCsv from '../ElementSettingTableColumnsForCs
|
|||||||
import { mimeTypes } from '../../../../../../configData';
|
import { mimeTypes } from '../../../../../../configData';
|
||||||
import ElementSettingReportHeader from '../ElementSettingReportHeader';
|
import ElementSettingReportHeader from '../ElementSettingReportHeader';
|
||||||
import ElementSettingReportEnable from '../ElementSettingReportEnable';
|
import ElementSettingReportEnable from '../ElementSettingReportEnable';
|
||||||
|
import getTokens from '../../../../../../helpers/getTokens';
|
||||||
|
|
||||||
|
|
||||||
const ElementSetting = ({ setting, changeFn, updateDataFn, bandoStatus }) => {
|
const ElementSetting = ({ setting, changeFn, updateDataFn, bandoStatus }) => {
|
||||||
@@ -72,6 +73,15 @@ const ElementSetting = ({ setting, changeFn, updateDataFn, bandoStatus }) => {
|
|||||||
|
|
||||||
const header = renderHeader();
|
const header = renderHeader();
|
||||||
|
|
||||||
|
const invalidFormula = (value) => {
|
||||||
|
try {
|
||||||
|
const context = getTokens(value)
|
||||||
|
return false;
|
||||||
|
} catch {
|
||||||
|
return __('Potrebbe essere un errore nella formula!')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const getProperField = (setting) => {
|
const getProperField = (setting) => {
|
||||||
if (setting.name === 'options') {
|
if (setting.name === 'options') {
|
||||||
return <ElementSettingRepeater
|
return <ElementSettingRepeater
|
||||||
@@ -145,6 +155,14 @@ const ElementSetting = ({ setting, changeFn, updateDataFn, bandoStatus }) => {
|
|||||||
name={setting.name}
|
name={setting.name}
|
||||||
bandoStatus={bandoStatus}
|
bandoStatus={bandoStatus}
|
||||||
setDataFn={updateDataFn}/>
|
setDataFn={updateDataFn}/>
|
||||||
|
} else if (setting.name === 'formula') {
|
||||||
|
const isInvalid = invalidFormula(setting.value);
|
||||||
|
return <>
|
||||||
|
<InputText id={setting.name} aria-describedby={`${setting.name}-help`}
|
||||||
|
value={setting.value}
|
||||||
|
onChange={(e) => changeFn(e.target.value, setting.name)}/>
|
||||||
|
<p style={{margiTop: 0, fontSize: '14px', color: '#df3636'}}>{isInvalid}</p>
|
||||||
|
</>
|
||||||
} else {
|
} else {
|
||||||
return <InputText id={setting.name} aria-describedby={`${setting.name}-help`}
|
return <InputText id={setting.name} aria-describedby={`${setting.name}-help`}
|
||||||
value={setting.value}
|
value={setting.value}
|
||||||
|
|||||||
@@ -103,12 +103,17 @@ const BandoFormsPreview = () => {
|
|||||||
const formula = head(o.settings.filter(o => o.name === 'formula'));
|
const formula = head(o.settings.filter(o => o.name === 'formula'));
|
||||||
|
|
||||||
if (formula && !isEmpty(formula.value)) {
|
if (formula && !isEmpty(formula.value)) {
|
||||||
|
try {
|
||||||
context = getTokens(formula.value)
|
context = getTokens(formula.value)
|
||||||
.filter(v => !['false', 'null', 'true'].includes(v))
|
.filter(v => !['false', 'null', 'true'].includes(v))
|
||||||
.reduce((acc, cur) => {
|
.reduce((acc, cur) => {
|
||||||
acc[cur] = isNil(context[cur]) ? 0 : parseCommaDecimal(context[cur]);
|
acc[cur] = isNil(context[cur]) ? 0 : parseCommaDecimal(context[cur]);
|
||||||
return acc;
|
return acc;
|
||||||
}, context);
|
}, context);
|
||||||
|
} catch {
|
||||||
|
console.error('Error in formula', formula)
|
||||||
|
context = {}
|
||||||
|
}
|
||||||
const mathFormula = renderWithDataVars(formula.value, context);
|
const mathFormula = renderWithDataVars(formula.value, context);
|
||||||
try {
|
try {
|
||||||
updatedFormValues[o.id] = evaluate(mathFormula);
|
updatedFormValues[o.id] = evaluate(mathFormula);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import React, { useEffect, useState, useCallback, useMemo } from 'react';
|
import React, { useEffect, useState, useCallback } from 'react';
|
||||||
import { __ } from '@wordpress/i18n';
|
import { __ } from '@wordpress/i18n';
|
||||||
|
|
||||||
import translationStrings from '../../../../translationStringsForComponents';
|
import translationStrings from '../../../../translationStringsForComponents';
|
||||||
|
|||||||
@@ -940,13 +940,17 @@ const DomandaEditInstructorManager = () => {
|
|||||||
const formula = head(o.settings.filter(o => o.name === 'formula'));
|
const formula = head(o.settings.filter(o => o.name === 'formula'));
|
||||||
|
|
||||||
if (formula && !isEmpty(formula.value)) {
|
if (formula && !isEmpty(formula.value)) {
|
||||||
|
try {
|
||||||
context = getTokens(formula.value)
|
context = getTokens(formula.value)
|
||||||
.filter(v => !['false', 'null', 'true'].includes(v))
|
.filter(v => !['false', 'null', 'true'].includes(v))
|
||||||
.reduce((acc, cur) => {
|
.reduce((acc, cur) => {
|
||||||
acc[cur] = isNil(context[cur]) ? 0 : parseCommaDecimal(context[cur]);
|
acc[cur] = isNil(context[cur]) ? 0 : parseCommaDecimal(context[cur]);
|
||||||
return acc;
|
return acc;
|
||||||
}, context);
|
}, context);
|
||||||
|
} catch {
|
||||||
|
console.error('Error in formula', formula)
|
||||||
|
context = {}
|
||||||
|
}
|
||||||
const mathFormula = renderWithDataVars(formula.value, context);
|
const mathFormula = renderWithDataVars(formula.value, context);
|
||||||
try {
|
try {
|
||||||
updatedFormValues[o.id] = evaluate(mathFormula);
|
updatedFormValues[o.id] = evaluate(mathFormula);
|
||||||
|
|||||||
@@ -940,12 +940,17 @@ const DomandaEditPreInstructor = () => {
|
|||||||
const formula = head(o.settings.filter(o => o.name === 'formula'));
|
const formula = head(o.settings.filter(o => o.name === 'formula'));
|
||||||
|
|
||||||
if (formula && !isEmpty(formula.value)) {
|
if (formula && !isEmpty(formula.value)) {
|
||||||
|
try {
|
||||||
context = getTokens(formula.value)
|
context = getTokens(formula.value)
|
||||||
.filter(v => !['false', 'null', 'true'].includes(v))
|
.filter(v => !['false', 'null', 'true'].includes(v))
|
||||||
.reduce((acc, cur) => {
|
.reduce((acc, cur) => {
|
||||||
acc[cur] = isNil(context[cur]) ? 0 : parseCommaDecimal(context[cur]);
|
acc[cur] = isNil(context[cur]) ? 0 : parseCommaDecimal(context[cur]);
|
||||||
return acc;
|
return acc;
|
||||||
}, context);
|
}, context);
|
||||||
|
} catch {
|
||||||
|
console.error('Error in formula', formula)
|
||||||
|
context = {}
|
||||||
|
}
|
||||||
|
|
||||||
const mathFormula = renderWithDataVars(formula.value, context);
|
const mathFormula = renderWithDataVars(formula.value, context);
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user