@legalplace/wizardx-core 2.4.0 → 2.5.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.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,23 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [2.5.0](https://git.legalplace.eu/legalplace/monorepo/compare/@legalplace/wizardx-core@2.4.0...@legalplace/wizardx-core@2.5.0) (2021-12-06)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * fix push api[#3338](https://git.legalplace.eu/legalplace/monorepo/issues/3338) ([1c961d5](https://git.legalplace.eu/legalplace/monorepo/commits/1c961d5a459513f791c2afb363881aa3d9214add))
12
+ * fixing issue with smartscript not getting executed after init_inputs api[#3338](https://git.legalplace.eu/legalplace/monorepo/issues/3338) ([2c96fd6](https://git.legalplace.eu/legalplace/monorepo/commits/2c96fd63a6d2e7685e75ee9125a4759831548139))
13
+
14
+
15
+ ### Features
16
+
17
+ * Adding possibility to clone instance and improving UX on kanoon softSocial modal api[#3338](https://git.legalplace.eu/legalplace/monorepo/issues/3338) ([cec91b7](https://git.legalplace.eu/legalplace/monorepo/commits/cec91b79a512de1699e75fbb0e1bf95359f43376))
18
+
19
+
20
+
21
+
22
+
6
23
  # [2.4.0](https://git.legalplace.eu/legalplace/monorepo/compare/@legalplace/wizardx-core@2.3.0...@legalplace/wizardx-core@2.4.0) (2021-12-03)
7
24
 
8
25
 
@@ -1,4 +1,6 @@
1
+ import { StateType } from "../../types/State.type";
1
2
  import { ActionsType } from "../../types/Actions.type";
3
+ export declare const initInputsAction: (inputs: StateType.Inputs, references?: StateType.References | undefined) => ActionsType.Inputs.initInputs;
2
4
  export declare const initOptionAction: (id: number, values: boolean[]) => ActionsType.Inputs.initOption;
3
5
  export declare const updateOptionAction: (id: number, value: boolean, index: number) => ActionsType.Inputs.updateOptionInput;
4
6
  export declare const initVariableAction: (id: number, values: (string | number)[]) => ActionsType.Inputs.initVariable;
@@ -1,4 +1,9 @@
1
- import { INIT_OPTION, INIT_VARIABLE, UPDATE_OPTION_INPUT, UPDATE_VARIABLE_INPUT, ADD_MULTIPLE_OCCURENCY, DELETE_MULTIPLE_OCCURENCY, } from "../constants/inputs";
1
+ import { INIT_INPUTS, INIT_OPTION, INIT_VARIABLE, UPDATE_OPTION_INPUT, UPDATE_VARIABLE_INPUT, ADD_MULTIPLE_OCCURENCY, DELETE_MULTIPLE_OCCURENCY, } from "../constants/inputs";
2
+ export const initInputsAction = (inputs, references) => ({
3
+ type: INIT_INPUTS,
4
+ inputs,
5
+ references,
6
+ });
2
7
  export const initOptionAction = (id, values) => ({
3
8
  type: INIT_OPTION,
4
9
  id,
@@ -31,6 +31,7 @@ export declare const actionsLibrary: {
31
31
  setMandatorySectionAction: (id: number, value: boolean) => import("../../types/Actions.type").ActionsType.Mandatories.setMandatorySection;
32
32
  setMandatoryOptionAction: (id: number, index: number, value: boolean) => import("../../types/Actions.type").ActionsType.Mandatories.setMandatoryOption;
33
33
  setMandatoryVariableAction: (id: number, index: number, value: boolean) => import("../../types/Actions.type").ActionsType.Mandatories.setMandatoryVariable;
34
+ initInputsAction: (inputs: import("../../types/State.type").StateType.Inputs, references?: import("../../types/State.type").StateType.References | undefined) => import("../../types/Actions.type").ActionsType.Inputs.initInputs;
34
35
  initOptionAction: (id: number, values: boolean[]) => import("../../types/Actions.type").ActionsType.Inputs.initOption;
35
36
  updateOptionAction: (id: number, value: boolean, index: number) => import("../../types/Actions.type").ActionsType.Inputs.updateOptionInput;
36
37
  initVariableAction: (id: number, values: (string | number)[]) => import("../../types/Actions.type").ActionsType.Inputs.initVariable;
@@ -4,3 +4,4 @@ export declare const INIT_OPTION = "INIT_OPTION";
4
4
  export declare const UPDATE_OPTION_INPUT = "UPDATE_OPTION_INPUT";
5
5
  export declare const INIT_VARIABLE = "INIT_VARIABLE";
6
6
  export declare const UPDATE_VARIABLE_INPUT = "UPDATE_VARIABLE_INPUT";
7
+ export declare const INIT_INPUTS = "INIT_INPUTS";
@@ -4,3 +4,4 @@ export const INIT_OPTION = "INIT_OPTION";
4
4
  export const UPDATE_OPTION_INPUT = "UPDATE_OPTION_INPUT";
5
5
  export const INIT_VARIABLE = "INIT_VARIABLE";
6
6
  export const UPDATE_VARIABLE_INPUT = "UPDATE_VARIABLE_INPUT";
7
+ export const INIT_INPUTS = "INIT_INPUTS";
@@ -1,10 +1,11 @@
1
1
  import cloneDeep from "lodash/cloneDeep";
2
2
  import { generatePath } from "react-router-dom";
3
3
  import { getConfig } from "../../config";
4
- import { ADD_MULTIPLE_OCCURENCY, DELETE_MULTIPLE_OCCURENCY, UPDATE_OPTION_INPUT, UPDATE_VARIABLE_INPUT, } from "../constants/inputs";
4
+ import { INIT_INPUTS, ADD_MULTIPLE_OCCURENCY, DELETE_MULTIPLE_OCCURENCY, UPDATE_OPTION_INPUT, UPDATE_VARIABLE_INPUT, } from "../constants/inputs";
5
5
  import { ENABLE_SMARTSCRIPT } from "../constants/smartscript";
6
6
  import { PathReader } from "../../libs/PathReader";
7
7
  import { initSmartscriptTriggersAction } from "../actions/smartscript";
8
+ import { updateOptionAction, updateVariableAction } from "../actions/inputs";
8
9
  let iframe = null;
9
10
  const watchEnableSmartScript = (mpi, next, action) => {
10
11
  next(action);
@@ -77,12 +78,29 @@ const watchUpdateVariableInput = (mpi, next, action) => {
77
78
  }
78
79
  }
79
80
  };
81
+ const watchInitInputs = (mpi, next, action) => {
82
+ next(action);
83
+ if (!iframe)
84
+ return;
85
+ const { inputs } = action;
86
+ Object.keys(inputs.options).forEach((id) => {
87
+ inputs.options[id].forEach((value, index) => {
88
+ watchUpdateOptionInput(mpi, next, updateOptionAction(parseInt(id, 10), value, index));
89
+ });
90
+ });
91
+ Object.keys(inputs.variables).forEach((id) => {
92
+ inputs.variables[id].forEach((value, index) => {
93
+ watchUpdateVariableInput(mpi, next, updateVariableAction(parseInt(id, 10), value, index));
94
+ });
95
+ });
96
+ };
80
97
  const watchersEnum = {
81
98
  [ENABLE_SMARTSCRIPT]: watchEnableSmartScript,
82
99
  [UPDATE_OPTION_INPUT]: watchUpdateOptionInput,
83
100
  [UPDATE_VARIABLE_INPUT]: watchUpdateVariableInput,
84
101
  [ADD_MULTIPLE_OCCURENCY]: watchUpdateOptionInput,
85
102
  [DELETE_MULTIPLE_OCCURENCY]: watchUpdateOptionInput,
103
+ [INIT_INPUTS]: watchInitInputs,
86
104
  };
87
105
  const smartscriptMiddleware = (mpi) => (next) => (action) => {
88
106
  if (Object.prototype.hasOwnProperty.call(watchersEnum, action.type)) {
@@ -1,12 +1,10 @@
1
1
  import { call, put, takeLatest, select, fork, join } from "redux-saga/effects";
2
2
  import Cookies from "universal-cookie";
3
+ import { initInputsAction } from "../actions/inputs";
3
4
  import { initMetaAction, initPaginationAction, initInstanceAction, fetchModelSucceededAction, fetchModelFailedAction, initCustomizationMetaAction, fetchModelUnhealthyAction, initCustomizationAutoDefaultAction, fetchModelUserLockedAction, updateAvailableAppStatesAction, goPageAction, fetchModelNonBlockingAction, setModelUuidAction, } from "../actions/app";
4
- import { ConditionsInitiator } from "../../libs/ConditionsInitiator";
5
5
  import { initReferencesAction } from "../actions/references";
6
- import { initOptionAction, initVariableAction } from "../actions/inputs";
7
- import { initConditionsAction } from "../actions/conditions";
8
6
  import { selectSectionConditionValue } from "../selectors/conditions";
9
- import { selectAllSectionsReferences, selectOptionRelations, } from "../selectors/references";
7
+ import { selectAllSectionsReferences } from "../selectors/references";
10
8
  import { selectInstanceUniqid, isStepAvailable } from "../selectors/app";
11
9
  import { getConfig, updateConfig } from "../../config";
12
10
  import { isLevelAccessibleForUser } from "../selectors/user";
@@ -18,13 +16,11 @@ import Globals from "../../Globals";
18
16
  import { getFetchModelArguments, getCreateInstanceArguments, getClientConfigArguments, getWizardConfigArguments, getModelInformationArguments, } from "../../service/api.manager";
19
17
  import { loadTheme, setWizardTheme } from "../../ThemeLoader";
20
18
  import { loadPlugins } from "../../PluginLoader";
21
- import { selectMandatoryOptionItem, selectMandatoryOption, } from "../selectors/mandatories";
22
- import { initMandatoryOptionAction, initMandatoryVariableAction, } from "../actions/mandatories";
23
19
  import { enableSmartscriptAction } from "../actions/smartscript";
24
20
  import { FETCH_MODEL, FETCH_MODEL_PREREQUISITES, } from "../constants/sagas/model";
25
21
  import { fetchModelAction } from "../actions/sagas/model";
22
+ import { initInputsDecorator } from "./initInputs";
26
23
  const cookies = new Cookies();
27
- const getValues = (arr1, arr2) => arr1.map((v, index) => arr2[index] || v);
28
24
  function* setFetchModelToNonBlocking(firstCurrentAppState) {
29
25
  yield put(initPaginationAction({
30
26
  currentPage: 1,
@@ -273,51 +269,7 @@ function* fetchModelDecorator(action) {
273
269
  if (OvcConverter.isOvc(ovc))
274
270
  ovc = OvcConverter.convertToOptionsVariables(ovc, references);
275
271
  const inputs = new IntputsInitiator(references, ovc).getInputs();
276
- const conditions = new ConditionsInitiator(references, inputs).getConditions();
277
- yield put(initConditionsAction(conditions));
278
- const optionsIds = Object.keys(inputs.options);
279
- for (let i = 0; i < optionsIds.length; i += 1) {
280
- let optionId = parseInt(optionsIds[i], 10);
281
- let values = inputs.options[optionId];
282
- yield put(initOptionAction(optionId, values));
283
- const { meta: meta2 } = references.options[optionId];
284
- const { type } = meta2;
285
- let { mandatory } = meta2;
286
- let sendOptionAction = true;
287
- if (["checkbox", "radio"].includes(type)) {
288
- if (type === "radio") {
289
- const { parents } = selectOptionRelations(optionId);
290
- const parentId = parents[0];
291
- const isMandatoryOption = selectMandatoryOptionItem(parentId);
292
- if (typeof isMandatoryOption !== "undefined") {
293
- const mandatoryOption = selectMandatoryOption(parentId);
294
- sendOptionAction = !mandatoryOption.every((v) => v === true);
295
- if (sendOptionAction === true && mandatoryOption) {
296
- if (values.length >= mandatoryOption.length) {
297
- values = getValues(values, [...mandatoryOption]);
298
- }
299
- else {
300
- values = getValues([...mandatoryOption], values);
301
- }
302
- }
303
- }
304
- mandatory = references.options[parentId].meta.mandatory;
305
- optionId = parentId;
306
- }
307
- if (mandatory === true && sendOptionAction === true) {
308
- yield put(initMandatoryOptionAction(optionId, values));
309
- }
310
- }
311
- }
312
- const variablesIds = Object.keys(inputs.variables);
313
- for (let i = 0; i < variablesIds.length; i += 1) {
314
- const variableId = variablesIds[i];
315
- const values = inputs.variables[variableId];
316
- yield put(initVariableAction(parseInt(variableId, 10), values));
317
- if (references.variables[variableId].mandatory === true)
318
- yield put(initMandatoryVariableAction(parseInt(variableId, 10), values.map((value) => `${value}`.trim().length > 0)));
319
- }
320
- yield put(initConditionsAction(conditions));
272
+ yield call(initInputsDecorator, initInputsAction(inputs, references));
321
273
  const sectionsReferences = selectAllSectionsReferences();
322
274
  if (sectionsReferences === undefined)
323
275
  throw new Error("Sections references not found");
@@ -0,0 +1,5 @@
1
+ import { StateType } from "../../types/State.type";
2
+ import { ActionsType } from "../../types/Actions.type";
3
+ export declare function initInputsDecorator(action: ActionsType.Inputs.initInputs): Generator<import("redux-saga/effects").SelectEffect | import("redux-saga/effects").PutEffect<ActionsType.Conditions.initConditions> | import("redux-saga/effects").PutEffect<ActionsType.Inputs.initOption> | import("redux-saga/effects").PutEffect<ActionsType.Mandatories.initMandatoryOption> | import("redux-saga/effects").PutEffect<ActionsType.Inputs.initVariable> | import("redux-saga/effects").PutEffect<ActionsType.Mandatories.initMandatoryVariable>, void, StateType>;
4
+ declare function initInputsSaga(): Generator<import("redux-saga/effects").ForkEffect<never>, void, unknown>;
5
+ export default initInputsSaga;
@@ -0,0 +1,63 @@
1
+ import { select, takeLatest, put } from "redux-saga/effects";
2
+ import { INIT_INPUTS } from "../constants/inputs";
3
+ import { selectMandatoryOptionItem, selectMandatoryOption, } from "../selectors/mandatories";
4
+ import { initMandatoryOptionAction, initMandatoryVariableAction, } from "../actions/mandatories";
5
+ import { initOptionAction, initVariableAction } from "../actions/inputs";
6
+ import { initConditionsAction } from "../actions/conditions";
7
+ import { ConditionsInitiator } from "../../libs/ConditionsInitiator";
8
+ import { selectOptionRelations } from "../selectors/references";
9
+ const getValues = (arr1, arr2) => arr1.map((v, index) => arr2[index] || v);
10
+ export function* initInputsDecorator(action) {
11
+ const state = yield select((s) => s);
12
+ const references = action.references ? action.references : state.references;
13
+ const { inputs } = action;
14
+ const conditions = new ConditionsInitiator(references, inputs).getConditions();
15
+ yield put(initConditionsAction(conditions));
16
+ const optionsIds = Object.keys(inputs.options);
17
+ for (let i = 0; i < optionsIds.length; i += 1) {
18
+ let optionId = parseInt(optionsIds[i], 10);
19
+ let values = inputs.options[optionId];
20
+ yield put(initOptionAction(optionId, values));
21
+ const { meta: meta2 } = references.options[optionId];
22
+ const { type } = meta2;
23
+ let { mandatory } = meta2;
24
+ let sendOptionAction = true;
25
+ if (["checkbox", "radio"].includes(type)) {
26
+ if (type === "radio") {
27
+ const { parents } = selectOptionRelations(optionId);
28
+ const parentId = parents[0];
29
+ const isMandatoryOption = selectMandatoryOptionItem(parentId);
30
+ if (typeof isMandatoryOption !== "undefined") {
31
+ const mandatoryOption = selectMandatoryOption(parentId);
32
+ sendOptionAction = !mandatoryOption.every((v) => v === true);
33
+ if (sendOptionAction === true && mandatoryOption) {
34
+ if (values.length >= mandatoryOption.length) {
35
+ values = getValues(values, [...mandatoryOption]);
36
+ }
37
+ else {
38
+ values = getValues([...mandatoryOption], values);
39
+ }
40
+ }
41
+ }
42
+ mandatory = references.options[parentId].meta.mandatory;
43
+ optionId = parentId;
44
+ }
45
+ if (mandatory === true && sendOptionAction === true) {
46
+ yield put(initMandatoryOptionAction(optionId, values));
47
+ }
48
+ }
49
+ }
50
+ const variablesIds = Object.keys(inputs.variables);
51
+ for (let i = 0; i < variablesIds.length; i += 1) {
52
+ const variableId = variablesIds[i];
53
+ const values = inputs.variables[variableId];
54
+ yield put(initVariableAction(parseInt(variableId, 10), values));
55
+ if (references.variables[variableId].mandatory === true)
56
+ yield put(initMandatoryVariableAction(parseInt(variableId, 10), values.map((value) => `${value}`.trim().length > 0)));
57
+ }
58
+ yield put(initConditionsAction(conditions));
59
+ }
60
+ function* initInputsSaga() {
61
+ yield takeLatest(INIT_INPUTS, initInputsDecorator);
62
+ }
63
+ export default initInputsSaga;
@@ -3,12 +3,14 @@ import setDefaultsSaga from "./setDefaults";
3
3
  import saveDataSaga from "./saveData";
4
4
  import homogeneousRadioInputsSaga from "./homogeneousRadioInputsSaga";
5
5
  import setUserEmailSaga from "./setUserEmail";
6
+ import initInputsSaga from "./initInputs";
6
7
  const sagas = [
7
8
  fetchModelSaga,
8
9
  setDefaultsSaga,
9
10
  saveDataSaga,
10
11
  setUserEmailSaga,
11
12
  homogeneousRadioInputsSaga,
13
+ initInputsSaga,
12
14
  ];
13
15
  export const sagasRunner = (sagaMiddleware) => {
14
16
  sagas.forEach((saga) => sagaMiddleware.run(saga));
@@ -7,6 +7,7 @@ export declare const selectorsLibrary: {
7
7
  isLevelAccessibleForUser: (level: "ADMIN" | "MANAGER" | "USER" | "GUEST" | "SUPER") => Readonly<boolean>;
8
8
  selectIsSmartscriptOptionIndexHidden: (id: number, index: number) => Readonly<boolean>;
9
9
  selectIsSmartscriptVariableIndexHidden: (id: number, index: number) => Readonly<boolean>;
10
+ selectReferences: () => Readonly<import("@legalplace/referencesparser/dist/libs/References.type").ReferencesType>;
10
11
  selectOutputReference: (id: number) => Readonly<import("@legalplace/referencesparser/dist/libs/References.type").ReferencesSingleOutputType | undefined>;
11
12
  selectBoxReference: (id: number) => Readonly<import("@legalplace/referencesparser/dist/libs/References.type").ReferencesSingleBoxType>;
12
13
  isOptionMultiple: (id: number) => Readonly<boolean | undefined>;
@@ -1,3 +1,4 @@
1
+ export declare const selectReferences: () => Readonly<import("@legalplace/referencesparser/dist/libs/References.type").ReferencesType>;
1
2
  export declare const selectOutputReference: (id: number) => Readonly<import("@legalplace/referencesparser/dist/libs/References.type").ReferencesSingleOutputType | undefined>;
2
3
  export declare const selectBoxReference: (id: number) => Readonly<import("@legalplace/referencesparser/dist/libs/References.type").ReferencesSingleBoxType>;
3
4
  export declare const isOptionMultiple: (id: number) => Readonly<boolean | undefined>;
@@ -1,4 +1,5 @@
1
1
  import { createSelector } from "./selectors";
2
+ export const selectReferences = createSelector((state) => state.references);
2
3
  export const selectOutputReference = createSelector((state, id) => {
3
4
  if (typeof state.references === "undefined")
4
5
  return undefined;
@@ -3,7 +3,7 @@ import { StateType } from "./State.type";
3
3
  import { UPDATE_AVAILABLE_SECTIONS, UPDATE_AVAILABLE_APPSTATES, GO_PREVIOUS_PAGE, GO_NEXT_PAGE, GO_PAGE, INIT_PAGINATION, UPDATE_INSTANCE_PAID, INIT_INSTANCE, UPDATE_INSTANCE, INIT_META, UPDATE_CURRENT_APPSTATE, UPDATE_CURRENT_SECTION_ID, FETCH_MODEL_SUCCEEDED, FETCH_MODEL_FAILED, SET_DATA_STATUS, SET_FETCH_STATUS, INIT_CUSTOMIZATION_META, FETCH_MODEL_UNHEALTHY, FETCH_MODEL_USER_LOCKED, INIT_CUSTOMIZATION_AUTO_DEFAULT, FETCH_MODEL_NONBLOCKING, SET_MODEL_UUID } from "../redux/constants/app";
4
4
  import { INIT_USER, SET_USER_STATUS, SET_USER_VALID_TOKEN } from "../redux/constants/user";
5
5
  import { INIT_REFERENCES, UPDATE_VARIABLE_META, UPDATE_OPTION_META } from "../redux/constants/references";
6
- import { INIT_OPTION, UPDATE_OPTION_INPUT, INIT_VARIABLE, UPDATE_VARIABLE_INPUT, ADD_MULTIPLE_OCCURENCY, DELETE_MULTIPLE_OCCURENCY } from "../redux/constants/inputs";
6
+ import { INIT_INPUTS, INIT_OPTION, UPDATE_OPTION_INPUT, INIT_VARIABLE, UPDATE_VARIABLE_INPUT, ADD_MULTIPLE_OCCURENCY, DELETE_MULTIPLE_OCCURENCY } from "../redux/constants/inputs";
7
7
  import { INIT_CONDITIONS, UPDATE_OPTION_CONDITION, UPDATE_VARIABLE_CONDITION, UPDATE_SECTION_CONDITION, UPDATE_PREFILLER_CONDITION, UPDATE_OPTION_VALIDATOR_CONDITION, UPDATE_VARIABLE_VALIDATOR_CONDITION, UPDATE_DOCUMENT_CONDITION } from "../redux/constants/conditions";
8
8
  import { FETCH_MODEL, FETCH_MODEL_PREREQUISITES } from "../redux/constants/sagas/model";
9
9
  import { SAVE_DATA } from "../redux/constants/sagas/data";
@@ -154,6 +154,11 @@ export declare namespace ActionsType {
154
154
  }
155
155
  }
156
156
  namespace Inputs {
157
+ interface initInputs {
158
+ type: typeof INIT_INPUTS;
159
+ references?: StateType.References;
160
+ inputs: StateType.Inputs;
161
+ }
157
162
  interface initOption {
158
163
  type: typeof INIT_OPTION;
159
164
  id: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@legalplace/wizardx-core",
3
- "version": "2.4.0",
3
+ "version": "2.5.0",
4
4
  "author": "Moncef Hammou (moncef@legalplace.fr)",
5
5
  "license": "MIT",
6
6
  "exports": {
@@ -51,9 +51,9 @@
51
51
  "xss": "^1.0.9"
52
52
  },
53
53
  "devDependencies": {
54
- "@legalplace/eslint-config": "^2.1.0",
54
+ "@legalplace/eslint-config": "^2.1.1",
55
55
  "@legalplace/models-v3-types": "^3.6.0",
56
- "@legalplace/prettier-config": "^2.1.0",
56
+ "@legalplace/prettier-config": "^2.1.1",
57
57
  "@swc-node/jest": "^1.3.2",
58
58
  "@swc/core": "^1.2.93",
59
59
  "@swc/jest": "^0.2.4",
@@ -92,5 +92,5 @@
92
92
  "*.test.ts",
93
93
  "*.test.tsx"
94
94
  ],
95
- "gitHead": "9273e6b6c177b2ded27acfab75da4b29d7fb474d"
95
+ "gitHead": "f3097ba70f4f85a78efee7fb6d0de511eb6eae46"
96
96
  }
@@ -1,5 +1,7 @@
1
+ import { StateType } from "../../types/State.type";
1
2
  import { ActionsType } from "../../types/Actions.type";
2
3
  import {
4
+ INIT_INPUTS,
3
5
  INIT_OPTION,
4
6
  INIT_VARIABLE,
5
7
  UPDATE_OPTION_INPUT,
@@ -8,6 +10,20 @@ import {
8
10
  DELETE_MULTIPLE_OCCURENCY,
9
11
  } from "../constants/inputs";
10
12
 
13
+ /**
14
+ * Initiates inputs
15
+ * @param inputs inputs object
16
+ * @param references (optional) references object
17
+ */
18
+ export const initInputsAction = (
19
+ inputs: StateType.Inputs,
20
+ references?: StateType.References
21
+ ): ActionsType.Inputs.initInputs => ({
22
+ type: INIT_INPUTS,
23
+ inputs,
24
+ references,
25
+ });
26
+
11
27
  /**
12
28
  * Initiates option's input
13
29
  * @param id Option's id
@@ -11,3 +11,5 @@ export const UPDATE_OPTION_INPUT = "UPDATE_OPTION_INPUT";
11
11
  // State.inputs.variables
12
12
  export const INIT_VARIABLE = "INIT_VARIABLE";
13
13
  export const UPDATE_VARIABLE_INPUT = "UPDATE_VARIABLE_INPUT";
14
+
15
+ export const INIT_INPUTS = "INIT_INPUTS";
@@ -5,6 +5,7 @@ import { getConfig } from "../../config";
5
5
  import { ActionsType } from "../../types/Actions.type";
6
6
  import { StateType } from "../../types/State.type";
7
7
  import {
8
+ INIT_INPUTS,
8
9
  ADD_MULTIPLE_OCCURENCY,
9
10
  DELETE_MULTIPLE_OCCURENCY,
10
11
  UPDATE_OPTION_INPUT,
@@ -13,6 +14,7 @@ import {
13
14
  import { ENABLE_SMARTSCRIPT } from "../constants/smartscript";
14
15
  import { PathReader } from "../../libs/PathReader";
15
16
  import { initSmartscriptTriggersAction } from "../actions/smartscript";
17
+ import { updateOptionAction, updateVariableAction } from "../actions/inputs";
16
18
 
17
19
  let iframe: HTMLIFrameElement | null = null;
18
20
 
@@ -153,6 +155,44 @@ const watchUpdateVariableInput = (
153
155
  }
154
156
  };
155
157
 
158
+ /**
159
+ * Watches inputs init
160
+ * @param mpi MiddlewareAPI
161
+ * @param next Dispatch function
162
+ * @param action INIT_INPUT action
163
+ */
164
+ const watchInitInputs = (
165
+ mpi: MiddlewareAPI<Dispatch, StateType>,
166
+ next: Dispatch,
167
+ action: ActionsType.Inputs.initInputs
168
+ ) => {
169
+ next(action);
170
+
171
+ if (!iframe) return;
172
+
173
+ const { inputs } = action;
174
+
175
+ Object.keys(inputs.options).forEach((id) => {
176
+ inputs.options[id].forEach((value, index) => {
177
+ watchUpdateOptionInput(
178
+ mpi,
179
+ next,
180
+ updateOptionAction(parseInt(id, 10), value, index)
181
+ );
182
+ });
183
+ });
184
+
185
+ Object.keys(inputs.variables).forEach((id) => {
186
+ inputs.variables[id].forEach((value, index) => {
187
+ watchUpdateVariableInput(
188
+ mpi,
189
+ next,
190
+ updateVariableAction(parseInt(id, 10), value, index)
191
+ );
192
+ });
193
+ });
194
+ };
195
+
156
196
  export type WatcherActions =
157
197
  | ActionsType.SmartScript.enableSmartScript
158
198
  | ActionsType.Inputs.updateOptionInput
@@ -168,6 +208,7 @@ const watchersEnum: Record<
168
208
  [UPDATE_VARIABLE_INPUT]: watchUpdateVariableInput,
169
209
  [ADD_MULTIPLE_OCCURENCY]: watchUpdateOptionInput,
170
210
  [DELETE_MULTIPLE_OCCURENCY]: watchUpdateOptionInput,
211
+ [INIT_INPUTS]: watchInitInputs,
171
212
  };
172
213
 
173
214
  /**
@@ -2,6 +2,7 @@ import { call, put, takeLatest, select, fork, join } from "redux-saga/effects";
2
2
  import Cookies from "universal-cookie";
3
3
  import type { CustomizationMetaDefault } from "@legalplace/models-v3-types";
4
4
  import type { HealthCheckReport } from "@legalplace/model-healthcheck/dist/libs/HealthCheck.type";
5
+ import { initInputsAction } from "../actions/inputs";
5
6
  import {
6
7
  initMetaAction,
7
8
  initPaginationAction,
@@ -17,15 +18,9 @@ import {
17
18
  fetchModelNonBlockingAction,
18
19
  setModelUuidAction,
19
20
  } from "../actions/app";
20
- import { ConditionsInitiator } from "../../libs/ConditionsInitiator";
21
21
  import { initReferencesAction } from "../actions/references";
22
- import { initOptionAction, initVariableAction } from "../actions/inputs";
23
- import { initConditionsAction } from "../actions/conditions";
24
22
  import { selectSectionConditionValue } from "../selectors/conditions";
25
- import {
26
- selectAllSectionsReferences,
27
- selectOptionRelations,
28
- } from "../selectors/references";
23
+ import { selectAllSectionsReferences } from "../selectors/references";
29
24
  import { ActionsType } from "../../types/Actions.type";
30
25
  import { selectInstanceUniqid, isStepAvailable } from "../selectors/app";
31
26
  import { getConfig, updateConfig } from "../../config";
@@ -45,14 +40,6 @@ import {
45
40
  } from "../../service/api.manager";
46
41
  import { loadTheme, setWizardTheme } from "../../ThemeLoader";
47
42
  import { loadPlugins } from "../../PluginLoader";
48
- import {
49
- selectMandatoryOptionItem,
50
- selectMandatoryOption,
51
- } from "../selectors/mandatories";
52
- import {
53
- initMandatoryOptionAction,
54
- initMandatoryVariableAction,
55
- } from "../actions/mandatories";
56
43
  import { enableSmartscriptAction } from "../actions/smartscript";
57
44
  import {
58
45
  FETCH_MODEL,
@@ -64,12 +51,10 @@ import {
64
51
  WizardConfigResponse,
65
52
  CreateInstanceResponse,
66
53
  } from "../../types/api.type";
54
+ import { initInputsDecorator } from "./initInputs";
67
55
 
68
56
  const cookies = new Cookies();
69
57
 
70
- const getValues = (arr1: boolean[], arr2: boolean[]) =>
71
- arr1.map((v, index) => arr2[index] || v);
72
-
73
58
  function* setFetchModelToNonBlocking(firstCurrentAppState?: string) {
74
59
  yield put(
75
60
  initPaginationAction({
@@ -630,84 +615,7 @@ function* fetchModelDecorator(action: ActionsType.Sagas.Model.fetchModel): any {
630
615
  // Data
631
616
  const inputs = new IntputsInitiator(references, ovc).getInputs();
632
617
 
633
- // Initiating Conditions
634
- const conditions = new ConditionsInitiator(
635
- references,
636
- inputs
637
- ).getConditions();
638
-
639
- /**
640
- * Initiating conditions first before initiating inputs
641
- */
642
- yield put(initConditionsAction(conditions));
643
-
644
- /**
645
- * Initiating inputs
646
- */
647
-
648
- // Options
649
- const optionsIds = Object.keys(inputs.options);
650
- for (let i = 0; i < optionsIds.length; i += 1) {
651
- let optionId = parseInt(optionsIds[i], 10);
652
- let values = inputs.options[optionId];
653
- yield put(initOptionAction(optionId, values));
654
- // If option is mandatory we initiate it
655
- const { meta: meta2 } = references.options[optionId];
656
- const { type } = meta2;
657
- let { mandatory } = meta2;
658
- let sendOptionAction = true;
659
- if (["checkbox", "radio"].includes(type)) {
660
- if (type === "radio") {
661
- const { parents } = selectOptionRelations(optionId);
662
- // Get parentId
663
- const parentId = parents[0];
664
- // check if optin exist on mandatory
665
- const isMandatoryOption = selectMandatoryOptionItem(parentId);
666
- // If parentId value = true don't send an action
667
- if (typeof isMandatoryOption !== "undefined") {
668
- const mandatoryOption = selectMandatoryOption(parentId);
669
- sendOptionAction = !mandatoryOption.every((v) => v === true);
670
- // handle multiple
671
- if (sendOptionAction === true && mandatoryOption) {
672
- if (values.length >= mandatoryOption.length) {
673
- values = getValues(values, [...mandatoryOption]);
674
- } else {
675
- values = getValues([...mandatoryOption], values);
676
- }
677
- }
678
- }
679
-
680
- mandatory = references.options[parentId].meta.mandatory;
681
- optionId = parentId;
682
- }
683
-
684
- if (mandatory === true && sendOptionAction === true) {
685
- yield put(initMandatoryOptionAction(optionId, values));
686
- }
687
- }
688
- }
689
-
690
- // Variables
691
- const variablesIds = Object.keys(inputs.variables);
692
- for (let i = 0; i < variablesIds.length; i += 1) {
693
- const variableId = variablesIds[i];
694
- const values = inputs.variables[variableId];
695
- yield put(initVariableAction(parseInt(variableId, 10), values));
696
-
697
- // If variable is mandatory we initiate it
698
- if (references.variables[variableId].mandatory === true)
699
- yield put(
700
- initMandatoryVariableAction(
701
- parseInt(variableId, 10),
702
- values.map((value) => `${value}`.trim().length > 0)
703
- )
704
- );
705
- }
706
-
707
- /**
708
- * Initiating conditions a second time after initiating inputs
709
- */
710
- yield put(initConditionsAction(conditions));
618
+ yield call(initInputsDecorator, initInputsAction(inputs, references));
711
619
 
712
620
  /**
713
621
  * Initiating pagination
@@ -0,0 +1,110 @@
1
+ import { select, takeLatest, put } from "redux-saga/effects";
2
+ import { StateType } from "../../types/State.type";
3
+ import { ActionsType } from "../../types/Actions.type";
4
+ import { INIT_INPUTS } from "../constants/inputs";
5
+ import {
6
+ selectMandatoryOptionItem,
7
+ selectMandatoryOption,
8
+ } from "../selectors/mandatories";
9
+ import {
10
+ initMandatoryOptionAction,
11
+ initMandatoryVariableAction,
12
+ } from "../actions/mandatories";
13
+ import { initOptionAction, initVariableAction } from "../actions/inputs";
14
+ import { initConditionsAction } from "../actions/conditions";
15
+ import { ConditionsInitiator } from "../../libs/ConditionsInitiator";
16
+ import { selectOptionRelations } from "../selectors/references";
17
+
18
+ const getValues = (arr1: boolean[], arr2: boolean[]) =>
19
+ arr1.map((v, index) => arr2[index] || v);
20
+
21
+ export function* initInputsDecorator(action: ActionsType.Inputs.initInputs) {
22
+ const state: StateType = yield select((s) => s);
23
+ const references = action.references ? action.references : state.references;
24
+ const { inputs } = action;
25
+
26
+ // Initiating Conditions
27
+ const conditions = new ConditionsInitiator(
28
+ references,
29
+ inputs
30
+ ).getConditions();
31
+
32
+ /**
33
+ * Initiating conditions first before initiating inputs
34
+ */
35
+ yield put(initConditionsAction(conditions));
36
+
37
+ /**
38
+ * Initiating inputs
39
+ */
40
+
41
+ // Options
42
+ const optionsIds = Object.keys(inputs.options);
43
+ for (let i = 0; i < optionsIds.length; i += 1) {
44
+ let optionId = parseInt(optionsIds[i], 10);
45
+ let values = inputs.options[optionId];
46
+ yield put(initOptionAction(optionId, values));
47
+ // If option is mandatory we initiate it
48
+ const { meta: meta2 } = references.options[optionId];
49
+ const { type } = meta2;
50
+ let { mandatory } = meta2;
51
+ let sendOptionAction = true;
52
+ if (["checkbox", "radio"].includes(type)) {
53
+ if (type === "radio") {
54
+ const { parents } = selectOptionRelations(optionId);
55
+ // Get parentId
56
+ const parentId = parents[0];
57
+ // check if optin exist on mandatory
58
+ const isMandatoryOption = selectMandatoryOptionItem(parentId);
59
+ // If parentId value = true don't send an action
60
+ if (typeof isMandatoryOption !== "undefined") {
61
+ const mandatoryOption = selectMandatoryOption(parentId);
62
+ sendOptionAction = !mandatoryOption.every((v) => v === true);
63
+ // handle multiple
64
+ if (sendOptionAction === true && mandatoryOption) {
65
+ if (values.length >= mandatoryOption.length) {
66
+ values = getValues(values, [...mandatoryOption]);
67
+ } else {
68
+ values = getValues([...mandatoryOption], values);
69
+ }
70
+ }
71
+ }
72
+
73
+ mandatory = references.options[parentId].meta.mandatory;
74
+ optionId = parentId;
75
+ }
76
+
77
+ if (mandatory === true && sendOptionAction === true) {
78
+ yield put(initMandatoryOptionAction(optionId, values));
79
+ }
80
+ }
81
+ }
82
+
83
+ // Variables
84
+ const variablesIds = Object.keys(inputs.variables);
85
+ for (let i = 0; i < variablesIds.length; i += 1) {
86
+ const variableId = variablesIds[i];
87
+ const values = inputs.variables[variableId];
88
+ yield put(initVariableAction(parseInt(variableId, 10), values));
89
+
90
+ // If variable is mandatory we initiate it
91
+ if (references.variables[variableId].mandatory === true)
92
+ yield put(
93
+ initMandatoryVariableAction(
94
+ parseInt(variableId, 10),
95
+ values.map((value) => `${value}`.trim().length > 0)
96
+ )
97
+ );
98
+ }
99
+
100
+ /**
101
+ * Initiating conditions a second time after initiating inputs
102
+ */
103
+ yield put(initConditionsAction(conditions));
104
+ }
105
+
106
+ function* initInputsSaga() {
107
+ yield takeLatest(INIT_INPUTS, initInputsDecorator);
108
+ }
109
+
110
+ export default initInputsSaga;
@@ -4,6 +4,7 @@ import setDefaultsSaga from "./setDefaults";
4
4
  import saveDataSaga from "./saveData";
5
5
  import homogeneousRadioInputsSaga from "./homogeneousRadioInputsSaga";
6
6
  import setUserEmailSaga from "./setUserEmail";
7
+ import initInputsSaga from "./initInputs";
7
8
 
8
9
  const sagas: { (): any }[] = [
9
10
  fetchModelSaga,
@@ -11,6 +12,7 @@ const sagas: { (): any }[] = [
11
12
  saveDataSaga,
12
13
  setUserEmailSaga,
13
14
  homogeneousRadioInputsSaga,
15
+ initInputsSaga,
14
16
  ];
15
17
 
16
18
  /**
@@ -8,6 +8,10 @@ import { createSelector } from "./selectors";
8
8
  * memoization for them
9
9
  */
10
10
 
11
+ export const selectReferences = createSelector(
12
+ (state: StateType) => state.references
13
+ );
14
+
11
15
  /**
12
16
  * Returns output's reference
13
17
  * @param id Option's id
@@ -39,6 +39,7 @@ import {
39
39
  UPDATE_OPTION_META,
40
40
  } from "../redux/constants/references";
41
41
  import {
42
+ INIT_INPUTS,
42
43
  INIT_OPTION,
43
44
  UPDATE_OPTION_INPUT,
44
45
  INIT_VARIABLE,
@@ -329,6 +330,13 @@ export namespace ActionsType {
329
330
 
330
331
  // Inputs
331
332
  export namespace Inputs {
333
+ // INIT_INPUTS
334
+ export interface initInputs {
335
+ type: typeof INIT_INPUTS;
336
+ references?: StateType.References;
337
+ inputs: StateType.Inputs;
338
+ }
339
+
332
340
  // INIT_OPTION
333
341
  export interface initOption {
334
342
  type: typeof INIT_OPTION;