@legalplace/wizardx-core 2.6.3 → 2.7.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 +43 -0
- package/dist/App.js +13 -4
- package/dist/PluginLoader.d.ts +3 -1
- package/dist/PluginLoader.js +12 -0
- package/dist/ThemeLoader.d.ts +2 -2
- package/dist/componentsConnectors/connectBox.d.ts +3 -1
- package/dist/componentsConnectors/connectDocument.d.ts +3 -1
- package/dist/componentsConnectors/connectHeader.d.ts +3 -1
- package/dist/componentsConnectors/connectMetaTitle.d.ts +3 -1
- package/dist/componentsConnectors/connectOption.d.ts +6 -2
- package/dist/componentsConnectors/connectOption.js +1 -1
- package/dist/componentsConnectors/connectPagination.d.ts +3 -1
- package/dist/componentsConnectors/connectPreview.d.ts +3 -1
- package/dist/componentsConnectors/connectProgress.d.ts +3 -1
- package/dist/componentsConnectors/connectRootOption.d.ts +3 -1
- package/dist/componentsConnectors/connectSection.d.ts +3 -1
- package/dist/componentsConnectors/connectSection.js +7 -10
- package/dist/componentsConnectors/connectSummary.d.ts +3 -1
- package/dist/componentsConnectors/connectSummaryItem.d.ts +3 -1
- package/dist/componentsConnectors/connectVariable.d.ts +6 -2
- package/dist/componentsConnectors/connectVariable.js +1 -1
- package/dist/componentsConnectors/connectWizardWrapper.d.ts +3 -1
- package/dist/componentsConnectors/connector/componentConnector.d.ts +5 -1
- package/dist/componentsConnectors/connector/componentConnector.js +44 -4
- package/dist/componentsConnectors/connector/index.d.ts +1 -0
- package/dist/componentsConnectors/connector/index.js +1 -0
- package/dist/componentsConnectors/index.d.ts +17 -0
- package/dist/componentsConnectors/index.js +17 -0
- package/dist/componentsConnectors/library.d.ts +43 -15
- package/dist/constants/phoneValidation.d.ts +0 -1
- package/dist/constants/phoneValidation.js +0 -1
- package/dist/helpers/apiEndpoint.d.ts +1 -0
- package/dist/helpers/apiEndpoint.js +4 -0
- package/dist/helpers/index.d.ts +4 -0
- package/dist/helpers/index.js +4 -0
- package/dist/helpers/propsEqualityCheck.d.ts +1 -0
- package/dist/helpers/propsEqualityCheck.js +9 -0
- package/dist/hooks/index.d.ts +4 -0
- package/dist/hooks/index.js +4 -0
- package/dist/hooks/useActions.d.ts +2 -0
- package/dist/hooks/useActions.js +4 -0
- package/dist/hooks/useDispatch.d.ts +1 -0
- package/dist/hooks/useDispatch.js +4 -0
- package/dist/hooks/useSelectors.d.ts +2 -0
- package/dist/hooks/useSelectors.js +4 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +13 -0
- package/dist/libs/EventsTracking.d.ts +0 -1
- package/dist/libs/EventsTracking.js +0 -18
- package/dist/libs/PathReader.d.ts +10 -6
- package/dist/libs/PathReader.js +47 -28
- package/dist/libs/index.d.ts +5 -0
- package/dist/libs/index.js +5 -0
- package/dist/redux/actions/index.d.ts +9 -0
- package/dist/redux/actions/index.js +9 -0
- package/dist/redux/actions/library.d.ts +59 -63
- package/dist/redux/actions/sagas/index.d.ts +3 -0
- package/dist/redux/actions/sagas/index.js +3 -0
- package/dist/redux/actions/sagas/model.d.ts +1 -5
- package/dist/redux/constants/app.d.ts +2 -0
- package/dist/redux/constants/app.js +2 -0
- package/dist/redux/constants/index.d.ts +8 -0
- package/dist/redux/constants/index.js +8 -0
- package/dist/redux/constants/sagas/index.d.ts +3 -0
- package/dist/redux/constants/sagas/index.js +3 -0
- package/dist/redux/index.d.ts +5 -0
- package/dist/redux/index.js +5 -0
- package/dist/redux/middlewares/conditionsWatcherMiddleware.js +11 -5
- package/dist/redux/middlewares/conditionsWatcherMiddleware.test.js +120 -113
- package/dist/redux/middlewares/paginationWatcherMiddleware.js +2 -2
- package/dist/redux/middlewares/smartscriptMiddleware.js +8 -0
- package/dist/redux/reducers/pluginsStore.d.ts +3 -0
- package/dist/redux/reducers/pluginsStore.js +12 -0
- package/dist/redux/routerHistory.js +2 -2
- package/dist/redux/sagas/fetchModel.js +22 -6
- package/dist/redux/sagas/initInputs.js +6 -7
- package/dist/redux/sagas/saveData.js +3 -46
- package/dist/redux/sagas/setUserEmail.js +1 -28
- package/dist/redux/selectors/app.js +13 -18
- package/dist/redux/selectors/cache.d.ts +17 -0
- package/dist/redux/selectors/cache.js +35 -0
- package/dist/redux/selectors/conditions.js +7 -7
- package/dist/redux/selectors/index.d.ts +8 -0
- package/dist/redux/selectors/index.js +8 -0
- package/dist/redux/selectors/inputs.js +3 -3
- package/dist/redux/selectors/library.d.ts +2 -2
- package/dist/redux/selectors/references.js +26 -26
- package/dist/redux/selectors/selectors.d.ts +2 -2
- package/dist/redux/selectors/selectors.js +19 -8
- package/dist/redux/selectors/selectors.test.js +6 -6
- package/dist/redux/selectors/user.js +5 -5
- package/dist/redux/store.d.ts +1 -1
- package/dist/redux/store.js +12 -4
- package/dist/service/api.manager.d.ts +1 -6
- package/dist/service/index.d.ts +3 -0
- package/dist/service/index.js +3 -0
- package/dist/types/PluginConfig.type.d.ts +57 -0
- package/dist/types/PluginConfig.type.js +1 -0
- package/dist/types/State.type.d.ts +6 -0
- package/dist/types/config.type.d.ts +3 -1
- package/dist/types/index.d.ts +11 -0
- package/dist/types/index.js +11 -0
- package/package.json +11 -12
- package/.depcheckrc +0 -1
- package/.eslintignore +0 -2
- package/.eslintrc +0 -5
- package/__mocks__/fileMock.js +0 -1
- package/babel.config.json +0 -3
- package/dist/helpers/sendinblueHelper.d.ts +0 -4
- package/dist/helpers/sendinblueHelper.js +0 -46
- package/dist/libs/Extracts.d.ts +0 -20
- package/dist/libs/Extracts.js +0 -110
- package/jest.config.ts +0 -193
- package/setupJest.ts +0 -8
- package/src/App.test.tsx +0 -41
- package/src/App.tsx +0 -152
- package/src/Globals.ts +0 -69
- package/src/Loader.tsx +0 -8
- package/src/PluginLoader.test.tsx +0 -70
- package/src/PluginLoader.tsx +0 -407
- package/src/Shimmer.tsx +0 -108
- package/src/ThemeLoader.test.tsx +0 -82
- package/src/ThemeLoader.tsx +0 -95
- package/src/components/PluginRoute.tsx +0 -48
- package/src/components/SmartScript.tsx +0 -166
- package/src/components/UserLocked/UserLockedComponent.tsx +0 -33
- package/src/components/View.test.tsx +0 -110
- package/src/components/View.tsx +0 -114
- package/src/componentsConnectors/connectBox.test.tsx +0 -226
- package/src/componentsConnectors/connectBox.tsx +0 -70
- package/src/componentsConnectors/connectDocument.test.tsx +0 -108
- package/src/componentsConnectors/connectDocument.tsx +0 -64
- package/src/componentsConnectors/connectHeader.tsx +0 -21
- package/src/componentsConnectors/connectMetaTitle.test.tsx +0 -40
- package/src/componentsConnectors/connectMetaTitle.tsx +0 -8
- package/src/componentsConnectors/connectOption.tsx +0 -222
- package/src/componentsConnectors/connectPagination.tsx +0 -102
- package/src/componentsConnectors/connectPreview.tsx +0 -5
- package/src/componentsConnectors/connectProgress.tsx +0 -59
- package/src/componentsConnectors/connectRootOption.tsx +0 -95
- package/src/componentsConnectors/connectSection.tsx +0 -79
- package/src/componentsConnectors/connectSummary.tsx +0 -21
- package/src/componentsConnectors/connectSummaryItem.tsx +0 -102
- package/src/componentsConnectors/connectTermsheet.tsx +0 -359
- package/src/componentsConnectors/connectVariable.tsx +0 -191
- package/src/componentsConnectors/connectWizardWrapper.tsx +0 -30
- package/src/componentsConnectors/connector/componentConnector.tsx +0 -219
- package/src/componentsConnectors/library.ts +0 -35
- package/src/config.test.ts +0 -63
- package/src/config.ts +0 -11
- package/src/constants/emailValidation.ts +0 -2
- package/src/constants/phoneValidation.ts +0 -6
- package/src/definitions/path.join.d.ts +0 -4
- package/src/helpers/outputsParsing.ts +0 -412
- package/src/helpers/preloadTheme.ts +0 -17
- package/src/helpers/scriptsLoader.ts +0 -20
- package/src/helpers/sendinblueHelper.ts +0 -65
- package/src/hooks/usePrevious.ts +0 -9
- package/src/libs/ConditionsInitiator.ts +0 -164
- package/src/libs/ConditionsRunner/DataPopulator.ts +0 -266
- package/src/libs/ConditionsRunner.ts +0 -454
- package/src/libs/DocumentsOutputs.ts +0 -171
- package/src/libs/Eval/EvalBase.ts +0 -116
- package/src/libs/Eval/EvalFunctions.ts +0 -724
- package/src/libs/Eval/NumbersToLetters.ts +0 -185
- package/src/libs/EvalVariable.ts +0 -265
- package/src/libs/EventsTracking.ts +0 -276
- package/src/libs/Extracts.ts +0 -159
- package/src/libs/InputsInitiator.ts +0 -136
- package/src/libs/NumAuto.test.ts +0 -55
- package/src/libs/NumAuto.ts +0 -56
- package/src/libs/OvcConverter.ts +0 -285
- package/src/libs/PathReader.ts +0 -272
- package/src/libs/SectionValidity.test.ts +0 -146
- package/src/libs/SectionValidity.ts +0 -110
- package/src/libs/SmartScriptStore.ts +0 -492
- package/src/misc/test_model.ts +0 -14603
- package/src/misc/test_models/connectDocumen.testmodel.json +0 -178
- package/src/misc/test_models/setDefaults.testmodel.json +0 -279
- package/src/misc/test_models/testmodel.json +0 -1
- package/src/polyfills/index.ts +0 -5
- package/src/polyfills/objectValues.ts +0 -4
- package/src/polyfills/prepend.ts +0 -31
- package/src/polyfills/stringRepeat.ts +0 -44
- package/src/redux/actions/app.test.ts +0 -123
- package/src/redux/actions/app.ts +0 -249
- package/src/redux/actions/conditions.test.ts +0 -84
- package/src/redux/actions/conditions.ts +0 -135
- package/src/redux/actions/inputs.test.ts +0 -85
- package/src/redux/actions/inputs.ts +0 -111
- package/src/redux/actions/library.ts +0 -23
- package/src/redux/actions/mandatories.ts +0 -98
- package/src/redux/actions/references.test.ts +0 -48
- package/src/redux/actions/references.ts +0 -37
- package/src/redux/actions/sagas/data.test.ts +0 -11
- package/src/redux/actions/sagas/data.ts +0 -18
- package/src/redux/actions/sagas/model.test.ts +0 -14
- package/src/redux/actions/sagas/model.ts +0 -48
- package/src/redux/actions/sagas/user.ts +0 -25
- package/src/redux/actions/smartscript.ts +0 -55
- package/src/redux/actions/user.test.ts +0 -18
- package/src/redux/actions/user.ts +0 -41
- package/src/redux/constants/app.ts +0 -36
- package/src/redux/constants/conditions.ts +0 -25
- package/src/redux/constants/inputs.ts +0 -15
- package/src/redux/constants/mandatories.ts +0 -11
- package/src/redux/constants/references.ts +0 -7
- package/src/redux/constants/sagas/data.ts +0 -1
- package/src/redux/constants/sagas/model.ts +0 -2
- package/src/redux/constants/sagas/user.ts +0 -2
- package/src/redux/constants/smartscript.ts +0 -9
- package/src/redux/constants/user.ts +0 -6
- package/src/redux/listeners/subscriber.test.ts +0 -45
- package/src/redux/listeners/subscriber.ts +0 -29
- package/src/redux/middlewares/conditionsWatcherMiddleware.test.ts +0 -370
- package/src/redux/middlewares/conditionsWatcherMiddleware.ts +0 -321
- package/src/redux/middlewares/evaluationsWatcherMiddleware.test.ts +0 -323
- package/src/redux/middlewares/evaluationsWatcherMiddleware.ts +0 -250
- package/src/redux/middlewares/mandatoriesWatcherMiddleware.ts +0 -473
- package/src/redux/middlewares/multiplesActionsMiddleware.test.ts +0 -230
- package/src/redux/middlewares/multiplesActionsMiddleware.ts +0 -121
- package/src/redux/middlewares/paginationWatcherMiddleware.ts +0 -251
- package/src/redux/middlewares/pluginsHookMiddleware.ts +0 -24
- package/src/redux/middlewares/prefillerWatcherMiddleware.test.ts +0 -118
- package/src/redux/middlewares/prefillerWatcherMiddleware.ts +0 -462
- package/src/redux/middlewares/smartscriptMiddleware.ts +0 -228
- package/src/redux/middlewares/thirdpartyScriptsMiddleware.ts +0 -41
- package/src/redux/reducers/app/customizations/initCustomizationAutoDefault.ts +0 -16
- package/src/redux/reducers/app/customizations/initCustomizationMeta.ts +0 -16
- package/src/redux/reducers/app/instance/initInstance.ts +0 -29
- package/src/redux/reducers/app/instance/setDataStatus.ts +0 -16
- package/src/redux/reducers/app/instance/updateInstance.ts +0 -30
- package/src/redux/reducers/app/instance/updateInstancePaid.ts +0 -20
- package/src/redux/reducers/app/instance.test.ts +0 -106
- package/src/redux/reducers/app/meta/fetchModelFailed.ts +0 -11
- package/src/redux/reducers/app/meta/fetchModelNonBlocking.ts +0 -11
- package/src/redux/reducers/app/meta/fetchModelSucceeded.ts +0 -11
- package/src/redux/reducers/app/meta/fetchModelUnhealthy.ts +0 -18
- package/src/redux/reducers/app/meta/fetchModelUserLocked.ts +0 -11
- package/src/redux/reducers/app/meta/initMeta.ts +0 -22
- package/src/redux/reducers/app/meta/setModelUuid.ts +0 -17
- package/src/redux/reducers/app/meta.test.ts +0 -90
- package/src/redux/reducers/app/pagination/goNextPage.ts +0 -69
- package/src/redux/reducers/app/pagination/goPage.ts +0 -81
- package/src/redux/reducers/app/pagination/goPreviousPage.ts +0 -60
- package/src/redux/reducers/app/pagination/initPagination.ts +0 -46
- package/src/redux/reducers/app/pagination/updateAvailableAppStates.ts +0 -77
- package/src/redux/reducers/app/pagination.test.ts +0 -363
- package/src/redux/reducers/app/wizard/updateAvailableSections.ts +0 -40
- package/src/redux/reducers/app/wizard.test.ts +0 -84
- package/src/redux/reducers/app.test.ts +0 -336
- package/src/redux/reducers/app.ts +0 -150
- package/src/redux/reducers/conditions/addMultipleOccurency.test.ts +0 -131
- package/src/redux/reducers/conditions/addMultipleOccurency.ts +0 -155
- package/src/redux/reducers/conditions/deleteMultipleOccurency.test.ts +0 -95
- package/src/redux/reducers/conditions/deleteMultipleOccurency.ts +0 -141
- package/src/redux/reducers/conditions/initConditions.ts +0 -18
- package/src/redux/reducers/conditions/updateDocumentConditions.test.ts +0 -47
- package/src/redux/reducers/conditions/updateDocumentConditions.ts +0 -21
- package/src/redux/reducers/conditions/updateOptionConditions.ts +0 -24
- package/src/redux/reducers/conditions/updateOptionValidatorCondition.test.ts +0 -50
- package/src/redux/reducers/conditions/updateOptionValidatorCondition.ts +0 -28
- package/src/redux/reducers/conditions/updatePrefillerConditions.ts +0 -29
- package/src/redux/reducers/conditions/updateSectionConditions.ts +0 -28
- package/src/redux/reducers/conditions/updateVariableConditions.ts +0 -25
- package/src/redux/reducers/conditions/updateVariableValidatorCondition.test.ts +0 -50
- package/src/redux/reducers/conditions/updateVariableValidatorCondition.ts +0 -28
- package/src/redux/reducers/conditions.test.ts +0 -241
- package/src/redux/reducers/conditions.ts +0 -68
- package/src/redux/reducers/inputs/addMultipleOccurency.test.ts +0 -117
- package/src/redux/reducers/inputs/addMultipleOccurency.ts +0 -50
- package/src/redux/reducers/inputs/deleteMultipleOccurency.test.ts +0 -70
- package/src/redux/reducers/inputs/deleteMultipleOccurency.ts +0 -50
- package/src/redux/reducers/inputs/initOption.ts +0 -16
- package/src/redux/reducers/inputs/initVariable.ts +0 -16
- package/src/redux/reducers/inputs/updateOptionInput.ts +0 -24
- package/src/redux/reducers/inputs/updateVariableInput.ts +0 -24
- package/src/redux/reducers/inputs.test.ts +0 -221
- package/src/redux/reducers/inputs.ts +0 -51
- package/src/redux/reducers/mandatories/addMultipleOccurency.ts +0 -52
- package/src/redux/reducers/mandatories/deleteMultipleOccurency.ts +0 -55
- package/src/redux/reducers/mandatories/initMandatoryOption.ts +0 -17
- package/src/redux/reducers/mandatories/initMandatoryVariable.ts +0 -17
- package/src/redux/reducers/mandatories/setMandatoryIgnore.ts +0 -17
- package/src/redux/reducers/mandatories/setMandatoryOption.ts +0 -25
- package/src/redux/reducers/mandatories/setMandatorySection.ts +0 -20
- package/src/redux/reducers/mandatories/setMandatoryVariable.ts +0 -24
- package/src/redux/reducers/mandatories.ts +0 -56
- package/src/redux/reducers/references/initReferences.ts +0 -37
- package/src/redux/reducers/references/updateOptionMeta.ts +0 -73
- package/src/redux/reducers/references/updateVariableMeta.ts +0 -72
- package/src/redux/reducers/references.ts +0 -59
- package/src/redux/reducers/smartscript/enableSmartScript.ts +0 -13
- package/src/redux/reducers/smartscript/initSmartScriptTriggers.ts +0 -14
- package/src/redux/reducers/smartscript/updateSmartscriptOptionHidden.ts +0 -30
- package/src/redux/reducers/smartscript/updateSmartscriptVariableHidden.ts +0 -30
- package/src/redux/reducers/smartscript.ts +0 -47
- package/src/redux/reducers/user/initUser.ts +0 -15
- package/src/redux/reducers/user/setUserStatus.ts +0 -13
- package/src/redux/reducers/user/setUserValidToken.ts +0 -13
- package/src/redux/reducers/user.test.ts +0 -51
- package/src/redux/reducers/user.ts +0 -40
- package/src/redux/routerHistore.test.ts +0 -19
- package/src/redux/routerHistory.ts +0 -26
- package/src/redux/sagas/fetchModel.test.ts +0 -76
- package/src/redux/sagas/fetchModel.ts +0 -683
- package/src/redux/sagas/homogeneousRadioInputsSaga.ts +0 -42
- package/src/redux/sagas/initInputs.ts +0 -110
- package/src/redux/sagas/runner.test.ts +0 -12
- package/src/redux/sagas/runner.ts +0 -26
- package/src/redux/sagas/saveData.test.ts +0 -125
- package/src/redux/sagas/saveData.ts +0 -116
- package/src/redux/sagas/setDefaults.test.ts +0 -100
- package/src/redux/sagas/setDefaults.ts +0 -167
- package/src/redux/sagas/setUserEmail.ts +0 -221
- package/src/redux/selectors/app.test.ts +0 -162
- package/src/redux/selectors/app.ts +0 -331
- package/src/redux/selectors/conditions.test.ts +0 -92
- package/src/redux/selectors/conditions.ts +0 -293
- package/src/redux/selectors/inputs.test.ts +0 -72
- package/src/redux/selectors/inputs.ts +0 -76
- package/src/redux/selectors/library.ts +0 -17
- package/src/redux/selectors/mandatories.ts +0 -83
- package/src/redux/selectors/references.test.ts +0 -660
- package/src/redux/selectors/references.ts +0 -413
- package/src/redux/selectors/selectors.test.ts +0 -21
- package/src/redux/selectors/selectors.ts +0 -87
- package/src/redux/selectors/smartscript.ts +0 -30
- package/src/redux/selectors/user.test.ts +0 -39
- package/src/redux/selectors/user.ts +0 -45
- package/src/redux/store.test.ts +0 -22
- package/src/redux/store.ts +0 -100
- package/src/service/api.manager.ts +0 -261
- package/src/service/auth.service.ts +0 -5
- package/src/service/pardot.service.ts +0 -10
- package/src/tests-misc/plugins/jestTestPlugin/after.tsx +0 -5
- package/src/tests-misc/plugins/jestTestPlugin/before.tsx +0 -11
- package/src/tests-misc/plugins/jestTestPlugin/index.ts +0 -11
- package/src/tests-misc/plugins/jestTestPlugin/title.tsx +0 -8
- package/src/tests-misc/themes/jestTestTheme/components/EmailComponent.tsx +0 -5
- package/src/tests-misc/themes/jestTestTheme/components/TermsheetComponent.tsx +0 -5
- package/src/tests-misc/themes/jestTestTheme/components/WizardComponent.tsx +0 -5
- package/src/tests-misc/themes/jestTestTheme/faltyIndex.ts +0 -3
- package/src/tests-misc/themes/jestTestTheme/faltyIndexLoader.ts +0 -1
- package/src/tests-misc/themes/jestTestTheme/index.ts +0 -13
- package/src/types/Actions.type.ts +0 -612
- package/src/types/Components.type.ts +0 -181
- package/src/types/State.type.ts +0 -323
- package/src/types/Termsheet.type.ts +0 -28
- package/src/types/api.type.ts +0 -37
- package/src/types/config.type.ts +0 -55
- package/src/types/env.type.ts +0 -5
- package/src/types/getActions.type.ts +0 -3
- package/src/types/getConnectors.type.ts +0 -5
- package/src/types/getSelectors.type.ts +0 -3
- package/src/wizard-params.ts +0 -56
- package/tsconfig.json +0 -43
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { put, takeLatest } from "redux-saga/effects";
|
|
2
|
-
import { UPDATE_OPTION_INPUT } from "../constants/inputs";
|
|
3
|
-
import { ActionsType } from "../../types/Actions.type";
|
|
4
|
-
import { selectRadioSiblings } from "../selectors/references";
|
|
5
|
-
import { updateOptionAction } from "../actions/inputs";
|
|
6
|
-
import { selectOptionInputByIndex } from "../selectors/inputs";
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* This Saga helps make sure radio inputs are homogenous,
|
|
10
|
-
* when a radio is set to true, this saga makes sure all
|
|
11
|
-
* its siblings are false
|
|
12
|
-
* @param action UPDATE_OPTION_INPUT Action
|
|
13
|
-
*/
|
|
14
|
-
function* homogeneousRadioInputsDecorator(
|
|
15
|
-
action: ActionsType.Inputs.updateOptionInput
|
|
16
|
-
) {
|
|
17
|
-
// Getting option siblings
|
|
18
|
-
const { id, index, value } = action;
|
|
19
|
-
|
|
20
|
-
if (value === true) {
|
|
21
|
-
/**
|
|
22
|
-
* In case the option we are asked to update
|
|
23
|
-
* is a radio, and we need to set it to true
|
|
24
|
-
* we need to make sure all its siblings are
|
|
25
|
-
* set to false
|
|
26
|
-
*/
|
|
27
|
-
const radioSiblings = selectRadioSiblings(id);
|
|
28
|
-
if (radioSiblings && value === true) {
|
|
29
|
-
for (let i = 0; i < radioSiblings.length; i += 1) {
|
|
30
|
-
const siblingId = radioSiblings[i];
|
|
31
|
-
if (selectOptionInputByIndex(siblingId, index) === true)
|
|
32
|
-
yield put(updateOptionAction(siblingId, false, index));
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function* homogeneousRadioInputsSaga() {
|
|
39
|
-
yield takeLatest(UPDATE_OPTION_INPUT, homogeneousRadioInputsDecorator);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export default homogeneousRadioInputsSaga;
|
|
@@ -1,110 +0,0 @@
|
|
|
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;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { sagasRunner } from './runner';
|
|
2
|
-
|
|
3
|
-
describe('Runner', () => {
|
|
4
|
-
it('Runs sagas', () => {
|
|
5
|
-
// @ts-ignore: Ignoring for mock
|
|
6
|
-
const SagaMiddleware: SagaMiddleware = {
|
|
7
|
-
run: jest.fn(),
|
|
8
|
-
};
|
|
9
|
-
sagasRunner(SagaMiddleware);
|
|
10
|
-
expect(SagaMiddleware.run).toHaveBeenCalled();
|
|
11
|
-
});
|
|
12
|
-
});
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { SagaMiddleware } from "@redux-saga/core";
|
|
2
|
-
import fetchModelSaga from "./fetchModel";
|
|
3
|
-
import setDefaultsSaga from "./setDefaults";
|
|
4
|
-
import saveDataSaga from "./saveData";
|
|
5
|
-
import homogeneousRadioInputsSaga from "./homogeneousRadioInputsSaga";
|
|
6
|
-
import setUserEmailSaga from "./setUserEmail";
|
|
7
|
-
import initInputsSaga from "./initInputs";
|
|
8
|
-
|
|
9
|
-
const sagas: { (): any }[] = [
|
|
10
|
-
fetchModelSaga,
|
|
11
|
-
setDefaultsSaga,
|
|
12
|
-
saveDataSaga,
|
|
13
|
-
setUserEmailSaga,
|
|
14
|
-
homogeneousRadioInputsSaga,
|
|
15
|
-
initInputsSaga,
|
|
16
|
-
];
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
*
|
|
20
|
-
* @param sagaMiddleware Saga's middleware
|
|
21
|
-
*/
|
|
22
|
-
export const sagasRunner = (
|
|
23
|
-
sagaMiddleware: SagaMiddleware<Record<string, unknown>>
|
|
24
|
-
) => {
|
|
25
|
-
sagas.forEach((saga) => sagaMiddleware.run(saga));
|
|
26
|
-
};
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import * as fs from 'fs';
|
|
2
|
-
import { ReferencesParser } from '@legalplace/referencesparser';
|
|
3
|
-
import { createAppStore, getStore } from '../store';
|
|
4
|
-
import {
|
|
5
|
-
initMetaAction,
|
|
6
|
-
initPaginationAction,
|
|
7
|
-
initInstanceAction,
|
|
8
|
-
} from '../actions/app';
|
|
9
|
-
import { initReferencesAction } from '../actions/references';
|
|
10
|
-
import { IntputsInitiator } from '../../libs/InputsInitiator';
|
|
11
|
-
import {
|
|
12
|
-
initOptionAction,
|
|
13
|
-
initVariableAction,
|
|
14
|
-
updateOptionAction,
|
|
15
|
-
} from '../actions/inputs';
|
|
16
|
-
import { initConditionsAction } from '../actions/conditions';
|
|
17
|
-
import { ConditionsInitiator } from '../../libs/ConditionsInitiator';
|
|
18
|
-
import { saveDataAction } from '../actions/sagas/data';
|
|
19
|
-
|
|
20
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
21
|
-
require('jest-fetch-mock').enableMocks();
|
|
22
|
-
|
|
23
|
-
const permalink = 'test-model';
|
|
24
|
-
const uniqid = 'myMockUniqid';
|
|
25
|
-
const mockApiEndpoint = 'https://api.mock/api/v1/';
|
|
26
|
-
|
|
27
|
-
// Mocking config
|
|
28
|
-
jest.mock('../../config', () => ({
|
|
29
|
-
getConfig: () => ({
|
|
30
|
-
apiEndpoint: mockApiEndpoint,
|
|
31
|
-
}),
|
|
32
|
-
}));
|
|
33
|
-
|
|
34
|
-
describe('Save data saga', () => {
|
|
35
|
-
let store: any;
|
|
36
|
-
beforeEach(() => {
|
|
37
|
-
createAppStore('memory');
|
|
38
|
-
store = getStore();
|
|
39
|
-
store.dispatch({
|
|
40
|
-
type: 'SET_DEFAULTS',
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
// Initiating references
|
|
44
|
-
const model = JSON.parse(
|
|
45
|
-
fs.readFileSync(
|
|
46
|
-
'./src/misc/test_models/setDefaults.testmodel.json',
|
|
47
|
-
'utf8'
|
|
48
|
-
)
|
|
49
|
-
);
|
|
50
|
-
const references = new ReferencesParser(model).getReferences();
|
|
51
|
-
store.dispatch(initReferencesAction(references));
|
|
52
|
-
|
|
53
|
-
// Inputs initiation
|
|
54
|
-
const inputs = new IntputsInitiator(references, null).getInputs();
|
|
55
|
-
Object.keys(inputs.options).forEach((optionId) => {
|
|
56
|
-
const values = inputs.options[optionId];
|
|
57
|
-
store.dispatch(initOptionAction(parseInt(optionId, 10), values));
|
|
58
|
-
});
|
|
59
|
-
Object.keys(inputs.variables).forEach((variableId) => {
|
|
60
|
-
const values = inputs.variables[variableId];
|
|
61
|
-
store.dispatch(initVariableAction(parseInt(variableId, 10), values));
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
// Initiating Meta
|
|
65
|
-
store.dispatch(
|
|
66
|
-
initMetaAction({
|
|
67
|
-
id: 123,
|
|
68
|
-
title: 'Test model',
|
|
69
|
-
permalink,
|
|
70
|
-
modelVersion: 1,
|
|
71
|
-
prefix: '',
|
|
72
|
-
productType: 'demarche',
|
|
73
|
-
})
|
|
74
|
-
);
|
|
75
|
-
|
|
76
|
-
// Initiating Meta
|
|
77
|
-
store.dispatch(
|
|
78
|
-
initInstanceAction({
|
|
79
|
-
uniqid,
|
|
80
|
-
isPaid: false,
|
|
81
|
-
dataStatus: 'unsaved',
|
|
82
|
-
steps: '*',
|
|
83
|
-
})
|
|
84
|
-
);
|
|
85
|
-
|
|
86
|
-
// Initiating Pagination
|
|
87
|
-
store.dispatch(
|
|
88
|
-
initPaginationAction({
|
|
89
|
-
availableAppStates: ['wizard', 'termsheet'],
|
|
90
|
-
currentAppState: 'wizard',
|
|
91
|
-
currentPage: 4,
|
|
92
|
-
greatestPage: 4,
|
|
93
|
-
currentSectionId: 1,
|
|
94
|
-
availableSections: [1, 3],
|
|
95
|
-
})
|
|
96
|
-
);
|
|
97
|
-
|
|
98
|
-
// Initiating conditions
|
|
99
|
-
const conditions = new ConditionsInitiator(
|
|
100
|
-
references,
|
|
101
|
-
inputs
|
|
102
|
-
).getConditions();
|
|
103
|
-
store.dispatch(initConditionsAction(conditions));
|
|
104
|
-
|
|
105
|
-
// Setting defaults
|
|
106
|
-
store.dispatch({ type: 'SET_DEFAULTS' });
|
|
107
|
-
|
|
108
|
-
// Making some more updates in the inputs
|
|
109
|
-
store.dispatch(updateOptionAction(15, true, 0));
|
|
110
|
-
|
|
111
|
-
// Resetting fetch mocks
|
|
112
|
-
fetchMock.resetMocks();
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
it('Sends save request to API', () => {
|
|
116
|
-
fetchMock.mockResponseOnce(JSON.stringify({ status: 'success' }));
|
|
117
|
-
|
|
118
|
-
store.dispatch(saveDataAction());
|
|
119
|
-
|
|
120
|
-
expect(fetchMock.mock.calls.length).toEqual(1);
|
|
121
|
-
expect(fetchMock.mock.calls[0][0]).toEqual(
|
|
122
|
-
`${mockApiEndpoint}wizard/instance/${permalink}/${uniqid}`
|
|
123
|
-
);
|
|
124
|
-
});
|
|
125
|
-
});
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import { call, put, takeLatest } from "redux-saga/effects";
|
|
2
|
-
import { v4 as uuid } from "uuid";
|
|
3
|
-
import { setDataStatus } from "../actions/app";
|
|
4
|
-
import {
|
|
5
|
-
selectPermalink,
|
|
6
|
-
selectInstanceUniqid,
|
|
7
|
-
selectDocumentTitle,
|
|
8
|
-
selectInstanceIsPaid,
|
|
9
|
-
} from "../selectors/app";
|
|
10
|
-
import { SAVE_DATA } from "../constants/sagas/data";
|
|
11
|
-
import { selectInputs } from "../selectors/inputs";
|
|
12
|
-
import { OvcConverter } from "../../libs/OvcConverter";
|
|
13
|
-
import { ActionsType } from "../../types/Actions.type";
|
|
14
|
-
import { updateInstanceArguments } from "../../service/api.manager";
|
|
15
|
-
import { getSendinblueIdentifyAttributes } from "../../helpers/sendinblueHelper";
|
|
16
|
-
import { getConfig } from "../../config";
|
|
17
|
-
import { selectUserEmail } from "../selectors/user";
|
|
18
|
-
|
|
19
|
-
const getSendinblueData = async (uniqid: string, paid: boolean) => {
|
|
20
|
-
const email = selectUserEmail();
|
|
21
|
-
const apiEndpoint =
|
|
22
|
-
getConfig().apiEndpoint + (/\/$/.test(getConfig().apiEndpoint) ? "" : "/");
|
|
23
|
-
|
|
24
|
-
// Getting OVC
|
|
25
|
-
const ovc = OvcConverter.convertToOvc(selectInputs());
|
|
26
|
-
|
|
27
|
-
// Counting filled variables
|
|
28
|
-
const nbFilledVars = Object.keys(ovc.v).reduce((p, c) => {
|
|
29
|
-
const currentValue = ovc.v[c];
|
|
30
|
-
// eslint-disable-next-line no-nested-ternary
|
|
31
|
-
const o: number = Array.isArray(currentValue)
|
|
32
|
-
? currentValue.reduce((_p: number, _c) => _p + (_c !== "" ? 1 : 0), 0)
|
|
33
|
-
: currentValue !== ""
|
|
34
|
-
? 1
|
|
35
|
-
: 0;
|
|
36
|
-
return p + o;
|
|
37
|
-
}, 0);
|
|
38
|
-
// if (typeof window.sendinblue !== 'undefined' && response.user) {
|
|
39
|
-
const attributes = await getSendinblueIdentifyAttributes(
|
|
40
|
-
uniqid as string,
|
|
41
|
-
selectDocumentTitle(),
|
|
42
|
-
nbFilledVars,
|
|
43
|
-
paid,
|
|
44
|
-
window.location.host
|
|
45
|
-
);
|
|
46
|
-
return [apiEndpoint, email, attributes];
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
function* saveDataDecorator(
|
|
50
|
-
action: ActionsType.Sagas.Data.saveData
|
|
51
|
-
): Generator<any, any, any> {
|
|
52
|
-
try {
|
|
53
|
-
// eslint-disable-next-line no-console
|
|
54
|
-
yield put(setDataStatus("saving"));
|
|
55
|
-
const permalink = selectPermalink();
|
|
56
|
-
const uniqid = selectInstanceUniqid();
|
|
57
|
-
// @ts-ignore because of saga implementation
|
|
58
|
-
const response = yield call(
|
|
59
|
-
// @ts-ignore because of saga implementation
|
|
60
|
-
fetch,
|
|
61
|
-
...updateInstanceArguments(
|
|
62
|
-
permalink,
|
|
63
|
-
uniqid,
|
|
64
|
-
OvcConverter.convertToOvc(selectInputs()),
|
|
65
|
-
action.confirmAnswer ? 0 : 1,
|
|
66
|
-
action.additionalProperties
|
|
67
|
-
)
|
|
68
|
-
);
|
|
69
|
-
// @ts-ignore because of saga implementation
|
|
70
|
-
const responseData = yield call([response, "json"]);
|
|
71
|
-
// Redirecting if we recieved order to
|
|
72
|
-
if (action.redirect === true) {
|
|
73
|
-
if (responseData.redirect_to) {
|
|
74
|
-
try {
|
|
75
|
-
// Get Data to send to sendinblue
|
|
76
|
-
const [apiEndpoint, email, attributes] = yield call(
|
|
77
|
-
// @ts-ignore: due to saga implementation
|
|
78
|
-
getSendinblueData,
|
|
79
|
-
[uniqid as string, selectInstanceIsPaid()]
|
|
80
|
-
);
|
|
81
|
-
yield call(fetch, `${apiEndpoint}event/create/${uniqid}/${uuid()}`, {
|
|
82
|
-
method: "POST",
|
|
83
|
-
credentials: "include",
|
|
84
|
-
headers: {
|
|
85
|
-
"Content-Type": "application/json",
|
|
86
|
-
},
|
|
87
|
-
body: JSON.stringify({
|
|
88
|
-
email,
|
|
89
|
-
attributes,
|
|
90
|
-
}),
|
|
91
|
-
});
|
|
92
|
-
} catch (error) {
|
|
93
|
-
// keep going in case the request fail for now
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
window.onbeforeunload = () => {};
|
|
97
|
-
window.location.href = responseData.redirect_to;
|
|
98
|
-
} else if (action.redirectFallback) {
|
|
99
|
-
window.onbeforeunload = () => {};
|
|
100
|
-
window.location.href = action.redirectFallback;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
yield put(setDataStatus("saved"));
|
|
105
|
-
} catch (e) {
|
|
106
|
-
// eslint-disable-next-line no-console
|
|
107
|
-
console.error(e);
|
|
108
|
-
yield put(setDataStatus("failed"));
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
function* saveDataSaga() {
|
|
113
|
-
yield takeLatest(SAVE_DATA, saveDataDecorator);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
export default saveDataSaga;
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import * as fs from 'fs';
|
|
2
|
-
import { ReferencesParser } from '@legalplace/referencesparser';
|
|
3
|
-
import { createAppStore, getStore } from '../store';
|
|
4
|
-
import { initMetaAction, initPaginationAction } from '../actions/app';
|
|
5
|
-
import { initReferencesAction } from '../actions/references';
|
|
6
|
-
import { IntputsInitiator } from '../../libs/InputsInitiator';
|
|
7
|
-
import { initOptionAction, initVariableAction } from '../actions/inputs';
|
|
8
|
-
import { initConditionsAction } from '../actions/conditions';
|
|
9
|
-
import { ConditionsInitiator } from '../../libs/ConditionsInitiator';
|
|
10
|
-
|
|
11
|
-
describe('Set defaults saga', () => {
|
|
12
|
-
let store: any;
|
|
13
|
-
beforeEach(() => {
|
|
14
|
-
createAppStore('memory');
|
|
15
|
-
store = getStore();
|
|
16
|
-
store.dispatch({
|
|
17
|
-
type: 'SET_DEFAULTS',
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
// Initiating references
|
|
21
|
-
const model = JSON.parse(
|
|
22
|
-
fs.readFileSync(
|
|
23
|
-
'./src/misc/test_models/setDefaults.testmodel.json',
|
|
24
|
-
'utf8'
|
|
25
|
-
)
|
|
26
|
-
);
|
|
27
|
-
const references = new ReferencesParser(model).getReferences();
|
|
28
|
-
store.dispatch(initReferencesAction(references));
|
|
29
|
-
|
|
30
|
-
// Inputs initiation
|
|
31
|
-
const inputs = new IntputsInitiator(references, null).getInputs();
|
|
32
|
-
Object.keys(inputs.options).forEach((optionId) => {
|
|
33
|
-
const values = inputs.options[optionId];
|
|
34
|
-
store.dispatch(initOptionAction(parseInt(optionId, 10), values));
|
|
35
|
-
});
|
|
36
|
-
Object.keys(inputs.variables).forEach((variableId) => {
|
|
37
|
-
const values = inputs.variables[variableId];
|
|
38
|
-
store.dispatch(initVariableAction(parseInt(variableId, 10), values));
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
// Initiating Meta
|
|
42
|
-
store.dispatch(
|
|
43
|
-
initMetaAction({
|
|
44
|
-
id: 123,
|
|
45
|
-
title: 'Test model',
|
|
46
|
-
permalink: 'test-model',
|
|
47
|
-
prefix: '',
|
|
48
|
-
modelVersion: 1,
|
|
49
|
-
productType: 'demarche',
|
|
50
|
-
})
|
|
51
|
-
);
|
|
52
|
-
|
|
53
|
-
// Initiating Pagination
|
|
54
|
-
store.dispatch(
|
|
55
|
-
initPaginationAction({
|
|
56
|
-
availableAppStates: ['wizard', 'termsheet'],
|
|
57
|
-
currentAppState: 'wizard',
|
|
58
|
-
currentPage: 4,
|
|
59
|
-
greatestPage: 4,
|
|
60
|
-
currentSectionId: 1,
|
|
61
|
-
availableSections: [1, 3],
|
|
62
|
-
})
|
|
63
|
-
);
|
|
64
|
-
|
|
65
|
-
// Initiating conditions
|
|
66
|
-
const conditions = new ConditionsInitiator(
|
|
67
|
-
references,
|
|
68
|
-
inputs
|
|
69
|
-
).getConditions();
|
|
70
|
-
store.dispatch(initConditionsAction(conditions));
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it('Sets defaults properly', () => {
|
|
74
|
-
// Setting defaults
|
|
75
|
-
store.dispatch({ type: 'SET_DEFAULTS' });
|
|
76
|
-
|
|
77
|
-
expect(store.getState().app.wizard.availableSections).toStrictEqual([
|
|
78
|
-
1, 2, 3,
|
|
79
|
-
]);
|
|
80
|
-
|
|
81
|
-
expect(store.getState().inputs.options).toStrictEqual({
|
|
82
|
-
1: [true],
|
|
83
|
-
2: [true],
|
|
84
|
-
3: [false],
|
|
85
|
-
4: [true],
|
|
86
|
-
5: [true],
|
|
87
|
-
6: [true],
|
|
88
|
-
7: [true],
|
|
89
|
-
8: [true],
|
|
90
|
-
9: [true],
|
|
91
|
-
10: [true],
|
|
92
|
-
11: [false],
|
|
93
|
-
12: [true],
|
|
94
|
-
13: [false],
|
|
95
|
-
14: [true],
|
|
96
|
-
15: [false],
|
|
97
|
-
16: [false],
|
|
98
|
-
});
|
|
99
|
-
});
|
|
100
|
-
});
|
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
import { call, put, takeLatest } from "redux-saga/effects";
|
|
2
|
-
import {
|
|
3
|
-
selectCurrentPage,
|
|
4
|
-
selectAvailableSections,
|
|
5
|
-
selectCurrentSectionId,
|
|
6
|
-
} from "../selectors/app";
|
|
7
|
-
import {
|
|
8
|
-
selectSectionDefaults,
|
|
9
|
-
selectRadioSiblings,
|
|
10
|
-
} from "../selectors/references";
|
|
11
|
-
import {
|
|
12
|
-
selectOptionInput,
|
|
13
|
-
selectOptionInputByIndex,
|
|
14
|
-
} from "../selectors/inputs";
|
|
15
|
-
import { updateOptionAction } from "../actions/inputs";
|
|
16
|
-
import { goPageAction } from "../actions/app";
|
|
17
|
-
import { selectOptionConditionValue } from "../selectors/conditions";
|
|
18
|
-
|
|
19
|
-
function setOptionsDefaults(
|
|
20
|
-
id: number,
|
|
21
|
-
defaults: any,
|
|
22
|
-
parentIndexes?: number[]
|
|
23
|
-
): any {
|
|
24
|
-
let ActionsToDispatch: any = [];
|
|
25
|
-
|
|
26
|
-
// Getting current condition
|
|
27
|
-
const currentConditions = selectOptionConditionValue(id);
|
|
28
|
-
|
|
29
|
-
// Getting current values
|
|
30
|
-
const currentValues = selectOptionInput(id);
|
|
31
|
-
|
|
32
|
-
// Getting indexes to execute defaults on if we recieved no parent indexes
|
|
33
|
-
const Indexes: number[] = parentIndexes === undefined ? [] : parentIndexes;
|
|
34
|
-
if (parentIndexes === undefined) {
|
|
35
|
-
if (currentConditions !== undefined) {
|
|
36
|
-
currentConditions.forEach((value, index) => {
|
|
37
|
-
if (value === true) Indexes.push(index);
|
|
38
|
-
});
|
|
39
|
-
} else {
|
|
40
|
-
currentValues.forEach((value, index) => {
|
|
41
|
-
if (value === true) Indexes.push(index);
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// Getting current value
|
|
47
|
-
const defaultValue = defaults.isDefault ? defaults.isDefault : false;
|
|
48
|
-
|
|
49
|
-
// If it neither a default value, nor it's true, we stop here
|
|
50
|
-
if (
|
|
51
|
-
currentValues.reduce((p: boolean, c: boolean) => p && c, true) !== true &&
|
|
52
|
-
defaultValue !== true
|
|
53
|
-
)
|
|
54
|
-
return [];
|
|
55
|
-
|
|
56
|
-
// Getting options radio sibling
|
|
57
|
-
const siblings = selectRadioSiblings(id);
|
|
58
|
-
|
|
59
|
-
// Looping through indexes
|
|
60
|
-
Indexes.forEach((occurencyIndex: number) => {
|
|
61
|
-
const currentValueOccurency = currentValues[occurencyIndex];
|
|
62
|
-
// If current occurency is true we stop here
|
|
63
|
-
if (currentValueOccurency === true || defaultValue === false) return;
|
|
64
|
-
|
|
65
|
-
// Determining whether one of its radio siblings is already true
|
|
66
|
-
let siblingsValue = false;
|
|
67
|
-
if (Array.isArray(siblings) && siblings.length > 0) {
|
|
68
|
-
siblings.forEach((siblingId) => {
|
|
69
|
-
const indexValue = selectOptionInputByIndex(siblingId, occurencyIndex);
|
|
70
|
-
siblingsValue =
|
|
71
|
-
siblingsValue || (indexValue === undefined ? false : indexValue);
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// If defaultValue is true and none of it's siblings are, it's
|
|
76
|
-
// safe to set it to true
|
|
77
|
-
if (!siblingsValue) {
|
|
78
|
-
ActionsToDispatch.push([id, defaultValue, occurencyIndex]);
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
// Going through children
|
|
83
|
-
Object.keys(defaults.children).forEach((childId) => {
|
|
84
|
-
ActionsToDispatch = [
|
|
85
|
-
...ActionsToDispatch,
|
|
86
|
-
...setOptionsDefaults(
|
|
87
|
-
parseInt(childId, 10),
|
|
88
|
-
defaults.children[childId],
|
|
89
|
-
Indexes
|
|
90
|
-
),
|
|
91
|
-
];
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
return ActionsToDispatch;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
function* setDefaultOptionsSection(id: number) {
|
|
98
|
-
let ActionsToDispatch: [number, boolean, number][] = [];
|
|
99
|
-
// Getting section's defaults
|
|
100
|
-
const sectionDefaults = selectSectionDefaults(id);
|
|
101
|
-
if (sectionDefaults === undefined) return [];
|
|
102
|
-
|
|
103
|
-
Object.keys(sectionDefaults).forEach((optionId) => {
|
|
104
|
-
ActionsToDispatch = [
|
|
105
|
-
...ActionsToDispatch,
|
|
106
|
-
...setOptionsDefaults(parseInt(optionId, 10), sectionDefaults[optionId]),
|
|
107
|
-
];
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
// Setting default options
|
|
111
|
-
for (let i = 0; i < ActionsToDispatch.length; i += 1) {
|
|
112
|
-
yield put(updateOptionAction(...ActionsToDispatch[i]));
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
return ActionsToDispatch;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
function* setDefaultOptions() {
|
|
119
|
-
let ActionsToDispatch: [number, boolean, number][] = [];
|
|
120
|
-
// Getting current page & available sections list
|
|
121
|
-
const currentPage = selectCurrentPage();
|
|
122
|
-
const availableSections = selectAvailableSections();
|
|
123
|
-
|
|
124
|
-
// Getting sections
|
|
125
|
-
let sections = [...availableSections].splice(0, currentPage - 1);
|
|
126
|
-
|
|
127
|
-
// Getting previous availableSections
|
|
128
|
-
const previousAvailableSections = selectAvailableSections();
|
|
129
|
-
const previousSectionIndex = previousAvailableSections.indexOf(
|
|
130
|
-
selectCurrentSectionId()
|
|
131
|
-
);
|
|
132
|
-
|
|
133
|
-
// Going through sections
|
|
134
|
-
for (let i = 0; i < sections.length; i += 1) {
|
|
135
|
-
const sectionId = sections[i];
|
|
136
|
-
// @ts-ignore: because of saga implementation of call function
|
|
137
|
-
const actions = yield call(setDefaultOptionsSection, [sectionId]);
|
|
138
|
-
|
|
139
|
-
// If available sections changed, we update the sections array
|
|
140
|
-
sections = [...selectAvailableSections()].splice(0, currentPage - 1);
|
|
141
|
-
ActionsToDispatch = [...ActionsToDispatch, ...actions];
|
|
142
|
-
}
|
|
143
|
-
// Getting current availableSections
|
|
144
|
-
const currentAvailableSections = selectAvailableSections();
|
|
145
|
-
const currentSectionIndex = currentAvailableSections.indexOf(
|
|
146
|
-
selectCurrentSectionId()
|
|
147
|
-
);
|
|
148
|
-
|
|
149
|
-
if (
|
|
150
|
-
selectAvailableSections().length <= currentSectionIndex &&
|
|
151
|
-
currentSectionIndex !== previousSectionIndex
|
|
152
|
-
) {
|
|
153
|
-
let newPage = currentPage;
|
|
154
|
-
if (currentSectionIndex > previousSectionIndex) {
|
|
155
|
-
newPage += currentSectionIndex - previousSectionIndex;
|
|
156
|
-
} else {
|
|
157
|
-
newPage -= previousSectionIndex - currentSectionIndex;
|
|
158
|
-
}
|
|
159
|
-
yield put(goPageAction(newPage));
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
function* setDefaultsSaga() {
|
|
164
|
-
yield takeLatest("SET_DEFAULTS", setDefaultOptions);
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
export default setDefaultsSaga;
|