@legalplace/wizardx-core 2.6.4 → 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 +35 -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/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/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 +2 -0
- 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 -11
- 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/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 -4
- 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/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 -250
- 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 -55
- package/src/redux/sagas/setDefaults.test.ts +0 -100
- package/src/redux/sagas/setDefaults.ts +0 -167
- package/src/redux/sagas/setUserEmail.ts +0 -175
- 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,370 +0,0 @@
|
|
|
1
|
-
import conditionsWatcherMiddleware from './conditionsWatcherMiddleware';
|
|
2
|
-
import {
|
|
3
|
-
addMultipleOccurencyAction,
|
|
4
|
-
deleteMultipleOccurencyAction,
|
|
5
|
-
updateOptionAction,
|
|
6
|
-
updateVariableAction,
|
|
7
|
-
} from '../actions/inputs';
|
|
8
|
-
import { StateType } from '../../types/State.type';
|
|
9
|
-
import { initConditionsAction } from '../actions/conditions';
|
|
10
|
-
|
|
11
|
-
const mockInputs: StateType.Inputs = {
|
|
12
|
-
variables: {
|
|
13
|
-
1: ['Hello'],
|
|
14
|
-
2: [],
|
|
15
|
-
3: [],
|
|
16
|
-
},
|
|
17
|
-
options: {
|
|
18
|
-
1: [true],
|
|
19
|
-
2: [true, true],
|
|
20
|
-
3: [true, false],
|
|
21
|
-
4: [false, true],
|
|
22
|
-
7: [true, true],
|
|
23
|
-
8: [true, true],
|
|
24
|
-
},
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
// Mocking MPI
|
|
28
|
-
const mpi = {
|
|
29
|
-
dispatch: jest.fn(),
|
|
30
|
-
getState: () => ({
|
|
31
|
-
inputs: mockInputs,
|
|
32
|
-
}),
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
// Mocking Next
|
|
36
|
-
const next = jest.fn();
|
|
37
|
-
|
|
38
|
-
const initialConditions = {
|
|
39
|
-
options: {},
|
|
40
|
-
variables: {},
|
|
41
|
-
documents: {},
|
|
42
|
-
sections: {},
|
|
43
|
-
prefillers: {},
|
|
44
|
-
validators: {
|
|
45
|
-
options: {},
|
|
46
|
-
variables: {},
|
|
47
|
-
},
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
const mockOptionsRelations: StateType.References.Relations['options'] = {
|
|
51
|
-
2: {
|
|
52
|
-
options: [],
|
|
53
|
-
variables: [],
|
|
54
|
-
sections: {},
|
|
55
|
-
documents: [],
|
|
56
|
-
prefillers: [],
|
|
57
|
-
validators: {
|
|
58
|
-
options: [],
|
|
59
|
-
variables: [],
|
|
60
|
-
},
|
|
61
|
-
parents: [],
|
|
62
|
-
children: {
|
|
63
|
-
options: [3, 4],
|
|
64
|
-
variables: [2, 3],
|
|
65
|
-
},
|
|
66
|
-
dependants: [7, 8],
|
|
67
|
-
},
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
// Mocking reference selecteor
|
|
71
|
-
// ../selectors/inputs.ts
|
|
72
|
-
jest.mock('../selectors/inputs', () => ({
|
|
73
|
-
__esModule: true,
|
|
74
|
-
selectOptionInput: (id: number) => mockInputs.options[id],
|
|
75
|
-
selectOptionInputByIndex: (id: number, index: number) =>
|
|
76
|
-
mockInputs.options[id][index],
|
|
77
|
-
selectVariableInput: (id: number) => mockInputs.variables[id],
|
|
78
|
-
selectVariableInputByIndex: (id: number, index: number) =>
|
|
79
|
-
mockInputs.variables[id][index],
|
|
80
|
-
}));
|
|
81
|
-
|
|
82
|
-
jest.mock('../../libs/ConditionsRunner', () => {
|
|
83
|
-
class ConditionsRunnerMock {
|
|
84
|
-
dispatch: any;
|
|
85
|
-
|
|
86
|
-
constructor(dispatch: any) {
|
|
87
|
-
this.dispatch = dispatch;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
executeHooks(...args: any[]) {
|
|
91
|
-
this.dispatch({
|
|
92
|
-
type: 'EXEC_HOOKS_MOCK',
|
|
93
|
-
arguments: args,
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
return {
|
|
98
|
-
__esModule: true,
|
|
99
|
-
ConditionsRunner: ConditionsRunnerMock,
|
|
100
|
-
};
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
const mockOptionsConditions: Record<string, any> = {};
|
|
104
|
-
const mockVariablesConditions: Record<string, any> = {};
|
|
105
|
-
|
|
106
|
-
// Mocking reference selecteor
|
|
107
|
-
// ../selectors/references.ts
|
|
108
|
-
jest.mock('../selectors/references', () => ({
|
|
109
|
-
__esModule: true,
|
|
110
|
-
selectOptionRelations: (id: number) => mockOptionsRelations[id],
|
|
111
|
-
selectOptionConditionsObject: (id: number) => mockOptionsConditions[id],
|
|
112
|
-
selectVariableConditionsObject: (id: number) => mockVariablesConditions[id],
|
|
113
|
-
}));
|
|
114
|
-
|
|
115
|
-
describe('Conditions Watcher Middleware Test suit', () => {
|
|
116
|
-
beforeEach(() => {
|
|
117
|
-
jest.clearAllMocks();
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
it('Completes INIT_CONDITIONS action correctly', () => {
|
|
121
|
-
// Running watcher
|
|
122
|
-
conditionsWatcherMiddleware(mpi)(next)(
|
|
123
|
-
initConditionsAction(initialConditions)
|
|
124
|
-
);
|
|
125
|
-
|
|
126
|
-
expect(next.mock.calls.length).toBe(1);
|
|
127
|
-
expect(next.mock.calls[0][0]).toStrictEqual({
|
|
128
|
-
type: 'INIT_CONDITIONS',
|
|
129
|
-
...initialConditions,
|
|
130
|
-
});
|
|
131
|
-
expect(mpi.dispatch.mock.calls.length).toBe(12);
|
|
132
|
-
expect(mpi.dispatch.mock.calls[0][0]).toStrictEqual({
|
|
133
|
-
type: 'EXEC_HOOKS_MOCK',
|
|
134
|
-
arguments: ['options', 1, 0],
|
|
135
|
-
});
|
|
136
|
-
expect(mpi.dispatch.mock.calls[1][0]).toStrictEqual({
|
|
137
|
-
type: 'EXEC_HOOKS_MOCK',
|
|
138
|
-
arguments: ['options', 2, 0],
|
|
139
|
-
});
|
|
140
|
-
expect(mpi.dispatch.mock.calls[2][0]).toStrictEqual({
|
|
141
|
-
type: 'EXEC_HOOKS_MOCK',
|
|
142
|
-
arguments: ['options', 2, 1],
|
|
143
|
-
});
|
|
144
|
-
expect(mpi.dispatch.mock.calls[3][0]).toStrictEqual({
|
|
145
|
-
type: 'EXEC_HOOKS_MOCK',
|
|
146
|
-
arguments: ['options', 3, 0],
|
|
147
|
-
});
|
|
148
|
-
expect(mpi.dispatch.mock.calls[4][0]).toStrictEqual({
|
|
149
|
-
type: 'EXEC_HOOKS_MOCK',
|
|
150
|
-
arguments: ['options', 3, 1],
|
|
151
|
-
});
|
|
152
|
-
expect(mpi.dispatch.mock.calls[5][0]).toStrictEqual({
|
|
153
|
-
type: 'EXEC_HOOKS_MOCK',
|
|
154
|
-
arguments: ['options', 4, 0],
|
|
155
|
-
});
|
|
156
|
-
expect(mpi.dispatch.mock.calls[6][0]).toStrictEqual({
|
|
157
|
-
type: 'EXEC_HOOKS_MOCK',
|
|
158
|
-
arguments: ['options', 4, 1],
|
|
159
|
-
});
|
|
160
|
-
expect(mpi.dispatch.mock.calls[7][0]).toStrictEqual({
|
|
161
|
-
type: 'EXEC_HOOKS_MOCK',
|
|
162
|
-
arguments: ['options', 7, 0],
|
|
163
|
-
});
|
|
164
|
-
expect(mpi.dispatch.mock.calls[8][0]).toStrictEqual({
|
|
165
|
-
type: 'EXEC_HOOKS_MOCK',
|
|
166
|
-
arguments: ['options', 7, 1],
|
|
167
|
-
});
|
|
168
|
-
expect(mpi.dispatch.mock.calls[9][0]).toStrictEqual({
|
|
169
|
-
type: 'EXEC_HOOKS_MOCK',
|
|
170
|
-
arguments: ['options', 8, 0],
|
|
171
|
-
});
|
|
172
|
-
expect(mpi.dispatch.mock.calls[10][0]).toStrictEqual({
|
|
173
|
-
type: 'EXEC_HOOKS_MOCK',
|
|
174
|
-
arguments: ['options', 8, 1],
|
|
175
|
-
});
|
|
176
|
-
expect(mpi.dispatch.mock.calls[11][0]).toStrictEqual({
|
|
177
|
-
type: 'EXEC_HOOKS_MOCK',
|
|
178
|
-
arguments: ['variables', 1, 0],
|
|
179
|
-
});
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
it('Completes UPDATE_OPTION_INPUT action correctly', () => {
|
|
183
|
-
// Running watcher
|
|
184
|
-
conditionsWatcherMiddleware(mpi)(next)(updateOptionAction(3, false, 0));
|
|
185
|
-
|
|
186
|
-
expect(next.mock.calls.length).toBe(1);
|
|
187
|
-
expect(next.mock.calls[0][0]).toStrictEqual({
|
|
188
|
-
type: 'UPDATE_OPTION_INPUT',
|
|
189
|
-
id: 3,
|
|
190
|
-
index: 0,
|
|
191
|
-
value: false,
|
|
192
|
-
});
|
|
193
|
-
expect(mpi.dispatch.mock.calls.length).toBe(2);
|
|
194
|
-
expect(mpi.dispatch.mock.calls[0][0]).toStrictEqual({
|
|
195
|
-
type: 'SET_DATA_STATUS',
|
|
196
|
-
dataStatus: 'unsaved',
|
|
197
|
-
});
|
|
198
|
-
expect(mpi.dispatch.mock.calls[1][0]).toStrictEqual({
|
|
199
|
-
type: 'EXEC_HOOKS_MOCK',
|
|
200
|
-
arguments: ['options', 3, 0],
|
|
201
|
-
});
|
|
202
|
-
});
|
|
203
|
-
|
|
204
|
-
it('Completes UPDATE_VARIABLE_INPUT action correctly', () => {
|
|
205
|
-
// Running watcher
|
|
206
|
-
conditionsWatcherMiddleware(mpi)(next)(updateVariableAction(1, 'Hey', 0));
|
|
207
|
-
|
|
208
|
-
expect(next.mock.calls.length).toBe(1);
|
|
209
|
-
expect(next.mock.calls[0][0]).toStrictEqual({
|
|
210
|
-
type: 'UPDATE_VARIABLE_INPUT',
|
|
211
|
-
id: 1,
|
|
212
|
-
index: 0,
|
|
213
|
-
value: 'Hey',
|
|
214
|
-
});
|
|
215
|
-
expect(mpi.dispatch.mock.calls.length).toBe(2);
|
|
216
|
-
expect(mpi.dispatch.mock.calls[0][0]).toStrictEqual({
|
|
217
|
-
type: 'SET_DATA_STATUS',
|
|
218
|
-
dataStatus: 'unsaved',
|
|
219
|
-
});
|
|
220
|
-
expect(mpi.dispatch.mock.calls[1][0]).toStrictEqual({
|
|
221
|
-
type: 'EXEC_HOOKS_MOCK',
|
|
222
|
-
arguments: ['variables', 1, 0],
|
|
223
|
-
});
|
|
224
|
-
});
|
|
225
|
-
|
|
226
|
-
it('Completes ADD_MULTIPLE_OCCURENCY action correctly', () => {
|
|
227
|
-
// Running watcher
|
|
228
|
-
conditionsWatcherMiddleware(mpi)(next)(addMultipleOccurencyAction(2));
|
|
229
|
-
|
|
230
|
-
expect(next.mock.calls.length).toBe(1);
|
|
231
|
-
expect(next.mock.calls[0][0]).toStrictEqual({
|
|
232
|
-
type: 'ADD_MULTIPLE_OCCURENCY',
|
|
233
|
-
id: 2,
|
|
234
|
-
});
|
|
235
|
-
expect(mpi.dispatch.mock.calls.length).toBe(15);
|
|
236
|
-
expect(mpi.dispatch.mock.calls[0][0]).toStrictEqual({
|
|
237
|
-
type: 'SET_DATA_STATUS',
|
|
238
|
-
dataStatus: 'unsaved',
|
|
239
|
-
});
|
|
240
|
-
expect(mpi.dispatch.mock.calls[1][0]).toStrictEqual({
|
|
241
|
-
type: 'EXEC_HOOKS_MOCK',
|
|
242
|
-
arguments: ['options', 2, 0],
|
|
243
|
-
});
|
|
244
|
-
expect(mpi.dispatch.mock.calls[2][0]).toStrictEqual({
|
|
245
|
-
type: 'EXEC_HOOKS_MOCK',
|
|
246
|
-
arguments: ['options', 2, 1],
|
|
247
|
-
});
|
|
248
|
-
expect(mpi.dispatch.mock.calls[3][0]).toStrictEqual({
|
|
249
|
-
type: 'EXEC_HOOKS_MOCK',
|
|
250
|
-
arguments: ['options', 3, 0],
|
|
251
|
-
});
|
|
252
|
-
expect(mpi.dispatch.mock.calls[4][0]).toStrictEqual({
|
|
253
|
-
type: 'EXEC_HOOKS_MOCK',
|
|
254
|
-
arguments: ['options', 3, 1],
|
|
255
|
-
});
|
|
256
|
-
expect(mpi.dispatch.mock.calls[5][0]).toStrictEqual({
|
|
257
|
-
type: 'EXEC_HOOKS_MOCK',
|
|
258
|
-
arguments: ['options', 4, 0],
|
|
259
|
-
});
|
|
260
|
-
expect(mpi.dispatch.mock.calls[6][0]).toStrictEqual({
|
|
261
|
-
type: 'EXEC_HOOKS_MOCK',
|
|
262
|
-
arguments: ['options', 4, 1],
|
|
263
|
-
});
|
|
264
|
-
expect(mpi.dispatch.mock.calls[7][0]).toStrictEqual({
|
|
265
|
-
type: 'EXEC_HOOKS_MOCK',
|
|
266
|
-
arguments: ['options', 7, 0],
|
|
267
|
-
});
|
|
268
|
-
expect(mpi.dispatch.mock.calls[8][0]).toStrictEqual({
|
|
269
|
-
type: 'EXEC_HOOKS_MOCK',
|
|
270
|
-
arguments: ['options', 7, 1],
|
|
271
|
-
});
|
|
272
|
-
expect(mpi.dispatch.mock.calls[9][0]).toStrictEqual({
|
|
273
|
-
type: 'EXEC_HOOKS_MOCK',
|
|
274
|
-
arguments: ['options', 8, 0],
|
|
275
|
-
});
|
|
276
|
-
expect(mpi.dispatch.mock.calls[10][0]).toStrictEqual({
|
|
277
|
-
type: 'EXEC_HOOKS_MOCK',
|
|
278
|
-
arguments: ['options', 8, 1],
|
|
279
|
-
});
|
|
280
|
-
expect(mpi.dispatch.mock.calls[11][0]).toStrictEqual({
|
|
281
|
-
type: 'EXEC_HOOKS_MOCK',
|
|
282
|
-
arguments: ['variables', 2, 0],
|
|
283
|
-
});
|
|
284
|
-
expect(mpi.dispatch.mock.calls[12][0]).toStrictEqual({
|
|
285
|
-
type: 'EXEC_HOOKS_MOCK',
|
|
286
|
-
arguments: ['variables', 2, 1],
|
|
287
|
-
});
|
|
288
|
-
expect(mpi.dispatch.mock.calls[13][0]).toStrictEqual({
|
|
289
|
-
type: 'EXEC_HOOKS_MOCK',
|
|
290
|
-
arguments: ['variables', 3, 0],
|
|
291
|
-
});
|
|
292
|
-
expect(mpi.dispatch.mock.calls[14][0]).toStrictEqual({
|
|
293
|
-
type: 'EXEC_HOOKS_MOCK',
|
|
294
|
-
arguments: ['variables', 3, 1],
|
|
295
|
-
});
|
|
296
|
-
});
|
|
297
|
-
|
|
298
|
-
it('Completes DELETE_MULTIPLE_OCCURENCY action correctly', () => {
|
|
299
|
-
// Running watcher
|
|
300
|
-
conditionsWatcherMiddleware(mpi)(next)(deleteMultipleOccurencyAction(2, 1));
|
|
301
|
-
|
|
302
|
-
expect(next.mock.calls.length).toBe(1);
|
|
303
|
-
expect(next.mock.calls[0][0]).toStrictEqual({
|
|
304
|
-
type: 'DELETE_MULTIPLE_OCCURENCY',
|
|
305
|
-
id: 2,
|
|
306
|
-
index: 1,
|
|
307
|
-
});
|
|
308
|
-
expect(mpi.dispatch.mock.calls.length).toBe(15);
|
|
309
|
-
expect(mpi.dispatch.mock.calls[0][0]).toStrictEqual({
|
|
310
|
-
type: 'SET_DATA_STATUS',
|
|
311
|
-
dataStatus: 'unsaved',
|
|
312
|
-
});
|
|
313
|
-
expect(mpi.dispatch.mock.calls[1][0]).toStrictEqual({
|
|
314
|
-
type: 'EXEC_HOOKS_MOCK',
|
|
315
|
-
arguments: ['options', 2, 0],
|
|
316
|
-
});
|
|
317
|
-
expect(mpi.dispatch.mock.calls[2][0]).toStrictEqual({
|
|
318
|
-
type: 'EXEC_HOOKS_MOCK',
|
|
319
|
-
arguments: ['options', 2, 1],
|
|
320
|
-
});
|
|
321
|
-
expect(mpi.dispatch.mock.calls[3][0]).toStrictEqual({
|
|
322
|
-
type: 'EXEC_HOOKS_MOCK',
|
|
323
|
-
arguments: ['options', 3, 0],
|
|
324
|
-
});
|
|
325
|
-
expect(mpi.dispatch.mock.calls[4][0]).toStrictEqual({
|
|
326
|
-
type: 'EXEC_HOOKS_MOCK',
|
|
327
|
-
arguments: ['options', 3, 1],
|
|
328
|
-
});
|
|
329
|
-
expect(mpi.dispatch.mock.calls[5][0]).toStrictEqual({
|
|
330
|
-
type: 'EXEC_HOOKS_MOCK',
|
|
331
|
-
arguments: ['options', 4, 0],
|
|
332
|
-
});
|
|
333
|
-
expect(mpi.dispatch.mock.calls[6][0]).toStrictEqual({
|
|
334
|
-
type: 'EXEC_HOOKS_MOCK',
|
|
335
|
-
arguments: ['options', 4, 1],
|
|
336
|
-
});
|
|
337
|
-
expect(mpi.dispatch.mock.calls[7][0]).toStrictEqual({
|
|
338
|
-
type: 'EXEC_HOOKS_MOCK',
|
|
339
|
-
arguments: ['options', 7, 0],
|
|
340
|
-
});
|
|
341
|
-
expect(mpi.dispatch.mock.calls[8][0]).toStrictEqual({
|
|
342
|
-
type: 'EXEC_HOOKS_MOCK',
|
|
343
|
-
arguments: ['options', 7, 1],
|
|
344
|
-
});
|
|
345
|
-
expect(mpi.dispatch.mock.calls[9][0]).toStrictEqual({
|
|
346
|
-
type: 'EXEC_HOOKS_MOCK',
|
|
347
|
-
arguments: ['options', 8, 0],
|
|
348
|
-
});
|
|
349
|
-
expect(mpi.dispatch.mock.calls[10][0]).toStrictEqual({
|
|
350
|
-
type: 'EXEC_HOOKS_MOCK',
|
|
351
|
-
arguments: ['options', 8, 1],
|
|
352
|
-
});
|
|
353
|
-
expect(mpi.dispatch.mock.calls[11][0]).toStrictEqual({
|
|
354
|
-
type: 'EXEC_HOOKS_MOCK',
|
|
355
|
-
arguments: ['variables', 2, 0],
|
|
356
|
-
});
|
|
357
|
-
expect(mpi.dispatch.mock.calls[12][0]).toStrictEqual({
|
|
358
|
-
type: 'EXEC_HOOKS_MOCK',
|
|
359
|
-
arguments: ['variables', 2, 1],
|
|
360
|
-
});
|
|
361
|
-
expect(mpi.dispatch.mock.calls[13][0]).toStrictEqual({
|
|
362
|
-
type: 'EXEC_HOOKS_MOCK',
|
|
363
|
-
arguments: ['variables', 3, 0],
|
|
364
|
-
});
|
|
365
|
-
expect(mpi.dispatch.mock.calls[14][0]).toStrictEqual({
|
|
366
|
-
type: 'EXEC_HOOKS_MOCK',
|
|
367
|
-
arguments: ['variables', 3, 1],
|
|
368
|
-
});
|
|
369
|
-
});
|
|
370
|
-
});
|
|
@@ -1,321 +0,0 @@
|
|
|
1
|
-
import { Dispatch, MiddlewareAPI } from "redux";
|
|
2
|
-
import {
|
|
3
|
-
UPDATE_OPTION_INPUT,
|
|
4
|
-
UPDATE_VARIABLE_INPUT,
|
|
5
|
-
ADD_MULTIPLE_OCCURENCY,
|
|
6
|
-
DELETE_MULTIPLE_OCCURENCY,
|
|
7
|
-
} from "../constants/inputs";
|
|
8
|
-
import {
|
|
9
|
-
selectOptionInput,
|
|
10
|
-
selectOptionInputByIndex,
|
|
11
|
-
selectVariableInputByIndex,
|
|
12
|
-
selectVariableInput,
|
|
13
|
-
} from "../selectors/inputs";
|
|
14
|
-
import { ActionsType } from "../../types/Actions.type";
|
|
15
|
-
import { ConditionsRunner } from "../../libs/ConditionsRunner";
|
|
16
|
-
import {
|
|
17
|
-
INIT_CONDITIONS,
|
|
18
|
-
UPDATE_SECTION_CONDITION,
|
|
19
|
-
UPDATE_OPTION_CONDITION,
|
|
20
|
-
UPDATE_VARIABLE_CONDITION,
|
|
21
|
-
} from "../constants/conditions";
|
|
22
|
-
import {
|
|
23
|
-
selectOptionRelations,
|
|
24
|
-
selectOptionConditionsObject,
|
|
25
|
-
selectVariableConditionsObject,
|
|
26
|
-
} from "../selectors/references";
|
|
27
|
-
import { setDataStatus } from "../actions/app";
|
|
28
|
-
import {
|
|
29
|
-
selectSectionConditionValue,
|
|
30
|
-
selectOptionConditionValue,
|
|
31
|
-
selectVariableConditionValue,
|
|
32
|
-
} from "../selectors/conditions";
|
|
33
|
-
import { StateType } from "../../types/State.type";
|
|
34
|
-
|
|
35
|
-
export type WatcherActions =
|
|
36
|
-
| ActionsType.Inputs.updateOptionInput
|
|
37
|
-
| ActionsType.Inputs.updateVariableInput
|
|
38
|
-
| ActionsType.Inputs.addMultipleOccurency
|
|
39
|
-
| ActionsType.Inputs.deleteMultipleOccurency
|
|
40
|
-
| ActionsType.Conditions.initConditions;
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Watching UPDATE_OPTION_INPUT action
|
|
44
|
-
* @param mpi MiddlewareAPI
|
|
45
|
-
* @param next Dispatch function
|
|
46
|
-
* @param action Actions
|
|
47
|
-
*/
|
|
48
|
-
const watchUpdateOptionInput = (
|
|
49
|
-
mpi: MiddlewareAPI<Dispatch, StateType>,
|
|
50
|
-
next: Dispatch,
|
|
51
|
-
action: ActionsType.Inputs.updateOptionInput
|
|
52
|
-
) => {
|
|
53
|
-
const { id, index, value } = action;
|
|
54
|
-
const oldValue = selectOptionInputByIndex(id, index);
|
|
55
|
-
|
|
56
|
-
const nextResult = next(action);
|
|
57
|
-
if (value !== oldValue) {
|
|
58
|
-
mpi.dispatch(setDataStatus("unsaved"));
|
|
59
|
-
const Conditions = new ConditionsRunner(mpi.dispatch);
|
|
60
|
-
Conditions.executeHooks("options", id, index);
|
|
61
|
-
}
|
|
62
|
-
return nextResult;
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Watching UPDATE_OPTION_CONDITION action
|
|
67
|
-
* @param mpi MiddlewareAPI
|
|
68
|
-
* @param next Dispatch function
|
|
69
|
-
* @param action Actions
|
|
70
|
-
*/
|
|
71
|
-
const watchUpdateOptionCondition = (
|
|
72
|
-
mpi: MiddlewareAPI<Dispatch, StateType>,
|
|
73
|
-
next: Dispatch,
|
|
74
|
-
action: ActionsType.Conditions.updateOptionCondition
|
|
75
|
-
) => {
|
|
76
|
-
const { id, index, value } = action;
|
|
77
|
-
const oldValue = selectOptionConditionValue(id, index);
|
|
78
|
-
|
|
79
|
-
const nextResult = next(action);
|
|
80
|
-
if (value !== oldValue) {
|
|
81
|
-
mpi.dispatch(setDataStatus("unsaved"));
|
|
82
|
-
const Conditions = new ConditionsRunner(mpi.dispatch);
|
|
83
|
-
Conditions.executeHooks("options", id, index);
|
|
84
|
-
}
|
|
85
|
-
return nextResult;
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* Watching UPDATE_VARIALE_INPUT action
|
|
90
|
-
* @param mpi MiddlewareAPI
|
|
91
|
-
* @param next Dispatch function
|
|
92
|
-
* @param action Actions
|
|
93
|
-
*/
|
|
94
|
-
|
|
95
|
-
const watchUpdateVariableInput = (
|
|
96
|
-
mpi: MiddlewareAPI<Dispatch, StateType>,
|
|
97
|
-
next: Dispatch,
|
|
98
|
-
action: ActionsType.Inputs.updateVariableInput
|
|
99
|
-
) => {
|
|
100
|
-
const { id, index, value } = action;
|
|
101
|
-
const oldValue = selectVariableInputByIndex(id, index);
|
|
102
|
-
|
|
103
|
-
const nextResult = next(action);
|
|
104
|
-
if (value !== oldValue) {
|
|
105
|
-
mpi.dispatch(setDataStatus("unsaved"));
|
|
106
|
-
const Conditions = new ConditionsRunner(mpi.dispatch);
|
|
107
|
-
Conditions.executeHooks("variables", id, index);
|
|
108
|
-
}
|
|
109
|
-
return nextResult;
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Watching UPDATE_VARIALE_INPUT action
|
|
114
|
-
* @param mpi MiddlewareAPI
|
|
115
|
-
* @param next Dispatch function
|
|
116
|
-
* @param action Actions
|
|
117
|
-
*/
|
|
118
|
-
|
|
119
|
-
const watchUpdateVariableCondition = (
|
|
120
|
-
mpi: MiddlewareAPI<Dispatch, StateType>,
|
|
121
|
-
next: Dispatch,
|
|
122
|
-
action: ActionsType.Conditions.updateVariableCondition
|
|
123
|
-
) => {
|
|
124
|
-
const { id, index, value } = action;
|
|
125
|
-
const oldValue = selectVariableConditionValue(id, index);
|
|
126
|
-
|
|
127
|
-
const nextResult = next(action);
|
|
128
|
-
if (value !== oldValue) {
|
|
129
|
-
mpi.dispatch(setDataStatus("unsaved"));
|
|
130
|
-
const Conditions = new ConditionsRunner(mpi.dispatch);
|
|
131
|
-
Conditions.executeHooks("variables", id, index);
|
|
132
|
-
}
|
|
133
|
-
return nextResult;
|
|
134
|
-
};
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
* Watching UPDATE_SECTION_CONDITION action
|
|
138
|
-
* @param mpi MiddlewareAPI
|
|
139
|
-
* @param next Dispatch function
|
|
140
|
-
* @param action Actions
|
|
141
|
-
*/
|
|
142
|
-
const watchUpdateSectionCondition = (
|
|
143
|
-
mpi: MiddlewareAPI<Dispatch, StateType>,
|
|
144
|
-
next: Dispatch,
|
|
145
|
-
action: ActionsType.Conditions.updateSectionCondition
|
|
146
|
-
) => {
|
|
147
|
-
const Conditions = new ConditionsRunner(mpi.dispatch);
|
|
148
|
-
|
|
149
|
-
if (action.document !== "main") {
|
|
150
|
-
return next(action);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
const { id, value } = action;
|
|
154
|
-
const oldValue = selectSectionConditionValue(id);
|
|
155
|
-
|
|
156
|
-
const nextResult = next(action);
|
|
157
|
-
if (value !== oldValue) {
|
|
158
|
-
Conditions.executeHooks("sections", id, 0);
|
|
159
|
-
}
|
|
160
|
-
return nextResult;
|
|
161
|
-
};
|
|
162
|
-
|
|
163
|
-
/**
|
|
164
|
-
* Watching ADD_MULTIPLE_OCCURENCY && DELETE_MULTIPLE_OCCURENCY action
|
|
165
|
-
* @param mpi MiddlewareAPI
|
|
166
|
-
* @param next Dispatch function
|
|
167
|
-
* @param action Actions
|
|
168
|
-
*/
|
|
169
|
-
|
|
170
|
-
const watchMultipleOccurenciesChange = (
|
|
171
|
-
mpi: MiddlewareAPI<Dispatch, StateType>,
|
|
172
|
-
next: Dispatch,
|
|
173
|
-
action: ActionsType.Inputs.deleteMultipleOccurency
|
|
174
|
-
) => {
|
|
175
|
-
const nextResult = next(action);
|
|
176
|
-
const Conditions = new ConditionsRunner(mpi.dispatch);
|
|
177
|
-
mpi.dispatch(setDataStatus("unsaved"));
|
|
178
|
-
|
|
179
|
-
const { id } = action;
|
|
180
|
-
|
|
181
|
-
// Getting multiple children
|
|
182
|
-
const optionRelations = selectOptionRelations(id);
|
|
183
|
-
if (optionRelations === undefined)
|
|
184
|
-
throw new Error(`Options relations for option ${id} do not exist`);
|
|
185
|
-
|
|
186
|
-
// Adding values to input's arrays
|
|
187
|
-
const options: number[] = [
|
|
188
|
-
id,
|
|
189
|
-
...optionRelations.children.options,
|
|
190
|
-
...optionRelations.dependants,
|
|
191
|
-
];
|
|
192
|
-
const { variables } = optionRelations.children;
|
|
193
|
-
|
|
194
|
-
// Executing self conditions for options
|
|
195
|
-
for (let i = 0; i < options.length; i += 1) {
|
|
196
|
-
// Getting the condition object
|
|
197
|
-
const condition = selectOptionConditionsObject(options[i]);
|
|
198
|
-
if (typeof condition === "object") {
|
|
199
|
-
// Executing hooks on options
|
|
200
|
-
condition.dataMap.o.forEach((optionId: number) => {
|
|
201
|
-
selectOptionInput(optionId).forEach((input, index) =>
|
|
202
|
-
Conditions.executeHooks("options", optionId, index)
|
|
203
|
-
);
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
// Executing hooks on variables
|
|
207
|
-
condition.dataMap.v.forEach((variableId: number) =>
|
|
208
|
-
selectVariableInput(variableId).forEach((input, index) =>
|
|
209
|
-
Conditions.executeHooks("variables", variableId, index)
|
|
210
|
-
)
|
|
211
|
-
);
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
// Executing self conditions for variables
|
|
216
|
-
for (let i = 0; i < variables.length; i += 1) {
|
|
217
|
-
// Getting the condition object
|
|
218
|
-
const condition = selectVariableConditionsObject(variables[i]);
|
|
219
|
-
if (typeof condition === "object") {
|
|
220
|
-
// Executing hooks on options
|
|
221
|
-
condition.dataMap.o.forEach((optionId: number) =>
|
|
222
|
-
selectOptionInput(optionId).forEach((input, index) =>
|
|
223
|
-
Conditions.executeHooks("options", optionId, index)
|
|
224
|
-
)
|
|
225
|
-
);
|
|
226
|
-
|
|
227
|
-
// Executing hooks on variables
|
|
228
|
-
condition.dataMap.v.forEach((variableId: number) =>
|
|
229
|
-
selectVariableInput(variableId).forEach((input, index) =>
|
|
230
|
-
Conditions.executeHooks("variables", variableId, index)
|
|
231
|
-
)
|
|
232
|
-
);
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
// Prefillier
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
// Getting occurencies
|
|
239
|
-
const occurencies = selectOptionInput(id).length;
|
|
240
|
-
|
|
241
|
-
// Executing hooks on options
|
|
242
|
-
for (let i = 0; i < options.length; i += 1) {
|
|
243
|
-
for (let index = 0; index < occurencies; index += 1) {
|
|
244
|
-
Conditions.executeHooks("options", options[i], index);
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
// Executing hooks on variables
|
|
249
|
-
for (let i = 0; i < variables.length; i += 1) {
|
|
250
|
-
for (let index = 0; index < occurencies; index += 1) {
|
|
251
|
-
Conditions.executeHooks("variables", variables[i], index);
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
return nextResult;
|
|
255
|
-
};
|
|
256
|
-
|
|
257
|
-
/**
|
|
258
|
-
* Watching INIT_CONDITIONS action
|
|
259
|
-
* @param mpi MiddlewareAPI
|
|
260
|
-
* @param next Dispatch function
|
|
261
|
-
* @param action Actions
|
|
262
|
-
*/
|
|
263
|
-
const watchInitConditions = (
|
|
264
|
-
mpi: MiddlewareAPI<Dispatch, StateType>,
|
|
265
|
-
next: Dispatch,
|
|
266
|
-
action: WatcherActions
|
|
267
|
-
) => {
|
|
268
|
-
const nextResult = next(action);
|
|
269
|
-
const Conditions = new ConditionsRunner(mpi.dispatch);
|
|
270
|
-
const stateInputs = mpi.getState().inputs;
|
|
271
|
-
const options = Object.keys(stateInputs.options);
|
|
272
|
-
const variables = Object.keys(stateInputs.variables);
|
|
273
|
-
|
|
274
|
-
// Executing conditions on options
|
|
275
|
-
for (let i = 0; i < options.length; i += 1) {
|
|
276
|
-
const values = mpi.getState().inputs.options[parseInt(options[i], 10)];
|
|
277
|
-
for (let index = 0; index < values.length; index += 1) {
|
|
278
|
-
Conditions.executeHooks("options", parseInt(options[i], 10), index);
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
// Executing conditions on variables
|
|
283
|
-
for (let i = 0; i < variables.length; i += 1) {
|
|
284
|
-
const values = mpi.getState().inputs.variables[parseInt(variables[i], 10)];
|
|
285
|
-
for (let index = 0; index < values.length; index += 1) {
|
|
286
|
-
Conditions.executeHooks("variables", parseInt(variables[i], 10), index);
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
return nextResult;
|
|
290
|
-
};
|
|
291
|
-
|
|
292
|
-
// Enumerating watchers
|
|
293
|
-
const watchersEnum: Record<
|
|
294
|
-
string,
|
|
295
|
-
(mpi: MiddlewareAPI<Dispatch, StateType>, next: Dispatch, action: any) => void
|
|
296
|
-
> = {
|
|
297
|
-
[UPDATE_OPTION_INPUT]: watchUpdateOptionInput,
|
|
298
|
-
[UPDATE_OPTION_CONDITION]: watchUpdateOptionCondition,
|
|
299
|
-
[UPDATE_VARIABLE_INPUT]: watchUpdateVariableInput,
|
|
300
|
-
[UPDATE_VARIABLE_CONDITION]: watchUpdateVariableCondition,
|
|
301
|
-
[UPDATE_SECTION_CONDITION]: watchUpdateSectionCondition,
|
|
302
|
-
[INIT_CONDITIONS]: watchInitConditions,
|
|
303
|
-
[ADD_MULTIPLE_OCCURENCY]: watchMultipleOccurenciesChange,
|
|
304
|
-
[DELETE_MULTIPLE_OCCURENCY]: watchMultipleOccurenciesChange,
|
|
305
|
-
};
|
|
306
|
-
|
|
307
|
-
/**
|
|
308
|
-
* Condition Watcher Middleware
|
|
309
|
-
* @param mpi MiddlewareAPI
|
|
310
|
-
* @param next Dispatch function
|
|
311
|
-
* @param action Actions
|
|
312
|
-
*/
|
|
313
|
-
const conditionsWatcherMiddleware =
|
|
314
|
-
(mpi: MiddlewareAPI) => (next: Dispatch) => (action: WatcherActions) => {
|
|
315
|
-
if (Object.prototype.hasOwnProperty.call(watchersEnum, action.type)) {
|
|
316
|
-
return watchersEnum[action.type].apply(null, [mpi, next, action]);
|
|
317
|
-
}
|
|
318
|
-
return next(action);
|
|
319
|
-
};
|
|
320
|
-
|
|
321
|
-
export default conditionsWatcherMiddleware;
|