@legalplace/wizardx-core 2.1.0-alpha.5 → 2.1.0-alpha.7

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,30 @@
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.1.0-alpha.7](https://git.legalplace.eu/legalplace/monorepo/compare/@legalplace/wizardx-core@2.1.0-alpha.6...@legalplace/wizardx-core@2.1.0-alpha.7) (2021-11-24)
7
+
8
+ **Note:** Version bump only for package @legalplace/wizardx-core
9
+
10
+
11
+
12
+
13
+
14
+ # [2.1.0-alpha.6](https://git.legalplace.eu/legalplace/monorepo/compare/@legalplace/wizardx-core@2.1.0-alpha.5...@legalplace/wizardx-core@2.1.0-alpha.6) (2021-11-23)
15
+
16
+
17
+ ### Bug Fixes
18
+
19
+ * fix push api[#3338](https://git.legalplace.eu/legalplace/monorepo/issues/3338) ([1c961d5](https://git.legalplace.eu/legalplace/monorepo/commits/1c961d5a459513f791c2afb363881aa3d9214add))
20
+
21
+
22
+ ### Features
23
+
24
+ * 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))
25
+
26
+
27
+
28
+
29
+
6
30
  # [2.1.0-alpha.5](https://git.legalplace.eu/legalplace/monorepo/compare/@legalplace/wizardx-core@2.1.0-alpha.4...@legalplace/wizardx-core@2.1.0-alpha.5) (2021-11-15)
7
31
 
8
32
 
@@ -15,6 +15,7 @@ declare const connectorSelectors: {
15
15
  selectUserValidToken: () => Readonly<boolean>;
16
16
  selectUserEmail: () => string;
17
17
  isLevelAccessibleForUser: (level: "ADMIN" | "MANAGER" | "USER" | "GUEST" | "SUPER") => Readonly<boolean>;
18
+ selectReferences: () => Readonly<import("@legalplace/referencesparser/dist/libs/References.type").ReferencesType>;
18
19
  selectOutputReference: (id: number) => Readonly<import("@legalplace/referencesparser/dist/libs/References.type").ReferencesSingleOutputType | undefined>;
19
20
  selectBoxReference: (id: number) => Readonly<import("@legalplace/referencesparser/dist/libs/References.type").ReferencesSingleBoxType>;
20
21
  isOptionMultiple: (id: number) => Readonly<boolean | undefined>;
@@ -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,
@@ -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,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,
@@ -277,51 +273,7 @@ function* fetchModelDecorator(action) {
277
273
  if (OvcConverter.isOvc(ovc))
278
274
  ovc = OvcConverter.convertToOptionsVariables(ovc, references);
279
275
  const inputs = new IntputsInitiator(references, ovc).getInputs();
280
- const conditions = new ConditionsInitiator(references, inputs).getConditions();
281
- yield put(initConditionsAction(conditions));
282
- const optionsIds = Object.keys(inputs.options);
283
- for (let i = 0; i < optionsIds.length; i += 1) {
284
- let optionId = parseInt(optionsIds[i], 10);
285
- let values = inputs.options[optionId];
286
- yield put(initOptionAction(optionId, values));
287
- const { meta: meta2 } = references.options[optionId];
288
- const { type } = meta2;
289
- let { mandatory } = meta2;
290
- let sendOptionAction = true;
291
- if (['checkbox', 'radio'].includes(type)) {
292
- if (type === 'radio') {
293
- const { parents } = selectOptionRelations(optionId);
294
- const parentId = parents[0];
295
- const isMandatoryOption = selectMandatoryOptionItem(parentId);
296
- if (typeof isMandatoryOption !== 'undefined') {
297
- const mandatoryOption = selectMandatoryOption(parentId);
298
- sendOptionAction = !mandatoryOption.every((v) => v === true);
299
- if (sendOptionAction === true && mandatoryOption) {
300
- if (values.length >= mandatoryOption.length) {
301
- values = getValues(values, [...mandatoryOption]);
302
- }
303
- else {
304
- values = getValues([...mandatoryOption], values);
305
- }
306
- }
307
- }
308
- mandatory = references.options[parentId].meta.mandatory;
309
- optionId = parentId;
310
- }
311
- if (mandatory === true && sendOptionAction === true) {
312
- yield put(initMandatoryOptionAction(optionId, values));
313
- }
314
- }
315
- }
316
- const variablesIds = Object.keys(inputs.variables);
317
- for (let i = 0; i < variablesIds.length; i += 1) {
318
- const variableId = variablesIds[i];
319
- const values = inputs.variables[variableId];
320
- yield put(initVariableAction(parseInt(variableId, 10), values));
321
- if (references.variables[variableId].mandatory === true)
322
- yield put(initMandatoryVariableAction(parseInt(variableId, 10), values.map((value) => `${value}`.trim().length > 0)));
323
- }
324
- yield put(initConditionsAction(conditions));
276
+ yield call(initInputsDecorator, initInputsAction(inputs, references));
325
277
  const sectionsReferences = selectAllSectionsReferences();
326
278
  if (sectionsReferences === undefined)
327
279
  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));
@@ -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;
@@ -27,10 +27,18 @@ const buildWizardUrl = (uri, prefix, queryParams) => {
27
27
  const searchParams = queryParams.toString()
28
28
  ? `?${queryParams.toString()}`
29
29
  : '';
30
+ console.log('BUILT URL: ', `${apiEndpoint}wizard/contractv1/${organizationPrefix}${uri}${searchParams}`, { uri, prefix, queryParams });
30
31
  return `${apiEndpoint}wizard/contractv1/${organizationPrefix}${uri}${searchParams}`;
31
32
  };
32
33
  const buildFetchModelUrl = (prefix, permalink, uniqidParam, queryParams) => {
33
34
  const uniqidOrFallback = uniqidParam || '/model';
35
+ console.log('fetchModel', {
36
+ prefix,
37
+ permalink,
38
+ uniqidParam,
39
+ queryParams,
40
+ uniqidOrFallback,
41
+ });
34
42
  return buildWizardUrl(`${permalink}${uniqidOrFallback}`, prefix, queryParams);
35
43
  };
36
44
  const buildWizardConfigUrl = (prefix, permalink, uniqidParam, queryParams) => {
@@ -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.1.0-alpha.5",
3
+ "version": "2.1.0-alpha.7",
4
4
  "author": "Moncef Hammou (moncef@legalplace.fr)",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
@@ -45,9 +45,9 @@
45
45
  "xss": "^1.0.9"
46
46
  },
47
47
  "devDependencies": {
48
- "@legalplace/eslint-config": "^2.0.1-alpha.0",
48
+ "@legalplace/eslint-config": "^2.0.3-alpha.0",
49
49
  "@legalplace/models-v3-types": "^3.6.0",
50
- "@legalplace/prettier-config": "^2.0.1-alpha.0",
50
+ "@legalplace/prettier-config": "^2.0.3-alpha.0",
51
51
  "@swc-node/jest": "^1.3.2",
52
52
  "@swc/core": "^1.2.93",
53
53
  "@swc/jest": "^0.2.4",
@@ -82,5 +82,5 @@
82
82
  "*.test.ts",
83
83
  "*.test.tsx"
84
84
  ],
85
- "gitHead": "945d0c37e3afd21b05178a02e5243a81acff60c1"
85
+ "gitHead": "2d15748fbe1a65a7c3f6dc3bdd13103e046d5eda"
86
86
  }
@@ -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,
@@ -3,6 +3,7 @@ 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
5
  import { Task } from '@redux-saga/core';
6
+ import { initInputsAction } from '../actions/inputs';
6
7
  import {
7
8
  initMetaAction,
8
9
  initPaginationAction,
@@ -18,15 +19,9 @@ import {
18
19
  fetchModelNonBlockingAction,
19
20
  setModelUuidAction,
20
21
  } from '../actions/app';
21
- import { ConditionsInitiator } from '../../libs/ConditionsInitiator';
22
22
  import { initReferencesAction } from '../actions/references';
23
- import { initOptionAction, initVariableAction } from '../actions/inputs';
24
- import { initConditionsAction } from '../actions/conditions';
25
23
  import { selectSectionConditionValue } from '../selectors/conditions';
26
- import {
27
- selectAllSectionsReferences,
28
- selectOptionRelations,
29
- } from '../selectors/references';
24
+ import { selectAllSectionsReferences } from '../selectors/references';
30
25
  import { ActionsType } from '../../types/Actions.type';
31
26
  import { selectInstanceUniqid, isStepAvailable } from '../selectors/app';
32
27
  import { getConfig, updateConfig } from '../../config';
@@ -46,14 +41,6 @@ import {
46
41
  } from '../../service/api.manager';
47
42
  import { loadTheme, setWizardTheme } from '../../ThemeLoader';
48
43
  import { loadPlugins } from '../../PluginLoader';
49
- import {
50
- selectMandatoryOptionItem,
51
- selectMandatoryOption,
52
- } from '../selectors/mandatories';
53
- import {
54
- initMandatoryOptionAction,
55
- initMandatoryVariableAction,
56
- } from '../actions/mandatories';
57
44
  import { enableSmartscriptAction } from '../actions/smartscript';
58
45
  import {
59
46
  FETCH_MODEL,
@@ -65,12 +52,10 @@ import {
65
52
  WizardConfigResponse,
66
53
  CreateInstanceResponse,
67
54
  } from '../../types/api.type';
55
+ import { initInputsDecorator } from './initInputs';
68
56
 
69
57
  const cookies = new Cookies();
70
58
 
71
- const getValues = (arr1: boolean[], arr2: boolean[]) =>
72
- arr1.map((v, index) => arr2[index] || v);
73
-
74
59
  function* setFetchModelToNonBlocking(firstCurrentAppState?: string) {
75
60
  yield put(
76
61
  initPaginationAction({
@@ -639,84 +624,7 @@ function* fetchModelDecorator(action: ActionsType.Sagas.Model.fetchModel): any {
639
624
  // Data
640
625
  const inputs = new IntputsInitiator(references, ovc).getInputs();
641
626
 
642
- // Initiating Conditions
643
- const conditions = new ConditionsInitiator(
644
- references,
645
- inputs
646
- ).getConditions();
647
-
648
- /**
649
- * Initiating conditions first before initiating inputs
650
- */
651
- yield put(initConditionsAction(conditions));
652
-
653
- /**
654
- * Initiating inputs
655
- */
656
-
657
- // Options
658
- const optionsIds = Object.keys(inputs.options);
659
- for (let i = 0; i < optionsIds.length; i += 1) {
660
- let optionId = parseInt(optionsIds[i], 10);
661
- let values = inputs.options[optionId];
662
- yield put(initOptionAction(optionId, values));
663
- // If option is mandatory we initiate it
664
- const { meta: meta2 } = references.options[optionId];
665
- const { type } = meta2;
666
- let { mandatory } = meta2;
667
- let sendOptionAction = true;
668
- if (['checkbox', 'radio'].includes(type)) {
669
- if (type === 'radio') {
670
- const { parents } = selectOptionRelations(optionId);
671
- // Get parentId
672
- const parentId = parents[0];
673
- // check if optin exist on mandatory
674
- const isMandatoryOption = selectMandatoryOptionItem(parentId);
675
- // If parentId value = true don't send an action
676
- if (typeof isMandatoryOption !== 'undefined') {
677
- const mandatoryOption = selectMandatoryOption(parentId);
678
- sendOptionAction = !mandatoryOption.every((v) => v === true);
679
- // handle multiple
680
- if (sendOptionAction === true && mandatoryOption) {
681
- if (values.length >= mandatoryOption.length) {
682
- values = getValues(values, [...mandatoryOption]);
683
- } else {
684
- values = getValues([...mandatoryOption], values);
685
- }
686
- }
687
- }
688
-
689
- mandatory = references.options[parentId].meta.mandatory;
690
- optionId = parentId;
691
- }
692
-
693
- if (mandatory === true && sendOptionAction === true) {
694
- yield put(initMandatoryOptionAction(optionId, values));
695
- }
696
- }
697
- }
698
-
699
- // Variables
700
- const variablesIds = Object.keys(inputs.variables);
701
- for (let i = 0; i < variablesIds.length; i += 1) {
702
- const variableId = variablesIds[i];
703
- const values = inputs.variables[variableId];
704
- yield put(initVariableAction(parseInt(variableId, 10), values));
705
-
706
- // If variable is mandatory we initiate it
707
- if (references.variables[variableId].mandatory === true)
708
- yield put(
709
- initMandatoryVariableAction(
710
- parseInt(variableId, 10),
711
- values.map((value) => `${value}`.trim().length > 0)
712
- )
713
- );
714
- }
715
-
716
- /**
717
- * Initiating conditions a second time after initiating inputs
718
- */
719
- yield put(initConditionsAction(conditions));
627
+ yield call(initInputsDecorator, initInputsAction(inputs, references));
720
628
 
721
629
  /**
722
630
  * 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
@@ -47,6 +47,12 @@ const buildWizardUrl = (
47
47
  const searchParams = queryParams.toString()
48
48
  ? `?${queryParams.toString()}`
49
49
  : '';
50
+
51
+ console.log(
52
+ 'BUILT URL: ',
53
+ `${apiEndpoint}wizard/contractv1/${organizationPrefix}${uri}${searchParams}`,
54
+ { uri, prefix, queryParams }
55
+ );
50
56
  return `${apiEndpoint}wizard/contractv1/${organizationPrefix}${uri}${searchParams}`;
51
57
  };
52
58
 
@@ -57,6 +63,13 @@ const buildFetchModelUrl = (
57
63
  queryParams: URLSearchParams
58
64
  ) => {
59
65
  const uniqidOrFallback = uniqidParam || '/model';
66
+ console.log('fetchModel', {
67
+ prefix,
68
+ permalink,
69
+ uniqidParam,
70
+ queryParams,
71
+ uniqidOrFallback,
72
+ });
60
73
  return buildWizardUrl(`${permalink}${uniqidOrFallback}`, prefix, queryParams);
61
74
  };
62
75
 
@@ -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;