@legalplace/wizardx-core 4.43.5 → 4.43.6

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,5 +1,6 @@
1
1
  import type { AnyAction, EmptyObject, Store } from "redux";
2
2
  import type { StateType } from "../types";
3
+ export declare const clearRelatedParentsCache: () => void;
3
4
  export declare const getRelatedParentsByVariableId: (variableId: number, index: number) => {
4
5
  id: number;
5
6
  value: Readonly<string | number>;
@@ -10,6 +11,15 @@ export declare const autoSave: (variablesData: {
10
11
  variablesIds: number[];
11
12
  updateValue: string;
12
13
  index: number;
14
+ linkedVariables?: Array<{
15
+ variablesIds: number[];
16
+ updateValue: string;
17
+ index: number;
18
+ }>;
19
+ linkedAutocomplete?: {
20
+ value: string;
21
+ index: number;
22
+ };
13
23
  }[], store: Store<EmptyObject & StateType, AnyAction> & {
14
24
  dispatch: unknown;
15
25
  }) => Promise<void>;
@@ -7,14 +7,21 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- import { saveDataAction, selectAutocompleteDataset, selectLinkedVariables, selectOptionReference, selectVariableConditionValue, selectVariableInputByIndex, selectVariableParents, selectVariablesReference, updateVariableAction, } from "../redux";
11
- import { fetchAutocompleteDataFromInputValue } from "../service";
12
- import { cleanString } from "../libs";
10
+ import { autocompleteDatasetConfig } from "../constants/autocomplete";
11
+ import { saveDataAction, selectAutocompleteDataset, selectOptionReference, selectVariableConditionValue, selectVariableInputByIndex, selectVariableParents, selectVariablesReference, setDisabledVariableAction, updateVariableAction, } from "../redux";
12
+ const relatedParentsCache = new Map();
13
+ export const clearRelatedParentsCache = () => {
14
+ relatedParentsCache.clear();
15
+ };
13
16
  export const getRelatedParentsByVariableId = (variableId, index) => {
17
+ const cacheKey = `${variableId}_${index}`;
18
+ if (relatedParentsCache.has(cacheKey)) {
19
+ return relatedParentsCache.get(cacheKey);
20
+ }
14
21
  const parentOptionId = selectVariableParents(variableId)[0];
15
22
  const optionData = selectOptionReference(parentOptionId);
16
23
  const variablesSection = selectVariablesReference(optionData === null || optionData === void 0 ? void 0 : optionData.variables);
17
- return variablesSection
24
+ const result = variablesSection
18
25
  .filter((variableItem) => variableItem.type === "autocomplete" &&
19
26
  Object.values((variableItem === null || variableItem === void 0 ? void 0 : variableItem.linkedVariables) || []).includes(variableId))
20
27
  .map((parentVariable) => ({
@@ -22,6 +29,8 @@ export const getRelatedParentsByVariableId = (variableId, index) => {
22
29
  value: selectVariableInputByIndex(parentVariable.id, index) || "",
23
30
  condition: selectVariableConditionValue(parentVariable.id, index),
24
31
  }));
32
+ relatedParentsCache.set(cacheKey, result);
33
+ return result;
25
34
  };
26
35
  export const getAutoCompleteParentVariableId = (variableId, index, type) => {
27
36
  if (type === "autocomplete") {
@@ -34,28 +43,6 @@ export const getAutoCompleteParentVariableId = (variableId, index, type) => {
34
43
  }
35
44
  return undefined;
36
45
  };
37
- const getResultAutoComplete = (variableId, updateValue, index, store) => __awaiter(void 0, void 0, void 0, function* () {
38
- const linkedVariables = selectLinkedVariables(variableId);
39
- const autocompleteDataset = selectAutocompleteDataset(variableId);
40
- const autocompleteResults = yield fetchAutocompleteDataFromInputValue({
41
- dataset: autocompleteDataset,
42
- inputValue: cleanString(updateValue),
43
- attributes: Object.keys(linkedVariables || {}),
44
- variableId,
45
- });
46
- if (!autocompleteResults) {
47
- window.parent.postMessage({ from: "WIZARD", data: "ERROR" }, "*");
48
- return;
49
- }
50
- if (autocompleteResults.length) {
51
- const selectedValue = autocompleteResults[0];
52
- yield store.dispatch(updateVariableAction(variableId, (selectedValue === null || selectedValue === void 0 ? void 0 : selectedValue.field) || (selectedValue === null || selectedValue === void 0 ? void 0 : selectedValue.primary) || updateValue, index));
53
- Object.entries(linkedVariables || {}).forEach(([key, linkedVariableId]) => __awaiter(void 0, void 0, void 0, function* () {
54
- yield store.dispatch(updateVariableAction(linkedVariableId, selectedValue[key] || "", index));
55
- }));
56
- store.dispatch(saveDataAction());
57
- }
58
- });
59
46
  export const autoSave = (variablesData, store) => __awaiter(void 0, void 0, void 0, function* () {
60
47
  yield variablesData.forEach((variableData, indexVariablesData) => __awaiter(void 0, void 0, void 0, function* () {
61
48
  yield variableData.variablesIds.forEach((variableId, indexVariable) => __awaiter(void 0, void 0, void 0, function* () {
@@ -63,13 +50,47 @@ export const autoSave = (variablesData, store) => __awaiter(void 0, void 0, void
63
50
  if (variableData.variablesIds.length > 1) {
64
51
  contentVariable = `${variableData.updateValue.split(",")[indexVariable] || ""}`.trim();
65
52
  }
66
- const variable = store.getState().references.variables[variableId];
67
- const variableParentId = getAutoCompleteParentVariableId(variableId, variableData.index, variable === null || variable === void 0 ? void 0 : variable.type);
68
- if (variableParentId) {
69
- yield getResultAutoComplete(variableParentId, contentVariable, variableData.index, store);
70
- return;
53
+ const autoCompleteParentsList = getRelatedParentsByVariableId(variableId, variableData.index);
54
+ if (autoCompleteParentsList.length) {
55
+ autoCompleteParentsList.forEach((parent) => __awaiter(void 0, void 0, void 0, function* () {
56
+ yield store.dispatch(updateVariableAction(parent.id, "autre", variableData.index));
57
+ }));
71
58
  }
72
59
  yield store.dispatch(updateVariableAction(variableId, contentVariable, variableData.index));
60
+ if (variableData.linkedVariables &&
61
+ variableData.linkedVariables.length > 0) {
62
+ const relatedAutocompleteParent = new Set();
63
+ variableData.linkedVariables.forEach((linkedVariableData) => __awaiter(void 0, void 0, void 0, function* () {
64
+ yield linkedVariableData.variablesIds.forEach((linkedVariableId, linkedIndexVariable) => __awaiter(void 0, void 0, void 0, function* () {
65
+ var _a;
66
+ let linkedContentVariable = linkedVariableData.updateValue;
67
+ if (linkedVariableData.variablesIds.length > 1) {
68
+ linkedContentVariable = `${linkedVariableData.updateValue.split(",")[linkedIndexVariable] || ""}`.trim();
69
+ }
70
+ const linkedVariableParentsList = (_a = getRelatedParentsByVariableId(linkedVariableId, linkedVariableData.index)) === null || _a === void 0 ? void 0 : _a.filter((parent) => !autoCompleteParentsList.find((autoCompleteParent) => autoCompleteParent.id === (parent === null || parent === void 0 ? void 0 : parent.id)));
71
+ if (linkedVariableParentsList.length) {
72
+ linkedVariableParentsList.forEach((parent) => __awaiter(void 0, void 0, void 0, function* () {
73
+ var _b;
74
+ if (!relatedAutocompleteParent.has(parent.id)) {
75
+ relatedAutocompleteParent.add(parent.id);
76
+ yield store.dispatch(updateVariableAction(parent.id, ((_b = variableData.linkedAutocomplete) === null || _b === void 0 ? void 0 : _b.value) || "autre", linkedVariableData.index));
77
+ }
78
+ }));
79
+ }
80
+ yield store.dispatch(updateVariableAction(linkedVariableId, linkedContentVariable, linkedVariableData.index));
81
+ if (relatedAutocompleteParent.size > 0) {
82
+ relatedAutocompleteParent.forEach((parentId) => __awaiter(void 0, void 0, void 0, function* () {
83
+ const autocompleteDataset = selectAutocompleteDataset(parentId);
84
+ const config = autocompleteDataset &&
85
+ autocompleteDatasetConfig[autocompleteDataset];
86
+ if (config === null || config === void 0 ? void 0 : config.shouldDisableLinkedVariables) {
87
+ yield store.dispatch(setDisabledVariableAction(linkedVariableId, true, linkedVariableData.index));
88
+ }
89
+ }));
90
+ }
91
+ }));
92
+ }));
93
+ }
73
94
  setTimeout(() => __awaiter(void 0, void 0, void 0, function* () {
74
95
  if (indexVariable === variableData.variablesIds.length - 1 &&
75
96
  indexVariablesData === variablesData.length - 1) {
@@ -33,10 +33,10 @@ function* saveDataDecorator(action) {
33
33
  window.location.href = redirectTo;
34
34
  }
35
35
  }
36
- window.parent.postMessage({ from: "WIZARD", data: "SUCCESS" }, "*");
37
36
  let proofsResponse = yield call(fetch, ...updateProofModule(uniqid));
38
37
  proofsResponse = yield call([proofsResponse, "json"]);
39
38
  yield put(setProofsAction(proofsResponse.proofs));
39
+ window.parent.postMessage({ from: "WIZARD", data: "SUCCESS" }, "*");
40
40
  yield put(setDataStatus("saved"));
41
41
  }
42
42
  catch (e) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@legalplace/wizardx-core",
3
- "version": "4.43.5",
3
+ "version": "4.43.6",
4
4
  "author": "Moncef Hammou (moncef@legalplace.fr)",
5
5
  "license": "MIT",
6
6
  "files": [
@@ -100,5 +100,5 @@
100
100
  "*.test.ts",
101
101
  "*.test.tsx"
102
102
  ],
103
- "gitHead": "8defec520a96faab25fd0ad90a4ec20567f9dba9"
103
+ "gitHead": "f3ab1ba30ca05d573edd37cdd5ea14ab0f025676"
104
104
  }