@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
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.60.6](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/compare/v1.60.5...v1.60.6) (2025-04-15)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* **modularui:** retry req when qs is changed but original req still loading ([1ffa2ee](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/commit/1ffa2eeccf7520b941f346fc2583afd028118e23))
|
|
11
|
+
|
|
5
12
|
## [1.60.5](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/compare/v1.60.4...v1.60.5) (2025-04-14)
|
|
6
13
|
|
|
7
14
|
|
package/esm/hooks/useForm.js
CHANGED
|
@@ -2,11 +2,9 @@ import { useDispatch } from "react-redux";
|
|
|
2
2
|
import Href from "../models/href/Href";
|
|
3
3
|
import { getSetting, HTTP_METHODS } from "../constants";
|
|
4
4
|
import { loadModularUI, removeModelByKey } from "../redux/_modularui";
|
|
5
|
-
import {
|
|
5
|
+
import { useModularUI } from "./useModularUI";
|
|
6
6
|
import { addRepeatableAttributeSet, cancelForm, cancelRepeatableAttributeSet, previousObject, removeRepeatableAttributeSet, showFormNotification, updateFormAttribute } from "../redux/actions";
|
|
7
7
|
import FormModel from "../models/form/FormModel";
|
|
8
|
-
const FORM_MODEL_KEY = "form";
|
|
9
|
-
|
|
10
8
|
/**
|
|
11
9
|
* Load a form by href
|
|
12
10
|
*/
|
|
@@ -15,7 +13,7 @@ export const useForm = (href, data) => {
|
|
|
15
13
|
if (!getSetting("ALWAYS_COMMIT_FORM")) {
|
|
16
14
|
formHref.addParameter("commit", "false");
|
|
17
15
|
}
|
|
18
|
-
const form = useModularUI(
|
|
16
|
+
const form = useModularUI("form", formHref, {
|
|
19
17
|
method: HTTP_METHODS.POST,
|
|
20
18
|
targetModel: FormModel,
|
|
21
19
|
removeOnUnmount: true,
|
|
@@ -35,22 +33,19 @@ export const useFormNavigation = () => {
|
|
|
35
33
|
const dispatch = useDispatch();
|
|
36
34
|
const previous = form => dispatch(previousObject(form));
|
|
37
35
|
const cancel = form => dispatch(cancelForm(form));
|
|
38
|
-
const submit = form => {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
targetModel: FormModel
|
|
52
|
-
}));
|
|
53
|
-
};
|
|
36
|
+
const submit = form => dispatch(loadModularUI(form.connectKey, form.selfhref, {
|
|
37
|
+
method: HTTP_METHODS.POST,
|
|
38
|
+
data: form.formdata,
|
|
39
|
+
updateHandler: newModel => {
|
|
40
|
+
if (newModel instanceof FormModel) {
|
|
41
|
+
const clonedModel = form.clone();
|
|
42
|
+
clonedModel.update(newModel);
|
|
43
|
+
return clonedModel;
|
|
44
|
+
}
|
|
45
|
+
return newModel;
|
|
46
|
+
},
|
|
47
|
+
targetModel: FormModel
|
|
48
|
+
}));
|
|
54
49
|
const remove = form => dispatch(removeModelByKey(form.connectKey));
|
|
55
50
|
const showFormNotificationAction = form => dispatch(showFormNotification(form));
|
|
56
51
|
return {
|
|
@@ -10,7 +10,7 @@ import type {
|
|
|
10
10
|
UpdateFormAction,
|
|
11
11
|
} from "../redux/_modularui";
|
|
12
12
|
import { loadModularUI, removeModelByKey } from "../redux/_modularui";
|
|
13
|
-
import {
|
|
13
|
+
import { useModularUI } from "./useModularUI";
|
|
14
14
|
|
|
15
15
|
import {
|
|
16
16
|
addRepeatableAttributeSet,
|
|
@@ -47,8 +47,6 @@ type AttributeUpdateHook = (
|
|
|
47
47
|
options: UpdateFormOptions,
|
|
48
48
|
) => void;
|
|
49
49
|
|
|
50
|
-
const FORM_MODEL_KEY = "form";
|
|
51
|
-
|
|
52
50
|
/**
|
|
53
51
|
* Load a form by href
|
|
54
52
|
*/
|
|
@@ -59,7 +57,7 @@ export const useForm = (href: string | Href, data?: Object): ?FormModel => {
|
|
|
59
57
|
formHref.addParameter("commit", "false");
|
|
60
58
|
}
|
|
61
59
|
|
|
62
|
-
const form = useModularUI(
|
|
60
|
+
const form = useModularUI("form", formHref, {
|
|
63
61
|
method: HTTP_METHODS.POST,
|
|
64
62
|
targetModel: FormModel,
|
|
65
63
|
removeOnUnmount: true,
|
|
@@ -83,15 +81,9 @@ export const useFormNavigation = (): FormNavigationHook => {
|
|
|
83
81
|
|
|
84
82
|
const cancel = (form: FormModel) => dispatch(cancelForm(form));
|
|
85
83
|
|
|
86
|
-
const submit = (form: FormModel) =>
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
form.selfhref.toString(),
|
|
90
|
-
form.locale,
|
|
91
|
-
);
|
|
92
|
-
|
|
93
|
-
return dispatch(
|
|
94
|
-
loadModularUI(connectKey, form.selfhref, {
|
|
84
|
+
const submit = (form: FormModel) =>
|
|
85
|
+
dispatch(
|
|
86
|
+
loadModularUI(form.connectKey, form.selfhref, {
|
|
95
87
|
method: HTTP_METHODS.POST,
|
|
96
88
|
data: form.formdata,
|
|
97
89
|
updateHandler: (newModel: ModularUIModel): ModularUIModel => {
|
|
@@ -105,7 +97,6 @@ export const useFormNavigation = (): FormNavigationHook => {
|
|
|
105
97
|
targetModel: FormModel,
|
|
106
98
|
}),
|
|
107
99
|
);
|
|
108
|
-
};
|
|
109
100
|
|
|
110
101
|
const remove = (form: FormModel) =>
|
|
111
102
|
dispatch(removeModelByKey(form.connectKey));
|
package/esm/hooks/useForm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useForm.js","names":["useDispatch","Href","getSetting","HTTP_METHODS","loadModularUI","removeModelByKey","
|
|
1
|
+
{"version":3,"file":"useForm.js","names":["useDispatch","Href","getSetting","HTTP_METHODS","loadModularUI","removeModelByKey","useModularUI","addRepeatableAttributeSet","cancelForm","cancelRepeatableAttributeSet","previousObject","removeRepeatableAttributeSet","showFormNotification","updateFormAttribute","FormModel","useForm","href","data","formHref","addParameter","form","method","POST","targetModel","removeOnUnmount","origin","contextPath","model","useFormNavigation","dispatch","previous","cancel","submit","connectKey","selfhref","formdata","updateHandler","newModel","clonedModel","clone","update","remove","showFormNotificationAction","useAttributeUpdate","object","attribute","value","options","useAttributeSet","save"],"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,SAASA,WAAW,QAAQ,aAAa;AAEzC,OAAOC,IAAI,MAAM,qBAAqB;AAEtC,SAASC,UAAU,EAAEC,YAAY,QAAQ,cAAc;AAMvD,SAASC,aAAa,EAAEC,gBAAgB,QAAQ,qBAAqB;AACrE,SAASC,YAAY,QAAQ,gBAAgB;AAE7C,SACEC,yBAAyB,EACzBC,UAAU,EACVC,4BAA4B,EAC5BC,cAAc,EACdC,4BAA4B,EAC5BC,oBAAoB,EACpBC,mBAAmB,QACd,kBAAkB;AAEzB,OAAOC,SAAS,MAAM,0BAA0B;AAyBhD;AACA;AACA;AACA,OAAO,MAAMC,OAAO,GAAGA,CAACC,IAAmB,EAAEC,IAAa,KAAiB;EACzE,MAAMC,QAAQ,GAAG,IAAIjB,IAAI,CAACe,IAAI,CAAC;EAE/B,IAAI,CAACd,UAAU,CAAC,oBAAoB,CAAC,EAAE;IACrCgB,QAAQ,CAACC,YAAY,CAAC,QAAQ,EAAE,OAAO,CAAC;EAC1C;EAEA,MAAMC,IAAI,GAAGd,YAAY,CAAC,MAAM,EAAEY,QAAQ,EAAE;IAC1CG,MAAM,EAAElB,YAAY,CAACmB,IAAI;IACzBC,WAAW,EAAET,SAAS;IACtBU,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IACN7B,oBAAoB,EAAE8B;EACxB,CAAC;AACH,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,kBAAkB,GAAGA,CAChCvB,IAAe,EACfwB,MAAuB,KACC;EACxB,MAAMf,QAAQ,GAAG7B,WAAW,CAAC,CAAC;EAE9B,OAAO,CACL6C,SAAwB,EACxBC,KAAa,EACbC,OAA0B,KACvBlB,QAAQ,CAAChB,mBAAmB,CAACO,IAAI,EAAEwB,MAAM,EAAEC,SAAS,EAAEC,KAAK,EAAEC,OAAO,CAAC,CAAC;AAC7E,CAAC;;AAED;AACA;AACA;AACA,OAAO,MAAMC,eAAe,GAAI5B,IAAe,IAAuB;EACpE,MAAMS,QAAQ,GAAG7B,WAAW,CAAC,CAAC;EAE9B,OAAO;IACLiD,IAAI,EAAEA,CAAA,KAAMpB,QAAQ,CAACtB,yBAAyB,CAACa,IAAI,CAAC,CAAC;IACrDW,MAAM,EAAGa,MAAuB,IAC9Bf,QAAQ,CAACpB,4BAA4B,CAACW,IAAI,EAAEwB,MAAM,CAAC,CAAC;IACtDH,MAAM,EAAGG,MAAuB,IAC9Bf,QAAQ,CAAClB,4BAA4B,CAACS,IAAI,EAAEwB,MAAM,CAAC;EACvD,CAAC;AACH,CAAC","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";
|
|
@@ -8,17 +8,9 @@ import { useLocale } from "./useI18n";
|
|
|
8
8
|
import Href from "../models/href/Href";
|
|
9
9
|
/**
|
|
10
10
|
*/
|
|
11
|
-
|
|
12
|
-
return `${modelKey}(${url})(${locale})`;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
*/
|
|
17
|
-
const useKeyForHook = function (modelKey, url) {
|
|
18
|
-
let removeQuerystringFromKey = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
|
11
|
+
const useKeyForHook = (modelKey, url) => {
|
|
19
12
|
const locale = useLocale();
|
|
20
|
-
|
|
21
|
-
return useMemo(() => createKeyForModularUIStore(modelKey, href, locale), [modelKey, href, locale]);
|
|
13
|
+
return useMemo(() => `${modelKey}(${url.split("?")[0]})(${locale})`, [modelKey, url, locale]);
|
|
22
14
|
};
|
|
23
15
|
|
|
24
16
|
/**
|
|
@@ -31,7 +23,7 @@ export const useModularUI = function (modelKey, url) {
|
|
|
31
23
|
};
|
|
32
24
|
const dispatch = useDispatch();
|
|
33
25
|
const href = useMemo(() => url?.toString() || "", [url]);
|
|
34
|
-
const key = useKeyForHook(modelKey, href
|
|
26
|
+
const key = useKeyForHook(modelKey, href);
|
|
35
27
|
const modelSelector = useMemo(() => state => state.modularui[key], [key]);
|
|
36
28
|
const model = useSelector(modelSelector);
|
|
37
29
|
if (url instanceof Href) {
|
|
@@ -18,26 +18,11 @@ import type { RequestModularUIOptions } from "../utils";
|
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
20
|
*/
|
|
21
|
-
|
|
22
|
-
modelKey: string,
|
|
23
|
-
url: string,
|
|
24
|
-
locale: string,
|
|
25
|
-
): string => {
|
|
26
|
-
return `${modelKey}(${url})(${locale})`;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
*/
|
|
31
|
-
const useKeyForHook = (
|
|
32
|
-
modelKey: string,
|
|
33
|
-
url: string,
|
|
34
|
-
removeQuerystringFromKey: boolean = true,
|
|
35
|
-
): string => {
|
|
21
|
+
const useKeyForHook = (modelKey: string, url: string) => {
|
|
36
22
|
const locale = useLocale();
|
|
37
|
-
const href = removeQuerystringFromKey ? url.split("?")[0] : url;
|
|
38
23
|
return useMemo(
|
|
39
|
-
() =>
|
|
40
|
-
[modelKey,
|
|
24
|
+
() => `${modelKey}(${url.split("?")[0]})(${locale})`,
|
|
25
|
+
[modelKey, url, locale],
|
|
41
26
|
);
|
|
42
27
|
};
|
|
43
28
|
|
|
@@ -54,11 +39,7 @@ export const useModularUI = (
|
|
|
54
39
|
): any => {
|
|
55
40
|
const dispatch = useDispatch();
|
|
56
41
|
const href = useMemo(() => url?.toString() || "", [url]);
|
|
57
|
-
const key = useKeyForHook(
|
|
58
|
-
modelKey,
|
|
59
|
-
href,
|
|
60
|
-
!options.method || options.method === HTTP_METHODS.GET,
|
|
61
|
-
);
|
|
42
|
+
const key = useKeyForHook(modelKey, href);
|
|
62
43
|
|
|
63
44
|
const modelSelector = useMemo(() => (state) => state.modularui[key], [key]);
|
|
64
45
|
const model = useSelector(modelSelector);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useModularUI.js","names":["useEffect","useRef","useMemo","useDispatch","useSelector","useLocation","HTTP_METHODS","loadModularUI","removeModelByKey","useDeepCompareEffect","useLocale","Href","
|
|
1
|
+
{"version":3,"file":"useModularUI.js","names":["useEffect","useRef","useMemo","useDispatch","useSelector","useLocation","HTTP_METHODS","loadModularUI","removeModelByKey","useDeepCompareEffect","useLocale","Href","useKeyForHook","modelKey","url","locale","split","useModularUI","options","arguments","length","undefined","method","GET","removeOnUnmount","dispatch","href","toString","key","modelSelector","state","modularui","model","origin","contextPath","location","redirectLocation","forceLoad","equals","prevOptions","prevHref","prevForceLoad","isOldReload","current","isReload","doForceLoad"],"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,SAASA,SAAS,EAAEC,MAAM,EAAEC,OAAO,QAAQ,OAAO;AAClD,SAASC,WAAW,EAAEC,WAAW,QAAQ,aAAa;AACtD,SAASC,WAAW,QAAQ,cAAc;AAE1C,SAASC,YAAY,QAAQ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QAAQ,CAACjB,gBAAgB,CAACoB,GAAG,CAAC,CAAC;MACjC,CAAC;IACH;EACF,CAAC,EAAE,CAACH,QAAQ,EAAEG,GAAG,EAAEV,OAAO,CAACM,eAAe,CAAC,CAAC;EAE5C,OAAOQ,KAAK;AACd,CAAC","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";
|
|
@@ -55,11 +55,12 @@ export const resetModularUI = () => ({
|
|
|
55
55
|
|
|
56
56
|
/**
|
|
57
57
|
*/
|
|
58
|
-
export const updateStatus = (key, status) => ({
|
|
58
|
+
export const updateStatus = (key, status, requestOptions) => ({
|
|
59
59
|
type: "MODULARUI/STATUS",
|
|
60
60
|
payload: {
|
|
61
61
|
key,
|
|
62
|
-
status
|
|
62
|
+
status,
|
|
63
|
+
requestOptions
|
|
63
64
|
}
|
|
64
65
|
});
|
|
65
66
|
|
|
@@ -132,14 +133,30 @@ export const loadModel = (key, href, options) => ({
|
|
|
132
133
|
|
|
133
134
|
/**
|
|
134
135
|
*/
|
|
135
|
-
export const loadModularUI = (key, href, options)
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
136
|
+
export const loadModularUI = function (key, href, options) {
|
|
137
|
+
let retryCount = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 3;
|
|
138
|
+
let retryDelay = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 200;
|
|
139
|
+
return (dispatch, getState) => {
|
|
140
|
+
const modularuiStore = getState()?.modularui;
|
|
141
|
+
const currentRequest = modularuiStore?.[key];
|
|
142
|
+
const isLoading = currentRequest?.status === MODULARUI_STATUS.LOADING;
|
|
143
|
+
if (isLoading) {
|
|
144
|
+
const isDifferentRequest = currentRequest.requestOptions?.href?.toString() !== href.toString();
|
|
145
|
+
if (isDifferentRequest && retryCount > 0) {
|
|
146
|
+
return new _Promise(resolve => {
|
|
147
|
+
setTimeout(() => {
|
|
148
|
+
resolve(dispatch(loadModularUI(key, href, options, retryCount - 1, retryDelay)));
|
|
149
|
+
}, retryDelay);
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// Same request is already loading — do nothing
|
|
154
|
+
return _Promise.resolve();
|
|
155
|
+
}
|
|
156
|
+
dispatch(startProgress());
|
|
157
|
+
const loadModelPromise = dispatch(loadModel(key, href, options));
|
|
158
|
+
return _Promise.resolve(loadModelPromise).then(() => dispatch(finishProgress())).catch(error => dispatch(handleError(error)));
|
|
159
|
+
};
|
|
143
160
|
};
|
|
144
161
|
|
|
145
162
|
/**
|
|
@@ -81,9 +81,10 @@ export const resetModularUI = (): ResetModularUIAction => ({
|
|
|
81
81
|
export const updateStatus = (
|
|
82
82
|
key: string,
|
|
83
83
|
status: $Keys<typeof MODULARUI_STATUS>,
|
|
84
|
+
requestOptions: any,
|
|
84
85
|
): UpdateStatusAction => ({
|
|
85
86
|
type: "MODULARUI/STATUS",
|
|
86
|
-
payload: { key, status },
|
|
87
|
+
payload: { key, status, requestOptions },
|
|
87
88
|
});
|
|
88
89
|
|
|
89
90
|
/**
|
|
@@ -177,13 +178,31 @@ export const loadModularUI =
|
|
|
177
178
|
key: string,
|
|
178
179
|
href: Href | string,
|
|
179
180
|
options?: RequestModularUIOptions,
|
|
181
|
+
retryCount: number = 3,
|
|
182
|
+
retryDelay: number = 200,
|
|
180
183
|
): ThunkAction =>
|
|
181
184
|
(dispatch: Dispatch, getState) => {
|
|
182
185
|
const modularuiStore = getState()?.modularui;
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
186
|
+
const currentRequest = modularuiStore?.[key];
|
|
187
|
+
|
|
188
|
+
const isLoading = currentRequest?.status === MODULARUI_STATUS.LOADING;
|
|
189
|
+
|
|
190
|
+
if (isLoading) {
|
|
191
|
+
const isDifferentRequest =
|
|
192
|
+
currentRequest.requestOptions?.href?.toString() !== href.toString();
|
|
193
|
+
if (isDifferentRequest && retryCount > 0) {
|
|
194
|
+
return new Promise((resolve) => {
|
|
195
|
+
setTimeout(() => {
|
|
196
|
+
resolve(
|
|
197
|
+
dispatch(
|
|
198
|
+
loadModularUI(key, href, options, retryCount - 1, retryDelay),
|
|
199
|
+
),
|
|
200
|
+
);
|
|
201
|
+
}, retryDelay);
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// Same request is already loading — do nothing
|
|
187
206
|
return Promise.resolve();
|
|
188
207
|
}
|
|
189
208
|
|
|
@@ -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","getRequestLocale","optionLocale","navigator","language","split","loadModel","href","options","origin","contextPath","method","GET","params","data","timeout","headers","events","onProgress","locale","childmodels","targetModel","forceTargetModel","cache","isReload","withCredentials","successAction","errorAction","error","errorResponse","isChangePassword","isResourceNotFoundAfterReload","ERROR","loadModularUI","dispatch","getState","modularuiStore","modularui","LOADING","_Promise","resolve","loadModelPromise","then","catch","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,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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;EACF;AACF,CAAC,CAAC;;AAEF;AACA;AACA,OAAO,MAAMC,aAAa,GACxBA,CACE/C,GAAW,EACXqB,IAAmB,EACnBC,OAAiC,KAEnC,CAAC0B,QAAkB,EAAEC,QAAQ,KAAK;EAChC,MAAMC,cAAc,GAAGD,QAAQ,CAAC,CAAC,EAAEE,SAAS;EAC5C,IACED,cAAc,IACdA,cAAc,CAAClD,GAAG,CAAC,EAAEY,MAAM,KAAKnB,gBAAgB,CAAC2D,OAAO,EACxD;IACA,OAAOC,QAAA,CAAQC,OAAO,CAAC,CAAC;EAC1B;EAEAN,QAAQ,CAACnD,aAAa,CAAC,CAAC,CAAC;EAEzB,MAAM0D,gBAAgB,GAAGP,QAAQ,CAAC5B,SAAS,CAACpB,GAAG,EAAEqB,IAAI,EAAEC,OAAO,CAAC,CAAC;EAEhE,OAAO+B,QAAA,CAAQC,OAAO,CAACC,gBAAgB,CAAC,CACrCC,IAAI,CAAC,MAAMR,QAAQ,CAACpD,cAAc,CAAC,CAAC,CAAC,CAAC,CACtC6D,KAAK,CAAEf,KAAK,IAAKM,QAAQ,CAAClD,WAAW,CAAC4C,KAAK,CAAC,CAAC,CAAC;AACnD,CAAC;;AAEH;AACA;AACA,OAAO,MAAMgB,WAAW,GAAGA,CACzBzD,KAAqB,EACrBqB,OAAiC,KAEjCyB,aAAa,CAAC9C,KAAK,CAACC,UAAU,EAAED,KAAK,CAAC0D,QAAQ,EAAE;EAC9C,GAAGrC,OAAO;EACVgB,QAAQ,EAAE;AACZ,CAAC,CAAC","ignoreList":[]}
|
|
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","requestOptions","loadModelSuccessAction","updateHandler","getRequestLocale","optionLocale","navigator","language","split","loadModel","href","options","origin","contextPath","method","GET","params","data","timeout","headers","events","onProgress","locale","childmodels","targetModel","forceTargetModel","cache","isReload","withCredentials","successAction","errorAction","error","errorResponse","isChangePassword","isResourceNotFoundAfterReload","ERROR","loadModularUI","retryCount","arguments","length","undefined","retryDelay","dispatch","getState","modularuiStore","modularui","currentRequest","isLoading","LOADING","isDifferentRequest","toString","_Promise","resolve","setTimeout","loadModelPromise","then","catch","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,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,MAA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,QAAQ,CACNN,aAAa,CAAChD,GAAG,EAAEsB,IAAI,EAAEC,OAAO,EAAE0B,UAAU,GAAG,CAAC,EAAEI,UAAU,CAC9D,CACF,CAAC;UACH,CAAC,EAAEA,UAAU,CAAC;QAChB,CAAC,CAAC;MACJ;;MAEA;MACA,OAAOU,QAAA,CAAQC,OAAO,CAAC,CAAC;IAC1B;IAEAV,QAAQ,CAACzD,aAAa,CAAC,CAAC,CAAC;IAEzB,MAAMqE,gBAAgB,GAAGZ,QAAQ,CAACjC,SAAS,CAACrB,GAAG,EAAEsB,IAAI,EAAEC,OAAO,CAAC,CAAC;IAEhE,OAAOwC,QAAA,CAAQC,OAAO,CAACE,gBAAgB,CAAC,CACrCC,IAAI,CAAC,MAAMb,QAAQ,CAAC1D,cAAc,CAAC,CAAC,CAAC,CAAC,CACtCwE,KAAK,CAAEzB,KAAK,IAAKW,QAAQ,CAACxD,WAAW,CAAC6C,KAAK,CAAC,CAAC,CAAC;EACnD,CAAC;AAAA;;AAEH;AACA;AACA,OAAO,MAAM0B,WAAW,GAAGA,CACzBpE,KAAqB,EACrBsB,OAAiC,KAEjCyB,aAAa,CAAC/C,KAAK,CAACC,UAAU,EAAED,KAAK,CAACqE,QAAQ,EAAE;EAC9C,GAAG/C,OAAO;EACVgB,QAAQ,EAAE;AACZ,CAAC,CAAC","ignoreList":[]}
|
|
@@ -82,7 +82,7 @@ const handleFetch = (action, locale, dispatch, next) => {
|
|
|
82
82
|
} = action.payload;
|
|
83
83
|
requestOptions.locale = locale;
|
|
84
84
|
const modularuiRequest = createRequest(requestOptions);
|
|
85
|
-
dispatch(updateStatus(key, MODULARUI_STATUS.LOADING));
|
|
85
|
+
dispatch(updateStatus(key, MODULARUI_STATUS.LOADING, requestOptions));
|
|
86
86
|
return modularuiRequest.fetch().then(model => responseHandler(next, dispatch, successAction, model)).catch(error => errorHandler(next, dispatch, errorAction, error));
|
|
87
87
|
};
|
|
88
88
|
|
|
@@ -150,7 +150,7 @@ const handleFetch = (
|
|
|
150
150
|
|
|
151
151
|
const modularuiRequest = createRequest(requestOptions);
|
|
152
152
|
|
|
153
|
-
dispatch(updateStatus(key, MODULARUI_STATUS.LOADING));
|
|
153
|
+
dispatch(updateStatus(key, MODULARUI_STATUS.LOADING, requestOptions));
|
|
154
154
|
|
|
155
155
|
return modularuiRequest
|
|
156
156
|
.fetch()
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ModularUIMiddleware.js","names":["ModularUIRequest","HTTP_METHODS","MODULARUI_STATUS","startProgress","finishProgress","handleError","updateStatus","createRequest","modularui","request","href","method","GET","params","data","locale","childmodels","isReload","cache","headers","events","onProgress","origin","contextPath","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 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,OAAOA,gBAAgB,MAAM,kCAAkC;AAC/D,SAASC,YAAY,EAAEC,gBAAgB,QAAQ,2BAA2B;AAE1E,SAASC,aAAa,EAAEC,cAAc,QAAQ,8BAA8B;AAC5E,SAASC,WAAW,QAAQ,kBAAkB;AAE9C,SAASC,YAAY,QAAQ,oBAAoB;AAyCjD;AACA;AACA;AACA,MAAMC,aAAa,GAAIC,SAAyB,IAAuB;EACrE,MAAMC,OAAO,GAAG,IAAIT,gBAAgB,CAACQ,SAAS,CAACE,IAAI,EAAE;IACnDC,MAAM,EAAEH,SAAS,CAACG,MAAM,IAAIV,YAAY,CAACW,GAAG;IAC5CC,MAAM,EAAEL,SAAS,CAACK,MAAM,IAAI,EAAE;IAC9BC,IAAI,EAAEN,SAAS,CAACM,IAAI,IAAI,CAAC,CAAC;IAC1BC,MAAM,EAAEP,SAAS,CAACO,MAAM;IACxBC,WAAW,EAAER,SAAS,CAACQ,WAAW,IAAI,IAAI;IAC1CC,QAAQ,EAAET,SAAS,CAACS,QAAQ;IAC5BC,KAAK,EAAEV,SAAS,CAACU,KAAK;IACtBC,OAAO,EAAEX,SAAS,CAACW,OAAO;IAC1BC,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ACxB,cAAc,CAAC,CAAC,CAAC;EAE1B,IAAImC,WAAW,EAAE;IACf,MAAME,WAAW,GAAGF,WAAW,CAACC,GAAG,CAAC;IAEpC,IAAIC,WAAW,YAAAT,QAAmB,EAAE;MAClCS,WAAW,CAACR,IAAI,CAAEC,MAAM,IAAKN,QAAQ,CAACM,MAAM,CAAC,CAAC;IAChD,CAAC,MAAM;MACLN,QAAQ,CAACa,WAAW,CAAC;IACvB;EACF;EAEA,OAAOd,IAAI,CAACtB,WAAW,CAACmC,GAAG,CAAC,CAAC;AAC/B,CAAC;;AAED;AACA;AACA,MAAME,WAAW,GAAGA,CAClBC,MAAuB,EACvB5B,MAAc,EACda,QAAkB,EAClBD,IAAc,KACX;EACHC,QAAQ,CAACzB,aAAa,CAAC,CAAC,CAAC;EAEzB,MAAM;IAAEyC,GAAG;IAAEf,aAAa;IAAEU,WAAW;IAAE,GAAGM;EAAe,CAAC,GAAGF,MAAM,CAACG,OAAO;EAC7ED,cAAc,CAAC9B,MAAM,GAAGA,MAAM;EAE9B,MAAMgC,gBAAgB,GAAGxC,aAAa,CAACsC,cAAc,CAAC;EAEtDjB,QAAQ,CAACtB,YAAY,CAACsC,GAAG,EAAE1C,gBAAgB,CAAC8C,OAAO,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"ModularUIMiddleware.js","names":["ModularUIRequest","HTTP_METHODS","MODULARUI_STATUS","startProgress","finishProgress","handleError","updateStatus","createRequest","modularui","request","href","method","GET","params","data","locale","childmodels","isReload","cache","headers","events","onProgress","origin","contextPath","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 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,OAAOA,gBAAgB,MAAM,kCAAkC;AAC/D,SAASC,YAAY,EAAEC,gBAAgB,QAAQ,2BAA2B;AAE1E,SAASC,aAAa,EAAEC,cAAc,QAAQ,8BAA8B;AAC5E,SAASC,WAAW,QAAQ,kBAAkB;AAE9C,SAASC,Y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AAC;EAEtDjB,QAAQ,CAACtB,YAAY,CAACsC,GAAG,EAAE1C,gBAAgB,CAAC8C,OAAO,EAAEH,cAAc,CAAC,CAAC;EAErE,OAAOE,gBAAgB,CACpBE,KAAK,CAAC,CAAC,CACPhB,IAAI,CAAEH,KAAK,IAAKJ,eAAe,CAACC,IAAI,EAAEC,QAAQ,EAAEC,aAAa,EAAEC,KAAK,CAAC,CAAC,CACtEK,KAAK,CAAEC,KAAK,IAAKE,YAAY,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,CAACvC,MAAM,EAC1BoC,GAAG,CAACvB,QAAQ,EACZD,IACF,CAAC;EACH;EAEA,OAAOA,IAAI,CAACgB,MAAM,CAAC;AACrB,CAAC","ignoreList":[]}
|
|
@@ -8,7 +8,8 @@ import { ApplicationModel } from "../../models";
|
|
|
8
8
|
const updateStatus = (state, _ref) => {
|
|
9
9
|
let {
|
|
10
10
|
key,
|
|
11
|
-
status
|
|
11
|
+
status,
|
|
12
|
+
requestOptions
|
|
12
13
|
} = _ref;
|
|
13
14
|
// model should always be available when status is not loading
|
|
14
15
|
if (status !== MODULARUI_STATUS.LOADING && !state[key]) {
|
|
@@ -19,7 +20,8 @@ const updateStatus = (state, _ref) => {
|
|
|
19
20
|
[key]: {
|
|
20
21
|
...state[key],
|
|
21
22
|
status,
|
|
22
|
-
lastModification: Date.now()
|
|
23
|
+
lastModification: Date.now(),
|
|
24
|
+
requestOptions: requestOptions || state[key]?.requestOptions
|
|
23
25
|
}
|
|
24
26
|
};
|
|
25
27
|
};
|
|
@@ -11,7 +11,15 @@ import type { ModularUIModel } from "../../models";
|
|
|
11
11
|
*/
|
|
12
12
|
const updateStatus = (
|
|
13
13
|
state: ModularUIState,
|
|
14
|
-
{
|
|
14
|
+
{
|
|
15
|
+
key,
|
|
16
|
+
status,
|
|
17
|
+
requestOptions,
|
|
18
|
+
}: {
|
|
19
|
+
key: string,
|
|
20
|
+
status: $Keys<typeof MODULARUI_STATUS>,
|
|
21
|
+
requestOptions: any,
|
|
22
|
+
},
|
|
15
23
|
) => {
|
|
16
24
|
// model should always be available when status is not loading
|
|
17
25
|
if (status !== MODULARUI_STATUS.LOADING && !state[key]) {
|
|
@@ -24,6 +32,7 @@ const updateStatus = (
|
|
|
24
32
|
...state[key],
|
|
25
33
|
status,
|
|
26
34
|
lastModification: Date.now(),
|
|
35
|
+
requestOptions: requestOptions || state[key]?.requestOptions,
|
|
27
36
|
},
|
|
28
37
|
};
|
|
29
38
|
};
|