@beinformed/ui 1.60.5 → 1.60.6
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/hooks/__tests__/useForm.spec.js.flow +1 -1
- package/esm/hooks/useForm.js +15 -20
- package/esm/hooks/useForm.js.flow +5 -14
- package/esm/hooks/useForm.js.map +1 -1
- package/esm/hooks/useModularUI.d.ts +0 -1
- package/esm/hooks/useModularUI.js +3 -11
- package/esm/hooks/useModularUI.js.flow +4 -23
- package/esm/hooks/useModularUI.js.map +1 -1
- package/esm/redux/_modularui/ModularUIActions.d.ts +2 -2
- package/esm/redux/_modularui/ModularUIActions.js +27 -10
- package/esm/redux/_modularui/ModularUIActions.js.flow +24 -5
- package/esm/redux/_modularui/ModularUIActions.js.map +1 -1
- package/esm/redux/_modularui/ModularUIMiddleware.js +1 -1
- package/esm/redux/_modularui/ModularUIMiddleware.js.flow +1 -1
- package/esm/redux/_modularui/ModularUIMiddleware.js.map +1 -1
- package/esm/redux/_modularui/ModularUIReducer.js +4 -2
- package/esm/redux/_modularui/ModularUIReducer.js.flow +10 -1
- package/esm/redux/_modularui/ModularUIReducer.js.map +1 -1
- package/esm/redux/_modularui/__tests__/actions.spec.js.flow +5 -1
- package/esm/redux/_modularui/types.d.ts +1 -0
- package/esm/redux/_modularui/types.js.flow +2 -0
- package/esm/redux/_modularui/types.js.map +1 -1
- package/lib/hooks/useForm.js +14 -19
- package/lib/hooks/useForm.js.map +1 -1
- package/lib/hooks/useModularUI.d.ts +0 -1
- package/lib/hooks/useModularUI.js +4 -13
- package/lib/hooks/useModularUI.js.map +1 -1
- package/lib/redux/_modularui/ModularUIActions.d.ts +2 -2
- package/lib/redux/_modularui/ModularUIActions.js +27 -10
- package/lib/redux/_modularui/ModularUIActions.js.map +1 -1
- package/lib/redux/_modularui/ModularUIMiddleware.js +1 -1
- package/lib/redux/_modularui/ModularUIMiddleware.js.map +1 -1
- package/lib/redux/_modularui/ModularUIReducer.js +4 -2
- package/lib/redux/_modularui/ModularUIReducer.js.map +1 -1
- package/lib/redux/_modularui/types.d.ts +1 -0
- package/lib/redux/_modularui/types.js.map +1 -1
- package/package.json +1 -1
- package/src/hooks/__tests__/useForm.spec.js +1 -1
- package/src/hooks/useForm.js +5 -14
- package/src/hooks/useModularUI.js +4 -23
- package/src/redux/_modularui/ModularUIActions.js +24 -5
- package/src/redux/_modularui/ModularUIMiddleware.js +1 -1
- package/src/redux/_modularui/ModularUIReducer.js +10 -1
- package/src/redux/_modularui/__tests__/actions.spec.js +5 -1
- package/src/redux/_modularui/types.js +2 -0
|
@@ -1 +1 @@
|
|
|
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 {
|
|
1
|
+
{"version":3,"file":"ModularUIReducer.js","names":["MODULARUI_STATUS","ApplicationModel","updateStatus","state","_ref","key","status","requestOptions","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 {\n key,\n status,\n requestOptions,\n }: {\n key: string,\n status: $Keys<typeof MODULARUI_STATUS>,\n requestOptions: any,\n },\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 requestOptions: requestOptions || state[key]?.requestOptions,\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,KAUlB;EAAA,IATH;IACEC,GAAG;IACHC,MAAM;IACNC;EAKF,CAAC,GAAAH,IAAA;EAED;EACA,IAAIE,MAAM,KAAKN,gBAAgB,CAACQ,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,CAAC;MAC5BJ,cAAc,EAAEA,cAAc,IAAIJ,KAAK,CAACE,GAAG,CAA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AA,QAAAE,SAAA,GAAAF,SAAA,MAAGF,YAAY;EAAA,IACpBK,MAAM,GAAAH,SAAA,CAAAC,MAAA,OAAAD,SAAA,MAAAE,SAAA;EAEN,IAAI,CAACC,MAAM,EAAE;IACX,OAAOpC,KAAK;EACd;EAEA,QAAQoC,MAAM,CAACC,IAAI;IACjB,KAAK,gBAAgB;MACnB,OAAOtB,aAAa,CAACf,KAAK,EAAEoC,MAAM,CAACE,OAAO,CAAC;IAE7C,KAAK,iBAAiB;MACpB,OAAOR,cAAc,CAAC9B,KAAK,CAAC;IAE9B,KAAK,kBAAkB;MACrB,OAAOD,YAAY,CAACC,KAAK,EAAEoC,MAAM,CAACE,OAAO,CAAC;IAE5C,KAAK,eAAe;MAClB,OAAO7B,QAAQ,CAACT,KAAK,EAAEoC,MAAM,CAACE,OAAO,CAAC;IAExC,KAAK,kBAAkB;IACvB,KAAK,uBAAuB;MAC1B,OAAOX,WAAW,CAAC3B,KAAK,EAAEoC,MAAM,CAACE,OAAO,CAAC;IAE3C,KAAK,sBAAsB;MACzB,OAAOT,SAAS,CAACO,MAAM,CAACE,OAAO,EAAEtC,KAAK,CAAC;IAEzC;MACE,OAAOA,KAAK;EAChB;AACF,CAAC","ignoreList":[]}
|
|
@@ -72,7 +72,11 @@ describe("modularui actions", () => {
|
|
|
72
72
|
expect(store.getActions()).toStrictEqual([
|
|
73
73
|
{
|
|
74
74
|
type: "MODULARUI/STATUS",
|
|
75
|
-
payload: {
|
|
75
|
+
payload: {
|
|
76
|
+
key: "application",
|
|
77
|
+
status: MODULARUI_STATUS.LOADING,
|
|
78
|
+
requestOptions: undefined,
|
|
79
|
+
},
|
|
76
80
|
},
|
|
77
81
|
]);
|
|
78
82
|
});
|
|
@@ -21,6 +21,7 @@ export type ModelEntry = {
|
|
|
21
21
|
+status: string,
|
|
22
22
|
+model: ModularUIModel,
|
|
23
23
|
+lastModification: number,
|
|
24
|
+
+requestOptions?: any,
|
|
24
25
|
};
|
|
25
26
|
|
|
26
27
|
export type ModularUIState = {
|
|
@@ -111,6 +112,7 @@ export type UpdateStatusAction = {
|
|
|
111
112
|
payload: {
|
|
112
113
|
key: string,
|
|
113
114
|
status: $Keys<MODULARUI_STATUS>,
|
|
115
|
+
requestOptions: any,
|
|
114
116
|
},
|
|
115
117
|
};
|
|
116
118
|
|
|
@@ -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 key: string,\n origin?: string,\n contextPath?: string,\n href: Href,\n method?: $Keys<HTTP_METHODS>,\n params?: string,\n data?: any,\n timeout?: number,\n headers?: {\n [headerName: string]: string,\n Accept?: string,\n \"Accept-Language\"?: string,\n \"Content-Type\"?: string,\n \"x-filename\"?: string,\n \"x-filesize\"?: string,\n },\n events?: { [eventName: string]: () => void },\n onProgress?: ProgressEventHandler,\n locale: string,\n childmodels?: boolean,\n targetModel?: TargetModel,\n forceTargetModel?: boolean,\n cache?: boolean,\n isReload?: boolean,\n withCredentials?: 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 +requestOptions?: any,\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 origin?: string,\n contextPath?: string,\n href: Href,\n method?: $Keys<HTTP_METHODS>,\n params?: string,\n data?: any,\n timeout?: number,\n headers?: {\n [headerName: string]: string,\n Accept?: string,\n \"Accept-Language\"?: string,\n \"Content-Type\"?: string,\n \"x-filename\"?: string,\n \"x-filesize\"?: string,\n },\n events?: { [eventName: string]: () => void },\n onProgress?: ProgressEventHandler,\n locale: string,\n childmodels?: boolean,\n targetModel?: TargetModel,\n forceTargetModel?: boolean,\n cache?: boolean,\n isReload?: boolean,\n withCredentials?: 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 requestOptions: any,\n },\n};\n\nexport type ModularUIConnector = (\n Component: ComponentType<any>,\n) => ComponentType<any>;\n"],"mappings":"","ignoreList":[]}
|
package/lib/hooks/useForm.js
CHANGED
|
@@ -12,8 +12,6 @@ var _modularui = require("../redux/_modularui");
|
|
|
12
12
|
var _useModularUI = require("./useModularUI");
|
|
13
13
|
var _actions = require("../redux/actions");
|
|
14
14
|
var _FormModel = _interopRequireDefault(require("../models/form/FormModel"));
|
|
15
|
-
const FORM_MODEL_KEY = "form";
|
|
16
|
-
|
|
17
15
|
/**
|
|
18
16
|
* Load a form by href
|
|
19
17
|
*/
|
|
@@ -22,7 +20,7 @@ const useForm = (href, data) => {
|
|
|
22
20
|
if (!(0, _constants.getSetting)("ALWAYS_COMMIT_FORM")) {
|
|
23
21
|
formHref.addParameter("commit", "false");
|
|
24
22
|
}
|
|
25
|
-
const form = (0, _useModularUI.useModularUI)(
|
|
23
|
+
const form = (0, _useModularUI.useModularUI)("form", formHref, {
|
|
26
24
|
method: _constants.HTTP_METHODS.POST,
|
|
27
25
|
targetModel: _FormModel.default,
|
|
28
26
|
removeOnUnmount: true,
|
|
@@ -43,22 +41,19 @@ const useFormNavigation = () => {
|
|
|
43
41
|
const dispatch = (0, _reactRedux.useDispatch)();
|
|
44
42
|
const previous = form => dispatch((0, _actions.previousObject)(form));
|
|
45
43
|
const cancel = form => dispatch((0, _actions.cancelForm)(form));
|
|
46
|
-
const submit = form => {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
targetModel: _FormModel.default
|
|
60
|
-
}));
|
|
61
|
-
};
|
|
44
|
+
const submit = form => dispatch((0, _modularui.loadModularUI)(form.connectKey, form.selfhref, {
|
|
45
|
+
method: _constants.HTTP_METHODS.POST,
|
|
46
|
+
data: form.formdata,
|
|
47
|
+
updateHandler: newModel => {
|
|
48
|
+
if (newModel instanceof _FormModel.default) {
|
|
49
|
+
const clonedModel = form.clone();
|
|
50
|
+
clonedModel.update(newModel);
|
|
51
|
+
return clonedModel;
|
|
52
|
+
}
|
|
53
|
+
return newModel;
|
|
54
|
+
},
|
|
55
|
+
targetModel: _FormModel.default
|
|
56
|
+
}));
|
|
62
57
|
const remove = form => dispatch((0, _modularui.removeModelByKey)(form.connectKey));
|
|
63
58
|
const showFormNotificationAction = form => dispatch((0, _actions.showFormNotification)(form));
|
|
64
59
|
return {
|
package/lib/hooks/useForm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useForm.js","names":["_reactRedux","require","_Href","_interopRequireDefault","_constants","_modularui","_useModularUI","_actions","_FormModel","
|
|
1
|
+
{"version":3,"file":"useForm.js","names":["_reactRedux","require","_Href","_interopRequireDefault","_constants","_modularui","_useModularUI","_actions","_FormModel","useForm","href","data","formHref","Href","getSetting","addParameter","form","useModularUI","method","HTTP_METHODS","POST","targetModel","FormModel","removeOnUnmount","origin","contextPath","model","exports","useFormNavigation","dispatch","useDispatch","previous","previousObject","cancel","cancelForm","submit","loadModularUI","connectKey","selfhref","formdata","updateHandler","newModel","clonedModel","clone","update","remove","removeModelByKey","showFormNotificationAction","showFormNotification","useAttributeUpdate","object","attribute","value","options","updateFormAttribute","useAttributeSet","save","addRepeatableAttributeSet","cancelRepeatableAttributeSet","removeRepeatableAttributeSet"],"sources":["../../src/hooks/useForm.js"],"sourcesContent":["// @flow\nimport { useDispatch } from \"react-redux\";\n\nimport Href from \"../models/href/Href\";\n\nimport { getSetting, HTTP_METHODS } from \"../constants\";\n\nimport type {\n RemoveModelByKeyAction,\n UpdateFormAction,\n} from \"../redux/_modularui\";\nimport { loadModularUI, removeModelByKey } from \"../redux/_modularui\";\nimport { useModularUI } from \"./useModularUI\";\n\nimport {\n addRepeatableAttributeSet,\n cancelForm,\n cancelRepeatableAttributeSet,\n previousObject,\n removeRepeatableAttributeSet,\n showFormNotification,\n updateFormAttribute,\n} from \"../redux/actions\";\n\nimport FormModel from \"../models/form/FormModel\";\n\nimport type { AttributeType, FormObjectModel, ModularUIModel } from \"../models\";\nimport type { UpdateFormOptions } from \"../redux/types\";\n\ntype FormNavigationHook = {\n previous: (form: FormModel) => UpdateFormAction,\n cancel: (form: FormModel) => void,\n submit: (form: FormModel) => void,\n showFormNotification: (form: FormModel) => void,\n remove: (form: FormModel) => RemoveModelByKeyAction,\n};\n\ntype AttributeSetHook = {\n save: () => UpdateFormAction,\n cancel: (object: FormObjectModel) => UpdateFormAction,\n remove: (object: FormObjectModel) => UpdateFormAction,\n};\n\ntype AttributeUpdateHook = (\n attribute: AttributeType,\n value: string,\n options: UpdateFormOptions,\n) => void;\n\n/**\n * Load a form by href\n */\nexport const useForm = (href: string | Href, data?: Object): ?FormModel => {\n const formHref = new Href(href);\n\n if (!getSetting(\"ALWAYS_COMMIT_FORM\")) {\n formHref.addParameter(\"commit\", \"false\");\n }\n\n const form = useModularUI(\"form\", formHref, {\n method: HTTP_METHODS.POST,\n targetModel: FormModel,\n removeOnUnmount: true,\n data,\n origin: formHref.origin,\n contextPath: formHref.contextPath,\n });\n\n if (form?.model) {\n return form.model;\n }\n};\n\n/**\n * Form navigation methods\n */\nexport const useFormNavigation = (): FormNavigationHook => {\n const dispatch = useDispatch();\n\n const previous = (form: FormModel) => dispatch(previousObject(form));\n\n const cancel = (form: FormModel) => dispatch(cancelForm(form));\n\n const submit = (form: FormModel) =>\n dispatch(\n loadModularUI(form.connectKey, form.selfhref, {\n method: HTTP_METHODS.POST,\n data: form.formdata,\n updateHandler: (newModel: ModularUIModel): ModularUIModel => {\n if (newModel instanceof FormModel) {\n const clonedModel: FormModel = form.clone();\n clonedModel.update(newModel);\n return clonedModel;\n }\n return newModel;\n },\n targetModel: FormModel,\n }),\n );\n\n const remove = (form: FormModel) =>\n dispatch(removeModelByKey(form.connectKey));\n\n const showFormNotificationAction = (form: FormModel) =>\n dispatch(showFormNotification(form));\n\n return {\n previous,\n cancel,\n submit,\n remove,\n showFormNotification: showFormNotificationAction,\n };\n};\n\n/**\n * Hook that returns a function to update attributes of a form object.\n * <br >\n * The returned function accepts the following options:\n *\n * - autosubmit: Automatically submit the form after a change\n * - autosav: Automatically save the form (in the background) after a change\n * - autoupdate: Automatically update the current form object after a change\n * - forceUpdate: Force the update even if conditions are not met.\n * - validate: Activate/deactivate the form object validation by an update.\n */\nexport const useAttributeUpdate = (\n form: FormModel,\n object: FormObjectModel,\n): AttributeUpdateHook => {\n const dispatch = useDispatch();\n\n return (\n attribute: AttributeType,\n value: string,\n options: UpdateFormOptions,\n ) => dispatch(updateFormAttribute(form, object, attribute, value, options));\n};\n\n/**\n * Attributeset actions\n */\nexport const useAttributeSet = (form: FormModel): AttributeSetHook => {\n const dispatch = useDispatch();\n\n return {\n save: () => dispatch(addRepeatableAttributeSet(form)),\n cancel: (object: FormObjectModel) =>\n dispatch(cancelRepeatableAttributeSet(form, object)),\n remove: (object: FormObjectModel) =>\n dispatch(removeRepeatableAttributeSet(form, object)),\n };\n};\n"],"mappings":";;;;;;;AACA,IAAAA,WAAA,GAAAC,OAAA;AAEA,IAAAC,KAAA,GAAAC,sBAAA,CAAAF,OAAA;AAEA,IAAAG,UAAA,GAAAH,OAAA;AAMA,IAAAI,UAAA,GAAAJ,OAAA;AACA,IAAAK,aAAA,GAAAL,OAAA;AAEA,IAAAM,QAAA,GAAAN,OAAA;AAUA,IAAAO,UAAA,GAAAL,sBAAA,CAAAF,OAAA;AAyBA;AACA;AACA;AACO,MAAMQ,OAAO,GAAGA,CAACC,IAAmB,EAAEC,IAAa,KAAiB;EACzE,MAAMC,QAAQ,GAAG,IAAIC,aAAI,CAACH,IAAI,CAAC;EAE/B,IAAI,CAAC,IAAAI,qBAAU,EAAC,oBAAoB,CAAC,EAAE;IACrCF,QAAQ,CAACG,YAAY,CAAC,QAAQ,EAAE,OAAO,CAAC;EAC1C;EAEA,MAAMC,IAAI,GAAG,IAAAC,0BAAY,EAAC,MAAM,EAAEL,QAAQ,EAAE;IAC1CM,MAAM,EAAEC,uBAAY,CAACC,IAAI;IACzBC,WAAW,EAAEC,kBAAS;IACtBC,eAAe,EAAE,IAAI;IACrBZ,IAAI;IACJa,MAAM,EAAEZ,QAAQ,CAACY,MAAM;IACvBC,WAAW,EAAEb,QAAQ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IACNG,oBAAoB,EAAED;EACxB,CAAC;AACH,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAVApB,OAAA,CAAAC,iBAAA,GAAAA,iBAAA;AAWO,MAAMqB,kBAAkB,GAAGA,CAChCjC,IAAe,EACfkC,MAAuB,KACC;EACxB,MAAMrB,QAAQ,GAAG,IAAAC,uBAAW,EAAC,CAAC;EAE9B,OAAO,CACLqB,SAAwB,EACxBC,KAAa,EACbC,OAA0B,KACvBxB,QAAQ,CAAC,IAAAyB,4BAAmB,EAACtC,IAAI,EAAEkC,MAAM,EAAEC,SAAS,EAAEC,KAAK,EAAEC,OAAO,CAAC,CAAC;AAC7E,CAAC;;AAED;AACA;AACA;AAFA1B,OAAA,CAAAsB,kBAAA,GAAAA,kBAAA;AAGO,MAAMM,eAAe,GAAIvC,IAAe,IAAuB;EACpE,MAAMa,QAAQ,GAAG,IAAAC,uBAAW,EAAC,CAAC;EAE9B,OAAO;IACL0B,IAAI,EAAEA,CAAA,KAAM3B,QAAQ,CAAC,IAAA4B,kCAAyB,EAACzC,IAAI,CAAC,CAAC;IACrDiB,MAAM,EAAGiB,MAAuB,IAC9BrB,QAAQ,CAAC,IAAA6B,qCAA4B,EAAC1C,IAAI,EAAEkC,MAAM,CAAC,CAAC;IACtDL,MAAM,EAAGK,MAAuB,IAC9BrB,QAAQ,CAAC,IAAA8B,qCAA4B,EAAC3C,IAAI,EAAEkC,MAAM,CAAC;EACvD,CAAC;AACH,CAAC;AAACvB,OAAA,CAAA4B,eAAA,GAAAA,eAAA","ignoreList":[]}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export function createKeyForModularUIStore(modelKey: string, url: string, locale: string): string;
|
|
2
1
|
export function useModularUI(modelKey: string, url: string | Href, options?: RequestModularUIOptions): any;
|
|
3
2
|
import Href from "../models/href/Href";
|
|
4
3
|
import { RequestModularUIOptions } from "../utils";
|
|
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequ
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.useModularUI =
|
|
7
|
+
exports.useModularUI = void 0;
|
|
8
8
|
var _react = require("react");
|
|
9
9
|
var _reactRedux = require("react-redux");
|
|
10
10
|
var _reactRouter = require("react-router");
|
|
@@ -15,18 +15,9 @@ var _useI18n = require("./useI18n");
|
|
|
15
15
|
var _Href = _interopRequireDefault(require("../models/href/Href"));
|
|
16
16
|
/**
|
|
17
17
|
*/
|
|
18
|
-
const
|
|
19
|
-
return `${modelKey}(${url})(${locale})`;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
*/
|
|
24
|
-
exports.createKeyForModularUIStore = createKeyForModularUIStore;
|
|
25
|
-
const useKeyForHook = function (modelKey, url) {
|
|
26
|
-
let removeQuerystringFromKey = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
|
18
|
+
const useKeyForHook = (modelKey, url) => {
|
|
27
19
|
const locale = (0, _useI18n.useLocale)();
|
|
28
|
-
|
|
29
|
-
return (0, _react.useMemo)(() => createKeyForModularUIStore(modelKey, href, locale), [modelKey, href, locale]);
|
|
20
|
+
return (0, _react.useMemo)(() => `${modelKey}(${url.split("?")[0]})(${locale})`, [modelKey, url, locale]);
|
|
30
21
|
};
|
|
31
22
|
|
|
32
23
|
/**
|
|
@@ -39,7 +30,7 @@ const useModularUI = function (modelKey, url) {
|
|
|
39
30
|
};
|
|
40
31
|
const dispatch = (0, _reactRedux.useDispatch)();
|
|
41
32
|
const href = (0, _react.useMemo)(() => url?.toString() || "", [url]);
|
|
42
|
-
const key = useKeyForHook(modelKey, href
|
|
33
|
+
const key = useKeyForHook(modelKey, href);
|
|
43
34
|
const modelSelector = (0, _react.useMemo)(() => state => state.modularui[key], [key]);
|
|
44
35
|
const model = (0, _reactRedux.useSelector)(modelSelector);
|
|
45
36
|
if (url instanceof _Href.default) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useModularUI.js","names":["_react","require","_reactRedux","_reactRouter","_constants","_ModularUIActions","_useDeepCompareEffect","_interopRequireDefault","_useI18n","_Href","
|
|
1
|
+
{"version":3,"file":"useModularUI.js","names":["_react","require","_reactRedux","_reactRouter","_constants","_ModularUIActions","_useDeepCompareEffect","_interopRequireDefault","_useI18n","_Href","useKeyForHook","modelKey","url","locale","useLocale","useMemo","split","useModularUI","options","arguments","length","undefined","method","HTTP_METHODS","GET","removeOnUnmount","dispatch","useDispatch","href","toString","key","modelSelector","state","modularui","model","useSelector","Href","origin","contextPath","location","useLocation","redirectLocation","forceLoad","equals","prevOptions","useRef","prevHref","prevForceLoad","useDeepCompareEffect","isOldReload","current","isReload","doForceLoad","loadModularUI","useEffect","removeModelByKey","exports"],"sources":["../../src/hooks/useModularUI.js"],"sourcesContent":["// @flow\nimport { useEffect, useRef, useMemo } from \"react\";\nimport { useDispatch, useSelector } from \"react-redux\";\nimport { useLocation } from \"react-router\";\n\nimport { HTTP_METHODS } from \"../constants\";\nimport {\n loadModularUI,\n removeModelByKey,\n} from \"../redux/_modularui/ModularUIActions\";\n\nimport useDeepCompareEffect from \"./useDeepCompareEffect\";\n\nimport { useLocale } from \"./useI18n\";\nimport Href from \"../models/href/Href\";\n\nimport type { RequestModularUIOptions } from \"../utils\";\n\n/**\n */\nconst useKeyForHook = (modelKey: string, url: string) => {\n const locale = useLocale();\n return useMemo(\n () => `${modelKey}(${url.split(\"?\")[0]})(${locale})`,\n [modelKey, url, locale],\n );\n};\n\n/**\n * Use redux action and selector to retrieve the correct modular ui service model\n */\nexport const useModularUI = (\n modelKey: string,\n url: string | Href,\n options: RequestModularUIOptions = {\n method: HTTP_METHODS.GET,\n removeOnUnmount: false,\n },\n): any => {\n const dispatch = useDispatch();\n const href = useMemo(() => url?.toString() || \"\", [url]);\n const key = useKeyForHook(modelKey, href);\n\n const modelSelector = useMemo(() => (state) => state.modularui[key], [key]);\n const model = useSelector(modelSelector);\n\n if (url instanceof Href) {\n options.origin = options.origin ?? url.origin;\n options.contextPath = options.contextPath ?? url.contextPath;\n }\n\n const location = useLocation();\n const redirectLocation = location.state?.redirectLocation;\n const forceLoad =\n model == null ||\n (redirectLocation instanceof Href ? redirectLocation?.equals(href) : false);\n\n const prevOptions = useRef(options);\n const prevHref = useRef(href);\n const prevForceLoad = useRef(forceLoad);\n\n // dispatch loadModularUI\n useDeepCompareEffect(() => {\n // prevent reloads when previous option had the isReload, but the new options not\n const isOldReload =\n prevHref.current === href &&\n prevOptions.current.isReload &&\n !options.isReload;\n\n const doForceLoad = forceLoad && !prevForceLoad.current;\n\n if (href !== \"\" && (doForceLoad || !isOldReload)) {\n dispatch(loadModularUI(key, href, options));\n }\n\n prevOptions.current = options;\n prevHref.current = href;\n prevForceLoad.current = forceLoad;\n }, [key, href, options, forceLoad]);\n\n useEffect(() => {\n if (options.removeOnUnmount) {\n return () => {\n dispatch(removeModelByKey(key));\n };\n }\n }, [dispatch, key, options.removeOnUnmount]);\n\n return model;\n};\n"],"mappings":";;;;;;;AACA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AACA,IAAAE,YAAA,GAAAF,OAAA;AAEA,IAAAG,UAAA,GAAAH,OAAA;AACA,IAAAI,iBAAA,GAAAJ,OAAA;AAKA,IAAAK,qBAAA,GAAAC,sBAAA,CAAAN,OAAA;AAEA,IAAAO,QAAA,GAAAP,OAAA;AACA,IAAAQ,KAAA,GAAAF,sBAAA,CAAAN,OAAA;AAIA;AACA;AACA,MAAMS,aAAa,GAAGA,CAACC,QAAgB,EAAEC,GAAW,KAAK;EACvD,MAAMC,MAAM,GAAG,IAAAC,kBAAS,EAAC,CAAC;EAC1B,OAAO,IAAAC,cAAO,EACZ,MAAM,GAAGJ,QAAQ,IAAIC,GAAG,CAACI,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,KAAKH,MAAM,GAAG,EACpD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AAMgB,WAAW,GAAG,IAAAC,aAAM,EAAC3B,OAAO,CAAC;EACnC,MAAM4B,QAAQ,GAAG,IAAAD,aAAM,EAACjB,IAAI,CAAC;EAC7B,MAAMmB,aAAa,GAAG,IAAAF,aAAM,EAACH,SAAS,CAAC;;EAEvC;EACA,IAAAM,6BAAoB,EAAC,MAAM;IACzB;IACA,MAAMC,WAAW,GACfH,QAAQ,CAACI,OAAO,KAAKtB,IAAI,IACzBgB,WAAW,CAACM,OAAO,CAACC,QAAQ,IAC5B,CAACjC,OAAO,CAACiC,QAAQ;IAEnB,MAAMC,WAAW,GAAGV,SAAS,IAAI,CAACK,aAAa,CAACG,OAAO;IAEvD,IAAItB,IAAI,KAAK,EAAE,KAAKwB,WAAW,IAAI,CAACH,WAAW,CAAC,EAAE;MAChDvB,QAAQ,CAAC,IAAA2B,+BAAa,EAACvB,GAAG,EAAEF,IAAI,EAAEV,OAAO,CAAC,CAAC;IAC7C;IAEA0B,WAAW,CAACM,OAAO,GAAGhC,OAAO;IAC7B4B,QAAQ,CAACI,OAAO,GAAGtB,IAAI;IACvBmB,aAAa,CAACG,OAAO,GAAGR,SAAS;EACnC,CAAC,EAAE,CAACZ,GAAG,EAAEF,IAAI,EAAEV,OAAO,EAAEwB,SAAS,CAAC,CAAC;EAEnC,IAAAY,gBAAS,EAAC,MAAM;IACd,IAAIpC,OAAO,CAACO,eAAe,EAAE;MAC3B,OAAO,MAAM;QACXC,QAAQ,CAAC,IAAA6B,kCAAgB,EAACzB,GAAG,CAAC,CAAC;MACjC,CAAC;IACH;EACF,CAAC,EAAE,CAACJ,QAAQ,EAAEI,GAAG,EAAEZ,OAAO,CAACO,eAAe,CAAC,CAAC;EAE5C,OAAOS,KAAK;AACd,CAAC;AAACsB,OAAA,CAAAvC,YAAA,GAAAA,YAAA","ignoreList":[]}
|
|
@@ -7,9 +7,9 @@ export function updateModel(model: ModularUIModel): UpdateModelAction;
|
|
|
7
7
|
export function updateForm(model: ModularUIModel): UpdateFormAction;
|
|
8
8
|
export function removeModelByKey(key: string): RemoveModelByKeyAction;
|
|
9
9
|
export function resetModularUI(): ResetModularUIAction;
|
|
10
|
-
export function updateStatus(key: string, status: $Keys<typeof MODULARUI_STATUS
|
|
10
|
+
export function updateStatus(key: string, status: $Keys<typeof MODULARUI_STATUS>, requestOptions: any): UpdateStatusAction;
|
|
11
11
|
export function loadModel(key: string, href: Href | string, options?: RequestModularUIOptions): ModularUIAction;
|
|
12
|
-
export function loadModularUI(key: string, href: Href | string, options?: RequestModularUIOptions): ThunkAction;
|
|
12
|
+
export function loadModularUI(key: string, href: Href | string, options?: RequestModularUIOptions, retryCount?: number, retryDelay?: number): ThunkAction;
|
|
13
13
|
export function reloadModel(model: ModularUIModel, options?: RequestModularUIOptions): ThunkAction;
|
|
14
14
|
import { ModularUIModel } from "../../models/types";
|
|
15
15
|
import { SetModelAction } from "./types";
|
|
@@ -68,11 +68,12 @@ const resetModularUI = () => ({
|
|
|
68
68
|
/**
|
|
69
69
|
*/
|
|
70
70
|
exports.resetModularUI = resetModularUI;
|
|
71
|
-
const updateStatus = (key, status) => ({
|
|
71
|
+
const updateStatus = (key, status, requestOptions) => ({
|
|
72
72
|
type: "MODULARUI/STATUS",
|
|
73
73
|
payload: {
|
|
74
74
|
key,
|
|
75
|
-
status
|
|
75
|
+
status,
|
|
76
|
+
requestOptions
|
|
76
77
|
}
|
|
77
78
|
});
|
|
78
79
|
|
|
@@ -147,14 +148,30 @@ const loadModel = (key, href, options) => ({
|
|
|
147
148
|
/**
|
|
148
149
|
*/
|
|
149
150
|
exports.loadModel = loadModel;
|
|
150
|
-
const loadModularUI = (key, href, options)
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
151
|
+
const loadModularUI = function (key, href, options) {
|
|
152
|
+
let retryCount = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 3;
|
|
153
|
+
let retryDelay = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 200;
|
|
154
|
+
return (dispatch, getState) => {
|
|
155
|
+
const modularuiStore = getState()?.modularui;
|
|
156
|
+
const currentRequest = modularuiStore?.[key];
|
|
157
|
+
const isLoading = currentRequest?.status === _Constants.MODULARUI_STATUS.LOADING;
|
|
158
|
+
if (isLoading) {
|
|
159
|
+
const isDifferentRequest = currentRequest.requestOptions?.href?.toString() !== href.toString();
|
|
160
|
+
if (isDifferentRequest && retryCount > 0) {
|
|
161
|
+
return new _promise.default(resolve => {
|
|
162
|
+
setTimeout(() => {
|
|
163
|
+
resolve(dispatch(loadModularUI(key, href, options, retryCount - 1, retryDelay)));
|
|
164
|
+
}, retryDelay);
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// Same request is already loading — do nothing
|
|
169
|
+
return _promise.default.resolve();
|
|
170
|
+
}
|
|
171
|
+
dispatch((0, _ProgressIndicator.startProgress)());
|
|
172
|
+
const loadModelPromise = dispatch(loadModel(key, href, options));
|
|
173
|
+
return _promise.default.resolve(loadModelPromise).then(() => dispatch((0, _ProgressIndicator.finishProgress)())).catch(error => dispatch((0, _Error.handleError)(error)));
|
|
174
|
+
};
|
|
158
175
|
};
|
|
159
176
|
|
|
160
177
|
/**
|
|
@@ -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","getRequestLocale","optionLocale","navigator","language","split","loadModel","href","options","origin","contextPath","Href","method","HTTP_METHODS","GET","params","data","timeout","headers","events","onProgress","locale","childmodels","targetModel","forceTargetModel","cache","isReload","withCredentials","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"],"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 * Retrieve the preferred language for this request, falls back to the browser language or english\n */\nconst getRequestLocale = (optionLocale: ?string): string => {\n if (optionLocale) {\n return optionLocale;\n }\n\n if (typeof navigator !== \"undefined\" && navigator?.language) {\n return navigator.language.split(\"-\")[0] || \"en\";\n }\n\n return \"en\";\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 params: options?.params,\n data: options?.data,\n timeout: options?.timeout,\n headers: options?.headers,\n events: options?.events,\n onProgress: options?.onProgress,\n locale: getRequestLocale(options?.locale),\n childmodels: options?.childmodels,\n targetModel: options?.targetModel,\n forceTargetModel: options?.forceTargetModel,\n cache: options?.cache,\n isReload: options?.isReload,\n withCredentials: options?.withCredentials,\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 (\n errorResponse.isChangePassword ||\n errorResponse.isResourceNotFoundAfterReload\n ) {\n return removeModelByKey(key);\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,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,QAAA;AAEO,MAAMO,UAAU,GACrBC,MAAqD,KAChC;EACrBJ,IAAI,EAAE,gBAAgB;EACtBC,OAAO,EAAEG;AACX,CAAC,CAAC;;AAEF;AACA;AADAF,OAAA,CAAAC,UAAA,GAAAA,UAAA;AAEO,MAAME,WAAW,GAAIP,KAAqB,KAAyB;EACxEE,IAAI,EAAE,kBAAkB;EACxBC,OAAO,EAAEH;AACX,CAAC,CAAC;;AAEF;AACA;AADAI,OAAA,CAAAG,WAAA,GAAAA,WAAA;AAEO,MAAMC,UAAU,GAAIR,KAAqB,KAAwB;EACtEE,IAAI,EAAE,uBAAuB;EAC7BC,OAAO,EAAEH;AACX,CAAC,CAAC;;AAEF;AACA;AADAI,OAAA,CAAAI,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A,GAAAA,WAAA","ignoreList":[]}
|
|
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","requestOptions","loadModelSuccessAction","updateHandler","getRequestLocale","optionLocale","navigator","language","split","loadModel","href","options","origin","contextPath","Href","method","HTTP_METHODS","GET","params","data","timeout","headers","events","onProgress","locale","childmodels","targetModel","forceTargetModel","cache","isReload","withCredentials","successAction","errorAction","error","errorResponse","ErrorResponse","isChangePassword","isResourceNotFoundAfterReload","MODULARUI_STATUS","ERROR","loadModularUI","retryCount","arguments","length","undefined","retryDelay","dispatch","getState","modularuiStore","modularui","currentRequest","isLoading","LOADING","isDifferentRequest","toString","_promise","default","resolve","setTimeout","startProgress","loadModelPromise","then","finishProgress","catch","handleError","reloadModel","selfhref"],"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 requestOptions: any,\n): UpdateStatusAction => ({\n type: \"MODULARUI/STATUS\",\n payload: { key, status, requestOptions },\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 * Retrieve the preferred language for this request, falls back to the browser language or english\n */\nconst getRequestLocale = (optionLocale: ?string): string => {\n if (optionLocale) {\n return optionLocale;\n }\n\n if (typeof navigator !== \"undefined\" && navigator?.language) {\n return navigator.language.split(\"-\")[0] || \"en\";\n }\n\n return \"en\";\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 params: options?.params,\n data: options?.data,\n timeout: options?.timeout,\n headers: options?.headers,\n events: options?.events,\n onProgress: options?.onProgress,\n locale: getRequestLocale(options?.locale),\n childmodels: options?.childmodels,\n targetModel: options?.targetModel,\n forceTargetModel: options?.forceTargetModel,\n cache: options?.cache,\n isReload: options?.isReload,\n withCredentials: options?.withCredentials,\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 (\n errorResponse.isChangePassword ||\n errorResponse.isResourceNotFoundAfterReload\n ) {\n return removeModelByKey(key);\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 retryCount: number = 3,\n retryDelay: number = 200,\n ): ThunkAction =>\n (dispatch: Dispatch, getState) => {\n const modularuiStore = getState()?.modularui;\n const currentRequest = modularuiStore?.[key];\n\n const isLoading = currentRequest?.status === MODULARUI_STATUS.LOADING;\n\n if (isLoading) {\n const isDifferentRequest =\n currentRequest.requestOptions?.href?.toString() !== href.toString();\n if (isDifferentRequest && retryCount > 0) {\n return new Promise((resolve) => {\n setTimeout(() => {\n resolve(\n dispatch(\n loadModularUI(key, href, options, retryCount - 1, retryDelay),\n ),\n );\n }, retryDelay);\n });\n }\n\n // Same request is already loading — do nothing\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,IAAAA,UAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,cAAA,GAAAD,s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kB,kBAAW,EAAC/B,KAAK,CAAC,CAAC,CAAC;EACnD,CAAC;AAAA;;AAEH;AACA;AADAzC,OAAA,CAAAgD,aAAA,GAAAA,aAAA;AAEO,MAAMyB,WAAW,GAAGA,CACzB7E,KAAqB,EACrBuB,OAAiC,KAEjC6B,aAAa,CAACpD,KAAK,CAACC,UAAU,EAAED,KAAK,CAAC8E,QAAQ,EAAE;EAC9C,GAAGvD,OAAO;EACVkB,QAAQ,EAAE;AACZ,CAAC,CAAC;AAACrC,OAAA,CAAAyE,WAAA,GAAAA,WAAA","ignoreList":[]}
|
|
@@ -89,7 +89,7 @@ const handleFetch = (action, locale, dispatch, next) => {
|
|
|
89
89
|
} = action.payload;
|
|
90
90
|
requestOptions.locale = locale;
|
|
91
91
|
const modularuiRequest = createRequest(requestOptions);
|
|
92
|
-
dispatch((0, _ModularUIActions.updateStatus)(key, _Constants.MODULARUI_STATUS.LOADING));
|
|
92
|
+
dispatch((0, _ModularUIActions.updateStatus)(key, _Constants.MODULARUI_STATUS.LOADING, requestOptions));
|
|
93
93
|
return modularuiRequest.fetch().then(model => responseHandler(next, dispatch, successAction, model)).catch(error => errorHandler(next, dispatch, errorAction, error));
|
|
94
94
|
};
|
|
95
95
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ModularUIMiddleware.js","names":["_ModularUIRequest","_interopRequireDefault","require","_Constants","_ProgressIndicator","_Error","_ModularUIActions","createRequest","modularui","request","ModularUIRequest","href","method","HTTP_METHODS","GET","params","data","locale","childmodels","isReload","cache","headers","events","onProgress","origin","contextPath","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 origin?: string,\n contextPath?: string,\n href: Href,\n method?: $Keys<typeof HTTP_METHODS>,\n params?: string,\n data?: any,\n timeout?: number,\n locale: string,\n childmodels?: boolean,\n targetModel?: TargetModel,\n forceTargetModel?: boolean,\n isReload?: boolean,\n cache?: boolean,\n headers?: {\n [headerName: string]: string,\n Accept?: string,\n \"Accept-Language\"?: string,\n \"Content-Type\"?: string,\n \"x-filename\"?: string,\n \"x-filesize\"?: string,\n },\n events?: { [eventName: string]: () => void },\n onProgress?: ProgressEventHandler,\n withCredentials?: 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 params: modularui.params || \"\",\n data: modularui.data || {},\n locale: modularui.locale,\n childmodels: modularui.childmodels ?? true,\n isReload: modularui.isReload,\n cache: modularui.cache,\n headers: modularui.headers,\n events: modularui.events,\n onProgress: modularui.onProgress,\n });\n\n if (modularui.origin) {\n request.origin = modularui.origin;\n }\n\n if (modularui.contextPath) {\n request.contextPath = modularui.contextPath;\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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AAGH,MAAM,CAACI,OAAO;EAC7ED,cAAc,CAAClC,MAAM,GAAGA,MAAM;EAE9B,MAAMoC,gBAAgB,GAAG9C,aAAa,CAAC4C,cAAc,CAAC;EAEtDrB,QAAQ,CAAC,IAAAwB,8BAAY,EAACJ,GAAG,EAAEK,2BAAgB,CAACC,OAAO,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"ModularUIMiddleware.js","names":["_ModularUIRequest","_interopRequireDefault","require","_Constants","_ProgressIndicator","_Error","_ModularUIActions","createRequest","modularui","request","ModularUIRequest","href","method","HTTP_METHODS","GET","params","data","locale","childmodels","isReload","cache","headers","events","onProgress","origin","contextPath","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 origin?: string,\n contextPath?: string,\n href: Href,\n method?: $Keys<typeof HTTP_METHODS>,\n params?: string,\n data?: any,\n timeout?: number,\n locale: string,\n childmodels?: boolean,\n targetModel?: TargetModel,\n forceTargetModel?: boolean,\n isReload?: boolean,\n cache?: boolean,\n headers?: {\n [headerName: string]: string,\n Accept?: string,\n \"Accept-Language\"?: string,\n \"Content-Type\"?: string,\n \"x-filename\"?: string,\n \"x-filesize\"?: string,\n },\n events?: { [eventName: string]: () => void },\n onProgress?: ProgressEventHandler,\n withCredentials?: 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 params: modularui.params || \"\",\n data: modularui.data || {},\n locale: modularui.locale,\n childmodels: modularui.childmodels ?? true,\n isReload: modularui.isReload,\n cache: modularui.cache,\n headers: modularui.headers,\n events: modularui.events,\n onProgress: modularui.onProgress,\n });\n\n if (modularui.origin) {\n request.origin = modularui.origin;\n }\n\n if (modularui.contextPath) {\n request.contextPath = modularui.contextPath;\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, requestOptions));\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;AAyCA;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,MAAM,EAAEP,SAAS,CAACO,MAAM,IAAI,EAAE;IAC9BC,IAAI,EAAER,SAAS,CAACQ,IAAI,IAAI,CAAC,CAAC;IAC1BC,MAAM,EAAET,SAAS,CAACS,MAAM;IACxBC,WAAW,EAAEV,SAAS,CAACU,WAAW,IAAI,IAAI;IAC1CC,QAAQ,EAAEX,SAAS,CAACW,QAAQ;IAC5BC,KAAK,EAAEZ,SAAS,CAACY,KAAK;IACtBC,OAAO,EAAEb,SA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ACdmB,MAAsB,IAAK;EAC1B,IAAIA,MAAM,CAACY,IAAI,KAAK,iBAAiB,EAAE;IACrC,OAAOb,WAAW;IAChB;IACAC,MAAM,EACNW,GAAG,CAACE,QAAQ,CAAC,CAAC,CAACC,IAAI,CAAC7C,MAAM,EAC1B0C,GAAG,CAAC7B,QAAQ,EACZD,IACF,CAAC;EACH;EAEA,OAAOA,IAAI,CAACmB,MAAM,CAAC;AACrB,CAAC;AAACe,OAAA,CAAAL,mBAAA,GAAAA,mBAAA","ignoreList":[]}
|
|
@@ -15,7 +15,8 @@ var _models = require("../../models");
|
|
|
15
15
|
const updateStatus = (state, _ref) => {
|
|
16
16
|
let {
|
|
17
17
|
key,
|
|
18
|
-
status
|
|
18
|
+
status,
|
|
19
|
+
requestOptions
|
|
19
20
|
} = _ref;
|
|
20
21
|
// model should always be available when status is not loading
|
|
21
22
|
if (status !== _Constants.MODULARUI_STATUS.LOADING && !state[key]) {
|
|
@@ -26,7 +27,8 @@ const updateStatus = (state, _ref) => {
|
|
|
26
27
|
[key]: {
|
|
27
28
|
...state[key],
|
|
28
29
|
status,
|
|
29
|
-
lastModification: Date.now()
|
|
30
|
+
lastModification: Date.now(),
|
|
31
|
+
requestOptions: requestOptions || state[key]?.requestOptions
|
|
30
32
|
}
|
|
31
33
|
};
|
|
32
34
|
};
|
|
@@ -1 +1 @@
|
|
|
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 {
|
|
1
|
+
{"version":3,"file":"ModularUIReducer.js","names":["_Constants","require","_models","updateStatus","state","_ref","key","status","requestOptions","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 {\n key,\n status,\n requestOptions,\n }: {\n key: string,\n status: $Keys<typeof MODULARUI_STATUS>,\n requestOptions: any,\n },\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 requestOptions: requestOptions || state[key]?.requestOptions,\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,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;IAEzC;MACE,OAAOA,KAAK;EAChB;AACF,CAAC;AAAC0C,OAAA,CAAAP,gBAAA,GAAAA,gBAAA","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 key: string,\n origin?: string,\n contextPath?: string,\n href: Href,\n method?: $Keys<HTTP_METHODS>,\n params?: string,\n data?: any,\n timeout?: number,\n headers?: {\n [headerName: string]: string,\n Accept?: string,\n \"Accept-Language\"?: string,\n \"Content-Type\"?: string,\n \"x-filename\"?: string,\n \"x-filesize\"?: string,\n },\n events?: { [eventName: string]: () => void },\n onProgress?: ProgressEventHandler,\n locale: string,\n childmodels?: boolean,\n targetModel?: TargetModel,\n forceTargetModel?: boolean,\n cache?: boolean,\n isReload?: boolean,\n withCredentials?: 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 +requestOptions?: any,\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 origin?: string,\n contextPath?: string,\n href: Href,\n method?: $Keys<HTTP_METHODS>,\n params?: string,\n data?: any,\n timeout?: number,\n headers?: {\n [headerName: string]: string,\n Accept?: string,\n \"Accept-Language\"?: string,\n \"Content-Type\"?: string,\n \"x-filename\"?: string,\n \"x-filesize\"?: string,\n },\n events?: { [eventName: string]: () => void },\n onProgress?: ProgressEventHandler,\n locale: string,\n childmodels?: boolean,\n targetModel?: TargetModel,\n forceTargetModel?: boolean,\n cache?: boolean,\n isReload?: boolean,\n withCredentials?: 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 requestOptions: any,\n },\n};\n\nexport type ModularUIConnector = (\n Component: ComponentType<any>,\n) => ComponentType<any>;\n"],"mappings":"","ignoreList":[]}
|
package/package.json
CHANGED