Skip to content

Commit 1a17fe7

Browse files
committed
This commit enables upstream consumers of the Evaluator class have a little more flexibility when extending evaluation behavior by converting the class from an entirely static class to a regular ES6 class. It also encapsulates repeated evaluation code (normalizing context, e.g.) into two convenience functions for evaluation and interpolation.
1 parent 11b36c4 commit 1a17fe7

File tree

28 files changed

+444
-367
lines changed

28 files changed

+444
-367
lines changed

Changelog.md

Lines changed: 37 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,40 @@
1-
## [Unreleased: 2.4.0-rc.1]
2-
3-
### Changed
4-
1+
## [Unreleased: 2.5.0-rc.1]
2+
### Changed
3+
- FIO-8228: Expanding the types for Project Roles and Access Information
4+
- FIO-8544: Replace async callbacks with async/await
5+
- FIO-9942: Fix issue with disabling evaluations
6+
- FIO-9668: Fix custom error messages are not highlighted
7+
- update exported evaluator to be 'extendable' version
8+
- FIO-9776: Excluded Address2 field from required validation
9+
- FIO-9642: enhance error information
10+
- FIO-8409: added serverOverride processor and tests
11+
- FIO-8118: removed datetime value from submission if null is submitted
12+
- FIO-8117 removed survey from data if value is falsy
13+
- FIO-8119: remove tags from data if value is null
14+
- Added .idea to gitignore for webstorm users
15+
- FIO-9357 fixed calculation based on DataSource component
16+
17+
## 2.4.1
18+
### Changed
19+
- FIO-9737: add deprecated tag to the unwind method
20+
- FIO-9908: fixed an issue where conditional setting with "show" set as a string does not work well
21+
22+
## 2.4.0
23+
### Changed
24+
- FIO-9934 fixed appearing extra validation messages
25+
- FIO-9874: fixed an issue where operands disappear
26+
27+
- FIO-9796: Fixed issue where the conditions from a previous run may be in the wrong state for conditionally hidden.
28+
- Hotfix/fix type aliases
29+
- FIO-9649: update componentMatches fn to not omit layout components; add tests
30+
- FIO-9668: Fix custom error messages are not highlighted
31+
- FIO-9508: includeAll flag now works with nested components
32+
- FIO-9511: fixed day component min/max validation message
33+
- FIO-9467: Fix rendering table component in wizard
34+
- FIO-9465: fix conditionals path for panel component
35+
- FIO-9357 fixed calculation based on DataSource component
36+
- FIO-9266/FIO-9267/FIO-9268: Fixes an issue where nested form validation will be skipped if parent form submits empty data
37+
- FIO-9159: add intentionallyHidden ephemeral state and breaking change to clearOnHide behavior
538
- Regression | Nested Form | Components in Nested forms should not validate hidden components without Validate When Hidden = true
639
- FIO-8347: Added ability to skip mask validation
740
- FIO-8273 fixed advanced logic for data components
@@ -17,153 +50,41 @@
1750
### Changed
1851

1952
- Official Release
20-
21-
## 2.3.0-rc.23
22-
23-
### Changed
24-
2553
- FIO-9021: Fixed eachComponentData iteration for nested forms
26-
27-
## 2.3.0-rc.22
28-
29-
### Changed
30-
3154
- FIO-9344 fixed require validation for day component
3255
- FIO-9329: fix issue where validateWhenHidden now validates hidden and conditionally hidden components
33-
34-
## 2.3.0-rc.21
35-
36-
### Changed
37-
3856
- FIO-9280 updated validation of value property
3957
- FIO-9299: ensure eachComponent does not mutate a component's path
40-
41-
## 2.3.0-rc.20
42-
43-
### Changed
44-
4558
- FIO-9308: Fixed the paths with nested forms by ensuring we are always dealing with the absolute paths with clearOnHide, conditions, filters, and validations
46-
47-
## 2.3.0-rc.19
48-
49-
### Changed
50-
5159
- FIO-9255: fixed an issue where nested forms lose data after submission if some parent has conditional components
52-
53-
## 2.3.0-rc.18
54-
55-
### Changed
56-
5760
- FIO-9261: fixed an issue where empty multiple value for url and datetime causes validation errors
58-
59-
## 2.3.0-rc.17
60-
61-
### Changed
62-
6361
- FIO-9201: Fix DataTable in quick inline embed issues
64-
65-
## 2.3.0-rc.16
66-
67-
### Changed
68-
6962
- FIO-9201: Fix DataTable in quick inline embed issues
70-
71-
## 2.3.0-rc.15
72-
73-
### Changed
74-
7563
- FIO-9244: fixed an issue where Radio component with Allow only available values checked does not submit
76-
77-
## 2.3.0-rc.14
78-
79-
### Changed
80-
8164
- FIO-9189: fixed an issue where data is lost after submission for the conditionally visible field when the condition is based on select resource
8265
- FIO-9219: condition is not equal to based on select box
83-
84-
## 2.3.0-rc.13
85-
86-
### Changed
87-
8866
- FIO-9186: fixed an issue where front-end validation is skipped for the components inside layout component inside editGrid
8967
- FIO-8632: Fixes an issue where required validation is not triggered for multiple value components like Select if it has no values added
90-
91-
## 2.3.0-rc.12
92-
93-
### Changed
94-
9568
- FIO-9086: use for validation only dataFormat (data storage format)
9669
- FIO-9202: fixed an issue where the data for the component inside fieldset insdie wizard is lost after submission
9770
- FIO-9220: remove hiddenChildren
98-
99-
### Changed
100-
101-
## 2.3.0-rc.11
102-
103-
### Changed
104-
10571
- FIO-9160: added support of different condition formats for selectboxes
106-
107-
## 2.3.0-rc.10
108-
109-
### Changed
110-
11172
- FIO-9143 fixed getValidationFormat error
112-
113-
## 2.3.0-rc.9
114-
115-
### Changed
116-
11773
- FIO-8731: Update fix to nested hidden components
11874
- FIO-9002: fix issue with conditionally hidden duplicate nested form paths
119-
120-
## 2.3.0-rc.8
121-
122-
### Changed
123-
12475
- FIO-8723: Clear values from submission for hidden comp with clearOnHide flag
12576
- FIO-8954: added Allow only available values validation for Data Source Type = URL
12677
- FIO-9085: Fix address submission logic
127-
128-
## 2.3.0-rc.7
129-
130-
### Changed
131-
13278
- FIO-9059: fixed an issue where the string type returns for textarea with json type
133-
134-
## 2.3.0-rc.6
135-
136-
### Changed
137-
13879
- FIO-9033 tagpad data is not saved
139-
140-
## 2.3.0-rc.5
141-
142-
### Changed
143-
14480
- FIO-9085: Fix components data removed from submission when conditional set for Address component value
14581
- FIO-8414: Fix required validation not working in Data Grid
146-
147-
## 2.3.0-rc.4
148-
149-
### Changed
150-
15182
- FIO-8986 fixed nornalization for day with default value and hidden fields
15283
- FIO-9055: separate rowPath from componentPath in getComponentActualValue fn
153-
154-
## 2.3.0-rc.3
155-
156-
### Changed
157-
15884
- FIO-8986 fixed validation for Day component with two hidden fields
15985
- FIO-8798: update normalization for day component
16086
- FIO-8626: Updated conditionally hidden logic
16187
- Increment minor version
162-
163-
## 2.3.0-rc.1
164-
165-
### Changed
166-
16788
- updated thresholds to current values
16889
- FIO-8450: Fix custom error message for unique validation
16990
- FIO-8598 fixed normalization of radio component values depending on storage type

config/webpack.config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ module.exports = {
55
mode: 'development',
66
entry: {
77
'formio.core.js': './lib/index.js',
8-
'formio.modules.js': './lib/modules/index.js',
98
'formio.js': './lib/sdk/index.js',
109
'formio.utils.js': './lib/utils/index.js',
1110
'formio.process.js': './lib/process/index.js',

config/webpack.prod.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ const config = require('./webpack.config');
22
config.mode = 'production';
33
config.entry = {
44
'formio.core.min.js': './lib/index.js',
5-
'formio.modules.min.js': './lib/modules/index.js',
65
'formio.min.js': './lib/sdk/index.js',
76
'formio.utils.min.js': './lib/utils/index.js',
87
};

src/experimental/core.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import 'core-js/features/object/from-entries';
22
import { Formio } from '../sdk';
3-
import { Evaluator, Utils } from '../utils';
3+
import { Evaluator, Utils, registerEvaluator } from '../utils';
44
import { Components, render } from './base';
55
import { Template } from './template';
66
import { merge } from 'lodash';
77
import components from './components';
8-
import modules from '../modules';
98

109
export default class FormioCore extends Formio {
1110
static Components = Components;
@@ -60,7 +59,7 @@ export default class FormioCore extends Formio {
6059
if (!(Formio as any).Evaluator) {
6160
return;
6261
}
63-
(Formio as any).Evaluator.registerEvaluator(plugin);
62+
registerEvaluator(plugin);
6463
break;
6564
default:
6665
console.log('Unknown plugin option', key);
@@ -95,4 +94,3 @@ export default class FormioCore extends Formio {
9594
}
9695

9796
FormioCore.use(components);
98-
FormioCore.use(modules);

src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
export * from './modules';
21
export * from './utils';
32
export * from './process/validation';
43
export * from './process/validation/rules';

src/modules/index.ts

Lines changed: 0 additions & 2 deletions
This file was deleted.

src/modules/jsonlogic/index.ts

Lines changed: 0 additions & 82 deletions
This file was deleted.

src/process/calculation/index.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { JSONLogicEvaluator } from 'modules/jsonlogic';
21
import {
32
ProcessorFn,
43
ProcessorFnSync,
@@ -8,7 +7,7 @@ import {
87
FetchScope,
98
} from 'types';
109
import { set } from 'lodash';
11-
import { normalizeContext } from 'utils/formUtil';
10+
import { evaluate } from 'utils';
1211

1312
export const shouldCalculate = (context: CalculationContext): boolean => {
1413
const { component, config } = context;
@@ -21,20 +20,25 @@ export const shouldCalculate = (context: CalculationContext): boolean => {
2120
export const calculateProcessSync: ProcessorFnSync<CalculationScope> = (
2221
context: CalculationContext,
2322
) => {
24-
const { component, data, evalContext, scope, path, value } = context;
25-
if (!shouldCalculate(context)) {
23+
const { component, data, scope, path, value } = context;
24+
if (!shouldCalculate(context) || !component.calculateValue) {
2625
return;
2726
}
2827

2928
const calculationContext = (scope as FetchScope).fetched
3029
? { ...context, data: { ...data, ...(scope as FetchScope).fetched } }
3130
: context;
32-
const evalContextValue = evalContext
33-
? evalContext(normalizeContext(calculationContext))
34-
: normalizeContext(calculationContext);
35-
evalContextValue.value = value || null;
31+
3632
if (!scope.calculated) scope.calculated = [];
37-
const newValue = JSONLogicEvaluator.evaluate(component.calculateValue, evalContextValue, 'value');
33+
const newValue = evaluate(
34+
component.calculateValue,
35+
calculationContext,
36+
'value',
37+
false,
38+
(context) => {
39+
context.value = value || null;
40+
},
41+
);
3842

3943
// Only set a new value if it is not "null" which would be the case if no calculation occurred.
4044
if (newValue !== null) {

0 commit comments

Comments
 (0)