@legalplace/wizardx-core 4.23.4 → 4.23.5

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.
@@ -1,6 +1,7 @@
1
1
  import { componentConnector } from "./connector/componentConnector";
2
2
  import { isStepAvailable } from "../redux/selectors/app";
3
- import { parseRawWithVariables, parseVariableLabel, } from "../helpers/outputsParsing";
3
+ import { selectVariableParents } from "../redux/selectors/references";
4
+ import { parseRawWithRelatedVariables, parseVariableLabel, } from "../helpers/outputsParsing";
4
5
  import { selectAutocompleteDataset, selectIsVariableDisabledByIndex, selectLinkedVariables, selectVariableDisabledTooltipByIndex, } from "../redux";
5
6
  export const canVariableDisplay = (id, index, selectors) => {
6
7
  const { selectVariableReference, isLevelAccessibleForUser } = selectors;
@@ -33,14 +34,15 @@ const stateToProps = (selectors) => (state, ownProps) => {
33
34
  }
34
35
  const mandatoryValidated = selectMandatoryVariableByIndex(id, index);
35
36
  const mandatoryIgnore = selectors.selectMandatoryIgnore();
37
+ const parentOptionId = selectVariableParents(id)[0];
36
38
  const validatorMessage = typeof ((_a = variable.validator) === null || _a === void 0 ? void 0 : _a.message) === "string"
37
- ? parseRawWithVariables(variable.validator.message)
39
+ ? parseRawWithRelatedVariables(variable.validator.message, parentOptionId, index)
38
40
  : "";
39
41
  const helper = variable.helper
40
- ? parseRawWithVariables(variable.helper, undefined, "________________")
42
+ ? parseRawWithRelatedVariables(variable.helper, parentOptionId, index, undefined, "________________")
41
43
  : undefined;
42
44
  const warning = variable.warning
43
- ? parseRawWithVariables(variable.warning, undefined, "________________")
45
+ ? parseRawWithRelatedVariables(variable.warning, parentOptionId, index, undefined, "________________")
44
46
  : undefined;
45
47
  return {
46
48
  id,
@@ -13,4 +13,6 @@ 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 type parseRawWithRelatedVariablesT = (text: string, optionId: number, index: number, inputs?: OptionsVariablesType, placeholder?: string) => string;
17
+ export declare const parseRawWithRelatedVariables: parseRawWithRelatedVariablesT;
16
18
  export declare const parsePrefillerValue: (variableId: number, inputIndex: number, prefillerIndex: number) => string;
@@ -181,6 +181,46 @@ export const parseRawWithVariables = (text, inputs, placeholder) => {
181
181
  });
182
182
  return parsedText;
183
183
  };
184
+ export const parseRawWithRelatedVariables = (text, optionId, index, inputs, placeholder = "") => {
185
+ const tagsMatch = text.match(/\[var:([0-9]+)\]/gi);
186
+ let variables = [];
187
+ if (tagsMatch !== null) {
188
+ const variablesTags = [...tagsMatch];
189
+ variables = variablesTags.map((current) => {
190
+ const outputVariableMatch = current.match(/([0-9]+)/);
191
+ if (outputVariableMatch === null)
192
+ return 0;
193
+ return parseInt(outputVariableMatch[0], 10);
194
+ });
195
+ }
196
+ variables = variables.filter((c, i) => variables.indexOf(c) === i);
197
+ const relatedVariables = {};
198
+ variables.forEach((variableId) => {
199
+ var _a;
200
+ let value;
201
+ if (inputs) {
202
+ value = (_a = inputs.variables[variableId]) === null || _a === void 0 ? void 0 : _a[0];
203
+ }
204
+ else {
205
+ const values = getRelatedVariablesValues(optionId, index, variables);
206
+ value = values[variableId];
207
+ }
208
+ if (value === undefined ||
209
+ value === null ||
210
+ (typeof value === "string" && value.trim().length === 0)) {
211
+ relatedVariables[variableId] = placeholder;
212
+ }
213
+ else {
214
+ relatedVariables[variableId] = value.toString();
215
+ }
216
+ });
217
+ let parsedText = `${text}`;
218
+ Object.keys(relatedVariables).forEach((variableId) => {
219
+ const value = relatedVariables[variableId];
220
+ parsedText = parsedText.replace(new RegExp(new RegExp(`\\[var:${variableId}\\]`, "gi"), "gi"), filterXSS(value));
221
+ });
222
+ return parsedText;
223
+ };
184
224
  export const parsePrefillerValue = (variableId, inputIndex, prefillerIndex) => {
185
225
  var _a, _b, _c;
186
226
  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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@legalplace/wizardx-core",
3
- "version": "4.23.4",
3
+ "version": "4.23.5",
4
4
  "author": "Moncef Hammou (moncef@legalplace.fr)",
5
5
  "license": "MIT",
6
6
  "files": [
@@ -96,5 +96,5 @@
96
96
  "*.test.ts",
97
97
  "*.test.tsx"
98
98
  ],
99
- "gitHead": "a88ceaca4f6fc7ddc1fba180d1e8b623fb71c608"
99
+ "gitHead": "b6228c8694fb988b34e5e07721cf28130178f418"
100
100
  }