@beinformed/ui 1.59.7 → 1.59.9
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 +10 -0
- package/esm/redux/_modularui/ModularUIActions.js +5 -1
- package/esm/redux/_modularui/ModularUIActions.js.map +1 -1
- package/esm/redux/_modularui/ModularUIReducer.js +8 -3
- package/esm/redux/_modularui/ModularUIReducer.js.map +1 -1
- package/lib/redux/_modularui/ModularUIActions.js +5 -1
- package/lib/redux/_modularui/ModularUIActions.js.flow +9 -1
- package/lib/redux/_modularui/ModularUIActions.js.map +1 -1
- package/lib/redux/_modularui/ModularUIReducer.js +8 -3
- package/lib/redux/_modularui/ModularUIReducer.js.flow +6 -3
- package/lib/redux/_modularui/ModularUIReducer.js.map +1 -1
- package/lib/redux/_modularui/__tests__/reducer.spec.js.flow +3 -3
- package/package.json +1 -1
- package/src/redux/_modularui/ModularUIActions.js +9 -1
- package/src/redux/_modularui/ModularUIReducer.js +6 -3
- package/src/redux/_modularui/__tests__/reducer.spec.js +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [commit-and-tag-version](https://github.com/absolute-version/commit-and-tag-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
## [1.59.9](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/compare/v1.59.8...v1.59.9) (2024-12-13)
|
|
6
|
+
|
|
7
|
+
## [1.59.8](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/compare/v1.59.7...v1.59.8) (2024-12-12)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### Bug Fixes
|
|
11
|
+
|
|
12
|
+
* **modularui:** log message in stead of exceptions ([9962997](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/commit/9962997e3efc18b658a2c9fb49c0440b350010c5))
|
|
13
|
+
* **modularui:** log message in stead of exceptions ([771a38c](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/commit/771a38c6d57882c4b609c55d443eef2f3ca53099))
|
|
14
|
+
|
|
5
15
|
## [1.59.7](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/compare/v1.59.6...v1.59.7) (2024-12-12)
|
|
6
16
|
|
|
7
17
|
|
|
@@ -116,7 +116,11 @@ export const loadModel = (key, href, options) => ({
|
|
|
116
116
|
|
|
117
117
|
/**
|
|
118
118
|
*/
|
|
119
|
-
export const loadModularUI = (key, href, options) => dispatch => {
|
|
119
|
+
export const loadModularUI = (key, href, options) => (dispatch, getState) => {
|
|
120
|
+
const modularuiStore = getState()?.modularui;
|
|
121
|
+
if (modularuiStore && modularuiStore[key]?.status === MODULARUI_STATUS.LOADING) {
|
|
122
|
+
return _Promise.resolve();
|
|
123
|
+
}
|
|
120
124
|
dispatch(startProgress());
|
|
121
125
|
const loadModelPromise = dispatch(loadModel(key, href, options));
|
|
122
126
|
return _Promise.resolve(loadModelPromise).then(() => dispatch(finishProgress())).catch(error => dispatch(handleError(error)));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ModularUIActions.js","names":["HTTP_METHODS","MODULARUI_STATUS","Href","ErrorResponse","finishProgress","startProgress","handleError","setModel","key","model","connectKey","type","payload","initModels","models","updateModel","updateForm","removeModelByKey","resetModularUI","updateStatus","status","loadModelSuccessAction","updateHandler","loadModel","href","options","origin","contextPath","method","GET","data","locale","childmodels","targetModel","forceTargetModel","cache","successAction","errorAction","error","errorResponse","isChangePassword","isResourceNotFoundAfterReload","ERROR","loadModularUI","dispatch","
|
|
1
|
+
{"version":3,"file":"ModularUIActions.js","names":["HTTP_METHODS","MODULARUI_STATUS","Href","ErrorResponse","finishProgress","startProgress","handleError","setModel","key","model","connectKey","type","payload","initModels","models","updateModel","updateForm","removeModelByKey","resetModularUI","updateStatus","status","loadModelSuccessAction","updateHandler","loadModel","href","options","origin","contextPath","method","GET","data","locale","childmodels","targetModel","forceTargetModel","cache","successAction","errorAction","error","errorResponse","isChangePassword","isResourceNotFoundAfterReload","ERROR","loadModularUI","dispatch","getState","modularuiStore","modularui","LOADING","_Promise","resolve","loadModelPromise","then","catch","reloadModel","selfhref","isReload"],"sources":["../../../src/redux/_modularui/ModularUIActions.js"],"sourcesContent":["// @flow\nimport { HTTP_METHODS, MODULARUI_STATUS } from \"../../constants/Constants\";\nimport Href from \"../../models/href/Href\";\nimport ErrorResponse from \"../../models/error/ErrorResponse\";\nimport { finishProgress, startProgress } from \"../actions/ProgressIndicator\";\nimport { handleError } from \"../actions/Error\";\n\nimport type { ModularUIModel } from \"../../models/types\";\nimport type { Dispatch, ThunkAction } from \"../types\";\nimport type {\n ModularUIAction,\n SetModelAction,\n InitModelAction,\n UpdateModelAction,\n UpdateFormAction,\n RemoveModelByKeyAction,\n ResetModularUIAction,\n UpdateStatusAction,\n} from \"./types\";\nimport type {\n RequestModularUIOptions,\n UpdateHandler,\n} from \"../../utils/fetch/types\";\n\n/**\n */\nexport const setModel = (\n key: string,\n model: ModularUIModel,\n): SetModelAction => {\n // set key on model for later reference\n model.connectKey = key;\n return {\n type: \"MODULARUI/SET\",\n payload: {\n key,\n model,\n },\n };\n};\n\n/**\n */\nexport const initModels = (\n models: Array<{ key: string, model: ModularUIModel }>,\n): InitModelAction => ({\n type: \"MODULARUI/INIT\",\n payload: models,\n});\n\n/**\n */\nexport const updateModel = (model: ModularUIModel): UpdateModelAction => ({\n type: \"MODULARUI/UPDATE\",\n payload: model,\n});\n\n/**\n */\nexport const updateForm = (model: ModularUIModel): UpdateFormAction => ({\n type: \"MODULARUI/UPDATE_FORM\",\n payload: model,\n});\n\n/**\n */\nexport const removeModelByKey = (key: string): RemoveModelByKeyAction => ({\n type: \"MODULARUI/REMOVE_KEY\",\n payload: key,\n});\n\n/**\n * Removes all models except the application model from the modular ui reducer\n */\nexport const resetModularUI = (): ResetModularUIAction => ({\n type: \"MODULARUI/RESET\",\n});\n\n/**\n */\nexport const updateStatus = (\n key: string,\n status: $Keys<typeof MODULARUI_STATUS>,\n): UpdateStatusAction => ({\n type: \"MODULARUI/STATUS\",\n payload: { key, status },\n});\n\n/**\n */\nconst loadModelSuccessAction = (\n key: string,\n model: ModularUIModel,\n updateHandler: UpdateHandler | void,\n): UpdateModelAction | SetModelAction => {\n if (updateHandler) {\n return updateModel(updateHandler(model));\n }\n return setModel(key, model);\n};\n\n/**\n * This action is handled by the modularui middleware\n */\nexport const loadModel = (\n key: string,\n href: Href | string,\n options?: RequestModularUIOptions,\n): ModularUIAction => ({\n type: \"MODULARUI/FETCH\",\n payload: {\n key,\n origin: options?.origin,\n contextPath: options?.contextPath,\n href:\n href instanceof Href\n ? href\n : new Href(href, \"\", {\n origin: options?.origin,\n contextPath: options?.contextPath,\n }),\n method: options?.method ?? HTTP_METHODS.GET,\n data: options?.data,\n locale: options?.locale ?? \"en\",\n childmodels: options?.childmodels,\n targetModel: options?.targetModel,\n forceTargetModel: options?.forceTargetModel,\n cache: options?.cache,\n /**\n */\n successAction: (model) =>\n loadModelSuccessAction(key, model, options?.updateHandler),\n /**\n */\n errorAction: (error) => {\n const errorResponse = new ErrorResponse(error, key, {\n origin: options?.origin,\n contextPath: options?.contextPath,\n });\n if (errorResponse.isChangePassword) {\n return {\n type: \"NO_ACTION\",\n };\n } else if (errorResponse.isResourceNotFoundAfterReload) {\n return removeModelByKey(key);\n }\n\n return updateStatus(key, MODULARUI_STATUS.ERROR);\n },\n },\n});\n\n/**\n */\nexport const loadModularUI =\n (\n key: string,\n href: Href | string,\n options?: RequestModularUIOptions,\n ): ThunkAction =>\n (dispatch: Dispatch, getState) => {\n const modularuiStore = getState()?.modularui;\n if (\n modularuiStore &&\n modularuiStore[key]?.status === MODULARUI_STATUS.LOADING\n ) {\n return Promise.resolve();\n }\n\n dispatch(startProgress());\n\n const loadModelPromise = dispatch(loadModel(key, href, options));\n\n return Promise.resolve(loadModelPromise)\n .then(() => dispatch(finishProgress()))\n .catch((error) => dispatch(handleError(error)));\n };\n\n/**\n */\nexport const reloadModel = (\n model: ModularUIModel,\n options?: RequestModularUIOptions,\n): ThunkAction =>\n loadModularUI(model.connectKey, model.selfhref, {\n ...options,\n isReload: true,\n });\n"],"mappings":";AACA,SAASA,YAAY,EAAEC,gBAAgB,QAAQ,2BAA2B;AAC1E,OAAOC,IAAI,MAAM,wBAAwB;AACzC,OAAOC,aAAa,MAAM,kCAAkC;AAC5D,SAASC,cAAc,EAAEC,aAAa,QAAQ,8BAA8B;AAC5E,SAASC,WAAW,QAAQ,kBAAkB;AAmB9C;AACA;AACA,OAAO,MAAMC,QAAQ,GAAGA,CACtBC,GAAW,EACXC,KAAqB,KACF;EACnB;EACAA,KAAK,CAACC,UAAU,GAAGF,GAAG;EACtB,OAAO;IACLG,IAAI,EAAE,eAAe;IACrBC,OAAO,EAAE;MACPJ,GAAG;MACHC;IACF;EACF,CAAC;AACH,CAAC;;AAED;AACA;AACA,OAAO,MAAMI,UAAU,GACrBC,MAAqD,KAChC;EACrBH,IAAI,EAAE,gBAAgB;EACtBC,OAAO,EAAEE;AACX,CAAC,CAAC;;AAEF;AACA;AACA,OAAO,MAAMC,WAAW,GAAIN,KAAqB,KAAyB;EACxEE,IAAI,EAAE,kBAAkB;EACxBC,OAAO,EAAEH;AACX,CAAC,CAAC;;AAEF;AACA;AACA,OAAO,MAAMO,UAAU,GAAIP,KAAqB,KAAwB;EACtEE,IAAI,EAAE,uBAAuB;EAC7BC,OAAO,EAAEH;AACX,CAAC,CAAC;;AAEF;AACA;AACA,OAAO,MAAMQ,gBAAgB,GAAIT,GAAW,KAA8B;EACxEG,IAAI,EAAE,sBAAsB;EAC5BC,OAAO,EAAEJ;AACX,CAAC,CAAC;;AAEF;AACA;AACA;AACA,OAAO,MAAMU,cAAc,GAAGA,CAAA,MAA6B;EACzDP,IAAI,EAAE;AACR,CAAC,CAAC;;AAEF;AACA;AACA,OAAO,MAAMQ,YAAY,GAAGA,CAC1BX,GAAW,EACXY,MAAsC,MACd;E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C,KAEjCkB,aAAa,CAAClC,KAAK,CAACC,UAAU,EAAED,KAAK,CAAC8C,QAAQ,EAAE;EAC9C,GAAG9B,OAAO;EACV+B,QAAQ,EAAE;AACZ,CAAC,CAAC","ignoreList":[]}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import _Object$assign from "@babel/runtime-corejs3/core-js-stable/object/assign";
|
|
2
2
|
import _findInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/find";
|
|
3
3
|
import _Object$keys from "@babel/runtime-corejs3/core-js-stable/object/keys";
|
|
4
|
-
import { IllegalArgumentException } from "../../exceptions";
|
|
5
4
|
import { MODULARUI_STATUS } from "../../constants/Constants";
|
|
6
5
|
import { ApplicationModel } from "../../models";
|
|
7
6
|
/**
|
|
@@ -46,7 +45,10 @@ const setModel = (state, _ref2) => {
|
|
|
46
45
|
}
|
|
47
46
|
};
|
|
48
47
|
}
|
|
49
|
-
|
|
48
|
+
|
|
49
|
+
// eslint-disable-next-line no-console
|
|
50
|
+
console.debug("No model for setModel");
|
|
51
|
+
return state;
|
|
50
52
|
};
|
|
51
53
|
|
|
52
54
|
/**
|
|
@@ -87,7 +89,10 @@ const updateModel = (state, model) => {
|
|
|
87
89
|
model
|
|
88
90
|
});
|
|
89
91
|
}
|
|
90
|
-
|
|
92
|
+
|
|
93
|
+
// eslint-disable-next-line no-console
|
|
94
|
+
console.debug(`ModularUIReducer: Cannot update model with key ${model.connectKey}`);
|
|
95
|
+
return state;
|
|
91
96
|
};
|
|
92
97
|
|
|
93
98
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ModularUIReducer.js","names":["
|
|
1
|
+
{"version":3,"file":"ModularUIReducer.js","names":["MODULARUI_STATUS","ApplicationModel","updateStatus","state","_ref","key","status","LOADING","lastModification","Date","now","setModel","_ref2","model","FINISHED","console","debug","initModularUI","models","newState","_Object$assign","forEach","_ref3","getModelKey","_context","_findInstanceProperty","_Object$keys","call","connectKey","updateModel","modelKey","removeKey","resetModularUI","initialState","ModularUIReducer","arguments","length","undefined","action","type","payload"],"sources":["../../../src/redux/_modularui/ModularUIReducer.js"],"sourcesContent":["// @flow\nimport { MODULARUI_STATUS } from \"../../constants/Constants\";\nimport { ApplicationModel } from \"../../models\";\n\nimport type { Reducer } from \"redux\";\nimport type { ReduxAction } from \"../types\";\nimport type { ModularUIState } from \"./types\";\nimport type { ModularUIModel } from \"../../models\";\n\n/**\n */\nconst updateStatus = (\n state: ModularUIState,\n { key, status }: { key: string, status: $Keys<typeof MODULARUI_STATUS> },\n) => {\n // model should always be available when status is not loading\n if (status !== MODULARUI_STATUS.LOADING && !state[key]) {\n return state;\n }\n\n return {\n ...state,\n [key]: {\n ...state[key],\n status,\n lastModification: Date.now(),\n },\n };\n};\n\n/**\n */\nconst setModel = (\n state: ModularUIState,\n { key, model }: { key: string, model: ?ModularUIModel },\n) => {\n if (!state[key]) {\n return state;\n }\n\n if (model) {\n return {\n ...state,\n [key]: {\n ...state[key],\n model,\n lastModification: Date.now(),\n status: MODULARUI_STATUS.FINISHED,\n },\n };\n }\n\n // eslint-disable-next-line no-console\n console.debug(\"No model for setModel\");\n return state;\n};\n\n/**\n */\nconst initModularUI = (\n state: ModularUIState,\n models: Array<{ key: string, model: ModularUIModel }>,\n) => {\n const newState = Object.assign({}, state);\n\n models.forEach(({ key, model }) => {\n newState[key] = {\n status: MODULARUI_STATUS.FINISHED,\n lastModification: Date.now(),\n model,\n };\n });\n\n return newState;\n};\n\n/**\n */\nconst getModelKey = (state: ModularUIState, model: ModularUIModel) =>\n Object.keys(state).find((key) => {\n const connectKey = state[key]?.model?.connectKey ?? \"\";\n return connectKey === model.connectKey;\n });\n\n/**\n */\nconst updateModel = (state: ModularUIState, model: ModularUIModel) => {\n const modelKey = getModelKey(state, model);\n\n if (modelKey) {\n return setModel(state, { key: modelKey, model });\n }\n\n // eslint-disable-next-line no-console\n console.debug(\n `ModularUIReducer: Cannot update model with key ${model.connectKey}`,\n );\n return state;\n};\n\n/**\n */\nconst removeKey = (modelKey: string, state: ModularUIState): ModularUIState => {\n const newState = Object.assign({}, state);\n delete newState[modelKey];\n return newState;\n};\n\n/**\n * Remove all but application models\n */\nconst resetModularUI = (state: ModularUIState) => {\n const newState: ModularUIState = {};\n\n for (const key in state) {\n if (state[key].model instanceof ApplicationModel) {\n newState[key] = { ...state[key] };\n }\n }\n\n return newState;\n};\n\nconst initialState: ModularUIState = {};\n\n/**\n * Modular UI Reducer\n */\nexport const ModularUIReducer: Reducer<ModularUIState, ReduxAction> = (\n state = initialState,\n action,\n) => {\n if (!action) {\n return state;\n }\n\n switch (action.type) {\n case \"MODULARUI/INIT\":\n return initModularUI(state, action.payload);\n\n case \"MODULARUI/RESET\":\n return resetModularUI(state);\n\n case \"MODULARUI/STATUS\":\n return updateStatus(state, action.payload);\n\n case \"MODULARUI/SET\":\n return setModel(state, action.payload);\n\n case \"MODULARUI/UPDATE\":\n case \"MODULARUI/UPDATE_FORM\":\n return updateModel(state, action.payload);\n\n case \"MODULARUI/REMOVE_KEY\":\n return removeKey(action.payload, state);\n\n default:\n return state;\n }\n};\n"],"mappings":";;;AACA,SAASA,gBAAgB,QAAQ,2BAA2B;AAC5D,SAASC,gBAAgB,QAAQ,cAAc;AAO/C;AACA;AACA,MAAMC,YAAY,GAAGA,CACnBC,KAAqB,EAAAC,IAAA,KAElB;EAAA,IADH;IAAEC,GAAG;IAAEC;EAAgE,CAAC,GAAAF,IAAA;EAExE;EACA,IAAIE,MAAM,KAAKN,gBAAgB,CAACO,OAAO,IAAI,CAACJ,KAAK,CAACE,GAAG,CAAC,EAAE;IACtD,OAAOF,KAAK;EACd;EAEA,OAAO;IACL,GAAGA,KAAK;IACR,CAACE,GAAG,GAAG;MACL,GAAGF,KAAK,CAACE,GAAG,CAAC;MACbC,MAAM;MACNE,gBAAgB,EAAEC,IAAI,CAACC,GAAG,CAAC;IAC7B;EACF,CAAC;AACH,CAAC;;AAED;AACA;AACA,MAAMC,QAAQ,GAAGA,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M,GAAAH,SAAA,CAAAC,MAAA,OAAAD,SAAA,MAAAE,SAAA;EAEN,IAAI,CAACC,MAAM,EAAE;IACX,OAAOnC,KAAK;EACd;EAEA,QAAQmC,MAAM,CAACC,IAAI;IACjB,KAAK,gBAAgB;MACnB,OAAOtB,aAAa,CAACd,KAAK,EAAEmC,MAAM,CAACE,OAAO,CAAC;IAE7C,KAAK,iBAAiB;MACpB,OAAOR,cAAc,CAAC7B,KAAK,CAAC;IAE9B,KAAK,kBAAkB;MACrB,OAAOD,YAAY,CAACC,KAAK,EAAEmC,MAAM,CAACE,OAAO,CAAC;IAE5C,KAAK,eAAe;MAClB,OAAO7B,QAAQ,CAACR,KAAK,EAAEmC,MAAM,CAACE,OAAO,CAAC;IAExC,KAAK,kBAAkB;IACvB,KAAK,uBAAuB;MAC1B,OAAOX,WAAW,CAAC1B,KAAK,EAAEmC,MAAM,CAACE,OAAO,CAAC;IAE3C,KAAK,sBAAsB;MACzB,OAAOT,SAAS,CAACO,MAAM,CAACE,OAAO,EAAErC,KAAK,CAAC;IAEzC;MACE,OAAOA,KAAK;EAChB;AACF,CAAC","ignoreList":[]}
|
|
@@ -131,7 +131,11 @@ const loadModel = (key, href, options) => ({
|
|
|
131
131
|
/**
|
|
132
132
|
*/
|
|
133
133
|
exports.loadModel = loadModel;
|
|
134
|
-
const loadModularUI = (key, href, options) => dispatch => {
|
|
134
|
+
const loadModularUI = (key, href, options) => (dispatch, getState) => {
|
|
135
|
+
const modularuiStore = getState()?.modularui;
|
|
136
|
+
if (modularuiStore && modularuiStore[key]?.status === _Constants.MODULARUI_STATUS.LOADING) {
|
|
137
|
+
return _promise.default.resolve();
|
|
138
|
+
}
|
|
135
139
|
dispatch((0, _ProgressIndicator.startProgress)());
|
|
136
140
|
const loadModelPromise = dispatch(loadModel(key, href, options));
|
|
137
141
|
return _promise.default.resolve(loadModelPromise).then(() => dispatch((0, _ProgressIndicator.finishProgress)())).catch(error => dispatch((0, _Error.handleError)(error)));
|
|
@@ -158,7 +158,15 @@ export const loadModularUI =
|
|
|
158
158
|
href: Href | string,
|
|
159
159
|
options?: RequestModularUIOptions,
|
|
160
160
|
): ThunkAction =>
|
|
161
|
-
(dispatch: Dispatch) => {
|
|
161
|
+
(dispatch: Dispatch, getState) => {
|
|
162
|
+
const modularuiStore = getState()?.modularui;
|
|
163
|
+
if (
|
|
164
|
+
modularuiStore &&
|
|
165
|
+
modularuiStore[key]?.status === MODULARUI_STATUS.LOADING
|
|
166
|
+
) {
|
|
167
|
+
return Promise.resolve();
|
|
168
|
+
}
|
|
169
|
+
|
|
162
170
|
dispatch(startProgress());
|
|
163
171
|
|
|
164
172
|
const loadModelPromise = dispatch(loadModel(key, href, options));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ModularUIActions.js","names":["_Constants","require","_Href","_interopRequireDefault","_ErrorResponse","_ProgressIndicator","_Error","setModel","key","model","connectKey","type","payload","exports","initModels","models","updateModel","updateForm","removeModelByKey","resetModularUI","updateStatus","status","loadModelSuccessAction","updateHandler","loadModel","href","options","origin","contextPath","Href","method","HTTP_METHODS","GET","data","locale","childmodels","targetModel","forceTargetModel","cache","successAction","errorAction","error","errorResponse","ErrorResponse","isChangePassword","isResourceNotFoundAfterReload","MODULARUI_STATUS","ERROR","loadModularUI","dispatch","
|
|
1
|
+
{"version":3,"file":"ModularUIActions.js","names":["_Constants","require","_Href","_interopRequireDefault","_ErrorResponse","_ProgressIndicator","_Error","setModel","key","model","connectKey","type","payload","exports","initModels","models","updateModel","updateForm","removeModelByKey","resetModularUI","updateStatus","status","loadModelSuccessAction","updateHandler","loadModel","href","options","origin","contextPath","Href","method","HTTP_METHODS","GET","data","locale","childmodels","targetModel","forceTargetModel","cache","successAction","errorAction","error","errorResponse","ErrorResponse","isChangePassword","isResourceNotFoundAfterReload","MODULARUI_STATUS","ERROR","loadModularUI","dispatch","getState","modularuiStore","modularui","LOADING","_promise","default","resolve","startProgress","loadModelPromise","then","finishProgress","catch","handleError","reloadModel","selfhref","isReload"],"sources":["../../../src/redux/_modularui/ModularUIActions.js"],"sourcesContent":["// @flow\nimport { HTTP_METHODS, MODULARUI_STATUS } from \"../../constants/Constants\";\nimport Href from \"../../models/href/Href\";\nimport ErrorResponse from \"../../models/error/ErrorResponse\";\nimport { finishProgress, startProgress } from \"../actions/ProgressIndicator\";\nimport { handleError } from \"../actions/Error\";\n\nimport type { ModularUIModel } from \"../../models/types\";\nimport type { Dispatch, ThunkAction } from \"../types\";\nimport type {\n ModularUIAction,\n SetModelAction,\n InitModelAction,\n UpdateModelAction,\n UpdateFormAction,\n RemoveModelByKeyAction,\n ResetModularUIAction,\n UpdateStatusAction,\n} from \"./types\";\nimport type {\n RequestModularUIOptions,\n UpdateHandler,\n} from \"../../utils/fetch/types\";\n\n/**\n */\nexport const setModel = (\n key: string,\n model: ModularUIModel,\n): SetModelAction => {\n // set key on model for later reference\n model.connectKey = key;\n return {\n type: \"MODULARUI/SET\",\n payload: {\n key,\n model,\n },\n };\n};\n\n/**\n */\nexport const initModels = (\n models: Array<{ key: string, model: ModularUIModel }>,\n): InitModelAction => ({\n type: \"MODULARUI/INIT\",\n payload: models,\n});\n\n/**\n */\nexport const updateModel = (model: ModularUIModel): UpdateModelAction => ({\n type: \"MODULARUI/UPDATE\",\n payload: model,\n});\n\n/**\n */\nexport const updateForm = (model: ModularUIModel): UpdateFormAction => ({\n type: \"MODULARUI/UPDATE_FORM\",\n payload: model,\n});\n\n/**\n */\nexport const removeModelByKey = (key: string): RemoveModelByKeyAction => ({\n type: \"MODULARUI/REMOVE_KEY\",\n payload: key,\n});\n\n/**\n * Removes all models except the application model from the modular ui reducer\n */\nexport const resetModularUI = (): ResetModularUIAction => ({\n type: \"MODULARUI/RESET\",\n});\n\n/**\n */\nexport const updateStatus = (\n key: string,\n status: $Keys<typeof MODULARUI_STATUS>,\n): UpdateStatusAction => ({\n type: \"MODULARUI/STATUS\",\n payload: { key, status },\n});\n\n/**\n */\nconst loadModelSuccessAction = (\n key: string,\n model: ModularUIModel,\n updateHandler: UpdateHandler | void,\n): UpdateModelAction | SetModelAction => {\n if (updateHandler) {\n return updateModel(updateHandler(model));\n }\n return setModel(key, model);\n};\n\n/**\n * This action is handled by the modularui middleware\n */\nexport const loadModel = (\n key: string,\n href: Href | string,\n options?: RequestModularUIOptions,\n): ModularUIAction => ({\n type: \"MODULARUI/FETCH\",\n payload: {\n key,\n origin: options?.origin,\n contextPath: options?.contextPath,\n href:\n href instanceof Href\n ? href\n : new Href(href, \"\", {\n origin: options?.origin,\n contextPath: options?.contextPath,\n }),\n method: options?.method ?? HTTP_METHODS.GET,\n data: options?.data,\n locale: options?.locale ?? \"en\",\n childmodels: options?.childmodels,\n targetModel: options?.targetModel,\n forceTargetModel: options?.forceTargetModel,\n cache: options?.cache,\n /**\n */\n successAction: (model) =>\n loadModelSuccessAction(key, model, options?.updateHandler),\n /**\n */\n errorAction: (error) => {\n const errorResponse = new ErrorResponse(error, key, {\n origin: options?.origin,\n contextPath: options?.contextPath,\n });\n if (errorResponse.isChangePassword) {\n return {\n type: \"NO_ACTION\",\n };\n } else if (errorResponse.isResourceNotFoundAfterReload) {\n return removeModelByKey(key);\n }\n\n return updateStatus(key, MODULARUI_STATUS.ERROR);\n },\n },\n});\n\n/**\n */\nexport const loadModularUI =\n (\n key: string,\n href: Href | string,\n options?: RequestModularUIOptions,\n ): ThunkAction =>\n (dispatch: Dispatch, getState) => {\n const modularuiStore = getState()?.modularui;\n if (\n modularuiStore &&\n modularuiStore[key]?.status === MODULARUI_STATUS.LOADING\n ) {\n return Promise.resolve();\n }\n\n dispatch(startProgress());\n\n const loadModelPromise = dispatch(loadModel(key, href, options));\n\n return Promise.resolve(loadModelPromise)\n .then(() => dispatch(finishProgress()))\n .catch((error) => dispatch(handleError(error)));\n };\n\n/**\n */\nexport const reloadModel = (\n model: ModularUIModel,\n options?: RequestModularUIOptions,\n): ThunkAction =>\n loadModularUI(model.connectKey, model.selfhref, {\n ...options,\n isReload: true,\n });\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CACtCC,KAAK,CAAEpB,KAAK,IAAKQ,QAAQ,CAAC,IAAAa,kBAAW,EAACrB,KAAK,CAAC,CAAC,CAAC;AACnD,CAAC;;AAEH;AACA;AADA5B,OAAA,CAAAmC,aAAA,GAAAA,aAAA;AAEO,MAAMe,WAAW,GAAGA,CACzBtD,KAAqB,EACrBiB,OAAiC,KAEjCsB,aAAa,CAACvC,KAAK,CAACC,UAAU,EAAED,KAAK,CAACuD,QAAQ,EAAE;EAC9C,GAAGtC,OAAO;EACVuC,QAAQ,EAAE;AACZ,CAAC,CAAC;AAACpD,OAAA,CAAAkD,WAAA,GAAAA,WAAA","ignoreList":[]}
|
|
@@ -8,7 +8,6 @@ exports.ModularUIReducer = void 0;
|
|
|
8
8
|
var _assign = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/assign"));
|
|
9
9
|
var _find = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/find"));
|
|
10
10
|
var _keys = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/keys"));
|
|
11
|
-
var _exceptions = require("../../exceptions");
|
|
12
11
|
var _Constants = require("../../constants/Constants");
|
|
13
12
|
var _models = require("../../models");
|
|
14
13
|
/**
|
|
@@ -53,7 +52,10 @@ const setModel = (state, _ref2) => {
|
|
|
53
52
|
}
|
|
54
53
|
};
|
|
55
54
|
}
|
|
56
|
-
|
|
55
|
+
|
|
56
|
+
// eslint-disable-next-line no-console
|
|
57
|
+
console.debug("No model for setModel");
|
|
58
|
+
return state;
|
|
57
59
|
};
|
|
58
60
|
|
|
59
61
|
/**
|
|
@@ -94,7 +96,10 @@ const updateModel = (state, model) => {
|
|
|
94
96
|
model
|
|
95
97
|
});
|
|
96
98
|
}
|
|
97
|
-
|
|
99
|
+
|
|
100
|
+
// eslint-disable-next-line no-console
|
|
101
|
+
console.debug(`ModularUIReducer: Cannot update model with key ${model.connectKey}`);
|
|
102
|
+
return state;
|
|
98
103
|
};
|
|
99
104
|
|
|
100
105
|
/**
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
// @flow
|
|
2
|
-
import { IllegalArgumentException } from "../../exceptions";
|
|
3
2
|
import { MODULARUI_STATUS } from "../../constants/Constants";
|
|
4
3
|
import { ApplicationModel } from "../../models";
|
|
5
4
|
|
|
@@ -51,7 +50,9 @@ const setModel = (
|
|
|
51
50
|
};
|
|
52
51
|
}
|
|
53
52
|
|
|
54
|
-
|
|
53
|
+
// eslint-disable-next-line no-console
|
|
54
|
+
console.debug("No model for setModel");
|
|
55
|
+
return state;
|
|
55
56
|
};
|
|
56
57
|
|
|
57
58
|
/**
|
|
@@ -90,9 +91,11 @@ const updateModel = (state: ModularUIState, model: ModularUIModel) => {
|
|
|
90
91
|
return setModel(state, { key: modelKey, model });
|
|
91
92
|
}
|
|
92
93
|
|
|
93
|
-
|
|
94
|
+
// eslint-disable-next-line no-console
|
|
95
|
+
console.debug(
|
|
94
96
|
`ModularUIReducer: Cannot update model with key ${model.connectKey}`,
|
|
95
97
|
);
|
|
98
|
+
return state;
|
|
96
99
|
};
|
|
97
100
|
|
|
98
101
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ModularUIReducer.js","names":["
|
|
1
|
+
{"version":3,"file":"ModularUIReducer.js","names":["_Constants","require","_models","updateStatus","state","_ref","key","status","MODULARUI_STATUS","LOADING","lastModification","Date","now","setModel","_ref2","model","FINISHED","console","debug","initModularUI","models","newState","_assign","default","forEach","_ref3","getModelKey","_context","_find","_keys","call","connectKey","updateModel","modelKey","removeKey","resetModularUI","ApplicationModel","initialState","ModularUIReducer","arguments","length","undefined","action","type","payload","exports"],"sources":["../../../src/redux/_modularui/ModularUIReducer.js"],"sourcesContent":["// @flow\nimport { MODULARUI_STATUS } from \"../../constants/Constants\";\nimport { ApplicationModel } from \"../../models\";\n\nimport type { Reducer } from \"redux\";\nimport type { ReduxAction } from \"../types\";\nimport type { ModularUIState } from \"./types\";\nimport type { ModularUIModel } from \"../../models\";\n\n/**\n */\nconst updateStatus = (\n state: ModularUIState,\n { key, status }: { key: string, status: $Keys<typeof MODULARUI_STATUS> },\n) => {\n // model should always be available when status is not loading\n if (status !== MODULARUI_STATUS.LOADING && !state[key]) {\n return state;\n }\n\n return {\n ...state,\n [key]: {\n ...state[key],\n status,\n lastModification: Date.now(),\n },\n };\n};\n\n/**\n */\nconst setModel = (\n state: ModularUIState,\n { key, model }: { key: string, model: ?ModularUIModel },\n) => {\n if (!state[key]) {\n return state;\n }\n\n if (model) {\n return {\n ...state,\n [key]: {\n ...state[key],\n model,\n lastModification: Date.now(),\n status: MODULARUI_STATUS.FINISHED,\n },\n };\n }\n\n // eslint-disable-next-line no-console\n console.debug(\"No model for setModel\");\n return state;\n};\n\n/**\n */\nconst initModularUI = (\n state: ModularUIState,\n models: Array<{ key: string, model: ModularUIModel }>,\n) => {\n const newState = Object.assign({}, state);\n\n models.forEach(({ key, model }) => {\n newState[key] = {\n status: MODULARUI_STATUS.FINISHED,\n lastModification: Date.now(),\n model,\n };\n });\n\n return newState;\n};\n\n/**\n */\nconst getModelKey = (state: ModularUIState, model: ModularUIModel) =>\n Object.keys(state).find((key) => {\n const connectKey = state[key]?.model?.connectKey ?? \"\";\n return connectKey === model.connectKey;\n });\n\n/**\n */\nconst updateModel = (state: ModularUIState, model: ModularUIModel) => {\n const modelKey = getModelKey(state, model);\n\n if (modelKey) {\n return setModel(state, { key: modelKey, model });\n }\n\n // eslint-disable-next-line no-console\n console.debug(\n `ModularUIReducer: Cannot update model with key ${model.connectKey}`,\n );\n return state;\n};\n\n/**\n */\nconst removeKey = (modelKey: string, state: ModularUIState): ModularUIState => {\n const newState = Object.assign({}, state);\n delete newState[modelKey];\n return newState;\n};\n\n/**\n * Remove all but application models\n */\nconst resetModularUI = (state: ModularUIState) => {\n const newState: ModularUIState = {};\n\n for (const key in state) {\n if (state[key].model instanceof ApplicationModel) {\n newState[key] = { ...state[key] };\n }\n }\n\n return newState;\n};\n\nconst initialState: ModularUIState = {};\n\n/**\n * Modular UI Reducer\n */\nexport const ModularUIReducer: Reducer<ModularUIState, ReduxAction> = (\n state = initialState,\n action,\n) => {\n if (!action) {\n return state;\n }\n\n switch (action.type) {\n case \"MODULARUI/INIT\":\n return initModularUI(state, action.payload);\n\n case \"MODULARUI/RESET\":\n return resetModularUI(state);\n\n case \"MODULARUI/STATUS\":\n return updateStatus(state, action.payload);\n\n case \"MODULARUI/SET\":\n return setModel(state, action.payload);\n\n case \"MODULARUI/UPDATE\":\n case \"MODULARUI/UPDATE_FORM\":\n return updateModel(state, action.payload);\n\n case \"MODULARUI/REMOVE_KEY\":\n return removeKey(action.payload, state);\n\n default:\n return state;\n }\n};\n"],"mappings":";;;;;;;;;;AACA,IAAAA,UAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AAOA;AACA;AACA,MAAME,YAAY,GAAGA,CACnBC,KAAqB,EAAAC,IAAA,KAElB;EAAA,IADH;IAAEC,GAAG;IAAEC;EAAgE,CAAC,GAAAF,IAAA;EAExE;EACA,IAAIE,MAAM,KAAKC,2BAAgB,CAACC,OAAO,IAAI,CAACL,KAAK,CAACE,GAAG,CAAC,EAAE;IACtD,OAAOF,KAAK;EACd;EAEA,OAAO;IACL,GAAGA,KAAK;IACR,CAACE,GAAG,GAAG;MACL,GAAGF,KAAK,CAACE,GAAG,CAAC;MACbC,MAAM;MACNG,gBAAgB,EAAEC,IAAI,CAACC,GAAG,CAAC;IAC7B;EACF,CAAC;AACH,CAAC;;AAED;AACA;AACA,MAAMC,QAAQ,GAAGA,CACfT,KAAqB,EAAAU,KAAA,KAElB;EAAA,IADH;IAAER,GAAG;IAAES;EAA+C,CAAC,GAAAD,KAAA;EAEvD,IAAI,CAACV,KAAK,CAACE,GAAG,CAAC,EAAE;IACf,OAAOF,KAAK;EACd;EAEA,IAAIW,KAAK,EAAE;IACT,OAAO;MACL,GAAGX,KAAK;MACR,CAACE,GAAG,GAAG;QACL,GAAGF,KAAK,CAACE,GAAG,CAAC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CAACE,OAAO,CAAC;IAE7C,KAAK,iBAAiB;MACpB,OAAOT,cAAc,CAAC/B,KAAK,CAAC;IAE9B,KAAK,kBAAkB;MACrB,OAAOD,YAAY,CAACC,KAAK,EAAEsC,MAAM,CAACE,OAAO,CAAC;IAE5C,KAAK,eAAe;MAClB,OAAO/B,QAAQ,CAACT,KAAK,EAAEsC,MAAM,CAACE,OAAO,CAAC;IAExC,KAAK,kBAAkB;IACvB,KAAK,uBAAuB;MAC1B,OAAOZ,WAAW,CAAC5B,KAAK,EAAEsC,MAAM,CAACE,OAAO,CAAC;IAE3C,KAAK,sBAAsB;MACzB,OAAOV,SAAS,CAACQ,MAAM,CAACE,OAAO,EAAExC,KAAK,CAAC;IAEzC;MACE,OAAOA,KAAK;EAChB;AACF,CAAC;AAACyC,OAAA,CAAAP,gBAAA,GAAAA,gBAAA","ignoreList":[]}
|
|
@@ -107,15 +107,15 @@ describe("modularui reducer", () => {
|
|
|
107
107
|
|
|
108
108
|
it("should handle MODULARUI/UPDATE without existing model", () => {
|
|
109
109
|
application.connectKey = "modelKey";
|
|
110
|
-
expect(
|
|
110
|
+
expect(
|
|
111
111
|
ModularUIReducer(
|
|
112
112
|
{},
|
|
113
113
|
{
|
|
114
114
|
type: "MODULARUI/UPDATE",
|
|
115
115
|
payload: application,
|
|
116
116
|
},
|
|
117
|
-
)
|
|
118
|
-
|
|
117
|
+
),
|
|
118
|
+
).toStrictEqual({});
|
|
119
119
|
});
|
|
120
120
|
|
|
121
121
|
it("should handle MODULARUI/REMOVE_KEY", () => {
|
package/package.json
CHANGED
|
@@ -158,7 +158,15 @@ export const loadModularUI =
|
|
|
158
158
|
href: Href | string,
|
|
159
159
|
options?: RequestModularUIOptions,
|
|
160
160
|
): ThunkAction =>
|
|
161
|
-
(dispatch: Dispatch) => {
|
|
161
|
+
(dispatch: Dispatch, getState) => {
|
|
162
|
+
const modularuiStore = getState()?.modularui;
|
|
163
|
+
if (
|
|
164
|
+
modularuiStore &&
|
|
165
|
+
modularuiStore[key]?.status === MODULARUI_STATUS.LOADING
|
|
166
|
+
) {
|
|
167
|
+
return Promise.resolve();
|
|
168
|
+
}
|
|
169
|
+
|
|
162
170
|
dispatch(startProgress());
|
|
163
171
|
|
|
164
172
|
const loadModelPromise = dispatch(loadModel(key, href, options));
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
// @flow
|
|
2
|
-
import { IllegalArgumentException } from "../../exceptions";
|
|
3
2
|
import { MODULARUI_STATUS } from "../../constants/Constants";
|
|
4
3
|
import { ApplicationModel } from "../../models";
|
|
5
4
|
|
|
@@ -51,7 +50,9 @@ const setModel = (
|
|
|
51
50
|
};
|
|
52
51
|
}
|
|
53
52
|
|
|
54
|
-
|
|
53
|
+
// eslint-disable-next-line no-console
|
|
54
|
+
console.debug("No model for setModel");
|
|
55
|
+
return state;
|
|
55
56
|
};
|
|
56
57
|
|
|
57
58
|
/**
|
|
@@ -90,9 +91,11 @@ const updateModel = (state: ModularUIState, model: ModularUIModel) => {
|
|
|
90
91
|
return setModel(state, { key: modelKey, model });
|
|
91
92
|
}
|
|
92
93
|
|
|
93
|
-
|
|
94
|
+
// eslint-disable-next-line no-console
|
|
95
|
+
console.debug(
|
|
94
96
|
`ModularUIReducer: Cannot update model with key ${model.connectKey}`,
|
|
95
97
|
);
|
|
98
|
+
return state;
|
|
96
99
|
};
|
|
97
100
|
|
|
98
101
|
/**
|
|
@@ -107,15 +107,15 @@ describe("modularui reducer", () => {
|
|
|
107
107
|
|
|
108
108
|
it("should handle MODULARUI/UPDATE without existing model", () => {
|
|
109
109
|
application.connectKey = "modelKey";
|
|
110
|
-
expect(
|
|
110
|
+
expect(
|
|
111
111
|
ModularUIReducer(
|
|
112
112
|
{},
|
|
113
113
|
{
|
|
114
114
|
type: "MODULARUI/UPDATE",
|
|
115
115
|
payload: application,
|
|
116
116
|
},
|
|
117
|
-
)
|
|
118
|
-
|
|
117
|
+
),
|
|
118
|
+
).toStrictEqual({});
|
|
119
119
|
});
|
|
120
120
|
|
|
121
121
|
it("should handle MODULARUI/REMOVE_KEY", () => {
|