@legalplace/wizardx-core 4.10.7 → 4.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -13,3 +13,4 @@ export declare type parseOptionLabelT = (id: number, index: number) => string;
|
|
|
13
13
|
export declare const parseOptionLabel: parseOptionLabelT;
|
|
14
14
|
export declare type parseRawT = (text: string, inputs?: OptionsVariablesType, placeholder?: string) => string;
|
|
15
15
|
export declare const parseRawWithVariables: parseRawT;
|
|
16
|
+
export declare const parsePrefillerValue: (variableId: number, inputIndex: number, prefillerIndex: number) => string;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { filterXSS } from "xss";
|
|
2
|
-
import { selectVariableParents, selectOptionRelations, selectVariableReference, selectOptionReference, selectVariableRelations, } from "../redux/selectors/references";
|
|
2
|
+
import { selectVariableParents, selectOptionRelations, selectVariableReference, selectOptionReference, selectVariableRelations, areVariablesSiblings, } from "../redux/selectors/references";
|
|
3
3
|
import { selectVariableInput, selectVariableInputByIndex, } from "../redux/selectors/inputs";
|
|
4
4
|
const frenchNumber = (value) => {
|
|
5
5
|
let result = typeof value === "number" ? value.toString() : value;
|
|
@@ -184,3 +184,46 @@ export const parseRawWithVariables = (text, inputs, placeholder) => {
|
|
|
184
184
|
});
|
|
185
185
|
return parsedText;
|
|
186
186
|
};
|
|
187
|
+
export const parsePrefillerValue = (variableId, inputIndex, prefillerIndex) => {
|
|
188
|
+
var _a, _b, _c;
|
|
189
|
+
const prefillerValue = (_c = (_b = (_a = selectVariableReference(variableId)) === null || _a === void 0 ? void 0 : _a.prefillings) === null || _b === void 0 ? void 0 : _b[prefillerIndex]) === null || _c === void 0 ? void 0 : _c.value;
|
|
190
|
+
if (!prefillerValue)
|
|
191
|
+
return "";
|
|
192
|
+
if (/\[var:([0-9]+)\]/gi.test(prefillerValue)) {
|
|
193
|
+
const tagsMatch = prefillerValue.match(/\[var:([0-9]+)\]/gi);
|
|
194
|
+
let variables = [];
|
|
195
|
+
if (tagsMatch !== null) {
|
|
196
|
+
const variablesTags = [...tagsMatch];
|
|
197
|
+
variables = variablesTags.map((current) => {
|
|
198
|
+
const outputVariableMatch = current.match(/([0-9]+)/);
|
|
199
|
+
if (outputVariableMatch === null)
|
|
200
|
+
return 0;
|
|
201
|
+
return parseInt(outputVariableMatch[0], 10);
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
variables = variables.filter((c, i) => variables.indexOf(c) === i);
|
|
205
|
+
variables = variables.filter((c) => selectVariableReference(c) !== undefined);
|
|
206
|
+
const variablesValues = {};
|
|
207
|
+
variables.forEach((currentVariableId) => {
|
|
208
|
+
const index = areVariablesSiblings(currentVariableId, variableId)
|
|
209
|
+
? inputIndex
|
|
210
|
+
: 0;
|
|
211
|
+
const value = selectVariableInputByIndex(currentVariableId, index);
|
|
212
|
+
if (value === undefined ||
|
|
213
|
+
value === null ||
|
|
214
|
+
(typeof value === "string" && value.trim().length === 0)) {
|
|
215
|
+
variablesValues[currentVariableId] = "";
|
|
216
|
+
}
|
|
217
|
+
else {
|
|
218
|
+
variablesValues[currentVariableId] = value.toString();
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
let parsedPrefillerValue = `${prefillerValue}`;
|
|
222
|
+
variables.forEach((currentVariableId) => {
|
|
223
|
+
const value = variablesValues[currentVariableId];
|
|
224
|
+
parsedPrefillerValue = parsedPrefillerValue.replace(new RegExp(`\\[var:${currentVariableId}\\]`, "gi"), filterXSS(value));
|
|
225
|
+
});
|
|
226
|
+
return parsedPrefillerValue;
|
|
227
|
+
}
|
|
228
|
+
return prefillerValue;
|
|
229
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const parsePrefillerValue: (variableId: number, inputIndex: number, prefillerIndex: number) => string;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { areVariablesSiblings, selectVariableInputByIndex, selectVariableReference, } from "..";
|
|
2
|
+
export const parsePrefillerValue = (variableId, inputIndex, prefillerIndex) => {
|
|
3
|
+
var _a, _b, _c;
|
|
4
|
+
const prefillerValue = (_c = (_b = (_a = selectVariableReference(variableId)) === null || _a === void 0 ? void 0 : _a.prefillings) === null || _b === void 0 ? void 0 : _b[prefillerIndex]) === null || _c === void 0 ? void 0 : _c.value;
|
|
5
|
+
if (!prefillerValue)
|
|
6
|
+
return "";
|
|
7
|
+
if (/\[var:([0-9]+)\]/gi.test(prefillerValue)) {
|
|
8
|
+
const tagsMatch = prefillerValue.match(/\[var:([0-9]+)\]/gi);
|
|
9
|
+
let variables = [];
|
|
10
|
+
if (tagsMatch !== null) {
|
|
11
|
+
const variablesTags = [...tagsMatch];
|
|
12
|
+
variables = variablesTags.map((current) => {
|
|
13
|
+
const outputVariableMatch = current.match(/([0-9]+)/);
|
|
14
|
+
if (outputVariableMatch === null)
|
|
15
|
+
return 0;
|
|
16
|
+
return parseInt(outputVariableMatch[0], 10);
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
variables = variables.filter((c, i) => variables.indexOf(c) === i);
|
|
20
|
+
variables = variables.filter((c) => selectVariableReference(c) !== undefined);
|
|
21
|
+
const variablesValues = {};
|
|
22
|
+
variables.forEach((currentVariableId) => {
|
|
23
|
+
const index = areVariablesSiblings(currentVariableId, variableId)
|
|
24
|
+
? inputIndex
|
|
25
|
+
: 0;
|
|
26
|
+
const value = selectVariableInputByIndex(currentVariableId, index);
|
|
27
|
+
if (value === undefined ||
|
|
28
|
+
value === null ||
|
|
29
|
+
(typeof value === "string" && value.trim().length === 0)) {
|
|
30
|
+
variablesValues[currentVariableId] = "";
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
variablesValues[currentVariableId] = value.toString();
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
let parsedPrefillerValue = `${prefillerValue}`;
|
|
37
|
+
variables.forEach((currentVariableId) => {
|
|
38
|
+
const value = variablesValues[currentVariableId];
|
|
39
|
+
parsedPrefillerValue = parsedPrefillerValue.replace(new RegExp(`\\[var:${currentVariableId}\\]`, "gi"), filterXSS(value));
|
|
40
|
+
});
|
|
41
|
+
return parsedPrefillerValue;
|
|
42
|
+
}
|
|
43
|
+
return prefillerValue;
|
|
44
|
+
};
|
|
@@ -7,49 +7,7 @@ import { updateVariableAction } from "../actions/inputs";
|
|
|
7
7
|
import { ADD_MULTIPLE_OCCURENCY, UPDATE_VARIABLE_INPUT, } from "../constants/inputs";
|
|
8
8
|
import { selectPrefillerConditionValue } from "../selectors/conditions";
|
|
9
9
|
import { FETCH_MODEL_SUCCEEDED } from "../constants/app";
|
|
10
|
-
|
|
11
|
-
var _a, _b, _c;
|
|
12
|
-
const prefillerValue = (_c = (_b = (_a = selectVariableReference(variableId)) === null || _a === void 0 ? void 0 : _a.prefillings) === null || _b === void 0 ? void 0 : _b[prefillerIndex]) === null || _c === void 0 ? void 0 : _c.value;
|
|
13
|
-
if (!prefillerValue)
|
|
14
|
-
return "";
|
|
15
|
-
if (/\[var:([0-9]+)\]/gi.test(prefillerValue)) {
|
|
16
|
-
const tagsMatch = prefillerValue.match(/\[var:([0-9]+)\]/gi);
|
|
17
|
-
let variables = [];
|
|
18
|
-
if (tagsMatch !== null) {
|
|
19
|
-
const variablesTags = [...tagsMatch];
|
|
20
|
-
variables = variablesTags.map((current) => {
|
|
21
|
-
const outputVariableMatch = current.match(/([0-9]+)/);
|
|
22
|
-
if (outputVariableMatch === null)
|
|
23
|
-
return 0;
|
|
24
|
-
return parseInt(outputVariableMatch[0], 10);
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
variables = variables.filter((c, i) => variables.indexOf(c) === i);
|
|
28
|
-
variables = variables.filter((c) => selectVariableReference(c) !== undefined);
|
|
29
|
-
const variablesValues = {};
|
|
30
|
-
variables.forEach((currentVariableId) => {
|
|
31
|
-
const index = areVariablesSiblings(currentVariableId, variableId)
|
|
32
|
-
? inputIndex
|
|
33
|
-
: 0;
|
|
34
|
-
const value = selectVariableInputByIndex(currentVariableId, index);
|
|
35
|
-
if (value === undefined ||
|
|
36
|
-
value === null ||
|
|
37
|
-
(typeof value === "string" && value.trim().length === 0)) {
|
|
38
|
-
variablesValues[currentVariableId] = "";
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
variablesValues[currentVariableId] = value.toString();
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
let parsedPrefillerValue = `${prefillerValue}`;
|
|
45
|
-
variables.forEach((currentVariableId) => {
|
|
46
|
-
const value = variablesValues[currentVariableId];
|
|
47
|
-
parsedPrefillerValue = parsedPrefillerValue.replace(new RegExp(`\\[var:${currentVariableId}\\]`, "gi"), filterXSS(value));
|
|
48
|
-
});
|
|
49
|
-
return parsedPrefillerValue;
|
|
50
|
-
}
|
|
51
|
-
return prefillerValue;
|
|
52
|
-
};
|
|
10
|
+
import { parsePrefillerValue } from "../../helpers/outputsParsing";
|
|
53
11
|
const watchUpdatePrefillerCondition = (mpi, next, action) => {
|
|
54
12
|
const result = next(action);
|
|
55
13
|
const variableId = action.id;
|
|
@@ -63,15 +21,14 @@ const watchUpdatePrefillerCondition = (mpi, next, action) => {
|
|
|
63
21
|
currentValue =
|
|
64
22
|
typeof currentValue === "number" ? currentValue.toString() : currentValue;
|
|
65
23
|
currentValue = typeof currentValue === "string" ? currentValue : "";
|
|
66
|
-
const
|
|
67
|
-
|
|
24
|
+
const { prefillings, prioritizePrefillings } = variableReference;
|
|
25
|
+
const firstUnconditionnedIndex = prefillings
|
|
26
|
+
? prefillings
|
|
68
27
|
.map((c) => c.conditions === undefined ||
|
|
69
28
|
ConditionsMapper.countConditions(c.conditions) === 0)
|
|
70
29
|
.indexOf(true)
|
|
71
30
|
: -1;
|
|
72
|
-
let prefillersValues =
|
|
73
|
-
? variableReference.prefillings
|
|
74
|
-
: new Array(prefillerConditions.length).fill("");
|
|
31
|
+
let prefillersValues = prefillings || new Array(prefillerConditions.length).fill("");
|
|
75
32
|
prefillersValues = prefillersValues.map((prefiller) => prefiller.value);
|
|
76
33
|
prefillersValues = prefillersValues.map((prefillerValue, prefillerIndex) => {
|
|
77
34
|
if (/\[var:([0-9]+)\]/gi.test(prefillerValue))
|
|
@@ -83,7 +40,8 @@ const watchUpdatePrefillerCondition = (mpi, next, action) => {
|
|
|
83
40
|
: firstUnconditionnedIndex > -1
|
|
84
41
|
? prefillersValues[firstUnconditionnedIndex]
|
|
85
42
|
: "";
|
|
86
|
-
if (
|
|
43
|
+
if (prioritizePrefillings ||
|
|
44
|
+
currentValue === "" ||
|
|
87
45
|
(prefillersValues.includes(currentValue) &&
|
|
88
46
|
currentValue !== newPrefillerValue)) {
|
|
89
47
|
mpi.dispatch(updateVariableAction(variableId, newPrefillerValue, variableIndex));
|
|
@@ -96,13 +54,13 @@ const watchAddMultipleOccurency = (mpi, next, action) => {
|
|
|
96
54
|
const childrenVariables = selectOptionRelations(optionId).children.variables;
|
|
97
55
|
const variableIndex = selectOptionInput(optionId).length - 1;
|
|
98
56
|
childrenVariables.forEach((variableId) => {
|
|
99
|
-
var _a
|
|
57
|
+
var _a;
|
|
100
58
|
const variableReference = selectVariableReference(variableId);
|
|
101
59
|
if (variableReference === undefined)
|
|
102
60
|
throw new Error(`Variable ${variableId} does not exist`);
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
const prefillerConditions = (
|
|
61
|
+
const { prefillings, prioritizePrefillings } = variableReference;
|
|
62
|
+
if (prefillings === null || prefillings === void 0 ? void 0 : prefillings.length) {
|
|
63
|
+
const prefillerConditions = (_a = selectPrefillerConditionValue(variableId)) === null || _a === void 0 ? void 0 : _a[variableIndex];
|
|
106
64
|
if (prefillerConditions === undefined)
|
|
107
65
|
return;
|
|
108
66
|
const firstTrueIndex = prefillerConditions.indexOf(true);
|
|
@@ -113,15 +71,11 @@ const watchAddMultipleOccurency = (mpi, next, action) => {
|
|
|
113
71
|
: currentValue;
|
|
114
72
|
currentValue = typeof currentValue === "string" ? currentValue : "";
|
|
115
73
|
currentValue = currentValue.trim();
|
|
116
|
-
const firstUndefinedCondition =
|
|
117
|
-
?
|
|
118
|
-
.map((c) => c.conditions)
|
|
119
|
-
.indexOf(undefined)
|
|
74
|
+
const firstUndefinedCondition = prefillings
|
|
75
|
+
? prefillings.map((c) => c.conditions).indexOf(undefined)
|
|
120
76
|
: -1;
|
|
121
|
-
let prefillersValues =
|
|
122
|
-
|
|
123
|
-
: new Array(prefillerConditions.length).fill("");
|
|
124
|
-
prefillersValues = prefillersValues.map((prefiller) => prefiller.value);
|
|
77
|
+
let prefillersValues = prefillings.map(({ value }) => value) ||
|
|
78
|
+
new Array(prefillerConditions.length).fill("");
|
|
125
79
|
prefillersValues = prefillersValues.map((prefillerValue) => {
|
|
126
80
|
if (/\[var:([0-9]+)\]/gi.test(prefillerValue)) {
|
|
127
81
|
const tagsMatch = prefillerValue.match(/\[var:([0-9]+)\]/gi);
|
|
@@ -166,7 +120,8 @@ const watchAddMultipleOccurency = (mpi, next, action) => {
|
|
|
166
120
|
: firstUndefinedCondition > -1
|
|
167
121
|
? prefillersValues[firstUndefinedCondition]
|
|
168
122
|
: "";
|
|
169
|
-
if (
|
|
123
|
+
if (prioritizePrefillings ||
|
|
124
|
+
currentValue === "" ||
|
|
170
125
|
(prefillersValues.includes(currentValue) &&
|
|
171
126
|
currentValue !== newPrefillerValue)) {
|
|
172
127
|
mpi.dispatch(updateVariableAction(variableId, newPrefillerValue, variableIndex));
|
|
@@ -179,17 +134,33 @@ const watchUpdateVariableInput = (mpi, next, action, noDispatch = false) => {
|
|
|
179
134
|
const { id, index } = action;
|
|
180
135
|
const { prefillingsContents } = selectVariableRelations(id);
|
|
181
136
|
const prefillersToUpdate = [];
|
|
182
|
-
if (prefillingsContents.length
|
|
137
|
+
if (prefillingsContents.length) {
|
|
183
138
|
prefillingsContents.forEach(({ variableId, prefillingIndex }) => {
|
|
184
139
|
const relationValues = selectVariableInput(variableId);
|
|
185
|
-
const
|
|
140
|
+
const { prefillings, prioritizePrefillings } = selectVariableReference(variableId);
|
|
186
141
|
relationValues.forEach((currentRelationValue, currentRelationIndex) => {
|
|
142
|
+
var _a;
|
|
187
143
|
if (areVariablesSiblings(variableId, id) &&
|
|
188
144
|
currentRelationIndex !== index)
|
|
189
145
|
return;
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
146
|
+
const prefillingConditions = (_a = selectPrefillerConditionValue(variableId)) === null || _a === void 0 ? void 0 : _a[currentRelationIndex];
|
|
147
|
+
const firstTruthfulPrefill = prefillingConditions === null || prefillingConditions === void 0 ? void 0 : prefillingConditions.indexOf(true);
|
|
148
|
+
const firstUnconditionnedIndex = prefillings
|
|
149
|
+
? prefillings
|
|
150
|
+
.map((c) => c.conditions === undefined ||
|
|
151
|
+
ConditionsMapper.countConditions(c.conditions) === 0)
|
|
152
|
+
.indexOf(true)
|
|
153
|
+
: -1;
|
|
154
|
+
const isCurrentPrefillActive = typeof firstTruthfulPrefill === "number" && firstTruthfulPrefill > -1
|
|
155
|
+
? prefillingIndex === firstTruthfulPrefill
|
|
156
|
+
: prefillingIndex === firstUnconditionnedIndex;
|
|
157
|
+
if (!isCurrentPrefillActive) {
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
if (prefillings &&
|
|
161
|
+
(prioritizePrefillings ||
|
|
162
|
+
currentRelationValue ===
|
|
163
|
+
parsePrefillerValue(variableId, index, prefillingIndex))) {
|
|
193
164
|
prefillersToUpdate.push({
|
|
194
165
|
variableId,
|
|
195
166
|
inputIndex: currentRelationIndex,
|
|
@@ -212,7 +183,7 @@ const watchFetchModelSucceeded = (mpi, next, action) => {
|
|
|
212
183
|
const { prefillers } = mpi.getState().conditions;
|
|
213
184
|
Object.keys(prefillers).forEach((variableStrId) => {
|
|
214
185
|
const variableId = parseInt(variableStrId, 10);
|
|
215
|
-
const { prefillings } = selectVariableReference(variableId);
|
|
186
|
+
const { prefillings, prioritizePrefillings } = selectVariableReference(variableId);
|
|
216
187
|
if (Array.isArray(prefillings)) {
|
|
217
188
|
const firstUnconditionnedIndex = prefillings
|
|
218
189
|
.map((c) => c.conditions === undefined ||
|
|
@@ -221,7 +192,7 @@ const watchFetchModelSucceeded = (mpi, next, action) => {
|
|
|
221
192
|
if (firstUnconditionnedIndex > -1) {
|
|
222
193
|
variables[variableId].forEach((value, variableIndex) => {
|
|
223
194
|
const prefillerValue = parsePrefillerValue(variableId, variableIndex, firstUnconditionnedIndex);
|
|
224
|
-
if (value.toString().trim().length === 0) {
|
|
195
|
+
if (value.toString().trim().length === 0 || prioritizePrefillings) {
|
|
225
196
|
mpi.dispatch(updateVariableAction(variableId, prefillerValue, variableIndex));
|
|
226
197
|
}
|
|
227
198
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@legalplace/wizardx-core",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.11.0",
|
|
4
4
|
"author": "Moncef Hammou (moncef@legalplace.fr)",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"files": [
|
|
@@ -24,9 +24,9 @@
|
|
|
24
24
|
"@legalplace/lp-events": "1.14.0",
|
|
25
25
|
"@legalplace/lplogic": "2.3.1",
|
|
26
26
|
"@legalplace/model-healthcheck": "^1.1.5",
|
|
27
|
-
"@legalplace/referencesparser": "^3.1.
|
|
27
|
+
"@legalplace/referencesparser": "^3.1.16",
|
|
28
28
|
"@legalplace/storybook": "^2.171.0",
|
|
29
|
-
"@legalplace/typeorm-constants": "^3.
|
|
29
|
+
"@legalplace/typeorm-constants": "^3.28.1",
|
|
30
30
|
"@loadable/component": "^5.15.0",
|
|
31
31
|
"@redux-saga/core": "^1.1.3",
|
|
32
32
|
"connected-react-router": "^6.8.0",
|
|
@@ -54,11 +54,11 @@
|
|
|
54
54
|
"xss": "^1.0.9"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
|
-
"@legalplace/data-gouv": "^1.5.
|
|
57
|
+
"@legalplace/data-gouv": "^1.5.6",
|
|
58
58
|
"@legalplace/eslint-config": "^2.2.0",
|
|
59
|
-
"@legalplace/models-v3-types": "^5.
|
|
59
|
+
"@legalplace/models-v3-types": "^5.11.0",
|
|
60
60
|
"@legalplace/prettier-config": "^2.1.3",
|
|
61
|
-
"@legalplace/typeorm-entities": "^5.29.
|
|
61
|
+
"@legalplace/typeorm-entities": "^5.29.2",
|
|
62
62
|
"@swc-node/jest": "^1.3.2",
|
|
63
63
|
"@swc/core": "^1.2.93",
|
|
64
64
|
"@swc/jest": "^0.2.4",
|
|
@@ -96,5 +96,5 @@
|
|
|
96
96
|
"*.test.ts",
|
|
97
97
|
"*.test.tsx"
|
|
98
98
|
],
|
|
99
|
-
"gitHead": "
|
|
99
|
+
"gitHead": "22c3f78e2558927f920b2cc6a080f6f19cbc532d"
|
|
100
100
|
}
|