@beinformed/ui 1.57.0-contextpath.0 → 1.57.0
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 +63 -0
- package/esm/constants/Settings.js +10 -2
- package/esm/constants/Settings.js.map +1 -1
- package/esm/hooks/useModularUI.js +24 -18
- package/esm/hooks/useModularUI.js.map +1 -1
- package/esm/hooks/useModularUIBasic.js +52 -41
- package/esm/hooks/useModularUIBasic.js.map +1 -1
- package/esm/models/concepts/ConceptDetailModel.js +1 -8
- package/esm/models/concepts/ConceptDetailModel.js.map +1 -1
- package/esm/models/concepts/ConceptIndexModel.js +1 -1
- package/esm/models/concepts/ConceptIndexModel.js.map +1 -1
- package/esm/models/concepts/ConceptLinkModel.js +8 -9
- package/esm/models/concepts/ConceptLinkModel.js.map +1 -1
- package/esm/models/concepts/ConceptTypeDetailModel.js +3 -20
- package/esm/models/concepts/ConceptTypeDetailModel.js.map +1 -1
- package/esm/models/concepts/SourceReferenceCollection.js +3 -1
- package/esm/models/concepts/SourceReferenceCollection.js.map +1 -1
- package/esm/models/concepts/SourceReferenceModel.js +9 -3
- package/esm/models/concepts/SourceReferenceModel.js.map +1 -1
- package/esm/models/content/ContentLinkModel.js +10 -4
- package/esm/models/content/ContentLinkModel.js.map +1 -1
- package/esm/models/content/SectionModel.js +10 -6
- package/esm/models/content/SectionModel.js.map +1 -1
- package/esm/models/error/ErrorResponse.js +20 -5
- package/esm/models/error/ErrorResponse.js.map +1 -1
- package/esm/models/href/Href.js +21 -4
- package/esm/models/href/Href.js.map +1 -1
- package/esm/models/list/ListItemCollection.js +1 -1
- package/esm/models/list/ListItemCollection.js.map +1 -1
- package/esm/modularui/CaptchaRequest.js +12 -3
- package/esm/modularui/CaptchaRequest.js.map +1 -1
- package/esm/modularui/ModularUIRequest.js +1 -1
- package/esm/modularui/ModularUIRequest.js.map +1 -1
- package/esm/modularui/UploadRequest.js +7 -3
- package/esm/modularui/UploadRequest.js.map +1 -1
- package/esm/redux/_modularui/ModularUIActions.js +11 -9
- package/esm/redux/_modularui/ModularUIActions.js.map +1 -1
- package/esm/redux/_modularui/ModularUIMiddleware.js +4 -1
- package/esm/redux/_modularui/ModularUIMiddleware.js.map +1 -1
- package/esm/redux/_modularui/ModularUIReducer.js +2 -1
- package/esm/redux/_modularui/ModularUIReducer.js.map +1 -1
- package/esm/redux/_modularui/ModularUISelectors.js +7 -6
- package/esm/redux/_modularui/ModularUISelectors.js.map +1 -1
- package/esm/redux/_modularui/types.js.map +1 -1
- package/esm/redux/actions/Application.js +11 -6
- package/esm/redux/actions/Application.js.map +1 -1
- package/esm/redux/connectors/PanelRenderer.js +0 -2
- package/esm/redux/connectors/PanelRenderer.js.map +1 -1
- package/esm/utils/helpers/checkResource.js +0 -2
- package/esm/utils/helpers/checkResource.js.map +1 -1
- package/esm/utils/helpers/repositoryResource.js +6 -5
- package/esm/utils/helpers/repositoryResource.js.map +1 -1
- package/lib/constants/Settings.js +10 -2
- package/lib/constants/Settings.js.flow +8 -2
- package/lib/constants/Settings.js.map +1 -1
- package/lib/hooks/__tests__/UseModularUIModel.spec.js.flow +11 -4
- package/lib/hooks/__tests__/useAuthentication.spec.js.flow +2 -8
- package/lib/hooks/__tests__/useForm.spec.js.flow +14 -12
- package/lib/hooks/__tests__/useModelCatalog.spec.js.flow +10 -4
- package/lib/hooks/__tests__/useModels.spec.js.flow +3 -12
- package/lib/hooks/__tests__/useModularUIBasic.spec.js.flow +9 -8
- package/lib/hooks/useModularUI.js +23 -17
- package/lib/hooks/useModularUI.js.flow +31 -16
- package/lib/hooks/useModularUI.js.map +1 -1
- package/lib/hooks/useModularUIBasic.js +52 -41
- package/lib/hooks/useModularUIBasic.js.flow +66 -50
- package/lib/hooks/useModularUIBasic.js.map +1 -1
- package/lib/models/concepts/ConceptDetailModel.js +1 -8
- package/lib/models/concepts/ConceptDetailModel.js.flow +2 -7
- package/lib/models/concepts/ConceptDetailModel.js.map +1 -1
- package/lib/models/concepts/ConceptIndexModel.js +1 -1
- package/lib/models/concepts/ConceptIndexModel.js.flow +7 -1
- package/lib/models/concepts/ConceptIndexModel.js.map +1 -1
- package/lib/models/concepts/ConceptLinkModel.js +8 -9
- package/lib/models/concepts/ConceptLinkModel.js.flow +14 -9
- package/lib/models/concepts/ConceptLinkModel.js.map +1 -1
- package/lib/models/concepts/ConceptTypeDetailModel.js +3 -20
- package/lib/models/concepts/ConceptTypeDetailModel.js.flow +3 -25
- package/lib/models/concepts/ConceptTypeDetailModel.js.map +1 -1
- package/lib/models/concepts/SourceReferenceCollection.js +3 -1
- package/lib/models/concepts/SourceReferenceCollection.js.flow +8 -1
- package/lib/models/concepts/SourceReferenceCollection.js.map +1 -1
- package/lib/models/concepts/SourceReferenceModel.js +9 -3
- package/lib/models/concepts/SourceReferenceModel.js.flow +19 -3
- package/lib/models/concepts/SourceReferenceModel.js.map +1 -1
- package/lib/models/concepts/__mock__/conceptindex.js.flow +15 -0
- package/lib/models/concepts/__tests__/ConceptIndexModel.spec.js.flow +30 -2
- package/lib/models/concepts/__tests__/ConceptTypeDetailModel.spec.js.flow +1 -18
- package/lib/models/content/ContentLinkModel.js +9 -4
- package/lib/models/content/ContentLinkModel.js.flow +19 -4
- package/lib/models/content/ContentLinkModel.js.map +1 -1
- package/lib/models/content/SectionModel.js +10 -6
- package/lib/models/content/SectionModel.js.flow +31 -5
- package/lib/models/content/SectionModel.js.map +1 -1
- package/lib/models/error/ErrorResponse.js +20 -5
- package/lib/models/error/ErrorResponse.js.flow +34 -5
- package/lib/models/error/ErrorResponse.js.map +1 -1
- package/lib/models/href/Href.js +21 -4
- package/lib/models/href/Href.js.flow +21 -4
- package/lib/models/href/Href.js.map +1 -1
- package/lib/models/href/__tests__/Href.spec.js.flow +9 -3
- package/lib/models/list/ListItemCollection.js +1 -1
- package/lib/models/list/ListItemCollection.js.flow +2 -0
- package/lib/models/list/ListItemCollection.js.map +1 -1
- package/lib/modularui/CaptchaRequest.js +11 -2
- package/lib/modularui/CaptchaRequest.js.flow +17 -3
- package/lib/modularui/CaptchaRequest.js.map +1 -1
- package/lib/modularui/ModularUIRequest.js +1 -1
- package/lib/modularui/ModularUIRequest.js.flow +3 -1
- package/lib/modularui/ModularUIRequest.js.map +1 -1
- package/lib/modularui/UploadRequest.js +6 -2
- package/lib/modularui/UploadRequest.js.flow +12 -2
- package/lib/modularui/UploadRequest.js.map +1 -1
- package/lib/redux/_modularui/ModularUIActions.js +11 -9
- package/lib/redux/_modularui/ModularUIActions.js.flow +20 -10
- package/lib/redux/_modularui/ModularUIActions.js.map +1 -1
- package/lib/redux/_modularui/ModularUIMiddleware.js +3 -0
- package/lib/redux/_modularui/ModularUIMiddleware.js.flow +6 -3
- package/lib/redux/_modularui/ModularUIMiddleware.js.map +1 -1
- package/lib/redux/_modularui/ModularUIReducer.js +2 -1
- package/lib/redux/_modularui/ModularUIReducer.js.flow +1 -0
- package/lib/redux/_modularui/ModularUIReducer.js.map +1 -1
- package/lib/redux/_modularui/ModularUISelectors.js +5 -6
- package/lib/redux/_modularui/ModularUISelectors.js.flow +22 -10
- package/lib/redux/_modularui/ModularUISelectors.js.map +1 -1
- package/lib/redux/_modularui/__tests__/actions.spec.js.flow +1 -4
- package/lib/redux/_modularui/types.js.flow +1 -0
- package/lib/redux/_modularui/types.js.map +1 -1
- package/lib/redux/actions/Application.js +10 -5
- package/lib/redux/actions/Application.js.flow +16 -5
- package/lib/redux/actions/Application.js.map +1 -1
- package/lib/redux/actions/__tests__/Application.spec.js.flow +1 -8
- package/lib/redux/actions/__tests__/Authorization.spec.js.flow +0 -4
- package/lib/redux/connectors/PanelRenderer.js +0 -2
- package/lib/redux/connectors/PanelRenderer.js.flow +0 -1
- package/lib/redux/connectors/PanelRenderer.js.map +1 -1
- package/lib/utils/helpers/checkResource.js +0 -2
- package/lib/utils/helpers/checkResource.js.flow +0 -2
- package/lib/utils/helpers/checkResource.js.map +1 -1
- package/lib/utils/helpers/repositoryResource.js +6 -5
- package/lib/utils/helpers/repositoryResource.js.flow +8 -6
- package/lib/utils/helpers/repositoryResource.js.map +1 -1
- package/package.json +18 -18
- package/src/constants/Settings.js +8 -2
- package/src/hooks/__tests__/UseModularUIModel.spec.js +11 -4
- package/src/hooks/__tests__/useAuthentication.spec.js +2 -8
- package/src/hooks/__tests__/useForm.spec.js +14 -12
- package/src/hooks/__tests__/useModelCatalog.spec.js +10 -4
- package/src/hooks/__tests__/useModels.spec.js +3 -12
- package/src/hooks/__tests__/useModularUIBasic.spec.js +9 -8
- package/src/hooks/useModularUI.js +31 -16
- package/src/hooks/useModularUIBasic.js +66 -50
- package/src/models/concepts/ConceptDetailModel.js +2 -7
- package/src/models/concepts/ConceptIndexModel.js +7 -1
- package/src/models/concepts/ConceptLinkModel.js +14 -9
- package/src/models/concepts/ConceptTypeDetailModel.js +3 -25
- package/src/models/concepts/SourceReferenceCollection.js +8 -1
- package/src/models/concepts/SourceReferenceModel.js +19 -3
- package/src/models/concepts/__mock__/conceptindex.js +15 -0
- package/src/models/concepts/__mock__/conceptindex_contributions.json +86 -0
- package/src/models/concepts/__mock__/conceptindex_data.json +323 -0
- package/src/models/concepts/__mock__/concepttype_hierarchy.json +1 -11
- package/src/models/concepts/__tests__/ConceptIndexModel.spec.js +30 -2
- package/src/models/concepts/__tests__/ConceptTypeDetailModel.spec.js +1 -18
- package/src/models/content/ContentLinkModel.js +19 -4
- package/src/models/content/SectionModel.js +31 -5
- package/src/models/error/ErrorResponse.js +34 -5
- package/src/models/href/Href.js +21 -4
- package/src/models/href/__tests__/Href.spec.js +9 -3
- package/src/models/list/ListItemCollection.js +2 -0
- package/src/modularui/CaptchaRequest.js +17 -3
- package/src/modularui/ModularUIRequest.js +3 -1
- package/src/modularui/UploadRequest.js +12 -2
- package/src/redux/_modularui/ModularUIActions.js +20 -10
- package/src/redux/_modularui/ModularUIMiddleware.js +6 -3
- package/src/redux/_modularui/ModularUIReducer.js +1 -0
- package/src/redux/_modularui/ModularUISelectors.js +22 -10
- package/src/redux/_modularui/__tests__/actions.spec.js +1 -4
- package/src/redux/_modularui/types.js +1 -0
- package/src/redux/actions/Application.js +16 -5
- package/src/redux/actions/__tests__/Application.spec.js +1 -8
- package/src/redux/actions/__tests__/Authorization.spec.js +0 -4
- package/src/redux/connectors/PanelRenderer.js +0 -1
- package/src/utils/helpers/checkResource.js +0 -2
- package/src/utils/helpers/repositoryResource.js +8 -6
|
@@ -18,8 +18,6 @@ const connectPanel = exports.connectPanel = (0, _ModularUIConnector.default)("Pa
|
|
|
18
18
|
if (!href && !match) {
|
|
19
19
|
throw new Error("Cannot determine panel url because of missing href and match");
|
|
20
20
|
}
|
|
21
|
-
|
|
22
|
-
// TODO SBO: origin and context?
|
|
23
21
|
const panelHref = href ? new _Href.default(href) : new _Href.default(match.url);
|
|
24
22
|
if (match && match.isExact) {
|
|
25
23
|
panelHref.addParametersFromString(querystring);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PanelRenderer.js","names":["_ModularUIConnector","_interopRequireDefault","require","_Href","connectPanel","exports","modularui","_ref","href","match","querystring","Error","panelHref","Href","url","isExact","addParametersFromString","propName"],"sources":["../../../src/redux/connectors/PanelRenderer.js"],"sourcesContent":["// @flow\nimport modularui from \"../_modularui/ModularUIConnector\";\nimport Href from \"../../models/href/Href\";\n\nimport type { ModularUIConnector } from \"../_modularui/types\";\n\n/**\n */\nexport const connectPanel: ModularUIConnector = modularui(\n \"PanelRenderer\",\n ({ href, match, querystring = \"\" }) => {\n if (!href && !match) {\n throw new Error(\n \"Cannot determine panel url because of missing href and match\",\n );\n }\n\n
|
|
1
|
+
{"version":3,"file":"PanelRenderer.js","names":["_ModularUIConnector","_interopRequireDefault","require","_Href","connectPanel","exports","modularui","_ref","href","match","querystring","Error","panelHref","Href","url","isExact","addParametersFromString","propName"],"sources":["../../../src/redux/connectors/PanelRenderer.js"],"sourcesContent":["// @flow\nimport modularui from \"../_modularui/ModularUIConnector\";\nimport Href from \"../../models/href/Href\";\n\nimport type { ModularUIConnector } from \"../_modularui/types\";\n\n/**\n */\nexport const connectPanel: ModularUIConnector = modularui(\n \"PanelRenderer\",\n ({ href, match, querystring = \"\" }) => {\n if (!href && !match) {\n throw new Error(\n \"Cannot determine panel url because of missing href and match\",\n );\n }\n\n const panelHref = href ? new Href(href) : new Href(match.url);\n\n if (match && match.isExact) {\n panelHref.addParametersFromString(querystring);\n }\n\n return panelHref;\n },\n {\n propName: \"panel\",\n },\n);\n"],"mappings":";;;;;;;AACA,IAAAA,mBAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,KAAA,GAAAF,sBAAA,CAAAC,OAAA;AAIA;AACA;AACO,MAAME,YAAgC,GAAAC,OAAA,CAAAD,YAAA,GAAG,IAAAE,2BAAS,EACvD,eAAe,EACfC,IAAA,IAAuC;EAAA,IAAtC;IAAEC,IAAI;IAAEC,KAAK;IAAEC,WAAW,GAAG;EAAG,CAAC,GAAAH,IAAA;EAChC,IAAI,CAACC,IAAI,IAAI,CAACC,KAAK,EAAE;IACnB,MAAM,IAAIE,KAAK,CACb,8DACF,CAAC;EACH;EAEA,MAAMC,SAAS,GAAGJ,IAAI,GAAG,IAAIK,aAAI,CAACL,IAAI,CAAC,GAAG,IAAIK,aAAI,CAACJ,KAAK,CAACK,GAAG,CAAC;EAE7D,IAAIL,KAAK,IAAIA,KAAK,CAACM,OAAO,EAAE;IAC1BH,SAAS,CAACI,uBAAuB,CAACN,WAAW,CAAC;EAChD;EAEA,OAAOE,SAAS;AAClB,CAAC,EACD;EACEK,QAAQ,EAAE;AACZ,CACF,CAAC","ignoreList":[]}
|
|
@@ -15,7 +15,6 @@ var _Href = _interopRequireDefault(require("../../models/href/Href"));
|
|
|
15
15
|
* @returns {boolean}
|
|
16
16
|
*/
|
|
17
17
|
const resourceExists = url => {
|
|
18
|
-
// TODO SBO: origin and context?
|
|
19
18
|
const fullUrl = new _Href.default(url).absolutehref;
|
|
20
19
|
const xhr = new XMLHttpRequest();
|
|
21
20
|
xhr.open("HEAD", fullUrl, false);
|
|
@@ -33,7 +32,6 @@ const resourceExists = url => {
|
|
|
33
32
|
*/
|
|
34
33
|
exports.resourceExists = resourceExists;
|
|
35
34
|
const resourceRedirectsToSecureLogin = url => {
|
|
36
|
-
// TODO SBO: origin and context?
|
|
37
35
|
const fullUrl = new _Href.default(url).absolutehref;
|
|
38
36
|
const xhr = new XMLHttpRequest();
|
|
39
37
|
xhr.open("HEAD", fullUrl, false);
|
|
@@ -9,7 +9,6 @@ import Href from "../../models/href/Href";
|
|
|
9
9
|
* @returns {boolean}
|
|
10
10
|
*/
|
|
11
11
|
export const resourceExists = (url: string | Href): boolean => {
|
|
12
|
-
// TODO SBO: origin and context?
|
|
13
12
|
const fullUrl = new Href(url).absolutehref;
|
|
14
13
|
|
|
15
14
|
const xhr = new XMLHttpRequest();
|
|
@@ -29,7 +28,6 @@ export const resourceExists = (url: string | Href): boolean => {
|
|
|
29
28
|
* @returns {boolean}
|
|
30
29
|
*/
|
|
31
30
|
export const resourceRedirectsToSecureLogin = (url: string | Href): boolean => {
|
|
32
|
-
// TODO SBO: origin and context?
|
|
33
31
|
const fullUrl = new Href(url).absolutehref;
|
|
34
32
|
|
|
35
33
|
const xhr = new XMLHttpRequest();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checkResource.js","names":["_Href","_interopRequireDefault","require","resourceExists","url","fullUrl","Href","absolutehref","xhr","XMLHttpRequest","open","setRequestHeader","send","status","exports","resourceRedirectsToSecureLogin","responseURL","_endsWith","default","call"],"sources":["../../../src/utils/helpers/checkResource.js"],"sourcesContent":["// @flow\nimport Href from \"../../models/href/Href\";\n\n/**\n * Checks if a given url to a modular ui resource exists using a HEAD request to the resource (synchronous)\n * When the resource returns a 404, the resource does not exists and the method returns false\n *\n * @param url\n * @returns {boolean}\n */\nexport const resourceExists = (url: string | Href): boolean => {\n
|
|
1
|
+
{"version":3,"file":"checkResource.js","names":["_Href","_interopRequireDefault","require","resourceExists","url","fullUrl","Href","absolutehref","xhr","XMLHttpRequest","open","setRequestHeader","send","status","exports","resourceRedirectsToSecureLogin","responseURL","_endsWith","default","call"],"sources":["../../../src/utils/helpers/checkResource.js"],"sourcesContent":["// @flow\nimport Href from \"../../models/href/Href\";\n\n/**\n * Checks if a given url to a modular ui resource exists using a HEAD request to the resource (synchronous)\n * When the resource returns a 404, the resource does not exists and the method returns false\n *\n * @param url\n * @returns {boolean}\n */\nexport const resourceExists = (url: string | Href): boolean => {\n const fullUrl = new Href(url).absolutehref;\n\n const xhr = new XMLHttpRequest();\n xhr.open(\"HEAD\", fullUrl, false);\n xhr.setRequestHeader(\"Accept\", \"application/json\");\n xhr.setRequestHeader(\"Content-Type\", \"application/json\");\n xhr.setRequestHeader(\"X-Requested-With\", \"XMLHttpRequest\");\n\n xhr.send();\n\n return xhr.status !== 404;\n};\n\n/**\n * Indicates if a request to the given url resuls in a redirect to /secureRedirect\n * @param url\n * @returns {boolean}\n */\nexport const resourceRedirectsToSecureLogin = (url: string | Href): boolean => {\n const fullUrl = new Href(url).absolutehref;\n\n const xhr = new XMLHttpRequest();\n xhr.open(\"HEAD\", fullUrl, false);\n xhr.setRequestHeader(\"Accept\", \"application/json\");\n xhr.setRequestHeader(\"Content-Type\", \"application/json\");\n xhr.setRequestHeader(\"X-Requested-With\", \"XMLHttpRequest\");\n xhr.send();\n\n const responseURL = xhr.responseURL ?? \"\";\n\n return xhr.status === 400 && responseURL.endsWith(\"/secureLogin\");\n};\n"],"mappings":";;;;;;;;AACA,IAAAA,KAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMC,cAAc,GAAIC,GAAkB,IAAc;EAC7D,MAAMC,OAAO,GAAG,IAAIC,aAAI,CAACF,GAAG,CAAC,CAACG,YAAY;EAE1C,MAAMC,GAAG,GAAG,IAAIC,cAAc,CAAC,CAAC;EAChCD,GAAG,CAACE,IAAI,CAAC,MAAM,EAAEL,OAAO,EAAE,KAAK,CAAC;EAChCG,GAAG,CAACG,gBAAgB,CAAC,QAAQ,EAAE,kBAAkB,CAAC;EAClDH,GAAG,CAACG,gBAAgB,CAAC,cAAc,EAAE,kBAAkB,CAAC;EACxDH,GAAG,CAACG,gBAAgB,CAAC,kBAAkB,EAAE,gBAAgB,CAAC;EAE1DH,GAAG,CAACI,IAAI,CAAC,CAAC;EAEV,OAAOJ,GAAG,CAACK,MAAM,KAAK,GAAG;AAC3B,CAAC;;AAED;AACA;AACA;AACA;AACA;AAJAC,OAAA,CAAAX,cAAA,GAAAA,cAAA;AAKO,MAAMY,8BAA8B,GAAIX,GAAkB,IAAc;EAC7E,MAAMC,OAAO,GAAG,IAAIC,aAAI,CAACF,GAAG,CAAC,CAACG,YAAY;EAE1C,MAAMC,GAAG,GAAG,IAAIC,cAAc,CAAC,CAAC;EAChCD,GAAG,CAACE,IAAI,CAAC,MAAM,EAAEL,OAAO,EAAE,KAAK,CAAC;EAChCG,GAAG,CAACG,gBAAgB,CAAC,QAAQ,EAAE,kBAAkB,CAAC;EAClDH,GAAG,CAACG,gBAAgB,CAAC,cAAc,EAAE,kBAAkB,CAAC;EACxDH,GAAG,CAACG,gBAAgB,CAAC,kBAAkB,EAAE,gBAAgB,CAAC;EAC1DH,GAAG,CAACI,IAAI,CAAC,CAAC;EAEV,MAAMI,WAAW,GAAGR,GAAG,CAACQ,WAAW,IAAI,EAAE;EAEzC,OAAOR,GAAG,CAACK,MAAM,KAAK,GAAG,IAAI,IAAAI,SAAA,CAAAC,OAAA,EAAAF,WAAW,EAAAG,IAAA,CAAXH,WAAW,EAAU,cAAc,CAAC;AACnE,CAAC;AAACF,OAAA,CAAAC,8BAAA,GAAAA,8BAAA","ignoreList":[]}
|
|
@@ -11,15 +11,16 @@ var _constants = require("../../constants");
|
|
|
11
11
|
* Creates an url to a resource in the Be Informed repository
|
|
12
12
|
* Only possible when serving using the UI Servlet of Be Informed
|
|
13
13
|
*/
|
|
14
|
-
const getRepositoryResourceUrl = resourceUrl
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
const getRepositoryResourceUrl = function (resourceUrl) {
|
|
15
|
+
let contextPath = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : (0, _constants.getBasePath)();
|
|
16
|
+
let origin = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "";
|
|
17
|
+
if ((0, _startsWith.default)(resourceUrl).call(resourceUrl, origin + contextPath)) {
|
|
17
18
|
return resourceUrl;
|
|
18
19
|
}
|
|
19
20
|
if ((0, _startsWith.default)(resourceUrl).call(resourceUrl, _constants.RESOURCE_PATH)) {
|
|
20
|
-
return `${
|
|
21
|
+
return `${origin}${contextPath}${resourceUrl}`;
|
|
21
22
|
}
|
|
22
|
-
return `${
|
|
23
|
+
return `${origin}${contextPath}${_constants.RESOURCE_PATH}${resourceUrl}`;
|
|
23
24
|
};
|
|
24
25
|
exports.getRepositoryResourceUrl = getRepositoryResourceUrl;
|
|
25
26
|
//# sourceMappingURL=repositoryResource.js.map
|
|
@@ -5,16 +5,18 @@ import { getBasePath, RESOURCE_PATH } from "../../constants";
|
|
|
5
5
|
* Creates an url to a resource in the Be Informed repository
|
|
6
6
|
* Only possible when serving using the UI Servlet of Be Informed
|
|
7
7
|
*/
|
|
8
|
-
export const getRepositoryResourceUrl = (
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
export const getRepositoryResourceUrl = (
|
|
9
|
+
resourceUrl: string,
|
|
10
|
+
contextPath: string = getBasePath(),
|
|
11
|
+
origin: string = "",
|
|
12
|
+
): string => {
|
|
13
|
+
if (resourceUrl.startsWith(origin + contextPath)) {
|
|
12
14
|
return resourceUrl;
|
|
13
15
|
}
|
|
14
16
|
|
|
15
17
|
if (resourceUrl.startsWith(RESOURCE_PATH)) {
|
|
16
|
-
return `${
|
|
18
|
+
return `${origin}${contextPath}${resourceUrl}`;
|
|
17
19
|
}
|
|
18
20
|
|
|
19
|
-
return `${
|
|
21
|
+
return `${origin}${contextPath}${RESOURCE_PATH}${resourceUrl}`;
|
|
20
22
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"repositoryResource.js","names":["_constants","require","getRepositoryResourceUrl","resourceUrl","
|
|
1
|
+
{"version":3,"file":"repositoryResource.js","names":["_constants","require","getRepositoryResourceUrl","resourceUrl","contextPath","arguments","length","undefined","getBasePath","origin","_startsWith","default","call","RESOURCE_PATH","exports"],"sources":["../../../src/utils/helpers/repositoryResource.js"],"sourcesContent":["// @flow\nimport { getBasePath, RESOURCE_PATH } from \"../../constants\";\n\n/**\n * Creates an url to a resource in the Be Informed repository\n * Only possible when serving using the UI Servlet of Be Informed\n */\nexport const getRepositoryResourceUrl = (\n resourceUrl: string,\n contextPath: string = getBasePath(),\n origin: string = \"\",\n): string => {\n if (resourceUrl.startsWith(origin + contextPath)) {\n return resourceUrl;\n }\n\n if (resourceUrl.startsWith(RESOURCE_PATH)) {\n return `${origin}${contextPath}${resourceUrl}`;\n }\n\n return `${origin}${contextPath}${RESOURCE_PATH}${resourceUrl}`;\n};\n"],"mappings":";;;;;;;;AACA,IAAAA,UAAA,GAAAC,OAAA;AAEA;AACA;AACA;AACA;AACO,MAAMC,wBAAwB,GAAG,SAAAA,CACtCC,WAAmB,EAGR;EAAA,IAFXC,WAAmB,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,IAAAG,sBAAW,EAAC,CAAC;EAAA,IACnCC,MAAc,GAAAJ,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,EAAE;EAEnB,IAAI,IAAAK,WAAA,CAAAC,OAAA,EAAAR,WAAW,EAAAS,IAAA,CAAXT,WAAW,EAAYM,MAAM,GAAGL,WAAW,CAAC,EAAE;IAChD,OAAOD,WAAW;EACpB;EAEA,IAAI,IAAAO,WAAA,CAAAC,OAAA,EAAAR,WAAW,EAAAS,IAAA,CAAXT,WAAW,EAAYU,wBAAa,CAAC,EAAE;IACzC,OAAO,GAAGJ,MAAM,GAAGL,WAAW,GAAGD,WAAW,EAAE;EAChD;EAEA,OAAO,GAAGM,MAAM,GAAGL,WAAW,GAAGS,wBAAa,GAAGV,WAAW,EAAE;AAChE,CAAC;AAACW,OAAA,CAAAZ,wBAAA,GAAAA,wBAAA","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@beinformed/ui",
|
|
3
|
-
"version": "1.57.0
|
|
3
|
+
"version": "1.57.0",
|
|
4
4
|
"description": "Toolbox for be informed javascript layouts",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
6
6
|
"bugs": "http://support.beinformed.com",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"flow": "flow",
|
|
30
30
|
"flow:ci": "flow check",
|
|
31
31
|
"flow-typed-install": "flow-typed install -l .flow/flow-typed/ --ignoreDeps peer --overwrite",
|
|
32
|
-
"test": "jest",
|
|
32
|
+
"test": "jest --bail",
|
|
33
33
|
"test:ci": "jest --ci",
|
|
34
34
|
"test:changed": "jest --onlyChanged",
|
|
35
35
|
"upgrade-interactive": "npm-check -u",
|
|
@@ -82,7 +82,7 @@
|
|
|
82
82
|
"styled-components": "^5.0.0"
|
|
83
83
|
},
|
|
84
84
|
"dependencies": {
|
|
85
|
-
"@babel/runtime-corejs3": "^7.25.
|
|
85
|
+
"@babel/runtime-corejs3": "^7.25.9",
|
|
86
86
|
"big.js": "^6.2.2",
|
|
87
87
|
"date-fns": "^4.1.0",
|
|
88
88
|
"deepmerge": "^4.3.1",
|
|
@@ -98,16 +98,16 @@
|
|
|
98
98
|
"setimmediate": "^1.0.5"
|
|
99
99
|
},
|
|
100
100
|
"devDependencies": {
|
|
101
|
-
"@babel/cli": "^7.25.
|
|
102
|
-
"@babel/core": "^7.25.
|
|
103
|
-
"@babel/eslint-parser": "^7.25.
|
|
104
|
-
"@babel/eslint-plugin": "^7.25.
|
|
101
|
+
"@babel/cli": "^7.25.9",
|
|
102
|
+
"@babel/core": "^7.25.9",
|
|
103
|
+
"@babel/eslint-parser": "^7.25.9",
|
|
104
|
+
"@babel/eslint-plugin": "^7.25.9",
|
|
105
105
|
"@babel/plugin-proposal-class-properties": "^7.18.6",
|
|
106
106
|
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
|
|
107
|
-
"@babel/plugin-transform-runtime": "^7.25.
|
|
108
|
-
"@babel/preset-env": "^7.25.
|
|
109
|
-
"@babel/preset-flow": "^7.25.
|
|
110
|
-
"@babel/preset-react": "^7.25.
|
|
107
|
+
"@babel/plugin-transform-runtime": "^7.25.9",
|
|
108
|
+
"@babel/preset-env": "^7.25.9",
|
|
109
|
+
"@babel/preset-flow": "^7.25.9",
|
|
110
|
+
"@babel/preset-react": "^7.25.9",
|
|
111
111
|
"@commitlint/cli": "^19.5.0",
|
|
112
112
|
"@commitlint/config-conventional": "^19.5.0",
|
|
113
113
|
"@testing-library/react": "^16.0.1",
|
|
@@ -115,7 +115,7 @@
|
|
|
115
115
|
"babel-jest": "^29.7.0",
|
|
116
116
|
"babel-plugin-styled-components": "^2.1.4",
|
|
117
117
|
"cherry-pick": "^0.5.0",
|
|
118
|
-
"commit-and-tag-version": "^12.
|
|
118
|
+
"commit-and-tag-version": "^12.5.0",
|
|
119
119
|
"cross-env": "^7.0.3",
|
|
120
120
|
"documentation": "^14.0.2",
|
|
121
121
|
"eslint": "^8.57.0",
|
|
@@ -124,21 +124,21 @@
|
|
|
124
124
|
"eslint-plugin-ft-flow": "^3.0.11",
|
|
125
125
|
"eslint-plugin-import": "^2.31.0",
|
|
126
126
|
"eslint-plugin-jest": "^28.8.3",
|
|
127
|
-
"eslint-plugin-jsdoc": "^50.3
|
|
128
|
-
"eslint-plugin-react": "^7.37.
|
|
129
|
-
"eslint-plugin-react-hooks": "^
|
|
127
|
+
"eslint-plugin-jsdoc": "^50.4.3",
|
|
128
|
+
"eslint-plugin-react": "^7.37.2",
|
|
129
|
+
"eslint-plugin-react-hooks": "^5.0.0",
|
|
130
130
|
"eslint-plugin-you-dont-need-lodash-underscore": "^6.14.0",
|
|
131
131
|
"flow-bin": "^0.200.1",
|
|
132
132
|
"flow-copy-source": "^2.0.9",
|
|
133
133
|
"flow-typed": "^3.9.0",
|
|
134
|
-
"hermes-eslint": "^0.
|
|
134
|
+
"hermes-eslint": "^0.25.0",
|
|
135
135
|
"history": "^4.0.0",
|
|
136
136
|
"husky": "^9.1.6",
|
|
137
137
|
"jest": "^29.7.0",
|
|
138
138
|
"jest-environment-jsdom": "^29.7.0",
|
|
139
139
|
"jest-junit": "^16.0.0",
|
|
140
140
|
"jest-sonar-reporter": "^2.0.0",
|
|
141
|
-
"jscodeshift": "^0.
|
|
141
|
+
"jscodeshift": "^17.0.0",
|
|
142
142
|
"lint-staged": "^15.2.10",
|
|
143
143
|
"polished": "^4.0.0",
|
|
144
144
|
"prettier": "^3.3.3",
|
|
@@ -149,7 +149,7 @@
|
|
|
149
149
|
"react-router": "^5.0.0",
|
|
150
150
|
"react-test-renderer": "^18.3.1",
|
|
151
151
|
"redux": "^4.2.1",
|
|
152
|
-
"redux-mock-store": "^1.5.
|
|
152
|
+
"redux-mock-store": "^1.5.5",
|
|
153
153
|
"redux-thunk": "^2.4.2",
|
|
154
154
|
"rimraf": "^6.0.1",
|
|
155
155
|
"styled-components": "^5.3.11",
|
|
@@ -172,12 +172,18 @@ export const getBasePath = (): string =>
|
|
|
172
172
|
/**
|
|
173
173
|
* Path to upload service
|
|
174
174
|
*/
|
|
175
|
-
export const getUploadPath = (
|
|
175
|
+
export const getUploadPath = (
|
|
176
|
+
contextPath: string = getBasePath(),
|
|
177
|
+
origin: string = "",
|
|
178
|
+
): string => `${origin}${contextPath}${UPLOAD_PATH}`;
|
|
176
179
|
|
|
177
180
|
/**
|
|
178
181
|
* Path to captcha service
|
|
179
182
|
*/
|
|
180
|
-
export const getCaptchaPath = (
|
|
183
|
+
export const getCaptchaPath = (
|
|
184
|
+
contextPath: string = getBasePath(),
|
|
185
|
+
origin: string = "",
|
|
186
|
+
): string => `${origin}${contextPath}${CAPTCHA_PATH}`;
|
|
181
187
|
|
|
182
188
|
/**
|
|
183
189
|
*/
|
|
@@ -4,6 +4,8 @@ import { Provider } from "react-redux";
|
|
|
4
4
|
import { renderHook } from "@testing-library/react";
|
|
5
5
|
import xhrMock from "xhr-mock";
|
|
6
6
|
|
|
7
|
+
import { useLocation } from "react-router";
|
|
8
|
+
|
|
7
9
|
import {
|
|
8
10
|
useApplication,
|
|
9
11
|
useTab,
|
|
@@ -32,6 +34,11 @@ import {
|
|
|
32
34
|
const middlewares = [thunk];
|
|
33
35
|
const mockStore = configureMockStore(middlewares);
|
|
34
36
|
|
|
37
|
+
jest.mock("react-router", () => ({
|
|
38
|
+
...jest.requireActual("react-router"), // Keep other methods from react-router as is
|
|
39
|
+
useLocation: jest.fn(), // Mock useLocation
|
|
40
|
+
}));
|
|
41
|
+
|
|
35
42
|
const JSON_TYPE = "application/json";
|
|
36
43
|
|
|
37
44
|
describe("modularui hooks", () => {
|
|
@@ -64,14 +71,11 @@ describe("modularui hooks", () => {
|
|
|
64
71
|
expect(result.current).toBeNull();
|
|
65
72
|
|
|
66
73
|
expect(store.getActions()).toStrictEqual([
|
|
67
|
-
{
|
|
68
|
-
type: "MODULARUI/STATUS",
|
|
69
|
-
payload: { key: `${key}(${url})(en)`, status: "LOADING" },
|
|
70
|
-
},
|
|
71
74
|
{ type: "START_PROGRESS" },
|
|
72
75
|
{
|
|
73
76
|
type: "MODULARUI/FETCH",
|
|
74
77
|
payload: expect.objectContaining({
|
|
78
|
+
key: `${key}(${url})(en)`,
|
|
75
79
|
href: new Href(url),
|
|
76
80
|
locale: "en",
|
|
77
81
|
targetModel: targetModel,
|
|
@@ -83,6 +87,9 @@ describe("modularui hooks", () => {
|
|
|
83
87
|
// replace the real XHR object with the mock XHR object before each test
|
|
84
88
|
// eslint-disable-next-line jest/no-hooks
|
|
85
89
|
beforeEach(() => {
|
|
90
|
+
useLocation.mockReturnValue({
|
|
91
|
+
state: null,
|
|
92
|
+
});
|
|
86
93
|
xhrMock.setup();
|
|
87
94
|
});
|
|
88
95
|
|
|
@@ -61,14 +61,11 @@ describe("authentication hooks", () => {
|
|
|
61
61
|
|
|
62
62
|
expect(store.getActions()).toStrictEqual([
|
|
63
63
|
{ type: "START_PROGRESS" },
|
|
64
|
-
{
|
|
65
|
-
type: "MODULARUI/STATUS",
|
|
66
|
-
payload: { key: "application(/)(en)", status: "LOADING" },
|
|
67
|
-
},
|
|
68
64
|
{ type: "START_PROGRESS" },
|
|
69
65
|
expect.objectContaining({
|
|
70
66
|
type: "MODULARUI/FETCH",
|
|
71
67
|
payload: expect.objectContaining({
|
|
68
|
+
key: "application(/)(en)",
|
|
72
69
|
href: new Href("/", "Application"),
|
|
73
70
|
}),
|
|
74
71
|
}),
|
|
@@ -108,14 +105,11 @@ describe("authentication hooks", () => {
|
|
|
108
105
|
expect(store.getActions()).toStrictEqual([
|
|
109
106
|
{ type: "START_PROGRESS" },
|
|
110
107
|
{ type: "MODULARUI/RESET" },
|
|
111
|
-
{
|
|
112
|
-
type: "MODULARUI/STATUS",
|
|
113
|
-
payload: { key: "application(/)(en)", status: "LOADING" },
|
|
114
|
-
},
|
|
115
108
|
{ type: "START_PROGRESS" },
|
|
116
109
|
expect.objectContaining({
|
|
117
110
|
type: "MODULARUI/FETCH",
|
|
118
111
|
payload: expect.objectContaining({
|
|
112
|
+
key: "application(/)(en)",
|
|
119
113
|
href: new Href("/", "Application"),
|
|
120
114
|
}),
|
|
121
115
|
}),
|
|
@@ -3,6 +3,7 @@ import thunk from "redux-thunk";
|
|
|
3
3
|
import { Provider } from "react-redux";
|
|
4
4
|
import { renderHook } from "@testing-library/react";
|
|
5
5
|
import xhrMock from "xhr-mock";
|
|
6
|
+
import { useLocation } from "react-router";
|
|
6
7
|
|
|
7
8
|
import {
|
|
8
9
|
useAttributeSet,
|
|
@@ -19,12 +20,22 @@ import { IllegalArgumentException } from "../../exceptions";
|
|
|
19
20
|
const middlewares = [thunk];
|
|
20
21
|
const mockStore = configureMockStore(middlewares);
|
|
21
22
|
|
|
23
|
+
jest.mock("react-router", () => ({
|
|
24
|
+
...jest.requireActual("react-router"), // Keep other methods from react-router as is
|
|
25
|
+
useLocation: jest.fn(), // Mock useLocation
|
|
26
|
+
}));
|
|
27
|
+
|
|
22
28
|
const JSON_TYPE = "application/json";
|
|
23
29
|
|
|
24
30
|
describe("form hooks", () => {
|
|
25
31
|
// replace the real XHR object with the mock XHR object before each test
|
|
26
32
|
// eslint-disable-next-line jest/no-hooks
|
|
27
|
-
beforeEach(() =>
|
|
33
|
+
beforeEach(() => {
|
|
34
|
+
useLocation.mockReturnValue({
|
|
35
|
+
state: null,
|
|
36
|
+
});
|
|
37
|
+
xhrMock.setup();
|
|
38
|
+
});
|
|
28
39
|
|
|
29
40
|
// put the real XHR object back and clear the mocks after each test
|
|
30
41
|
// eslint-disable-next-line jest/no-hooks
|
|
@@ -58,14 +69,11 @@ describe("form hooks", () => {
|
|
|
58
69
|
expect(result.current).toBeUndefined();
|
|
59
70
|
|
|
60
71
|
expect(store.getActions()).toStrictEqual([
|
|
61
|
-
{
|
|
62
|
-
type: "MODULARUI/STATUS",
|
|
63
|
-
payload: { key: "form(/form)(en)", status: "LOADING" },
|
|
64
|
-
},
|
|
65
72
|
{ type: "START_PROGRESS" },
|
|
66
73
|
{
|
|
67
74
|
type: "MODULARUI/FETCH",
|
|
68
75
|
payload: expect.objectContaining({
|
|
76
|
+
key: "form(/form)(en)",
|
|
69
77
|
href: new Href("/form?commit=false"),
|
|
70
78
|
locale: "en",
|
|
71
79
|
targetModel: FormModel,
|
|
@@ -102,17 +110,11 @@ describe("form hooks", () => {
|
|
|
102
110
|
href.resourcetype = "Form";
|
|
103
111
|
|
|
104
112
|
expect(store.getActions()).toStrictEqual([
|
|
105
|
-
{
|
|
106
|
-
type: "MODULARUI/STATUS",
|
|
107
|
-
payload: {
|
|
108
|
-
key: "form(/persons/persons/createperson)(en)",
|
|
109
|
-
status: "LOADING",
|
|
110
|
-
},
|
|
111
|
-
},
|
|
112
113
|
{ type: "START_PROGRESS" },
|
|
113
114
|
{
|
|
114
115
|
type: "MODULARUI/FETCH",
|
|
115
116
|
payload: expect.objectContaining({
|
|
117
|
+
key: "form(/persons/persons/createperson)(en)",
|
|
116
118
|
href: href,
|
|
117
119
|
locale: "en",
|
|
118
120
|
targetModel: FormModel,
|
|
@@ -3,6 +3,7 @@ import thunk from "redux-thunk";
|
|
|
3
3
|
import { Provider } from "react-redux";
|
|
4
4
|
import { renderHook } from "@testing-library/react";
|
|
5
5
|
import xhrMock from "xhr-mock";
|
|
6
|
+
import { useLocation } from "react-router";
|
|
6
7
|
|
|
7
8
|
import {
|
|
8
9
|
ConceptIndexModel,
|
|
@@ -26,6 +27,11 @@ import {
|
|
|
26
27
|
const middlewares = [thunk];
|
|
27
28
|
const mockStore = configureMockStore(middlewares);
|
|
28
29
|
|
|
30
|
+
jest.mock("react-router", () => ({
|
|
31
|
+
...jest.requireActual("react-router"), // Keep other methods from react-router as is
|
|
32
|
+
useLocation: jest.fn(), // Mock useLocation
|
|
33
|
+
}));
|
|
34
|
+
|
|
29
35
|
const JSON_TYPE = "application/json";
|
|
30
36
|
|
|
31
37
|
describe("modelcatalog hooks", () => {
|
|
@@ -58,14 +64,11 @@ describe("modelcatalog hooks", () => {
|
|
|
58
64
|
expect(result.current).toBeNull();
|
|
59
65
|
|
|
60
66
|
expect(store.getActions()).toStrictEqual([
|
|
61
|
-
{
|
|
62
|
-
type: "MODULARUI/STATUS",
|
|
63
|
-
payload: { key: `${key}(${url})(en)`, status: "LOADING" },
|
|
64
|
-
},
|
|
65
67
|
{ type: "START_PROGRESS" },
|
|
66
68
|
{
|
|
67
69
|
type: "MODULARUI/FETCH",
|
|
68
70
|
payload: expect.objectContaining({
|
|
71
|
+
key: `${key}(${url})(en)`,
|
|
69
72
|
href: new Href(url),
|
|
70
73
|
locale: "en",
|
|
71
74
|
targetModel: targetModel,
|
|
@@ -77,6 +80,9 @@ describe("modelcatalog hooks", () => {
|
|
|
77
80
|
// replace the real XHR object with the mock XHR object before each test
|
|
78
81
|
// eslint-disable-next-line jest/no-hooks
|
|
79
82
|
beforeEach(() => {
|
|
83
|
+
useLocation.mockReturnValue({
|
|
84
|
+
state: null,
|
|
85
|
+
});
|
|
80
86
|
xhrMock.setup();
|
|
81
87
|
});
|
|
82
88
|
|
|
@@ -37,14 +37,11 @@ describe("model hooks", () => {
|
|
|
37
37
|
|
|
38
38
|
result.current.reload(application);
|
|
39
39
|
expect(store.getActions()).toStrictEqual([
|
|
40
|
-
{
|
|
41
|
-
type: "MODULARUI/STATUS",
|
|
42
|
-
payload: { key: "application(/)(en)", status: "LOADING" },
|
|
43
|
-
},
|
|
44
40
|
{ type: "START_PROGRESS" },
|
|
45
41
|
{
|
|
46
42
|
type: "MODULARUI/FETCH",
|
|
47
43
|
payload: expect.objectContaining({
|
|
44
|
+
key: "application(/)(en)",
|
|
48
45
|
href: new Href("/", "Application"),
|
|
49
46
|
locale: "en",
|
|
50
47
|
}),
|
|
@@ -83,14 +80,11 @@ describe("model hooks", () => {
|
|
|
83
80
|
model.selfhref.equals(new Href("/")),
|
|
84
81
|
);
|
|
85
82
|
expect(store.getActions()).toStrictEqual([
|
|
86
|
-
{
|
|
87
|
-
type: "MODULARUI/STATUS",
|
|
88
|
-
payload: { key: "application(/)(en)", status: "LOADING" },
|
|
89
|
-
},
|
|
90
83
|
{ type: "START_PROGRESS" },
|
|
91
84
|
{
|
|
92
85
|
type: "MODULARUI/FETCH",
|
|
93
86
|
payload: expect.objectContaining({
|
|
87
|
+
key: "application(/)(en)",
|
|
94
88
|
href: new Href("/", "Application"),
|
|
95
89
|
locale: "en",
|
|
96
90
|
}),
|
|
@@ -130,14 +124,11 @@ describe("model hooks", () => {
|
|
|
130
124
|
model.selfhref.equals(new Href("/books/books")),
|
|
131
125
|
);
|
|
132
126
|
expect(store.getActions()).toStrictEqual([
|
|
133
|
-
{
|
|
134
|
-
type: "MODULARUI/STATUS",
|
|
135
|
-
payload: { key: "list(/books/books)(en)", status: "LOADING" },
|
|
136
|
-
},
|
|
137
127
|
{ type: "START_PROGRESS" },
|
|
138
128
|
{
|
|
139
129
|
type: "MODULARUI/FETCH",
|
|
140
130
|
payload: expect.objectContaining({
|
|
131
|
+
key: "list(/books/books)(en)",
|
|
141
132
|
href: caselist.selfhref,
|
|
142
133
|
locale: "en",
|
|
143
134
|
}),
|
|
@@ -6,16 +6,25 @@ import xhrMock from "xhr-mock";
|
|
|
6
6
|
|
|
7
7
|
import { useModularUIBasic } from "../useModularUIBasic";
|
|
8
8
|
import { ApplicationModel, Href } from "../../models";
|
|
9
|
+
import { useLocation } from "react-router";
|
|
9
10
|
|
|
10
11
|
const middlewares = [thunk];
|
|
11
12
|
const mockStore = configureMockStore(middlewares);
|
|
12
13
|
|
|
14
|
+
jest.mock("react-router", () => ({
|
|
15
|
+
...jest.requireActual("react-router"), // Keep other methods from react-router as is
|
|
16
|
+
useLocation: jest.fn(), // Mock useLocation
|
|
17
|
+
}));
|
|
18
|
+
|
|
13
19
|
const JSON_TYPE = "application/json";
|
|
14
20
|
|
|
15
21
|
describe("modularui hooks", () => {
|
|
16
22
|
// replace the real XHR object with the mock XHR object before each test
|
|
17
23
|
// eslint-disable-next-line jest/no-hooks
|
|
18
24
|
beforeEach(() => {
|
|
25
|
+
useLocation.mockReturnValue({
|
|
26
|
+
state: null,
|
|
27
|
+
});
|
|
19
28
|
xhrMock.setup();
|
|
20
29
|
});
|
|
21
30
|
|
|
@@ -57,10 +66,6 @@ describe("modularui hooks", () => {
|
|
|
57
66
|
expect(result.current).toBeNull();
|
|
58
67
|
|
|
59
68
|
expect(store.getActions()).toStrictEqual([
|
|
60
|
-
{
|
|
61
|
-
type: "MODULARUI/STATUS",
|
|
62
|
-
payload: { key: `app(/)(en)`, status: "LOADING" },
|
|
63
|
-
},
|
|
64
69
|
{ type: "START_PROGRESS" },
|
|
65
70
|
{
|
|
66
71
|
type: "MODULARUI/FETCH",
|
|
@@ -107,10 +112,6 @@ describe("modularui hooks", () => {
|
|
|
107
112
|
expect(result.current).toBeNull();
|
|
108
113
|
|
|
109
114
|
expect(store.getActions()).toStrictEqual([
|
|
110
|
-
{
|
|
111
|
-
type: "MODULARUI/STATUS",
|
|
112
|
-
payload: { key: `app(/)(en)`, status: "LOADING" },
|
|
113
|
-
},
|
|
114
115
|
{ type: "START_PROGRESS" },
|
|
115
116
|
{
|
|
116
117
|
type: "MODULARUI/FETCH",
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// @flow
|
|
2
|
-
import { useEffect, useRef } from "react";
|
|
2
|
+
import { useEffect, useRef, useMemo } from "react";
|
|
3
3
|
import { useDispatch, useSelector } from "react-redux";
|
|
4
|
+
import { useLocation } from "react-router";
|
|
4
5
|
|
|
5
6
|
import { HTTP_METHODS } from "../constants";
|
|
6
7
|
import {
|
|
@@ -11,15 +12,18 @@ import {
|
|
|
11
12
|
import useDeepCompareEffect from "./useDeepCompareEffect";
|
|
12
13
|
|
|
13
14
|
import { useLocale } from "./useI18n";
|
|
15
|
+
import Href from "../models/href/Href";
|
|
14
16
|
|
|
15
|
-
import type Href from "../models/href/Href";
|
|
16
17
|
import type { RequestModularUIOptions } from "../utils";
|
|
17
18
|
|
|
18
19
|
/**
|
|
19
20
|
*/
|
|
20
21
|
const useKeyForHook = (modelKey: string, url: string) => {
|
|
21
22
|
const locale = useLocale();
|
|
22
|
-
return
|
|
23
|
+
return useMemo(
|
|
24
|
+
() => `${modelKey}(${url.split("?")[0]})(${locale})`,
|
|
25
|
+
[modelKey, url, locale],
|
|
26
|
+
);
|
|
23
27
|
};
|
|
24
28
|
|
|
25
29
|
/**
|
|
@@ -34,11 +38,22 @@ export const useModularUI = (
|
|
|
34
38
|
},
|
|
35
39
|
): any => {
|
|
36
40
|
const dispatch = useDispatch();
|
|
37
|
-
const href = url?.toString() || "";
|
|
41
|
+
const href = useMemo(() => url?.toString() || "", [url]);
|
|
38
42
|
const key = useKeyForHook(modelKey, href);
|
|
39
43
|
|
|
44
|
+
if (url instanceof Href) {
|
|
45
|
+
options.origin = options.origin ?? url.origin;
|
|
46
|
+
options.contextPath = options.contextPath ?? url.contextPath;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const location = useLocation();
|
|
50
|
+
const redirectLocation = location.state?.redirectLocation;
|
|
51
|
+
const forceReload =
|
|
52
|
+
redirectLocation instanceof Href ? redirectLocation?.equals(href) : false;
|
|
53
|
+
|
|
40
54
|
const prevOptions = useRef(options);
|
|
41
55
|
const prevHref = useRef(href);
|
|
56
|
+
const prevForceReload = useRef(forceReload);
|
|
42
57
|
|
|
43
58
|
// dispatch loadModularUI
|
|
44
59
|
useDeepCompareEffect(() => {
|
|
@@ -48,25 +63,25 @@ export const useModularUI = (
|
|
|
48
63
|
prevOptions.current.isReload &&
|
|
49
64
|
!options.isReload;
|
|
50
65
|
|
|
51
|
-
|
|
66
|
+
const doForceReload = forceReload && !prevForceReload.current;
|
|
67
|
+
|
|
68
|
+
if (href !== "" && (doForceReload || !isOldReload)) {
|
|
52
69
|
dispatch(loadModularUI(key, href, options));
|
|
53
70
|
}
|
|
54
71
|
|
|
55
72
|
prevOptions.current = options;
|
|
56
73
|
prevHref.current = href;
|
|
57
|
-
|
|
74
|
+
prevForceReload.current = forceReload;
|
|
75
|
+
}, [key, href, options, forceReload]);
|
|
58
76
|
|
|
59
|
-
const { removeOnUnmount = false } = options;
|
|
60
77
|
useEffect(() => {
|
|
61
|
-
|
|
62
|
-
|
|
78
|
+
if (options.removeOnUnmount) {
|
|
79
|
+
return () => {
|
|
63
80
|
dispatch(removeModelByKey(key));
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}, [dispatch, key, removeOnUnmount]);
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
}, [dispatch, key, options.removeOnUnmount]);
|
|
67
84
|
|
|
68
|
-
|
|
69
|
-
return useSelector(
|
|
70
|
-
return state.modularui[key];
|
|
71
|
-
});
|
|
85
|
+
const selector = useMemo(() => (state) => state.modularui[key], [key]);
|
|
86
|
+
return useSelector(selector);
|
|
72
87
|
};
|