@beinformed/ui 1.56.4 → 1.56.5
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 +7 -0
- package/esm/redux/_modularui/ModularUIActions.js +10 -8
- package/esm/redux/_modularui/ModularUIActions.js.map +1 -1
- package/esm/redux/_modularui/ModularUIMiddleware.js +4 -1
- package/esm/redux/_modularui/ModularUIMiddleware.js.map +1 -1
- package/esm/redux/_modularui/ModularUIReducer.js +2 -1
- package/esm/redux/_modularui/ModularUIReducer.js.map +1 -1
- package/esm/redux/_modularui/types.js.map +1 -1
- package/lib/hooks/__tests__/UseModularUIModel.spec.js.flow +1 -4
- package/lib/hooks/__tests__/useAuthentication.spec.js.flow +2 -8
- package/lib/hooks/__tests__/useForm.spec.js.flow +2 -11
- package/lib/hooks/__tests__/useModelCatalog.spec.js.flow +1 -4
- package/lib/hooks/__tests__/useModels.spec.js.flow +3 -12
- package/lib/hooks/__tests__/useModularUIBasic.spec.js.flow +0 -8
- package/lib/redux/_modularui/ModularUIActions.js +10 -8
- package/lib/redux/_modularui/ModularUIActions.js.flow +14 -9
- package/lib/redux/_modularui/ModularUIActions.js.map +1 -1
- package/lib/redux/_modularui/ModularUIMiddleware.js +3 -0
- package/lib/redux/_modularui/ModularUIMiddleware.js.flow +6 -3
- package/lib/redux/_modularui/ModularUIMiddleware.js.map +1 -1
- package/lib/redux/_modularui/ModularUIReducer.js +2 -1
- package/lib/redux/_modularui/ModularUIReducer.js.flow +1 -0
- package/lib/redux/_modularui/ModularUIReducer.js.map +1 -1
- package/lib/redux/_modularui/__tests__/actions.spec.js.flow +1 -4
- package/lib/redux/_modularui/types.js.flow +1 -0
- package/lib/redux/_modularui/types.js.map +1 -1
- package/lib/redux/actions/__tests__/Application.spec.js.flow +1 -8
- package/lib/redux/actions/__tests__/Authorization.spec.js.flow +0 -4
- package/package.json +9 -9
- package/src/hooks/__tests__/UseModularUIModel.spec.js +1 -4
- package/src/hooks/__tests__/useAuthentication.spec.js +2 -8
- package/src/hooks/__tests__/useForm.spec.js +2 -11
- package/src/hooks/__tests__/useModelCatalog.spec.js +1 -4
- package/src/hooks/__tests__/useModels.spec.js +3 -12
- package/src/hooks/__tests__/useModularUIBasic.spec.js +0 -8
- package/src/redux/_modularui/ModularUIActions.js +14 -9
- package/src/redux/_modularui/ModularUIMiddleware.js +6 -3
- package/src/redux/_modularui/ModularUIReducer.js +1 -0
- package/src/redux/_modularui/__tests__/actions.spec.js +1 -4
- package/src/redux/_modularui/types.js +1 -0
- package/src/redux/actions/__tests__/Application.spec.js +1 -8
- package/src/redux/actions/__tests__/Authorization.spec.js +0 -4
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,13 @@
|
|
|
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.56.5](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/compare/v1.56.4...v1.56.5) (2024-10-17)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* **modularui:** don't start request if existing request for same model exists ([40dc861](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/commit/40dc86188e37ca3d8c3b99ea547b30cb500d284e))
|
|
11
|
+
|
|
5
12
|
## [1.56.4](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/compare/v1.56.3...v1.56.4) (2024-10-16)
|
|
6
13
|
|
|
7
14
|
|
|
@@ -78,6 +78,7 @@ const loadModelSuccessAction = (key, model, updateHandler) => {
|
|
|
78
78
|
export const loadModel = (key, href, options) => ({
|
|
79
79
|
type: "MODULARUI/FETCH",
|
|
80
80
|
payload: {
|
|
81
|
+
key,
|
|
81
82
|
href: href instanceof Href ? href : new Href(href),
|
|
82
83
|
method: options?.method ?? HTTP_METHODS.GET,
|
|
83
84
|
data: options?.data,
|
|
@@ -107,16 +108,17 @@ export const loadModel = (key, href, options) => ({
|
|
|
107
108
|
|
|
108
109
|
/**
|
|
109
110
|
*/
|
|
110
|
-
export const loadModularUI = (key, href, options) => dispatch => {
|
|
111
|
-
|
|
111
|
+
export const loadModularUI = (key, href, options) => (dispatch, getState) => {
|
|
112
|
+
const modularuiStore = getState()?.modularui;
|
|
113
|
+
if (modularuiStore && modularuiStore[key]?.status === MODULARUI_STATUS.LOADING) {
|
|
114
|
+
// don't create duplicate requests during loading
|
|
115
|
+
return dispatch({
|
|
116
|
+
type: "NO_ACTION"
|
|
117
|
+
});
|
|
118
|
+
}
|
|
112
119
|
dispatch(startProgress());
|
|
113
120
|
const loadModelPromise = dispatch(loadModel(key, href, options));
|
|
114
|
-
return _Promise.resolve(loadModelPromise).then(
|
|
115
|
-
if (response?.type === "FINISH_PROGRESS") {
|
|
116
|
-
dispatch(updateStatus(key, MODULARUI_STATUS.FINISHED));
|
|
117
|
-
}
|
|
118
|
-
return dispatch(finishProgress());
|
|
119
|
-
}).catch(error => dispatch(handleError(error)));
|
|
121
|
+
return _Promise.resolve(loadModelPromise).then(() => dispatch(finishProgress())).catch(error => dispatch(handleError(error)));
|
|
120
122
|
};
|
|
121
123
|
|
|
122
124
|
/**
|
|
@@ -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","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","method","GET","data","locale","childmodels","targetModel","forceTargetModel","cache","successAction","errorAction","error","errorResponse","isChangePassword","isResourceNotFoundAfterReload","ERROR","loadModularUI","dispatch","getState","modularuiStore","modularui","LOADING","loadModelPromise","_Promise","resolve","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 href: href instanceof Href ? href : new Href(href),\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 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 // don't create duplicate requests during loading\n return dispatch({\n type: \"NO_ACTION\",\n });\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,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
|
2
2
|
import ModularUIRequest from "../../modularui/ModularUIRequest";
|
|
3
|
-
import { HTTP_METHODS } from "../../constants/Constants";
|
|
3
|
+
import { HTTP_METHODS, MODULARUI_STATUS } from "../../constants/Constants";
|
|
4
4
|
import { startProgress, finishProgress } from "../actions/ProgressIndicator";
|
|
5
5
|
import { handleError } from "../actions/Error";
|
|
6
|
+
import { updateStatus } from "./ModularUIActions";
|
|
6
7
|
/**
|
|
7
8
|
* Symbol key that carries API call info interpreted by this Redux middleware.
|
|
8
9
|
*/
|
|
@@ -64,12 +65,14 @@ const errorHandler = (next, dispatch, errorAction, err) => {
|
|
|
64
65
|
const handleFetch = (action, locale, dispatch, next) => {
|
|
65
66
|
dispatch(startProgress());
|
|
66
67
|
const {
|
|
68
|
+
key,
|
|
67
69
|
successAction,
|
|
68
70
|
errorAction,
|
|
69
71
|
...requestOptions
|
|
70
72
|
} = action.payload;
|
|
71
73
|
requestOptions.locale = locale;
|
|
72
74
|
const modularuiRequest = createRequest(requestOptions);
|
|
75
|
+
dispatch(updateStatus(key, MODULARUI_STATUS.LOADING));
|
|
73
76
|
return modularuiRequest.fetch().then(model => responseHandler(next, dispatch, successAction, model)).catch(error => errorHandler(next, dispatch, errorAction, error));
|
|
74
77
|
};
|
|
75
78
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ModularUIMiddleware.js","names":["ModularUIRequest","HTTP_METHODS","startProgress","finishProgress","handleError","createRequest","modularui","request","href","method","GET","data","locale","childmodels","isReload","cache","targetModel","forceTargetModel","responseHandler","next","dispatch","successAction","model","successResult","_Promise","then","result","catch","error","Error","errorHandler","errorAction","err","errorResult","handleFetch","action","requestOptions","payload","modularuiRequest","fetch","modularUIMiddleware","api","type","getState","i18n"],"sources":["../../../src/redux/_modularui/ModularUIMiddleware.js"],"sourcesContent":["// @flow\nimport ModularUIRequest from \"../../modularui/ModularUIRequest\";\nimport { HTTP_METHODS } from \"../../constants/Constants\";\n\nimport { startProgress, finishProgress } from \"../actions/ProgressIndicator\";\
|
|
1
|
+
{"version":3,"file":"ModularUIMiddleware.js","names":["ModularUIRequest","HTTP_METHODS","MODULARUI_STATUS","startProgress","finishProgress","handleError","updateStatus","createRequest","modularui","request","href","method","GET","data","locale","childmodels","isReload","cache","targetModel","forceTargetModel","responseHandler","next","dispatch","successAction","model","successResult","_Promise","then","result","catch","error","Error","errorHandler","errorAction","err","errorResult","handleFetch","action","key","requestOptions","payload","modularuiRequest","LOADING","fetch","modularUIMiddleware","api","type","getState","i18n"],"sources":["../../../src/redux/_modularui/ModularUIMiddleware.js"],"sourcesContent":["// @flow\nimport ModularUIRequest from \"../../modularui/ModularUIRequest\";\nimport { HTTP_METHODS, MODULARUI_STATUS } from \"../../constants/Constants\";\n\nimport { startProgress, finishProgress } from \"../actions/ProgressIndicator\";\nimport { handleError } from \"../actions/Error\";\n\nimport { updateStatus } from \"./ModularUIActions\";\n\nimport type { Middleware, MiddlewareAPI } from \"redux\";\nimport type {\n ReduxAction,\n ReduxState,\n Dispatch,\n PossibleAction,\n} from \"../types\";\nimport type { ModularUIModel } from \"../../models/types\";\nimport type Href from \"../../models/href/Href\";\nimport type { ModularUIAction, SuccessAction, ErrorAction } from \"./types\";\nimport type { TargetModel } from \"../../modularui/types\";\n\ntype RequestOptions = {\n href: Href,\n method?: $Keys<typeof HTTP_METHODS>,\n data?: any,\n locale: string,\n childmodels?: boolean,\n targetModel?: TargetModel,\n forceTargetModel?: boolean,\n isReload?: boolean,\n cache?: boolean,\n};\n\n/**\n * Symbol key that carries API call info interpreted by this Redux middleware.\n */\nconst createRequest = (modularui: RequestOptions): ModularUIRequest => {\n const request = new ModularUIRequest(modularui.href, {\n method: modularui.method || HTTP_METHODS.GET,\n data: modularui.data || {},\n locale: modularui.locale,\n childmodels: modularui.childmodels ?? true,\n isReload: modularui.isReload,\n cache: modularui.cache,\n });\n\n if (modularui.targetModel) {\n request.targetModel = modularui.targetModel;\n request.forceTargetModel = modularui.forceTargetModel ?? false;\n }\n\n return request;\n};\n\n/**\n */\nconst responseHandler = (\n next: Dispatch,\n dispatch: Dispatch,\n successAction: SuccessAction,\n model: ModularUIModel,\n) => {\n if (successAction) {\n const successResult = successAction(model);\n\n if (successResult instanceof Promise) {\n successResult\n .then((result) => {\n dispatch(result);\n })\n .catch((error) => {\n next(handleError(error));\n });\n } else {\n try {\n dispatch(successResult);\n } catch (error) {\n throw new Error(\n `Result of successResult is not a valid redux action: ${error}`,\n );\n }\n }\n }\n\n return next(finishProgress());\n};\n\n/**\n */\nconst errorHandler = (\n next: Dispatch,\n dispatch: Dispatch,\n errorAction: ?ErrorAction,\n err: any,\n) => {\n dispatch(finishProgress());\n\n if (errorAction) {\n const errorResult = errorAction(err);\n\n if (errorResult instanceof Promise) {\n errorResult.then((result) => dispatch(result));\n } else {\n dispatch(errorResult);\n }\n }\n\n return next(handleError(err));\n};\n\n/**\n */\nconst handleFetch = (\n action: ModularUIAction,\n locale: string,\n dispatch: Dispatch,\n next: Dispatch,\n) => {\n dispatch(startProgress());\n\n const { key, successAction, errorAction, ...requestOptions } = action.payload;\n requestOptions.locale = locale;\n\n const modularuiRequest = createRequest(requestOptions);\n\n dispatch(updateStatus(key, MODULARUI_STATUS.LOADING));\n\n return modularuiRequest\n .fetch()\n .then((model) => responseHandler(next, dispatch, successAction, model))\n .catch((error) => errorHandler(next, dispatch, errorAction, error));\n};\n\n/**\n */\nexport const modularUIMiddleware: Middleware<\n ReduxState,\n ReduxAction,\n Dispatch,\n> =\n (api: MiddlewareAPI<ReduxState, ReduxAction, Dispatch>) =>\n (next: Dispatch) =>\n (action: PossibleAction) => {\n if (action.type === \"MODULARUI/FETCH\") {\n return handleFetch(\n // $FlowExpectedError[incompatible-exact]\n action,\n api.getState().i18n.locale,\n api.dispatch,\n next,\n );\n }\n\n return next(action);\n };\n"],"mappings":";AACA,OAAOA,gBAAgB,MAAM,kCAAkC;AAC/D,SAASC,YAAY,EAAEC,gBAAgB,QAAQ,2BAA2B;AAE1E,SAASC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Y,CAACX,IAAI,EAAEC,QAAQ,EAAEW,WAAW,EAAEH,KAAK,CAAC,CAAC;AACvE,CAAC;;AAED;AACA;AACA,OAAO,MAAMc,mBAIZ,GACEC,GAAqD,IACrDxB,IAAc,IACdgB,MAAsB,IAAK;EAC1B,IAAIA,MAAM,CAACS,IAAI,KAAK,iBAAiB,EAAE;IACrC,OAAOV,WAAW;IAChB;IACAC,MAAM,EACNQ,GAAG,CAACE,QAAQ,CAAC,CAAC,CAACC,IAAI,CAAClC,MAAM,EAC1B+B,GAAG,CAACvB,QAAQ,EACZD,IACF,CAAC;EACH;EAEA,OAAOA,IAAI,CAACgB,MAAM,CAAC;AACrB,CAAC","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ModularUIReducer.js","names":["IllegalArgumentException","MODULARUI_STATUS","ApplicationModel","updateStatus","state","_ref","key","status","LOADING","lastModification","Date","now","setModel","_ref2","model","initModularUI","models","newState","_Object$assign","forEach","_ref3","
|
|
1
|
+
{"version":3,"file":"ModularUIReducer.js","names":["IllegalArgumentException","MODULARUI_STATUS","ApplicationModel","updateStatus","state","_ref","key","status","LOADING","lastModification","Date","now","setModel","_ref2","model","FINISHED","initModularUI","models","newState","_Object$assign","forEach","_ref3","getModelKey","_context","_findInstanceProperty","_Object$keys","call","connectKey","updateModel","modelKey","Error","removeKey","resetModularUI","initialState","ModularUIReducer","arguments","length","undefined","action","type","payload"],"sources":["../../../src/redux/_modularui/ModularUIReducer.js"],"sourcesContent":["// @flow\nimport { IllegalArgumentException } from \"../../exceptions\";\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 throw new IllegalArgumentException(\"No model for setModel\");\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 throw new Error(\n `ModularUIReducer: Cannot update model with key ${model.connectKey}`,\n );\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,wBAAwB,QAAQ,kBAAkB;AAC3D,SAASC,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,CACfR,KAAqB,EAAAS,KAAA,KAElB;EAAA,IADH;IAAEP,GAAG;IAAEQ;EAA+C,CAAC,GAAAD,KAAA;EAEvD,IAAI,CAACT,KAAK,CAACE,GAAG,CAAC,EAAE;IACf,OAAOF,KAAK;EACd;EAEA,IAAIU,KAAK,EAAE;IACT,OAAO;MACL,GAAGV,KAAK;MACR,CAACE,GAAG,GAAG;QACL,GAAGF,KAAK,CAACE,GAAG,CAAC;QACbQ,KAAK;QACLL,gBAAgB,EAAEC,IAAI,CAACC,GAAG,CAAC,CAAC;QAC5BJ,MAAM,EAAEN,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,CAACR,KAAK,EAAEkC,MAAM,CAACE,OAAO,CAAC;IAExC,KAAK,kBAAkB;IACvB,KAAK,uBAAuB;MAC1B,OAAOZ,WAAW,CAACxB,KAAK,EAAEkC,MAAM,CAACE,OAAO,CAAC;IAE3C,KAAK,sBAAsB;MACzB,OAAOT,SAAS,CAACO,MAAM,CAACE,OAAO,EAAEpC,KAAK,CAAC;IAEzC;MACE,OAAOA,KAAK;EAChB;AACF,CAAC","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","names":[],"sources":["../../../src/redux/_modularui/types.js"],"sourcesContent":["// @flow\nimport type { ModularUIModel } from \"../../models/types\";\nimport type Href from \"../../models/href/Href\";\nimport type { FetchException } from \"../../exceptions\";\nimport type { NoAction } from \"../types\";\nimport typeof {\n HTTP_METHODS,\n MODULARUI_STATUS,\n} from \"../../constants/Constants\";\nimport type { ComponentType } from \"react\";\nimport type { TargetModel } from \"../../modularui/types\";\nimport type { RequestModularUIOptions } from \"../../utils/fetch/types\";\n\nexport type ModularUIOptions = {\n propName?: string,\n removeOnUnmount?: boolean,\n ...RequestModularUIOptions,\n};\n\nexport type ModelEntry = {\n +status: string,\n +model: ModularUIModel,\n +lastModification: number,\n};\n\nexport type ModularUIState = {\n [string]: ModelEntry,\n ...\n};\n\nexport type SetModelAction = {\n type: \"MODULARUI/SET\",\n payload: {\n key: string,\n model: ?ModularUIModel,\n },\n};\n\nexport type InitModelAction = {\n type: \"MODULARUI/INIT\",\n payload: Array<{\n key: string,\n model: ModularUIModel,\n }>,\n};\n\nexport type UpdateModelAction = {\n type: \"MODULARUI/UPDATE\",\n payload: ModularUIModel,\n};\n\nexport type UpdateFormAction = {\n type: \"MODULARUI/UPDATE_FORM\",\n payload: ModularUIModel,\n};\n\nexport type SuccessAction = (\n model: ModularUIModel,\n) => UpdateModelAction | SetModelAction;\n\nexport type ErrorAction = (\n error: FetchException,\n) => UpdateStatusAction | RemoveModelByKeyAction | NoAction;\n\nexport type ModularUIAction = {\n type: \"MODULARUI/FETCH\",\n payload: {\n href: Href,\n method?: $Keys<HTTP_METHODS>,\n data?: any,\n locale: string,\n childmodels?: boolean,\n targetModel?: TargetModel,\n forceTargetModel?: boolean,\n cache?: boolean,\n successAction: (\n model: ModularUIModel,\n ) => UpdateModelAction | SetModelAction,\n errorAction?: ErrorAction,\n },\n};\n\nexport type RemoveModelByKeyAction = {\n type: \"MODULARUI/REMOVE_KEY\",\n payload: string,\n};\n\nexport type ResetModularUIAction = {\n type: \"MODULARUI/RESET\",\n};\n\nexport type UpdateStatusAction = {\n type: \"MODULARUI/STATUS\",\n payload: {\n key: string,\n status: $Keys<MODULARUI_STATUS>,\n },\n};\n\nexport type ModularUIConnector = (\n Component: ComponentType<any>,\n) => ComponentType<any>;\n"],"mappings":"","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"types.js","names":[],"sources":["../../../src/redux/_modularui/types.js"],"sourcesContent":["// @flow\nimport type { ModularUIModel } from \"../../models/types\";\nimport type Href from \"../../models/href/Href\";\nimport type { FetchException } from \"../../exceptions\";\nimport type { NoAction } from \"../types\";\nimport typeof {\n HTTP_METHODS,\n MODULARUI_STATUS,\n} from \"../../constants/Constants\";\nimport type { ComponentType } from \"react\";\nimport type { TargetModel } from \"../../modularui/types\";\nimport type { RequestModularUIOptions } from \"../../utils/fetch/types\";\n\nexport type ModularUIOptions = {\n propName?: string,\n removeOnUnmount?: boolean,\n ...RequestModularUIOptions,\n};\n\nexport type ModelEntry = {\n +status: string,\n +model: ModularUIModel,\n +lastModification: number,\n};\n\nexport type ModularUIState = {\n [string]: ModelEntry,\n ...\n};\n\nexport type SetModelAction = {\n type: \"MODULARUI/SET\",\n payload: {\n key: string,\n model: ?ModularUIModel,\n },\n};\n\nexport type InitModelAction = {\n type: \"MODULARUI/INIT\",\n payload: Array<{\n key: string,\n model: ModularUIModel,\n }>,\n};\n\nexport type UpdateModelAction = {\n type: \"MODULARUI/UPDATE\",\n payload: ModularUIModel,\n};\n\nexport type UpdateFormAction = {\n type: \"MODULARUI/UPDATE_FORM\",\n payload: ModularUIModel,\n};\n\nexport type SuccessAction = (\n model: ModularUIModel,\n) => UpdateModelAction | SetModelAction;\n\nexport type ErrorAction = (\n error: FetchException,\n) => UpdateStatusAction | RemoveModelByKeyAction | NoAction;\n\nexport type ModularUIAction = {\n type: \"MODULARUI/FETCH\",\n payload: {\n key: string,\n href: Href,\n method?: $Keys<HTTP_METHODS>,\n data?: any,\n locale: string,\n childmodels?: boolean,\n targetModel?: TargetModel,\n forceTargetModel?: boolean,\n cache?: boolean,\n successAction: (\n model: ModularUIModel,\n ) => UpdateModelAction | SetModelAction,\n errorAction?: ErrorAction,\n },\n};\n\nexport type RemoveModelByKeyAction = {\n type: \"MODULARUI/REMOVE_KEY\",\n payload: string,\n};\n\nexport type ResetModularUIAction = {\n type: \"MODULARUI/RESET\",\n};\n\nexport type UpdateStatusAction = {\n type: \"MODULARUI/STATUS\",\n payload: {\n key: string,\n status: $Keys<MODULARUI_STATUS>,\n },\n};\n\nexport type ModularUIConnector = (\n Component: ComponentType<any>,\n) => ComponentType<any>;\n"],"mappings":"","ignoreList":[]}
|
|
@@ -71,14 +71,11 @@ describe("modularui hooks", () => {
|
|
|
71
71
|
expect(result.current).toBeNull();
|
|
72
72
|
|
|
73
73
|
expect(store.getActions()).toStrictEqual([
|
|
74
|
-
{
|
|
75
|
-
type: "MODULARUI/STATUS",
|
|
76
|
-
payload: { key: `${key}(${url})(en)`, status: "LOADING" },
|
|
77
|
-
},
|
|
78
74
|
{ type: "START_PROGRESS" },
|
|
79
75
|
{
|
|
80
76
|
type: "MODULARUI/FETCH",
|
|
81
77
|
payload: expect.objectContaining({
|
|
78
|
+
key: `${key}(${url})(en)`,
|
|
82
79
|
href: new Href(url),
|
|
83
80
|
locale: "en",
|
|
84
81
|
targetModel: targetModel,
|
|
@@ -61,14 +61,11 @@ describe("authentication hooks", () => {
|
|
|
61
61
|
|
|
62
62
|
expect(store.getActions()).toStrictEqual([
|
|
63
63
|
{ type: "START_PROGRESS" },
|
|
64
|
-
{
|
|
65
|
-
type: "MODULARUI/STATUS",
|
|
66
|
-
payload: { key: "application(/)(en)", status: "LOADING" },
|
|
67
|
-
},
|
|
68
64
|
{ type: "START_PROGRESS" },
|
|
69
65
|
expect.objectContaining({
|
|
70
66
|
type: "MODULARUI/FETCH",
|
|
71
67
|
payload: expect.objectContaining({
|
|
68
|
+
key: "application(/)(en)",
|
|
72
69
|
href: new Href("/", "Application"),
|
|
73
70
|
}),
|
|
74
71
|
}),
|
|
@@ -108,14 +105,11 @@ describe("authentication hooks", () => {
|
|
|
108
105
|
expect(store.getActions()).toStrictEqual([
|
|
109
106
|
{ type: "START_PROGRESS" },
|
|
110
107
|
{ type: "MODULARUI/RESET" },
|
|
111
|
-
{
|
|
112
|
-
type: "MODULARUI/STATUS",
|
|
113
|
-
payload: { key: "application(/)(en)", status: "LOADING" },
|
|
114
|
-
},
|
|
115
108
|
{ type: "START_PROGRESS" },
|
|
116
109
|
expect.objectContaining({
|
|
117
110
|
type: "MODULARUI/FETCH",
|
|
118
111
|
payload: expect.objectContaining({
|
|
112
|
+
key: "application(/)(en)",
|
|
119
113
|
href: new Href("/", "Application"),
|
|
120
114
|
}),
|
|
121
115
|
}),
|
|
@@ -69,14 +69,11 @@ describe("form hooks", () => {
|
|
|
69
69
|
expect(result.current).toBeUndefined();
|
|
70
70
|
|
|
71
71
|
expect(store.getActions()).toStrictEqual([
|
|
72
|
-
{
|
|
73
|
-
type: "MODULARUI/STATUS",
|
|
74
|
-
payload: { key: "form(/form)(en)", status: "LOADING" },
|
|
75
|
-
},
|
|
76
72
|
{ type: "START_PROGRESS" },
|
|
77
73
|
{
|
|
78
74
|
type: "MODULARUI/FETCH",
|
|
79
75
|
payload: expect.objectContaining({
|
|
76
|
+
key: "form(/form)(en)",
|
|
80
77
|
href: new Href("/form?commit=false"),
|
|
81
78
|
locale: "en",
|
|
82
79
|
targetModel: FormModel,
|
|
@@ -113,17 +110,11 @@ describe("form hooks", () => {
|
|
|
113
110
|
href.resourcetype = "Form";
|
|
114
111
|
|
|
115
112
|
expect(store.getActions()).toStrictEqual([
|
|
116
|
-
{
|
|
117
|
-
type: "MODULARUI/STATUS",
|
|
118
|
-
payload: {
|
|
119
|
-
key: "form(/persons/persons/createperson)(en)",
|
|
120
|
-
status: "LOADING",
|
|
121
|
-
},
|
|
122
|
-
},
|
|
123
113
|
{ type: "START_PROGRESS" },
|
|
124
114
|
{
|
|
125
115
|
type: "MODULARUI/FETCH",
|
|
126
116
|
payload: expect.objectContaining({
|
|
117
|
+
key: "form(/persons/persons/createperson)(en)",
|
|
127
118
|
href: href,
|
|
128
119
|
locale: "en",
|
|
129
120
|
targetModel: FormModel,
|
|
@@ -64,14 +64,11 @@ describe("modelcatalog hooks", () => {
|
|
|
64
64
|
expect(result.current).toBeNull();
|
|
65
65
|
|
|
66
66
|
expect(store.getActions()).toStrictEqual([
|
|
67
|
-
{
|
|
68
|
-
type: "MODULARUI/STATUS",
|
|
69
|
-
payload: { key: `${key}(${url})(en)`, status: "LOADING" },
|
|
70
|
-
},
|
|
71
67
|
{ type: "START_PROGRESS" },
|
|
72
68
|
{
|
|
73
69
|
type: "MODULARUI/FETCH",
|
|
74
70
|
payload: expect.objectContaining({
|
|
71
|
+
key: `${key}(${url})(en)`,
|
|
75
72
|
href: new Href(url),
|
|
76
73
|
locale: "en",
|
|
77
74
|
targetModel: targetModel,
|
|
@@ -37,14 +37,11 @@ describe("model hooks", () => {
|
|
|
37
37
|
|
|
38
38
|
result.current.reload(application);
|
|
39
39
|
expect(store.getActions()).toStrictEqual([
|
|
40
|
-
{
|
|
41
|
-
type: "MODULARUI/STATUS",
|
|
42
|
-
payload: { key: "application(/)(en)", status: "LOADING" },
|
|
43
|
-
},
|
|
44
40
|
{ type: "START_PROGRESS" },
|
|
45
41
|
{
|
|
46
42
|
type: "MODULARUI/FETCH",
|
|
47
43
|
payload: expect.objectContaining({
|
|
44
|
+
key: "application(/)(en)",
|
|
48
45
|
href: new Href("/", "Application"),
|
|
49
46
|
locale: "en",
|
|
50
47
|
}),
|
|
@@ -83,14 +80,11 @@ describe("model hooks", () => {
|
|
|
83
80
|
model.selfhref.equals(new Href("/")),
|
|
84
81
|
);
|
|
85
82
|
expect(store.getActions()).toStrictEqual([
|
|
86
|
-
{
|
|
87
|
-
type: "MODULARUI/STATUS",
|
|
88
|
-
payload: { key: "application(/)(en)", status: "LOADING" },
|
|
89
|
-
},
|
|
90
83
|
{ type: "START_PROGRESS" },
|
|
91
84
|
{
|
|
92
85
|
type: "MODULARUI/FETCH",
|
|
93
86
|
payload: expect.objectContaining({
|
|
87
|
+
key: "application(/)(en)",
|
|
94
88
|
href: new Href("/", "Application"),
|
|
95
89
|
locale: "en",
|
|
96
90
|
}),
|
|
@@ -130,14 +124,11 @@ describe("model hooks", () => {
|
|
|
130
124
|
model.selfhref.equals(new Href("/books/books")),
|
|
131
125
|
);
|
|
132
126
|
expect(store.getActions()).toStrictEqual([
|
|
133
|
-
{
|
|
134
|
-
type: "MODULARUI/STATUS",
|
|
135
|
-
payload: { key: "list(/books/books)(en)", status: "LOADING" },
|
|
136
|
-
},
|
|
137
127
|
{ type: "START_PROGRESS" },
|
|
138
128
|
{
|
|
139
129
|
type: "MODULARUI/FETCH",
|
|
140
130
|
payload: expect.objectContaining({
|
|
131
|
+
key: "list(/books/books)(en)",
|
|
141
132
|
href: caselist.selfhref,
|
|
142
133
|
locale: "en",
|
|
143
134
|
}),
|
|
@@ -66,10 +66,6 @@ describe("modularui hooks", () => {
|
|
|
66
66
|
expect(result.current).toBeNull();
|
|
67
67
|
|
|
68
68
|
expect(store.getActions()).toStrictEqual([
|
|
69
|
-
{
|
|
70
|
-
type: "MODULARUI/STATUS",
|
|
71
|
-
payload: { key: `app(/)(en)`, status: "LOADING" },
|
|
72
|
-
},
|
|
73
69
|
{ type: "START_PROGRESS" },
|
|
74
70
|
{
|
|
75
71
|
type: "MODULARUI/FETCH",
|
|
@@ -116,10 +112,6 @@ describe("modularui hooks", () => {
|
|
|
116
112
|
expect(result.current).toBeNull();
|
|
117
113
|
|
|
118
114
|
expect(store.getActions()).toStrictEqual([
|
|
119
|
-
{
|
|
120
|
-
type: "MODULARUI/STATUS",
|
|
121
|
-
payload: { key: `app(/)(en)`, status: "LOADING" },
|
|
122
|
-
},
|
|
123
115
|
{ type: "START_PROGRESS" },
|
|
124
116
|
{
|
|
125
117
|
type: "MODULARUI/FETCH",
|
|
@@ -92,6 +92,7 @@ const loadModelSuccessAction = (key, model, updateHandler) => {
|
|
|
92
92
|
const loadModel = (key, href, options) => ({
|
|
93
93
|
type: "MODULARUI/FETCH",
|
|
94
94
|
payload: {
|
|
95
|
+
key,
|
|
95
96
|
href: href instanceof _Href.default ? href : new _Href.default(href),
|
|
96
97
|
method: options?.method ?? _Constants.HTTP_METHODS.GET,
|
|
97
98
|
data: options?.data,
|
|
@@ -122,16 +123,17 @@ const loadModel = (key, href, options) => ({
|
|
|
122
123
|
/**
|
|
123
124
|
*/
|
|
124
125
|
exports.loadModel = loadModel;
|
|
125
|
-
const loadModularUI = (key, href, options) => dispatch => {
|
|
126
|
-
|
|
126
|
+
const loadModularUI = (key, href, options) => (dispatch, getState) => {
|
|
127
|
+
const modularuiStore = getState()?.modularui;
|
|
128
|
+
if (modularuiStore && modularuiStore[key]?.status === _Constants.MODULARUI_STATUS.LOADING) {
|
|
129
|
+
// don't create duplicate requests during loading
|
|
130
|
+
return dispatch({
|
|
131
|
+
type: "NO_ACTION"
|
|
132
|
+
});
|
|
133
|
+
}
|
|
127
134
|
dispatch((0, _ProgressIndicator.startProgress)());
|
|
128
135
|
const loadModelPromise = dispatch(loadModel(key, href, options));
|
|
129
|
-
return _promise.default.resolve(loadModelPromise).then(
|
|
130
|
-
if (response?.type === "FINISH_PROGRESS") {
|
|
131
|
-
dispatch(updateStatus(key, _Constants.MODULARUI_STATUS.FINISHED));
|
|
132
|
-
}
|
|
133
|
-
return dispatch((0, _ProgressIndicator.finishProgress)());
|
|
134
|
-
}).catch(error => dispatch((0, _Error.handleError)(error)));
|
|
136
|
+
return _promise.default.resolve(loadModelPromise).then(() => dispatch((0, _ProgressIndicator.finishProgress)())).catch(error => dispatch((0, _Error.handleError)(error)));
|
|
135
137
|
};
|
|
136
138
|
|
|
137
139
|
/**
|
|
@@ -109,6 +109,7 @@ export const loadModel = (
|
|
|
109
109
|
): ModularUIAction => ({
|
|
110
110
|
type: "MODULARUI/FETCH",
|
|
111
111
|
payload: {
|
|
112
|
+
key,
|
|
112
113
|
href: href instanceof Href ? href : new Href(href),
|
|
113
114
|
method: options?.method ?? HTTP_METHODS.GET,
|
|
114
115
|
data: options?.data,
|
|
@@ -146,20 +147,24 @@ export const loadModularUI =
|
|
|
146
147
|
href: Href | string,
|
|
147
148
|
options?: RequestModularUIOptions,
|
|
148
149
|
): ThunkAction =>
|
|
149
|
-
(dispatch: Dispatch) => {
|
|
150
|
-
|
|
150
|
+
(dispatch: Dispatch, getState) => {
|
|
151
|
+
const modularuiStore = getState()?.modularui;
|
|
152
|
+
if (
|
|
153
|
+
modularuiStore &&
|
|
154
|
+
modularuiStore[key]?.status === MODULARUI_STATUS.LOADING
|
|
155
|
+
) {
|
|
156
|
+
// don't create duplicate requests during loading
|
|
157
|
+
return dispatch({
|
|
158
|
+
type: "NO_ACTION",
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
|
|
151
162
|
dispatch(startProgress());
|
|
152
163
|
|
|
153
164
|
const loadModelPromise = dispatch(loadModel(key, href, options));
|
|
154
165
|
|
|
155
166
|
return Promise.resolve(loadModelPromise)
|
|
156
|
-
.then((
|
|
157
|
-
if (response?.type === "FINISH_PROGRESS") {
|
|
158
|
-
dispatch(updateStatus(key, MODULARUI_STATUS.FINISHED));
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
return dispatch(finishProgress());
|
|
162
|
-
})
|
|
167
|
+
.then(() => dispatch(finishProgress()))
|
|
163
168
|
.catch((error) => dispatch(handleError(error)));
|
|
164
169
|
};
|
|
165
170
|
|
|
@@ -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","Href","method","HTTP_METHODS","GET","data","locale","childmodels","targetModel","forceTargetModel","cache","successAction","errorAction","error","errorResponse","ErrorResponse","isChangePassword","isResourceNotFoundAfterReload","MODULARUI_STATUS","ERROR","loadModularUI","dispatch","LOADING","startProgress","loadModelPromise","_promise","default","resolve","then","
|
|
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","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","startProgress","loadModelPromise","_promise","default","resolve","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 href: href instanceof Href ? href : new Href(href),\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 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 // don't create duplicate requests during loading\n return dispatch({\n type: \"NO_ACTION\",\n });\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,IAAAA,UAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,cAAA,GAAAD,sBAAA,CAAAF,OAAA;AACA,IAAAI,kBAAA,GAAAJ,OAAA;AACA,IAAAK,MAAA,GAAAL,OAAA;AAmBA;AACA;AACO,MAAMM,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;AADAI,OAAA,CAAAN,QAAA,GAAAA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AAQ,CAAC,CAAC,EAAEE,SAAS;EAC5C,IACED,cAAc,IACdA,cAAc,CAACzC,GAAG,CAAC,EAAEa,MAAM,KAAKuB,2BAAgB,CAACO,OAAO,EACxD;IACA;IACA,OAAOJ,QAAQ,CAAC;MACdpC,IAAI,EAAE;IACR,CAAC,CAAC;EACJ;EAEAoC,QAAQ,CAAC,IAAAK,gCAAa,EAAC,CAAC,CAAC;EAEzB,MAAMC,gBAAgB,GAAGN,QAAQ,CAACvB,SAAS,CAAChB,GAAG,EAAEiB,IAAI,EAAEC,OAAO,CAAC,CAAC;EAEhE,OAAO4B,QAAA,CAAAC,OAAA,CAAQC,OAAO,CAACH,gBAAgB,CAAC,CACrCI,IAAI,CAAC,MAAMV,QAAQ,CAAC,IAAAW,iCAAc,EAAC,CAAC,CAAC,CAAC,CACtCC,KAAK,CAAEpB,KAAK,IAAKQ,QAAQ,CAAC,IAAAa,kBAAW,EAACrB,KAAK,CAAC,CAAC,CAAC;AACnD,CAAC;;AAEH;AACA;AADA1B,OAAA,CAAAiC,aAAA,GAAAA,aAAA;AAEO,MAAMe,WAAW,GAAGA,CACzBpD,KAAqB,EACrBiB,OAAiC,KAEjCoB,aAAa,CAACrC,KAAK,CAACC,UAAU,EAAED,KAAK,CAACqD,QAAQ,EAAE;EAC9C,GAAGpC,OAAO;EACVqC,QAAQ,EAAE;AACZ,CAAC,CAAC;AAAClD,OAAA,CAAAgD,WAAA,GAAAA,WAAA","ignoreList":[]}
|
|
@@ -10,6 +10,7 @@ var _ModularUIRequest = _interopRequireDefault(require("../../modularui/ModularU
|
|
|
10
10
|
var _Constants = require("../../constants/Constants");
|
|
11
11
|
var _ProgressIndicator = require("../actions/ProgressIndicator");
|
|
12
12
|
var _Error = require("../actions/Error");
|
|
13
|
+
var _ModularUIActions = require("./ModularUIActions");
|
|
13
14
|
/**
|
|
14
15
|
* Symbol key that carries API call info interpreted by this Redux middleware.
|
|
15
16
|
*/
|
|
@@ -71,12 +72,14 @@ const errorHandler = (next, dispatch, errorAction, err) => {
|
|
|
71
72
|
const handleFetch = (action, locale, dispatch, next) => {
|
|
72
73
|
dispatch((0, _ProgressIndicator.startProgress)());
|
|
73
74
|
const {
|
|
75
|
+
key,
|
|
74
76
|
successAction,
|
|
75
77
|
errorAction,
|
|
76
78
|
...requestOptions
|
|
77
79
|
} = action.payload;
|
|
78
80
|
requestOptions.locale = locale;
|
|
79
81
|
const modularuiRequest = createRequest(requestOptions);
|
|
82
|
+
dispatch((0, _ModularUIActions.updateStatus)(key, _Constants.MODULARUI_STATUS.LOADING));
|
|
80
83
|
return modularuiRequest.fetch().then(model => responseHandler(next, dispatch, successAction, model)).catch(error => errorHandler(next, dispatch, errorAction, error));
|
|
81
84
|
};
|
|
82
85
|
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
// @flow
|
|
2
2
|
import ModularUIRequest from "../../modularui/ModularUIRequest";
|
|
3
|
-
import { HTTP_METHODS } from "../../constants/Constants";
|
|
3
|
+
import { HTTP_METHODS, MODULARUI_STATUS } from "../../constants/Constants";
|
|
4
4
|
|
|
5
5
|
import { startProgress, finishProgress } from "../actions/ProgressIndicator";
|
|
6
|
-
|
|
7
6
|
import { handleError } from "../actions/Error";
|
|
8
7
|
|
|
8
|
+
import { updateStatus } from "./ModularUIActions";
|
|
9
|
+
|
|
9
10
|
import type { Middleware, MiddlewareAPI } from "redux";
|
|
10
11
|
import type {
|
|
11
12
|
ReduxAction,
|
|
@@ -117,11 +118,13 @@ const handleFetch = (
|
|
|
117
118
|
) => {
|
|
118
119
|
dispatch(startProgress());
|
|
119
120
|
|
|
120
|
-
const { successAction, errorAction, ...requestOptions } = action.payload;
|
|
121
|
+
const { key, successAction, errorAction, ...requestOptions } = action.payload;
|
|
121
122
|
requestOptions.locale = locale;
|
|
122
123
|
|
|
123
124
|
const modularuiRequest = createRequest(requestOptions);
|
|
124
125
|
|
|
126
|
+
dispatch(updateStatus(key, MODULARUI_STATUS.LOADING));
|
|
127
|
+
|
|
125
128
|
return modularuiRequest
|
|
126
129
|
.fetch()
|
|
127
130
|
.then((model) => responseHandler(next, dispatch, successAction, model))
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ModularUIMiddleware.js","names":["_ModularUIRequest","_interopRequireDefault","require","_Constants","_ProgressIndicator","_Error","createRequest","modularui","request","ModularUIRequest","href","method","HTTP_METHODS","GET","data","locale","childmodels","isReload","cache","targetModel","forceTargetModel","responseHandler","next","dispatch","successAction","model","successResult","_promise","default","then","result","catch","error","handleError","Error","finishProgress","errorHandler","errorAction","err","errorResult","handleFetch","action","startProgress","requestOptions","payload","modularuiRequest","fetch","modularUIMiddleware","api","type","getState","i18n","exports"],"sources":["../../../src/redux/_modularui/ModularUIMiddleware.js"],"sourcesContent":["// @flow\nimport ModularUIRequest from \"../../modularui/ModularUIRequest\";\nimport { HTTP_METHODS } from \"../../constants/Constants\";\n\nimport { startProgress, finishProgress } from \"../actions/ProgressIndicator\";\
|
|
1
|
+
{"version":3,"file":"ModularUIMiddleware.js","names":["_ModularUIRequest","_interopRequireDefault","require","_Constants","_ProgressIndicator","_Error","_ModularUIActions","createRequest","modularui","request","ModularUIRequest","href","method","HTTP_METHODS","GET","data","locale","childmodels","isReload","cache","targetModel","forceTargetModel","responseHandler","next","dispatch","successAction","model","successResult","_promise","default","then","result","catch","error","handleError","Error","finishProgress","errorHandler","errorAction","err","errorResult","handleFetch","action","startProgress","key","requestOptions","payload","modularuiRequest","updateStatus","MODULARUI_STATUS","LOADING","fetch","modularUIMiddleware","api","type","getState","i18n","exports"],"sources":["../../../src/redux/_modularui/ModularUIMiddleware.js"],"sourcesContent":["// @flow\nimport ModularUIRequest from \"../../modularui/ModularUIRequest\";\nimport { HTTP_METHODS, MODULARUI_STATUS } from \"../../constants/Constants\";\n\nimport { startProgress, finishProgress } from \"../actions/ProgressIndicator\";\nimport { handleError } from \"../actions/Error\";\n\nimport { updateStatus } from \"./ModularUIActions\";\n\nimport type { Middleware, MiddlewareAPI } from \"redux\";\nimport type {\n ReduxAction,\n ReduxState,\n Dispatch,\n PossibleAction,\n} from \"../types\";\nimport type { ModularUIModel } from \"../../models/types\";\nimport type Href from \"../../models/href/Href\";\nimport type { ModularUIAction, SuccessAction, ErrorAction } from \"./types\";\nimport type { TargetModel } from \"../../modularui/types\";\n\ntype RequestOptions = {\n href: Href,\n method?: $Keys<typeof HTTP_METHODS>,\n data?: any,\n locale: string,\n childmodels?: boolean,\n targetModel?: TargetModel,\n forceTargetModel?: boolean,\n isReload?: boolean,\n cache?: boolean,\n};\n\n/**\n * Symbol key that carries API call info interpreted by this Redux middleware.\n */\nconst createRequest = (modularui: RequestOptions): ModularUIRequest => {\n const request = new ModularUIRequest(modularui.href, {\n method: modularui.method || HTTP_METHODS.GET,\n data: modularui.data || {},\n locale: modularui.locale,\n childmodels: modularui.childmodels ?? true,\n isReload: modularui.isReload,\n cache: modularui.cache,\n });\n\n if (modularui.targetModel) {\n request.targetModel = modularui.targetModel;\n request.forceTargetModel = modularui.forceTargetModel ?? false;\n }\n\n return request;\n};\n\n/**\n */\nconst responseHandler = (\n next: Dispatch,\n dispatch: Dispatch,\n successAction: SuccessAction,\n model: ModularUIModel,\n) => {\n if (successAction) {\n const successResult = successAction(model);\n\n if (successResult instanceof Promise) {\n successResult\n .then((result) => {\n dispatch(result);\n })\n .catch((error) => {\n next(handleError(error));\n });\n } else {\n try {\n dispatch(successResult);\n } catch (error) {\n throw new Error(\n `Result of successResult is not a valid redux action: ${error}`,\n );\n }\n }\n }\n\n return next(finishProgress());\n};\n\n/**\n */\nconst errorHandler = (\n next: Dispatch,\n dispatch: Dispatch,\n errorAction: ?ErrorAction,\n err: any,\n) => {\n dispatch(finishProgress());\n\n if (errorAction) {\n const errorResult = errorAction(err);\n\n if (errorResult instanceof Promise) {\n errorResult.then((result) => dispatch(result));\n } else {\n dispatch(errorResult);\n }\n }\n\n return next(handleError(err));\n};\n\n/**\n */\nconst handleFetch = (\n action: ModularUIAction,\n locale: string,\n dispatch: Dispatch,\n next: Dispatch,\n) => {\n dispatch(startProgress());\n\n const { key, successAction, errorAction, ...requestOptions } = action.payload;\n requestOptions.locale = locale;\n\n const modularuiRequest = createRequest(requestOptions);\n\n dispatch(updateStatus(key, MODULARUI_STATUS.LOADING));\n\n return modularuiRequest\n .fetch()\n .then((model) => responseHandler(next, dispatch, successAction, model))\n .catch((error) => errorHandler(next, dispatch, errorAction, error));\n};\n\n/**\n */\nexport const modularUIMiddleware: Middleware<\n ReduxState,\n ReduxAction,\n Dispatch,\n> =\n (api: MiddlewareAPI<ReduxState, ReduxAction, Dispatch>) =>\n (next: Dispatch) =>\n (action: PossibleAction) => {\n if (action.type === \"MODULARUI/FETCH\") {\n return handleFetch(\n // $FlowExpectedError[incompatible-exact]\n action,\n api.getState().i18n.locale,\n api.dispatch,\n next,\n );\n }\n\n return next(action);\n };\n"],"mappings":";;;;;;;;AACA,IAAAA,iBAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,UAAA,GAAAD,OAAA;AAEA,IAAAE,kBAAA,GAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AAEA,IAAAI,iBAAA,GAAAJ,OAAA;AA0BA;AACA;AACA;AACA,MAAMK,aAAa,GAAIC,SAAyB,IAAuB;EACrE,MAAMC,OAAO,GAAG,IAAIC,yBAAgB,CAACF,SAAS,CAACG,IAAI,EAAE;IACnDC,MAAM,EAAEJ,SAAS,CAACI,MAAM,IAAIC,uBAAY,CAACC,GAAG;IAC5CC,IAAI,EAAEP,SAAS,CAACO,IAAI,IAAI,CAAC,CAAC;IAC1BC,MAAM,EAAER,SAAS,CAACQ,MAAM;IACxBC,WAAW,EAAET,SAAS,CAACS,WAAW,IAAI,IAAI;IAC1CC,QAAQ,EAAEV,SAAS,CAACU,QAAQ;IAC5BC,KAAK,EAAEX,SAAS,CAACW;EACnB,CAAC,CAAC;EAEF,IAAIX,SAAS,CAACY,WAAW,EAAE;IACzBX,OAAO,CAACW,WAAW,GAAGZ,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","_Constants","_models","updateStatus","state","_ref","key","status","MODULARUI_STATUS","LOADING","lastModification","Date","now","setModel","_ref2","model","IllegalArgumentException","initModularUI","models","newState","_assign","default","forEach","_ref3","
|
|
1
|
+
{"version":3,"file":"ModularUIReducer.js","names":["_exceptions","require","_Constants","_models","updateStatus","state","_ref","key","status","MODULARUI_STATUS","LOADING","lastModification","Date","now","setModel","_ref2","model","FINISHED","IllegalArgumentException","initModularUI","models","newState","_assign","default","forEach","_ref3","getModelKey","_context","_find","_keys","call","connectKey","updateModel","modelKey","Error","removeKey","resetModularUI","ApplicationModel","initialState","ModularUIReducer","arguments","length","undefined","action","type","payload","exports"],"sources":["../../../src/redux/_modularui/ModularUIReducer.js"],"sourcesContent":["// @flow\nimport { IllegalArgumentException } from \"../../exceptions\";\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 throw new IllegalArgumentException(\"No model for setModel\");\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 throw new Error(\n `ModularUIReducer: Cannot update model with key ${model.connectKey}`,\n );\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,WAAA,GAAAC,OAAA;AACA,IAAAC,UAAA,GAAAD,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AAOA;AACA;AACA,MAAMG,YAAY,GAAGA,CACnBC,KAAqB,EAAAC,IAAA,KAElB;EAAA,IADH;IAA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,CAACS,KAAK,YAAYqB,wBAAgB,EAAE;MAChDhB,QAAQ,CAACd,GAAG,CAAC,GAAG;QAAE,GAAGF,KAAK,CAACE,GAAG;MAAE,CAAC;IACnC;EACF;EAEA,OAAOc,QAAQ;AACjB,CAAC;AAED,MAAMiB,YAA4B,GAAG,CAAC,CAAC;;AAEvC;AACA;AACA;AACO,MAAMC,gBAAsD,GAAG,SAAAA,CAAA,EAGjE;EAAA,IAFHlC,KAAK,GAAAmC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAGF,YAAY;EAAA,IACpBK,MAAM,GAAAH,SAAA,CAAAC,MAAA,OAAAD,SAAA,MAAAE,SAAA;EAEN,IAAI,CAACC,MAAM,EAAE;IACX,OAAOtC,KAAK;EACd;EAEA,QAAQsC,MAAM,CAACC,IAAI;IACjB,KAAK,gBAAgB;MACnB,OAAOzB,aAAa,CAACd,KAAK,EAAEsC,MAAM,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,OAAOb,WAAW,CAAC3B,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":[]}
|
|
@@ -134,16 +134,13 @@ describe("modularui actions", () => {
|
|
|
134
134
|
await store.dispatch(loadModularUI("application", "/", {}));
|
|
135
135
|
|
|
136
136
|
expect(store.getActions()).toStrictEqual([
|
|
137
|
-
{
|
|
138
|
-
type: "MODULARUI/STATUS",
|
|
139
|
-
payload: { key: "application", status: MODULARUI_STATUS.LOADING },
|
|
140
|
-
},
|
|
141
137
|
{
|
|
142
138
|
type: "START_PROGRESS",
|
|
143
139
|
},
|
|
144
140
|
{
|
|
145
141
|
type: "MODULARUI/FETCH",
|
|
146
142
|
payload: expect.objectContaining({
|
|
143
|
+
key: "application",
|
|
147
144
|
href: new Href("/"),
|
|
148
145
|
method: HTTP_METHODS.GET,
|
|
149
146
|
data: undefined,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","names":[],"sources":["../../../src/redux/_modularui/types.js"],"sourcesContent":["// @flow\nimport type { ModularUIModel } from \"../../models/types\";\nimport type Href from \"../../models/href/Href\";\nimport type { FetchException } from \"../../exceptions\";\nimport type { NoAction } from \"../types\";\nimport typeof {\n HTTP_METHODS,\n MODULARUI_STATUS,\n} from \"../../constants/Constants\";\nimport type { ComponentType } from \"react\";\nimport type { TargetModel } from \"../../modularui/types\";\nimport type { RequestModularUIOptions } from \"../../utils/fetch/types\";\n\nexport type ModularUIOptions = {\n propName?: string,\n removeOnUnmount?: boolean,\n ...RequestModularUIOptions,\n};\n\nexport type ModelEntry = {\n +status: string,\n +model: ModularUIModel,\n +lastModification: number,\n};\n\nexport type ModularUIState = {\n [string]: ModelEntry,\n ...\n};\n\nexport type SetModelAction = {\n type: \"MODULARUI/SET\",\n payload: {\n key: string,\n model: ?ModularUIModel,\n },\n};\n\nexport type InitModelAction = {\n type: \"MODULARUI/INIT\",\n payload: Array<{\n key: string,\n model: ModularUIModel,\n }>,\n};\n\nexport type UpdateModelAction = {\n type: \"MODULARUI/UPDATE\",\n payload: ModularUIModel,\n};\n\nexport type UpdateFormAction = {\n type: \"MODULARUI/UPDATE_FORM\",\n payload: ModularUIModel,\n};\n\nexport type SuccessAction = (\n model: ModularUIModel,\n) => UpdateModelAction | SetModelAction;\n\nexport type ErrorAction = (\n error: FetchException,\n) => UpdateStatusAction | RemoveModelByKeyAction | NoAction;\n\nexport type ModularUIAction = {\n type: \"MODULARUI/FETCH\",\n payload: {\n href: Href,\n method?: $Keys<HTTP_METHODS>,\n data?: any,\n locale: string,\n childmodels?: boolean,\n targetModel?: TargetModel,\n forceTargetModel?: boolean,\n cache?: boolean,\n successAction: (\n model: ModularUIModel,\n ) => UpdateModelAction | SetModelAction,\n errorAction?: ErrorAction,\n },\n};\n\nexport type RemoveModelByKeyAction = {\n type: \"MODULARUI/REMOVE_KEY\",\n payload: string,\n};\n\nexport type ResetModularUIAction = {\n type: \"MODULARUI/RESET\",\n};\n\nexport type UpdateStatusAction = {\n type: \"MODULARUI/STATUS\",\n payload: {\n key: string,\n status: $Keys<MODULARUI_STATUS>,\n },\n};\n\nexport type ModularUIConnector = (\n Component: ComponentType<any>,\n) => ComponentType<any>;\n"],"mappings":"","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"types.js","names":[],"sources":["../../../src/redux/_modularui/types.js"],"sourcesContent":["// @flow\nimport type { ModularUIModel } from \"../../models/types\";\nimport type Href from \"../../models/href/Href\";\nimport type { FetchException } from \"../../exceptions\";\nimport type { NoAction } from \"../types\";\nimport typeof {\n HTTP_METHODS,\n MODULARUI_STATUS,\n} from \"../../constants/Constants\";\nimport type { ComponentType } from \"react\";\nimport type { TargetModel } from \"../../modularui/types\";\nimport type { RequestModularUIOptions } from \"../../utils/fetch/types\";\n\nexport type ModularUIOptions = {\n propName?: string,\n removeOnUnmount?: boolean,\n ...RequestModularUIOptions,\n};\n\nexport type ModelEntry = {\n +status: string,\n +model: ModularUIModel,\n +lastModification: number,\n};\n\nexport type ModularUIState = {\n [string]: ModelEntry,\n ...\n};\n\nexport type SetModelAction = {\n type: \"MODULARUI/SET\",\n payload: {\n key: string,\n model: ?ModularUIModel,\n },\n};\n\nexport type InitModelAction = {\n type: \"MODULARUI/INIT\",\n payload: Array<{\n key: string,\n model: ModularUIModel,\n }>,\n};\n\nexport type UpdateModelAction = {\n type: \"MODULARUI/UPDATE\",\n payload: ModularUIModel,\n};\n\nexport type UpdateFormAction = {\n type: \"MODULARUI/UPDATE_FORM\",\n payload: ModularUIModel,\n};\n\nexport type SuccessAction = (\n model: ModularUIModel,\n) => UpdateModelAction | SetModelAction;\n\nexport type ErrorAction = (\n error: FetchException,\n) => UpdateStatusAction | RemoveModelByKeyAction | NoAction;\n\nexport type ModularUIAction = {\n type: \"MODULARUI/FETCH\",\n payload: {\n key: string,\n href: Href,\n method?: $Keys<HTTP_METHODS>,\n data?: any,\n locale: string,\n childmodels?: boolean,\n targetModel?: TargetModel,\n forceTargetModel?: boolean,\n cache?: boolean,\n successAction: (\n model: ModularUIModel,\n ) => UpdateModelAction | SetModelAction,\n errorAction?: ErrorAction,\n },\n};\n\nexport type RemoveModelByKeyAction = {\n type: \"MODULARUI/REMOVE_KEY\",\n payload: string,\n};\n\nexport type ResetModularUIAction = {\n type: \"MODULARUI/RESET\",\n};\n\nexport type UpdateStatusAction = {\n type: \"MODULARUI/STATUS\",\n payload: {\n key: string,\n status: $Keys<MODULARUI_STATUS>,\n },\n};\n\nexport type ModularUIConnector = (\n Component: ComponentType<any>,\n) => ComponentType<any>;\n"],"mappings":"","ignoreList":[]}
|
|
@@ -16,14 +16,11 @@ describe("application actions", () => {
|
|
|
16
16
|
await store.dispatch(reloadApplication());
|
|
17
17
|
|
|
18
18
|
expect(store.getActions()).toStrictEqual([
|
|
19
|
-
{
|
|
20
|
-
type: "MODULARUI/STATUS",
|
|
21
|
-
payload: { key: "application(/)(en)", status: "LOADING" },
|
|
22
|
-
},
|
|
23
19
|
{ type: "START_PROGRESS" },
|
|
24
20
|
expect.objectContaining({
|
|
25
21
|
type: "MODULARUI/FETCH",
|
|
26
22
|
payload: expect.objectContaining({
|
|
23
|
+
key: "application(/)(en)",
|
|
27
24
|
href: new Href("/", "Application"),
|
|
28
25
|
}),
|
|
29
26
|
}),
|
|
@@ -43,10 +40,6 @@ describe("application actions", () => {
|
|
|
43
40
|
type: "MODULARUI/REMOVE_KEY",
|
|
44
41
|
payload: "/",
|
|
45
42
|
},
|
|
46
|
-
{
|
|
47
|
-
type: "MODULARUI/STATUS",
|
|
48
|
-
payload: { key: "application(/)(en)", status: "LOADING" },
|
|
49
|
-
},
|
|
50
43
|
{ type: "START_PROGRESS" },
|
|
51
44
|
expect.objectContaining({
|
|
52
45
|
type: "MODULARUI/FETCH",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@beinformed/ui",
|
|
3
|
-
"version": "1.56.
|
|
3
|
+
"version": "1.56.5",
|
|
4
4
|
"description": "Toolbox for be informed javascript layouts",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
6
6
|
"bugs": "http://support.beinformed.com",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"flow": "flow",
|
|
30
30
|
"flow:ci": "flow check",
|
|
31
31
|
"flow-typed-install": "flow-typed install -l .flow/flow-typed/ --ignoreDeps peer --overwrite",
|
|
32
|
-
"test": "jest",
|
|
32
|
+
"test": "jest --bail",
|
|
33
33
|
"test:ci": "jest --ci",
|
|
34
34
|
"test:changed": "jest --onlyChanged",
|
|
35
35
|
"upgrade-interactive": "npm-check -u",
|
|
@@ -99,13 +99,13 @@
|
|
|
99
99
|
},
|
|
100
100
|
"devDependencies": {
|
|
101
101
|
"@babel/cli": "^7.25.7",
|
|
102
|
-
"@babel/core": "^7.25.
|
|
103
|
-
"@babel/eslint-parser": "^7.25.
|
|
102
|
+
"@babel/core": "^7.25.8",
|
|
103
|
+
"@babel/eslint-parser": "^7.25.8",
|
|
104
104
|
"@babel/eslint-plugin": "^7.25.7",
|
|
105
105
|
"@babel/plugin-proposal-class-properties": "^7.18.6",
|
|
106
106
|
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
|
|
107
107
|
"@babel/plugin-transform-runtime": "^7.25.7",
|
|
108
|
-
"@babel/preset-env": "^7.25.
|
|
108
|
+
"@babel/preset-env": "^7.25.8",
|
|
109
109
|
"@babel/preset-flow": "^7.25.7",
|
|
110
110
|
"@babel/preset-react": "^7.25.7",
|
|
111
111
|
"@commitlint/cli": "^19.5.0",
|
|
@@ -115,7 +115,7 @@
|
|
|
115
115
|
"babel-jest": "^29.7.0",
|
|
116
116
|
"babel-plugin-styled-components": "^2.1.4",
|
|
117
117
|
"cherry-pick": "^0.5.0",
|
|
118
|
-
"commit-and-tag-version": "^12.
|
|
118
|
+
"commit-and-tag-version": "^12.5.0",
|
|
119
119
|
"cross-env": "^7.0.3",
|
|
120
120
|
"documentation": "^14.0.2",
|
|
121
121
|
"eslint": "^8.57.0",
|
|
@@ -124,21 +124,21 @@
|
|
|
124
124
|
"eslint-plugin-ft-flow": "^3.0.11",
|
|
125
125
|
"eslint-plugin-import": "^2.31.0",
|
|
126
126
|
"eslint-plugin-jest": "^28.8.3",
|
|
127
|
-
"eslint-plugin-jsdoc": "^50.3
|
|
127
|
+
"eslint-plugin-jsdoc": "^50.4.3",
|
|
128
128
|
"eslint-plugin-react": "^7.37.1",
|
|
129
129
|
"eslint-plugin-react-hooks": "^4.6.2",
|
|
130
130
|
"eslint-plugin-you-dont-need-lodash-underscore": "^6.14.0",
|
|
131
131
|
"flow-bin": "^0.200.1",
|
|
132
132
|
"flow-copy-source": "^2.0.9",
|
|
133
133
|
"flow-typed": "^3.9.0",
|
|
134
|
-
"hermes-eslint": "^0.
|
|
134
|
+
"hermes-eslint": "^0.25.0",
|
|
135
135
|
"history": "^4.0.0",
|
|
136
136
|
"husky": "^9.1.6",
|
|
137
137
|
"jest": "^29.7.0",
|
|
138
138
|
"jest-environment-jsdom": "^29.7.0",
|
|
139
139
|
"jest-junit": "^16.0.0",
|
|
140
140
|
"jest-sonar-reporter": "^2.0.0",
|
|
141
|
-
"jscodeshift": "^0.
|
|
141
|
+
"jscodeshift": "^17.0.0",
|
|
142
142
|
"lint-staged": "^15.2.10",
|
|
143
143
|
"polished": "^4.0.0",
|
|
144
144
|
"prettier": "^3.3.3",
|
|
@@ -71,14 +71,11 @@ describe("modularui hooks", () => {
|
|
|
71
71
|
expect(result.current).toBeNull();
|
|
72
72
|
|
|
73
73
|
expect(store.getActions()).toStrictEqual([
|
|
74
|
-
{
|
|
75
|
-
type: "MODULARUI/STATUS",
|
|
76
|
-
payload: { key: `${key}(${url})(en)`, status: "LOADING" },
|
|
77
|
-
},
|
|
78
74
|
{ type: "START_PROGRESS" },
|
|
79
75
|
{
|
|
80
76
|
type: "MODULARUI/FETCH",
|
|
81
77
|
payload: expect.objectContaining({
|
|
78
|
+
key: `${key}(${url})(en)`,
|
|
82
79
|
href: new Href(url),
|
|
83
80
|
locale: "en",
|
|
84
81
|
targetModel: targetModel,
|
|
@@ -61,14 +61,11 @@ describe("authentication hooks", () => {
|
|
|
61
61
|
|
|
62
62
|
expect(store.getActions()).toStrictEqual([
|
|
63
63
|
{ type: "START_PROGRESS" },
|
|
64
|
-
{
|
|
65
|
-
type: "MODULARUI/STATUS",
|
|
66
|
-
payload: { key: "application(/)(en)", status: "LOADING" },
|
|
67
|
-
},
|
|
68
64
|
{ type: "START_PROGRESS" },
|
|
69
65
|
expect.objectContaining({
|
|
70
66
|
type: "MODULARUI/FETCH",
|
|
71
67
|
payload: expect.objectContaining({
|
|
68
|
+
key: "application(/)(en)",
|
|
72
69
|
href: new Href("/", "Application"),
|
|
73
70
|
}),
|
|
74
71
|
}),
|
|
@@ -108,14 +105,11 @@ describe("authentication hooks", () => {
|
|
|
108
105
|
expect(store.getActions()).toStrictEqual([
|
|
109
106
|
{ type: "START_PROGRESS" },
|
|
110
107
|
{ type: "MODULARUI/RESET" },
|
|
111
|
-
{
|
|
112
|
-
type: "MODULARUI/STATUS",
|
|
113
|
-
payload: { key: "application(/)(en)", status: "LOADING" },
|
|
114
|
-
},
|
|
115
108
|
{ type: "START_PROGRESS" },
|
|
116
109
|
expect.objectContaining({
|
|
117
110
|
type: "MODULARUI/FETCH",
|
|
118
111
|
payload: expect.objectContaining({
|
|
112
|
+
key: "application(/)(en)",
|
|
119
113
|
href: new Href("/", "Application"),
|
|
120
114
|
}),
|
|
121
115
|
}),
|
|
@@ -69,14 +69,11 @@ describe("form hooks", () => {
|
|
|
69
69
|
expect(result.current).toBeUndefined();
|
|
70
70
|
|
|
71
71
|
expect(store.getActions()).toStrictEqual([
|
|
72
|
-
{
|
|
73
|
-
type: "MODULARUI/STATUS",
|
|
74
|
-
payload: { key: "form(/form)(en)", status: "LOADING" },
|
|
75
|
-
},
|
|
76
72
|
{ type: "START_PROGRESS" },
|
|
77
73
|
{
|
|
78
74
|
type: "MODULARUI/FETCH",
|
|
79
75
|
payload: expect.objectContaining({
|
|
76
|
+
key: "form(/form)(en)",
|
|
80
77
|
href: new Href("/form?commit=false"),
|
|
81
78
|
locale: "en",
|
|
82
79
|
targetModel: FormModel,
|
|
@@ -113,17 +110,11 @@ describe("form hooks", () => {
|
|
|
113
110
|
href.resourcetype = "Form";
|
|
114
111
|
|
|
115
112
|
expect(store.getActions()).toStrictEqual([
|
|
116
|
-
{
|
|
117
|
-
type: "MODULARUI/STATUS",
|
|
118
|
-
payload: {
|
|
119
|
-
key: "form(/persons/persons/createperson)(en)",
|
|
120
|
-
status: "LOADING",
|
|
121
|
-
},
|
|
122
|
-
},
|
|
123
113
|
{ type: "START_PROGRESS" },
|
|
124
114
|
{
|
|
125
115
|
type: "MODULARUI/FETCH",
|
|
126
116
|
payload: expect.objectContaining({
|
|
117
|
+
key: "form(/persons/persons/createperson)(en)",
|
|
127
118
|
href: href,
|
|
128
119
|
locale: "en",
|
|
129
120
|
targetModel: FormModel,
|
|
@@ -64,14 +64,11 @@ describe("modelcatalog hooks", () => {
|
|
|
64
64
|
expect(result.current).toBeNull();
|
|
65
65
|
|
|
66
66
|
expect(store.getActions()).toStrictEqual([
|
|
67
|
-
{
|
|
68
|
-
type: "MODULARUI/STATUS",
|
|
69
|
-
payload: { key: `${key}(${url})(en)`, status: "LOADING" },
|
|
70
|
-
},
|
|
71
67
|
{ type: "START_PROGRESS" },
|
|
72
68
|
{
|
|
73
69
|
type: "MODULARUI/FETCH",
|
|
74
70
|
payload: expect.objectContaining({
|
|
71
|
+
key: `${key}(${url})(en)`,
|
|
75
72
|
href: new Href(url),
|
|
76
73
|
locale: "en",
|
|
77
74
|
targetModel: targetModel,
|
|
@@ -37,14 +37,11 @@ describe("model hooks", () => {
|
|
|
37
37
|
|
|
38
38
|
result.current.reload(application);
|
|
39
39
|
expect(store.getActions()).toStrictEqual([
|
|
40
|
-
{
|
|
41
|
-
type: "MODULARUI/STATUS",
|
|
42
|
-
payload: { key: "application(/)(en)", status: "LOADING" },
|
|
43
|
-
},
|
|
44
40
|
{ type: "START_PROGRESS" },
|
|
45
41
|
{
|
|
46
42
|
type: "MODULARUI/FETCH",
|
|
47
43
|
payload: expect.objectContaining({
|
|
44
|
+
key: "application(/)(en)",
|
|
48
45
|
href: new Href("/", "Application"),
|
|
49
46
|
locale: "en",
|
|
50
47
|
}),
|
|
@@ -83,14 +80,11 @@ describe("model hooks", () => {
|
|
|
83
80
|
model.selfhref.equals(new Href("/")),
|
|
84
81
|
);
|
|
85
82
|
expect(store.getActions()).toStrictEqual([
|
|
86
|
-
{
|
|
87
|
-
type: "MODULARUI/STATUS",
|
|
88
|
-
payload: { key: "application(/)(en)", status: "LOADING" },
|
|
89
|
-
},
|
|
90
83
|
{ type: "START_PROGRESS" },
|
|
91
84
|
{
|
|
92
85
|
type: "MODULARUI/FETCH",
|
|
93
86
|
payload: expect.objectContaining({
|
|
87
|
+
key: "application(/)(en)",
|
|
94
88
|
href: new Href("/", "Application"),
|
|
95
89
|
locale: "en",
|
|
96
90
|
}),
|
|
@@ -130,14 +124,11 @@ describe("model hooks", () => {
|
|
|
130
124
|
model.selfhref.equals(new Href("/books/books")),
|
|
131
125
|
);
|
|
132
126
|
expect(store.getActions()).toStrictEqual([
|
|
133
|
-
{
|
|
134
|
-
type: "MODULARUI/STATUS",
|
|
135
|
-
payload: { key: "list(/books/books)(en)", status: "LOADING" },
|
|
136
|
-
},
|
|
137
127
|
{ type: "START_PROGRESS" },
|
|
138
128
|
{
|
|
139
129
|
type: "MODULARUI/FETCH",
|
|
140
130
|
payload: expect.objectContaining({
|
|
131
|
+
key: "list(/books/books)(en)",
|
|
141
132
|
href: caselist.selfhref,
|
|
142
133
|
locale: "en",
|
|
143
134
|
}),
|
|
@@ -66,10 +66,6 @@ describe("modularui hooks", () => {
|
|
|
66
66
|
expect(result.current).toBeNull();
|
|
67
67
|
|
|
68
68
|
expect(store.getActions()).toStrictEqual([
|
|
69
|
-
{
|
|
70
|
-
type: "MODULARUI/STATUS",
|
|
71
|
-
payload: { key: `app(/)(en)`, status: "LOADING" },
|
|
72
|
-
},
|
|
73
69
|
{ type: "START_PROGRESS" },
|
|
74
70
|
{
|
|
75
71
|
type: "MODULARUI/FETCH",
|
|
@@ -116,10 +112,6 @@ describe("modularui hooks", () => {
|
|
|
116
112
|
expect(result.current).toBeNull();
|
|
117
113
|
|
|
118
114
|
expect(store.getActions()).toStrictEqual([
|
|
119
|
-
{
|
|
120
|
-
type: "MODULARUI/STATUS",
|
|
121
|
-
payload: { key: `app(/)(en)`, status: "LOADING" },
|
|
122
|
-
},
|
|
123
115
|
{ type: "START_PROGRESS" },
|
|
124
116
|
{
|
|
125
117
|
type: "MODULARUI/FETCH",
|
|
@@ -109,6 +109,7 @@ export const loadModel = (
|
|
|
109
109
|
): ModularUIAction => ({
|
|
110
110
|
type: "MODULARUI/FETCH",
|
|
111
111
|
payload: {
|
|
112
|
+
key,
|
|
112
113
|
href: href instanceof Href ? href : new Href(href),
|
|
113
114
|
method: options?.method ?? HTTP_METHODS.GET,
|
|
114
115
|
data: options?.data,
|
|
@@ -146,20 +147,24 @@ export const loadModularUI =
|
|
|
146
147
|
href: Href | string,
|
|
147
148
|
options?: RequestModularUIOptions,
|
|
148
149
|
): ThunkAction =>
|
|
149
|
-
(dispatch: Dispatch) => {
|
|
150
|
-
|
|
150
|
+
(dispatch: Dispatch, getState) => {
|
|
151
|
+
const modularuiStore = getState()?.modularui;
|
|
152
|
+
if (
|
|
153
|
+
modularuiStore &&
|
|
154
|
+
modularuiStore[key]?.status === MODULARUI_STATUS.LOADING
|
|
155
|
+
) {
|
|
156
|
+
// don't create duplicate requests during loading
|
|
157
|
+
return dispatch({
|
|
158
|
+
type: "NO_ACTION",
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
|
|
151
162
|
dispatch(startProgress());
|
|
152
163
|
|
|
153
164
|
const loadModelPromise = dispatch(loadModel(key, href, options));
|
|
154
165
|
|
|
155
166
|
return Promise.resolve(loadModelPromise)
|
|
156
|
-
.then((
|
|
157
|
-
if (response?.type === "FINISH_PROGRESS") {
|
|
158
|
-
dispatch(updateStatus(key, MODULARUI_STATUS.FINISHED));
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
return dispatch(finishProgress());
|
|
162
|
-
})
|
|
167
|
+
.then(() => dispatch(finishProgress()))
|
|
163
168
|
.catch((error) => dispatch(handleError(error)));
|
|
164
169
|
};
|
|
165
170
|
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
// @flow
|
|
2
2
|
import ModularUIRequest from "../../modularui/ModularUIRequest";
|
|
3
|
-
import { HTTP_METHODS } from "../../constants/Constants";
|
|
3
|
+
import { HTTP_METHODS, MODULARUI_STATUS } from "../../constants/Constants";
|
|
4
4
|
|
|
5
5
|
import { startProgress, finishProgress } from "../actions/ProgressIndicator";
|
|
6
|
-
|
|
7
6
|
import { handleError } from "../actions/Error";
|
|
8
7
|
|
|
8
|
+
import { updateStatus } from "./ModularUIActions";
|
|
9
|
+
|
|
9
10
|
import type { Middleware, MiddlewareAPI } from "redux";
|
|
10
11
|
import type {
|
|
11
12
|
ReduxAction,
|
|
@@ -117,11 +118,13 @@ const handleFetch = (
|
|
|
117
118
|
) => {
|
|
118
119
|
dispatch(startProgress());
|
|
119
120
|
|
|
120
|
-
const { successAction, errorAction, ...requestOptions } = action.payload;
|
|
121
|
+
const { key, successAction, errorAction, ...requestOptions } = action.payload;
|
|
121
122
|
requestOptions.locale = locale;
|
|
122
123
|
|
|
123
124
|
const modularuiRequest = createRequest(requestOptions);
|
|
124
125
|
|
|
126
|
+
dispatch(updateStatus(key, MODULARUI_STATUS.LOADING));
|
|
127
|
+
|
|
125
128
|
return modularuiRequest
|
|
126
129
|
.fetch()
|
|
127
130
|
.then((model) => responseHandler(next, dispatch, successAction, model))
|
|
@@ -134,16 +134,13 @@ describe("modularui actions", () => {
|
|
|
134
134
|
await store.dispatch(loadModularUI("application", "/", {}));
|
|
135
135
|
|
|
136
136
|
expect(store.getActions()).toStrictEqual([
|
|
137
|
-
{
|
|
138
|
-
type: "MODULARUI/STATUS",
|
|
139
|
-
payload: { key: "application", status: MODULARUI_STATUS.LOADING },
|
|
140
|
-
},
|
|
141
137
|
{
|
|
142
138
|
type: "START_PROGRESS",
|
|
143
139
|
},
|
|
144
140
|
{
|
|
145
141
|
type: "MODULARUI/FETCH",
|
|
146
142
|
payload: expect.objectContaining({
|
|
143
|
+
key: "application",
|
|
147
144
|
href: new Href("/"),
|
|
148
145
|
method: HTTP_METHODS.GET,
|
|
149
146
|
data: undefined,
|
|
@@ -16,14 +16,11 @@ describe("application actions", () => {
|
|
|
16
16
|
await store.dispatch(reloadApplication());
|
|
17
17
|
|
|
18
18
|
expect(store.getActions()).toStrictEqual([
|
|
19
|
-
{
|
|
20
|
-
type: "MODULARUI/STATUS",
|
|
21
|
-
payload: { key: "application(/)(en)", status: "LOADING" },
|
|
22
|
-
},
|
|
23
19
|
{ type: "START_PROGRESS" },
|
|
24
20
|
expect.objectContaining({
|
|
25
21
|
type: "MODULARUI/FETCH",
|
|
26
22
|
payload: expect.objectContaining({
|
|
23
|
+
key: "application(/)(en)",
|
|
27
24
|
href: new Href("/", "Application"),
|
|
28
25
|
}),
|
|
29
26
|
}),
|
|
@@ -43,10 +40,6 @@ describe("application actions", () => {
|
|
|
43
40
|
type: "MODULARUI/REMOVE_KEY",
|
|
44
41
|
payload: "/",
|
|
45
42
|
},
|
|
46
|
-
{
|
|
47
|
-
type: "MODULARUI/STATUS",
|
|
48
|
-
payload: { key: "application(/)(en)", status: "LOADING" },
|
|
49
|
-
},
|
|
50
43
|
{ type: "START_PROGRESS" },
|
|
51
44
|
expect.objectContaining({
|
|
52
45
|
type: "MODULARUI/FETCH",
|