@beinformed/ui 1.54.2 → 1.54.3
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 +8 -0
- package/esm/redux/_modularui/ModularUIConnector.js +8 -3
- package/esm/redux/_modularui/ModularUIConnector.js.map +1 -1
- package/lib/redux/_modularui/ModularUIConnector.js +8 -3
- package/lib/redux/_modularui/ModularUIConnector.js.flow +10 -3
- package/lib/redux/_modularui/ModularUIConnector.js.map +1 -1
- package/package.json +1 -1
- package/src/redux/_modularui/ModularUIConnector.js +10 -3
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,14 @@
|
|
|
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.54.3](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/compare/v1.54.2...v1.54.3) (2024-09-18)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* **layouthint-config:** merge duplicate hint entries ([6dfefa3](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/commit/6dfefa36c7c00c4d7f139eff313c3a4c24853968))
|
|
11
|
+
* **modularui-connector:** make it possible to set removeOnUnmount with a property ([959ce04](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/commit/959ce0447fce2d725c7bd8316a2c1cc4477cc1d1))
|
|
12
|
+
|
|
5
13
|
## [1.54.2](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/compare/v1.54.1...v1.54.2) (2024-09-17)
|
|
6
14
|
|
|
7
15
|
|
|
@@ -41,6 +41,8 @@ const modularUIConnector = function (name, resource) {
|
|
|
41
41
|
} = options;
|
|
42
42
|
return Component => {
|
|
43
43
|
const WrappedComponent = props => {
|
|
44
|
+
// explicit property for removeOnMount overwrite the setting
|
|
45
|
+
const finalRemoveOnUnmount = props.removeOnUnmount === true ? true : removeOnUnmount;
|
|
44
46
|
const dispatch = useDispatch();
|
|
45
47
|
const location = useLocation();
|
|
46
48
|
const url = useUrl(resource, {
|
|
@@ -50,7 +52,10 @@ const modularUIConnector = function (name, resource) {
|
|
|
50
52
|
const displayName = getDisplayName(Component, name, props.contextId);
|
|
51
53
|
|
|
52
54
|
// Load the model through the useModUI hook
|
|
53
|
-
const modelEntry = useModularUI(displayName, url,
|
|
55
|
+
const modelEntry = useModularUI(displayName, url, {
|
|
56
|
+
...otherOptions,
|
|
57
|
+
removeOnUnmount: finalRemoveOnUnmount
|
|
58
|
+
});
|
|
54
59
|
const modelKey = modelEntry?.model?.connectKey;
|
|
55
60
|
|
|
56
61
|
// handle manual reload of model
|
|
@@ -79,11 +84,11 @@ const modularUIConnector = function (name, resource) {
|
|
|
79
84
|
// Remove model when hoc unloads
|
|
80
85
|
useEffect(() => {
|
|
81
86
|
return () => {
|
|
82
|
-
if (
|
|
87
|
+
if (finalRemoveOnUnmount) {
|
|
83
88
|
dispatch(removeModelByKey(modelKey));
|
|
84
89
|
}
|
|
85
90
|
};
|
|
86
|
-
}, [dispatch, modelKey]);
|
|
91
|
+
}, [dispatch, modelKey, finalRemoveOnUnmount]);
|
|
87
92
|
|
|
88
93
|
// Create new properties object to inject modularui properties to own props
|
|
89
94
|
const locale = useLocale();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ModularUIConnector.js","names":["useEffect","useDispatch","useLocation","loadModularUI","reloadModel","removeModelByKey","Href","getDisplayName","useUrl","useReload","useModularUI","useLocale","FormModel","jsx","_jsx","patchUpdateModelOption","oldOptions","updateModel","updateHandler","newModel","clonedModel","clone","update","modularUIConnector","name","resource","options","arguments","length","undefined","propName","removeOnUnmount","otherOptions","Component","WrappedComponent","props","dispatch","location","url","displayName","contextId","modelEntry","modelKey","model","connectKey","handleManualReload","reloadOptions","handleFetch","href","fetchOptions","reload","state","doReload","isReload","locale","newProps","status","lastModification","hasModel","Boolean","fetchModularUI"],"sources":["../../../src/redux/_modularui/ModularUIConnector.js"],"sourcesContent":["// @flow\nimport { useEffect } from \"react\";\nimport { useDispatch } from \"react-redux\";\nimport { useLocation } from \"react-router\";\n\nimport {\n loadModularUI,\n reloadModel,\n removeModelByKey,\n} from \"./ModularUIActions\";\n\nimport Href from \"../../models/href/Href\";\nimport { getDisplayName } from \"../../react/utils\";\n\nimport { useUrl, useReload } from \"./ModularUIUtils\";\nimport { useModularUI } from \"../../hooks/useModularUI\";\nimport { useLocale } from \"../../hooks/useI18n\";\n\nimport type { ComponentType, Node } from \"react\";\nimport type { Location } from \"react-router\";\nimport type { ModularUIModel } from \"../../models/types\";\nimport type { ModularUIOptions } from \"./types\";\nimport FormModel from \"../../models/form/FormModel\";\n\nexport type InjectedProps = {\n +modelKey: string,\n +location: Location,\n +status: string | null,\n +lastModification: number | null,\n +hasModel: boolean,\n +locale: string,\n +fetchModularUI: (href: string | Href, fetchOptions: Object) => void,\n +reloadModel: (model: ModularUIModel, options: Object) => void,\n +data?: ?ModularUIModel,\n};\n\nconst patchUpdateModelOption = (oldOptions: Object) => {\n if (\n \"updateModel\" in oldOptions &&\n oldOptions.updateModel instanceof FormModel\n ) {\n return {\n ...oldOptions,\n updateHandler: (newModel: ModularUIModel): ModularUIModel => {\n if (newModel instanceof FormModel) {\n // $FLowFixMe\n const clonedModel: FormModel = oldOptions.updateModel.clone();\n clonedModel.update(newModel);\n return clonedModel;\n }\n return newModel;\n },\n };\n }\n\n return oldOptions;\n};\n\n/**\n */\nconst modularUIConnector = (\n name: string,\n resource: string | Function,\n options: ModularUIOptions = { propName: \"data\", removeOnUnmount: false },\n): ((Component: ComponentType<any>) => (props: any) => Node) => {\n const {\n propName = \"data\",\n removeOnUnmount = false,\n ...otherOptions\n } = options;\n\n return (Component: ComponentType<any>) => {\n const WrappedComponent = (props: any) => {\n const dispatch = useDispatch();\n const location = useLocation();\n\n const url = useUrl(resource, { location, ...props });\n const displayName = getDisplayName(Component, name, props.contextId);\n\n // Load the model through the useModUI hook\n const modelEntry = useModularUI(displayName, url, otherOptions);\n const modelKey = modelEntry?.model?.connectKey;\n\n // handle manual reload of model\n const handleManualReload = (\n model: ModularUIModel,\n reloadOptions?: Object,\n ) => {\n dispatch(reloadModel(model, reloadOptions));\n };\n\n // Provide connected models with a fetchModularUI method to be able\n // to run the loadModularUI action from a handler / callback in the component\n const handleFetch = (href: string | Href, fetchOptions: Object) => {\n dispatch(\n loadModularUI(modelKey, href, patchUpdateModelOption(fetchOptions)),\n );\n };\n\n // Check if current model needs a reload\n const reload = location?.state?.reload ?? 0;\n const doReload = useReload(modelEntry, reload);\n useEffect(() => {\n if (doReload) {\n dispatch(\n loadModularUI(modelKey, url, {\n ...patchUpdateModelOption(otherOptions),\n isReload: true,\n }),\n );\n }\n }, [dispatch, doReload, url, modelKey]);\n\n // Remove model when hoc unloads\n useEffect(() => {\n return () => {\n if (
|
|
1
|
+
{"version":3,"file":"ModularUIConnector.js","names":["useEffect","useDispatch","useLocation","loadModularUI","reloadModel","removeModelByKey","Href","getDisplayName","useUrl","useReload","useModularUI","useLocale","FormModel","jsx","_jsx","patchUpdateModelOption","oldOptions","updateModel","updateHandler","newModel","clonedModel","clone","update","modularUIConnector","name","resource","options","arguments","length","undefined","propName","removeOnUnmount","otherOptions","Component","WrappedComponent","props","finalRemoveOnUnmount","dispatch","location","url","displayName","contextId","modelEntry","modelKey","model","connectKey","handleManualReload","reloadOptions","handleFetch","href","fetchOptions","reload","state","doReload","isReload","locale","newProps","status","lastModification","hasModel","Boolean","fetchModularUI"],"sources":["../../../src/redux/_modularui/ModularUIConnector.js"],"sourcesContent":["// @flow\nimport { useEffect } from \"react\";\nimport { useDispatch } from \"react-redux\";\nimport { useLocation } from \"react-router\";\n\nimport {\n loadModularUI,\n reloadModel,\n removeModelByKey,\n} from \"./ModularUIActions\";\n\nimport Href from \"../../models/href/Href\";\nimport { getDisplayName } from \"../../react/utils\";\n\nimport { useUrl, useReload } from \"./ModularUIUtils\";\nimport { useModularUI } from \"../../hooks/useModularUI\";\nimport { useLocale } from \"../../hooks/useI18n\";\n\nimport type { ComponentType, Node } from \"react\";\nimport type { Location } from \"react-router\";\nimport type { ModularUIModel } from \"../../models/types\";\nimport type { ModularUIOptions } from \"./types\";\nimport FormModel from \"../../models/form/FormModel\";\n\nexport type InjectedProps = {\n +modelKey: string,\n +location: Location,\n +status: string | null,\n +lastModification: number | null,\n +hasModel: boolean,\n +locale: string,\n +fetchModularUI: (href: string | Href, fetchOptions: Object) => void,\n +reloadModel: (model: ModularUIModel, options: Object) => void,\n +data?: ?ModularUIModel,\n};\n\nconst patchUpdateModelOption = (oldOptions: Object) => {\n if (\n \"updateModel\" in oldOptions &&\n oldOptions.updateModel instanceof FormModel\n ) {\n return {\n ...oldOptions,\n updateHandler: (newModel: ModularUIModel): ModularUIModel => {\n if (newModel instanceof FormModel) {\n // $FLowFixMe\n const clonedModel: FormModel = oldOptions.updateModel.clone();\n clonedModel.update(newModel);\n return clonedModel;\n }\n return newModel;\n },\n };\n }\n\n return oldOptions;\n};\n\n/**\n */\nconst modularUIConnector = (\n name: string,\n resource: string | Function,\n options: ModularUIOptions = { propName: \"data\", removeOnUnmount: false },\n): ((Component: ComponentType<any>) => (props: any) => Node) => {\n const {\n propName = \"data\",\n removeOnUnmount = false,\n ...otherOptions\n } = options;\n\n return (Component: ComponentType<any>) => {\n const WrappedComponent = (props: any) => {\n // explicit property for removeOnMount overwrite the setting\n const finalRemoveOnUnmount =\n props.removeOnUnmount === true ? true : removeOnUnmount;\n\n const dispatch = useDispatch();\n const location = useLocation();\n\n const url = useUrl(resource, { location, ...props });\n const displayName = getDisplayName(Component, name, props.contextId);\n\n // Load the model through the useModUI hook\n const modelEntry = useModularUI(displayName, url, {\n ...otherOptions,\n removeOnUnmount: finalRemoveOnUnmount,\n });\n const modelKey = modelEntry?.model?.connectKey;\n\n // handle manual reload of model\n const handleManualReload = (\n model: ModularUIModel,\n reloadOptions?: Object,\n ) => {\n dispatch(reloadModel(model, reloadOptions));\n };\n\n // Provide connected models with a fetchModularUI method to be able\n // to run the loadModularUI action from a handler / callback in the component\n const handleFetch = (href: string | Href, fetchOptions: Object) => {\n dispatch(\n loadModularUI(modelKey, href, patchUpdateModelOption(fetchOptions)),\n );\n };\n\n // Check if current model needs a reload\n const reload = location?.state?.reload ?? 0;\n const doReload = useReload(modelEntry, reload);\n useEffect(() => {\n if (doReload) {\n dispatch(\n loadModularUI(modelKey, url, {\n ...patchUpdateModelOption(otherOptions),\n isReload: true,\n }),\n );\n }\n }, [dispatch, doReload, url, modelKey]);\n\n // Remove model when hoc unloads\n useEffect(() => {\n return () => {\n if (finalRemoveOnUnmount) {\n dispatch(removeModelByKey(modelKey));\n }\n };\n }, [dispatch, modelKey, finalRemoveOnUnmount]);\n\n // Create new properties object to inject modularui properties to own props\n const locale = useLocale();\n const newProps: InjectedProps = {\n modelKey,\n [propName]: modelEntry ? modelEntry.model : null,\n location,\n status: modelEntry ? modelEntry.status : null,\n lastModification: modelEntry ? modelEntry.lastModification : null,\n hasModel: Boolean(modelEntry),\n locale,\n fetchModularUI: handleFetch,\n reloadModel: handleManualReload,\n };\n\n return <Component {...props} {...newProps} />;\n };\n\n WrappedComponent.displayName = `BI.modularui(${getDisplayName(\n WrappedComponent,\n name,\n )}`;\n\n return WrappedComponent;\n };\n};\n\nexport default modularUIConnector;\n"],"mappings":"AACA,SAASA,SAAS,QAAQ,OAAO;AACjC,SAASC,WAAW,QAAQ,aAAa;AACzC,SAASC,WAAW,QAAQ,cAAc;AAE1C,SACEC,aAAa,EACbC,WAAW,EACXC,gBAAgB,QACX,oBAAoB;AAE3B,OAAOC,IAAI,MAAM,wBAAwB;AACzC,SAASC,cAAc,QAAQ,mBAAmB;AAElD,SAASC,MAAM,EAAEC,SAAS,QAAQ,kBAAkB;AACpD,SAASC,YAAY,QAAQ,0BAA0B;AACvD,SAASC,SAAS,QAAQ,qBAAqB;AAM/C,OAAOC,SAAS,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A,MAAMmB,MAAM,GAAG5C,SAAS,CAAC,CAAC;MAC1B,MAAM6C,QAAuB,GAAG;QAC9Bb,QAAQ;QACR,CAACb,QAAQ,GAAGY,UAAU,GAAGA,UAAU,CAACE,KAAK,GAAG,IAAI;QAChDN,QAAQ;QACRmB,MAAM,EAAEf,UAAU,GAAGA,UAAU,CAACe,MAAM,GAAG,IAAI;QAC7CC,gBAAgB,EAAEhB,UAAU,GAAGA,UAAU,CAACgB,gBAAgB,GAAG,IAAI;QACjEC,QAAQ,EAAEC,OAAO,CAAClB,UAAU,CAAC;QAC7Ba,MAAM;QACNM,cAAc,EAAEb,WAAW;QAC3B5C,WAAW,EAAE0C;MACf,CAAC;MAED,oBAAOhC,IAAA,CAACmB,SAAS;QAAA,GAAKE,KAAK;QAAA,GAAMqB;MAAQ,CAAG,CAAC;IAC/C,CAAC;IAEDtB,gBAAgB,CAACM,WAAW,GAAG,gBAAgBjC,cAAc,CAC3D2B,gBAAgB,EAChBV,IACF,CAAC,EAAE;IAEH,OAAOU,gBAAgB;EACzB,CAAC;AACH,CAAC;AAED,eAAeX,kBAAkB","ignoreList":[]}
|
|
@@ -48,6 +48,8 @@ const modularUIConnector = function (name, resource) {
|
|
|
48
48
|
} = options;
|
|
49
49
|
return Component => {
|
|
50
50
|
const WrappedComponent = props => {
|
|
51
|
+
// explicit property for removeOnMount overwrite the setting
|
|
52
|
+
const finalRemoveOnUnmount = props.removeOnUnmount === true ? true : removeOnUnmount;
|
|
51
53
|
const dispatch = (0, _reactRedux.useDispatch)();
|
|
52
54
|
const location = (0, _reactRouter.useLocation)();
|
|
53
55
|
const url = (0, _ModularUIUtils.useUrl)(resource, {
|
|
@@ -57,7 +59,10 @@ const modularUIConnector = function (name, resource) {
|
|
|
57
59
|
const displayName = (0, _utils.getDisplayName)(Component, name, props.contextId);
|
|
58
60
|
|
|
59
61
|
// Load the model through the useModUI hook
|
|
60
|
-
const modelEntry = (0, _useModularUI.useModularUI)(displayName, url,
|
|
62
|
+
const modelEntry = (0, _useModularUI.useModularUI)(displayName, url, {
|
|
63
|
+
...otherOptions,
|
|
64
|
+
removeOnUnmount: finalRemoveOnUnmount
|
|
65
|
+
});
|
|
61
66
|
const modelKey = modelEntry?.model?.connectKey;
|
|
62
67
|
|
|
63
68
|
// handle manual reload of model
|
|
@@ -86,11 +91,11 @@ const modularUIConnector = function (name, resource) {
|
|
|
86
91
|
// Remove model when hoc unloads
|
|
87
92
|
(0, _react.useEffect)(() => {
|
|
88
93
|
return () => {
|
|
89
|
-
if (
|
|
94
|
+
if (finalRemoveOnUnmount) {
|
|
90
95
|
dispatch((0, _ModularUIActions.removeModelByKey)(modelKey));
|
|
91
96
|
}
|
|
92
97
|
};
|
|
93
|
-
}, [dispatch, modelKey]);
|
|
98
|
+
}, [dispatch, modelKey, finalRemoveOnUnmount]);
|
|
94
99
|
|
|
95
100
|
// Create new properties object to inject modularui properties to own props
|
|
96
101
|
const locale = (0, _useI18n.useLocale)();
|
|
@@ -71,6 +71,10 @@ const modularUIConnector = (
|
|
|
71
71
|
|
|
72
72
|
return (Component: ComponentType<any>) => {
|
|
73
73
|
const WrappedComponent = (props: any) => {
|
|
74
|
+
// explicit property for removeOnMount overwrite the setting
|
|
75
|
+
const finalRemoveOnUnmount =
|
|
76
|
+
props.removeOnUnmount === true ? true : removeOnUnmount;
|
|
77
|
+
|
|
74
78
|
const dispatch = useDispatch();
|
|
75
79
|
const location = useLocation();
|
|
76
80
|
|
|
@@ -78,7 +82,10 @@ const modularUIConnector = (
|
|
|
78
82
|
const displayName = getDisplayName(Component, name, props.contextId);
|
|
79
83
|
|
|
80
84
|
// Load the model through the useModUI hook
|
|
81
|
-
const modelEntry = useModularUI(displayName, url,
|
|
85
|
+
const modelEntry = useModularUI(displayName, url, {
|
|
86
|
+
...otherOptions,
|
|
87
|
+
removeOnUnmount: finalRemoveOnUnmount,
|
|
88
|
+
});
|
|
82
89
|
const modelKey = modelEntry?.model?.connectKey;
|
|
83
90
|
|
|
84
91
|
// handle manual reload of model
|
|
@@ -114,11 +121,11 @@ const modularUIConnector = (
|
|
|
114
121
|
// Remove model when hoc unloads
|
|
115
122
|
useEffect(() => {
|
|
116
123
|
return () => {
|
|
117
|
-
if (
|
|
124
|
+
if (finalRemoveOnUnmount) {
|
|
118
125
|
dispatch(removeModelByKey(modelKey));
|
|
119
126
|
}
|
|
120
127
|
};
|
|
121
|
-
}, [dispatch, modelKey]);
|
|
128
|
+
}, [dispatch, modelKey, finalRemoveOnUnmount]);
|
|
122
129
|
|
|
123
130
|
// Create new properties object to inject modularui properties to own props
|
|
124
131
|
const locale = useLocale();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ModularUIConnector.js","names":["_react","require","_reactRedux","_reactRouter","_ModularUIActions","_Href","_interopRequireDefault","_utils","_ModularUIUtils","_useModularUI","_useI18n","_FormModel","_jsxRuntime","patchUpdateModelOption","oldOptions","updateModel","FormModel","updateHandler","newModel","clonedModel","clone","update","modularUIConnector","name","resource","options","arguments","length","undefined","propName","removeOnUnmount","otherOptions","Component","WrappedComponent","props","dispatch","useDispatch","location","useLocation","url","useUrl","displayName","getDisplayName","contextId","modelEntry","useModularUI","modelKey","model","connectKey","handleManualReload","reloadOptions","reloadModel","handleFetch","href","fetchOptions","loadModularUI","reload","state","doReload","useReload","useEffect","isReload","removeModelByKey","locale","useLocale","newProps","status","lastModification","hasModel","Boolean","fetchModularUI","jsx","_default","exports","default"],"sources":["../../../src/redux/_modularui/ModularUIConnector.js"],"sourcesContent":["// @flow\nimport { useEffect } from \"react\";\nimport { useDispatch } from \"react-redux\";\nimport { useLocation } from \"react-router\";\n\nimport {\n loadModularUI,\n reloadModel,\n removeModelByKey,\n} from \"./ModularUIActions\";\n\nimport Href from \"../../models/href/Href\";\nimport { getDisplayName } from \"../../react/utils\";\n\nimport { useUrl, useReload } from \"./ModularUIUtils\";\nimport { useModularUI } from \"../../hooks/useModularUI\";\nimport { useLocale } from \"../../hooks/useI18n\";\n\nimport type { ComponentType, Node } from \"react\";\nimport type { Location } from \"react-router\";\nimport type { ModularUIModel } from \"../../models/types\";\nimport type { ModularUIOptions } from \"./types\";\nimport FormModel from \"../../models/form/FormModel\";\n\nexport type InjectedProps = {\n +modelKey: string,\n +location: Location,\n +status: string | null,\n +lastModification: number | null,\n +hasModel: boolean,\n +locale: string,\n +fetchModularUI: (href: string | Href, fetchOptions: Object) => void,\n +reloadModel: (model: ModularUIModel, options: Object) => void,\n +data?: ?ModularUIModel,\n};\n\nconst patchUpdateModelOption = (oldOptions: Object) => {\n if (\n \"updateModel\" in oldOptions &&\n oldOptions.updateModel instanceof FormModel\n ) {\n return {\n ...oldOptions,\n updateHandler: (newModel: ModularUIModel): ModularUIModel => {\n if (newModel instanceof FormModel) {\n // $FLowFixMe\n const clonedModel: FormModel = oldOptions.updateModel.clone();\n clonedModel.update(newModel);\n return clonedModel;\n }\n return newModel;\n },\n };\n }\n\n return oldOptions;\n};\n\n/**\n */\nconst modularUIConnector = (\n name: string,\n resource: string | Function,\n options: ModularUIOptions = { propName: \"data\", removeOnUnmount: false },\n): ((Component: ComponentType<any>) => (props: any) => Node) => {\n const {\n propName = \"data\",\n removeOnUnmount = false,\n ...otherOptions\n } = options;\n\n return (Component: ComponentType<any>) => {\n const WrappedComponent = (props: any) => {\n const dispatch = useDispatch();\n const location = useLocation();\n\n const url = useUrl(resource, { location, ...props });\n const displayName = getDisplayName(Component, name, props.contextId);\n\n // Load the model through the useModUI hook\n const modelEntry = useModularUI(displayName, url, otherOptions);\n const modelKey = modelEntry?.model?.connectKey;\n\n // handle manual reload of model\n const handleManualReload = (\n model: ModularUIModel,\n reloadOptions?: Object,\n ) => {\n dispatch(reloadModel(model, reloadOptions));\n };\n\n // Provide connected models with a fetchModularUI method to be able\n // to run the loadModularUI action from a handler / callback in the component\n const handleFetch = (href: string | Href, fetchOptions: Object) => {\n dispatch(\n loadModularUI(modelKey, href, patchUpdateModelOption(fetchOptions)),\n );\n };\n\n // Check if current model needs a reload\n const reload = location?.state?.reload ?? 0;\n const doReload = useReload(modelEntry, reload);\n useEffect(() => {\n if (doReload) {\n dispatch(\n loadModularUI(modelKey, url, {\n ...patchUpdateModelOption(otherOptions),\n isReload: true,\n }),\n );\n }\n }, [dispatch, doReload, url, modelKey]);\n\n // Remove model when hoc unloads\n useEffect(() => {\n return () => {\n if (
|
|
1
|
+
{"version":3,"file":"ModularUIConnector.js","names":["_react","require","_reactRedux","_reactRouter","_ModularUIActions","_Href","_interopRequireDefault","_utils","_ModularUIUtils","_useModularUI","_useI18n","_FormModel","_jsxRuntime","patchUpdateModelOption","oldOptions","updateModel","FormModel","updateHandler","newModel","clonedModel","clone","update","modularUIConnector","name","resource","options","arguments","length","undefined","propName","removeOnUnmount","otherOptions","Component","WrappedComponent","props","finalRemoveOnUnmount","dispatch","useDispatch","location","useLocation","url","useUrl","displayName","getDisplayName","contextId","modelEntry","useModularUI","modelKey","model","connectKey","handleManualReload","reloadOptions","reloadModel","handleFetch","href","fetchOptions","loadModularUI","reload","state","doReload","useReload","useEffect","isReload","removeModelByKey","locale","useLocale","newProps","status","lastModification","hasModel","Boolean","fetchModularUI","jsx","_default","exports","default"],"sources":["../../../src/redux/_modularui/ModularUIConnector.js"],"sourcesContent":["// @flow\nimport { useEffect } from \"react\";\nimport { useDispatch } from \"react-redux\";\nimport { useLocation } from \"react-router\";\n\nimport {\n loadModularUI,\n reloadModel,\n removeModelByKey,\n} from \"./ModularUIActions\";\n\nimport Href from \"../../models/href/Href\";\nimport { getDisplayName } from \"../../react/utils\";\n\nimport { useUrl, useReload } from \"./ModularUIUtils\";\nimport { useModularUI } from \"../../hooks/useModularUI\";\nimport { useLocale } from \"../../hooks/useI18n\";\n\nimport type { ComponentType, Node } from \"react\";\nimport type { Location } from \"react-router\";\nimport type { ModularUIModel } from \"../../models/types\";\nimport type { ModularUIOptions } from \"./types\";\nimport FormModel from \"../../models/form/FormModel\";\n\nexport type InjectedProps = {\n +modelKey: string,\n +location: Location,\n +status: string | null,\n +lastModification: number | null,\n +hasModel: boolean,\n +locale: string,\n +fetchModularUI: (href: string | Href, fetchOptions: Object) => void,\n +reloadModel: (model: ModularUIModel, options: Object) => void,\n +data?: ?ModularUIModel,\n};\n\nconst patchUpdateModelOption = (oldOptions: Object) => {\n if (\n \"updateModel\" in oldOptions &&\n oldOptions.updateModel instanceof FormModel\n ) {\n return {\n ...oldOptions,\n updateHandler: (newModel: ModularUIModel): ModularUIModel => {\n if (newModel instanceof FormModel) {\n // $FLowFixMe\n const clonedModel: FormModel = oldOptions.updateModel.clone();\n clonedModel.update(newModel);\n return clonedModel;\n }\n return newModel;\n },\n };\n }\n\n return oldOptions;\n};\n\n/**\n */\nconst modularUIConnector = (\n name: string,\n resource: string | Function,\n options: ModularUIOptions = { propName: \"data\", removeOnUnmount: false },\n): ((Component: ComponentType<any>) => (props: any) => Node) => {\n const {\n propName = \"data\",\n removeOnUnmount = false,\n ...otherOptions\n } = options;\n\n return (Component: ComponentType<any>) => {\n const WrappedComponent = (props: any) => {\n // explicit property for removeOnMount overwrite the setting\n const finalRemoveOnUnmount =\n props.removeOnUnmount === true ? true : removeOnUnmount;\n\n const dispatch = useDispatch();\n const location = useLocation();\n\n const url = useUrl(resource, { location, ...props });\n const displayName = getDisplayName(Component, name, props.contextId);\n\n // Load the model through the useModUI hook\n const modelEntry = useModularUI(displayName, url, {\n ...otherOptions,\n removeOnUnmount: finalRemoveOnUnmount,\n });\n const modelKey = modelEntry?.model?.connectKey;\n\n // handle manual reload of model\n const handleManualReload = (\n model: ModularUIModel,\n reloadOptions?: Object,\n ) => {\n dispatch(reloadModel(model, reloadOptions));\n };\n\n // Provide connected models with a fetchModularUI method to be able\n // to run the loadModularUI action from a handler / callback in the component\n const handleFetch = (href: string | Href, fetchOptions: Object) => {\n dispatch(\n loadModularUI(modelKey, href, patchUpdateModelOption(fetchOptions)),\n );\n };\n\n // Check if current model needs a reload\n const reload = location?.state?.reload ?? 0;\n const doReload = useReload(modelEntry, reload);\n useEffect(() => {\n if (doReload) {\n dispatch(\n loadModularUI(modelKey, url, {\n ...patchUpdateModelOption(otherOptions),\n isReload: true,\n }),\n );\n }\n }, [dispatch, doReload, url, modelKey]);\n\n // Remove model when hoc unloads\n useEffect(() => {\n return () => {\n if (finalRemoveOnUnmount) {\n dispatch(removeModelByKey(modelKey));\n }\n };\n }, [dispatch, modelKey, finalRemoveOnUnmount]);\n\n // Create new properties object to inject modularui properties to own props\n const locale = useLocale();\n const newProps: InjectedProps = {\n modelKey,\n [propName]: modelEntry ? modelEntry.model : null,\n location,\n status: modelEntry ? modelEntry.status : null,\n lastModification: modelEntry ? modelEntry.lastModification : null,\n hasModel: Boolean(modelEntry),\n locale,\n fetchModularUI: handleFetch,\n reloadModel: handleManualReload,\n };\n\n return <Component {...props} {...newProps} />;\n };\n\n WrappedComponent.displayName = `BI.modularui(${getDisplayName(\n WrappedComponent,\n name,\n )}`;\n\n return WrappedComponent;\n };\n};\n\nexport default modularUIConnector;\n"],"mappings":";;;;;;;AACA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AACA,IAAAE,YAAA,GAAAF,OAAA;AAEA,IAAAG,iBAAA,GAAAH,OAAA;AAMA,IAAAI,KAAA,GAAAC,sBAAA,CAAAL,OAAA;AACA,IAAAM,MAAA,GAAAN,OAAA;AAEA,IAAAO,eAAA,GAAAP,OAAA;AACA,IAAAQ,aAAA,GAAAR,OAAA;AACA,IAAAS,QAAA,GAAAT,OAAA;AAMA,IAAAU,UAAA,GAAAL,sBAAA,CAAAL,OAAA;AAAoD,IAAAW,WAAA,GAAAX,OAAA;AAcpD,MAAMY,sBAAsB,GAAIC,UAAkB,IAAK;EACrD,IACE,aAAa,IAAIA,UAAU,IAC3BA,UAAU,CAACC,WAAW,YAAYC,kBAAS,EAC3C;IACA,OAAO;MACL,GAAGF,UAAU;MACbG,aAAa,EAAGC,QAAwB,IAAqB;QAC3D,IAAIA,QAAQ,YAAYF,kBAAS,EAAE;UAC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AEtB,UAAU,GAAGA,UAAU,CAACsB,MAAM,GAAG,IAAI;QAC7CC,gBAAgB,EAAEvB,UAAU,GAAGA,UAAU,CAACuB,gBAAgB,GAAG,IAAI;QACjEC,QAAQ,EAAEC,OAAO,CAACzB,UAAU,CAAC;QAC7BmB,MAAM;QACNO,cAAc,EAAElB,WAAW;QAC3BD,WAAW,EAAEF;MACf,CAAC;MAED,oBAAO,IAAAtC,WAAA,CAAA4D,GAAA,EAACxC,SAAS;QAAA,GAAKE,KAAK;QAAA,GAAMgC;MAAQ,CAAG,CAAC;IAC/C,CAAC;IAEDjC,gBAAgB,CAACS,WAAW,GAAG,gBAAgB,IAAAC,qBAAc,EAC3DV,gBAAgB,EAChBV,IACF,CAAC,EAAE;IAEH,OAAOU,gBAAgB;EACzB,CAAC;AACH,CAAC;AAAC,IAAAwC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEarD,kBAAkB","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -71,6 +71,10 @@ const modularUIConnector = (
|
|
|
71
71
|
|
|
72
72
|
return (Component: ComponentType<any>) => {
|
|
73
73
|
const WrappedComponent = (props: any) => {
|
|
74
|
+
// explicit property for removeOnMount overwrite the setting
|
|
75
|
+
const finalRemoveOnUnmount =
|
|
76
|
+
props.removeOnUnmount === true ? true : removeOnUnmount;
|
|
77
|
+
|
|
74
78
|
const dispatch = useDispatch();
|
|
75
79
|
const location = useLocation();
|
|
76
80
|
|
|
@@ -78,7 +82,10 @@ const modularUIConnector = (
|
|
|
78
82
|
const displayName = getDisplayName(Component, name, props.contextId);
|
|
79
83
|
|
|
80
84
|
// Load the model through the useModUI hook
|
|
81
|
-
const modelEntry = useModularUI(displayName, url,
|
|
85
|
+
const modelEntry = useModularUI(displayName, url, {
|
|
86
|
+
...otherOptions,
|
|
87
|
+
removeOnUnmount: finalRemoveOnUnmount,
|
|
88
|
+
});
|
|
82
89
|
const modelKey = modelEntry?.model?.connectKey;
|
|
83
90
|
|
|
84
91
|
// handle manual reload of model
|
|
@@ -114,11 +121,11 @@ const modularUIConnector = (
|
|
|
114
121
|
// Remove model when hoc unloads
|
|
115
122
|
useEffect(() => {
|
|
116
123
|
return () => {
|
|
117
|
-
if (
|
|
124
|
+
if (finalRemoveOnUnmount) {
|
|
118
125
|
dispatch(removeModelByKey(modelKey));
|
|
119
126
|
}
|
|
120
127
|
};
|
|
121
|
-
}, [dispatch, modelKey]);
|
|
128
|
+
}, [dispatch, modelKey, finalRemoveOnUnmount]);
|
|
122
129
|
|
|
123
130
|
// Create new properties object to inject modularui properties to own props
|
|
124
131
|
const locale = useLocale();
|