@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.
Files changed (185) hide show
  1. package/CHANGELOG.md +63 -0
  2. package/esm/constants/Settings.js +10 -2
  3. package/esm/constants/Settings.js.map +1 -1
  4. package/esm/hooks/useModularUI.js +24 -18
  5. package/esm/hooks/useModularUI.js.map +1 -1
  6. package/esm/hooks/useModularUIBasic.js +52 -41
  7. package/esm/hooks/useModularUIBasic.js.map +1 -1
  8. package/esm/models/concepts/ConceptDetailModel.js +1 -8
  9. package/esm/models/concepts/ConceptDetailModel.js.map +1 -1
  10. package/esm/models/concepts/ConceptIndexModel.js +1 -1
  11. package/esm/models/concepts/ConceptIndexModel.js.map +1 -1
  12. package/esm/models/concepts/ConceptLinkModel.js +8 -9
  13. package/esm/models/concepts/ConceptLinkModel.js.map +1 -1
  14. package/esm/models/concepts/ConceptTypeDetailModel.js +3 -20
  15. package/esm/models/concepts/ConceptTypeDetailModel.js.map +1 -1
  16. package/esm/models/concepts/SourceReferenceCollection.js +3 -1
  17. package/esm/models/concepts/SourceReferenceCollection.js.map +1 -1
  18. package/esm/models/concepts/SourceReferenceModel.js +9 -3
  19. package/esm/models/concepts/SourceReferenceModel.js.map +1 -1
  20. package/esm/models/content/ContentLinkModel.js +10 -4
  21. package/esm/models/content/ContentLinkModel.js.map +1 -1
  22. package/esm/models/content/SectionModel.js +10 -6
  23. package/esm/models/content/SectionModel.js.map +1 -1
  24. package/esm/models/error/ErrorResponse.js +20 -5
  25. package/esm/models/error/ErrorResponse.js.map +1 -1
  26. package/esm/models/href/Href.js +21 -4
  27. package/esm/models/href/Href.js.map +1 -1
  28. package/esm/models/list/ListItemCollection.js +1 -1
  29. package/esm/models/list/ListItemCollection.js.map +1 -1
  30. package/esm/modularui/CaptchaRequest.js +12 -3
  31. package/esm/modularui/CaptchaRequest.js.map +1 -1
  32. package/esm/modularui/ModularUIRequest.js +1 -1
  33. package/esm/modularui/ModularUIRequest.js.map +1 -1
  34. package/esm/modularui/UploadRequest.js +7 -3
  35. package/esm/modularui/UploadRequest.js.map +1 -1
  36. package/esm/redux/_modularui/ModularUIActions.js +11 -9
  37. package/esm/redux/_modularui/ModularUIActions.js.map +1 -1
  38. package/esm/redux/_modularui/ModularUIMiddleware.js +4 -1
  39. package/esm/redux/_modularui/ModularUIMiddleware.js.map +1 -1
  40. package/esm/redux/_modularui/ModularUIReducer.js +2 -1
  41. package/esm/redux/_modularui/ModularUIReducer.js.map +1 -1
  42. package/esm/redux/_modularui/ModularUISelectors.js +7 -6
  43. package/esm/redux/_modularui/ModularUISelectors.js.map +1 -1
  44. package/esm/redux/_modularui/types.js.map +1 -1
  45. package/esm/redux/actions/Application.js +11 -6
  46. package/esm/redux/actions/Application.js.map +1 -1
  47. package/esm/redux/connectors/PanelRenderer.js +0 -2
  48. package/esm/redux/connectors/PanelRenderer.js.map +1 -1
  49. package/esm/utils/helpers/checkResource.js +0 -2
  50. package/esm/utils/helpers/checkResource.js.map +1 -1
  51. package/esm/utils/helpers/repositoryResource.js +6 -5
  52. package/esm/utils/helpers/repositoryResource.js.map +1 -1
  53. package/lib/constants/Settings.js +10 -2
  54. package/lib/constants/Settings.js.flow +8 -2
  55. package/lib/constants/Settings.js.map +1 -1
  56. package/lib/hooks/__tests__/UseModularUIModel.spec.js.flow +11 -4
  57. package/lib/hooks/__tests__/useAuthentication.spec.js.flow +2 -8
  58. package/lib/hooks/__tests__/useForm.spec.js.flow +14 -12
  59. package/lib/hooks/__tests__/useModelCatalog.spec.js.flow +10 -4
  60. package/lib/hooks/__tests__/useModels.spec.js.flow +3 -12
  61. package/lib/hooks/__tests__/useModularUIBasic.spec.js.flow +9 -8
  62. package/lib/hooks/useModularUI.js +23 -17
  63. package/lib/hooks/useModularUI.js.flow +31 -16
  64. package/lib/hooks/useModularUI.js.map +1 -1
  65. package/lib/hooks/useModularUIBasic.js +52 -41
  66. package/lib/hooks/useModularUIBasic.js.flow +66 -50
  67. package/lib/hooks/useModularUIBasic.js.map +1 -1
  68. package/lib/models/concepts/ConceptDetailModel.js +1 -8
  69. package/lib/models/concepts/ConceptDetailModel.js.flow +2 -7
  70. package/lib/models/concepts/ConceptDetailModel.js.map +1 -1
  71. package/lib/models/concepts/ConceptIndexModel.js +1 -1
  72. package/lib/models/concepts/ConceptIndexModel.js.flow +7 -1
  73. package/lib/models/concepts/ConceptIndexModel.js.map +1 -1
  74. package/lib/models/concepts/ConceptLinkModel.js +8 -9
  75. package/lib/models/concepts/ConceptLinkModel.js.flow +14 -9
  76. package/lib/models/concepts/ConceptLinkModel.js.map +1 -1
  77. package/lib/models/concepts/ConceptTypeDetailModel.js +3 -20
  78. package/lib/models/concepts/ConceptTypeDetailModel.js.flow +3 -25
  79. package/lib/models/concepts/ConceptTypeDetailModel.js.map +1 -1
  80. package/lib/models/concepts/SourceReferenceCollection.js +3 -1
  81. package/lib/models/concepts/SourceReferenceCollection.js.flow +8 -1
  82. package/lib/models/concepts/SourceReferenceCollection.js.map +1 -1
  83. package/lib/models/concepts/SourceReferenceModel.js +9 -3
  84. package/lib/models/concepts/SourceReferenceModel.js.flow +19 -3
  85. package/lib/models/concepts/SourceReferenceModel.js.map +1 -1
  86. package/lib/models/concepts/__mock__/conceptindex.js.flow +15 -0
  87. package/lib/models/concepts/__tests__/ConceptIndexModel.spec.js.flow +30 -2
  88. package/lib/models/concepts/__tests__/ConceptTypeDetailModel.spec.js.flow +1 -18
  89. package/lib/models/content/ContentLinkModel.js +9 -4
  90. package/lib/models/content/ContentLinkModel.js.flow +19 -4
  91. package/lib/models/content/ContentLinkModel.js.map +1 -1
  92. package/lib/models/content/SectionModel.js +10 -6
  93. package/lib/models/content/SectionModel.js.flow +31 -5
  94. package/lib/models/content/SectionModel.js.map +1 -1
  95. package/lib/models/error/ErrorResponse.js +20 -5
  96. package/lib/models/error/ErrorResponse.js.flow +34 -5
  97. package/lib/models/error/ErrorResponse.js.map +1 -1
  98. package/lib/models/href/Href.js +21 -4
  99. package/lib/models/href/Href.js.flow +21 -4
  100. package/lib/models/href/Href.js.map +1 -1
  101. package/lib/models/href/__tests__/Href.spec.js.flow +9 -3
  102. package/lib/models/list/ListItemCollection.js +1 -1
  103. package/lib/models/list/ListItemCollection.js.flow +2 -0
  104. package/lib/models/list/ListItemCollection.js.map +1 -1
  105. package/lib/modularui/CaptchaRequest.js +11 -2
  106. package/lib/modularui/CaptchaRequest.js.flow +17 -3
  107. package/lib/modularui/CaptchaRequest.js.map +1 -1
  108. package/lib/modularui/ModularUIRequest.js +1 -1
  109. package/lib/modularui/ModularUIRequest.js.flow +3 -1
  110. package/lib/modularui/ModularUIRequest.js.map +1 -1
  111. package/lib/modularui/UploadRequest.js +6 -2
  112. package/lib/modularui/UploadRequest.js.flow +12 -2
  113. package/lib/modularui/UploadRequest.js.map +1 -1
  114. package/lib/redux/_modularui/ModularUIActions.js +11 -9
  115. package/lib/redux/_modularui/ModularUIActions.js.flow +20 -10
  116. package/lib/redux/_modularui/ModularUIActions.js.map +1 -1
  117. package/lib/redux/_modularui/ModularUIMiddleware.js +3 -0
  118. package/lib/redux/_modularui/ModularUIMiddleware.js.flow +6 -3
  119. package/lib/redux/_modularui/ModularUIMiddleware.js.map +1 -1
  120. package/lib/redux/_modularui/ModularUIReducer.js +2 -1
  121. package/lib/redux/_modularui/ModularUIReducer.js.flow +1 -0
  122. package/lib/redux/_modularui/ModularUIReducer.js.map +1 -1
  123. package/lib/redux/_modularui/ModularUISelectors.js +5 -6
  124. package/lib/redux/_modularui/ModularUISelectors.js.flow +22 -10
  125. package/lib/redux/_modularui/ModularUISelectors.js.map +1 -1
  126. package/lib/redux/_modularui/__tests__/actions.spec.js.flow +1 -4
  127. package/lib/redux/_modularui/types.js.flow +1 -0
  128. package/lib/redux/_modularui/types.js.map +1 -1
  129. package/lib/redux/actions/Application.js +10 -5
  130. package/lib/redux/actions/Application.js.flow +16 -5
  131. package/lib/redux/actions/Application.js.map +1 -1
  132. package/lib/redux/actions/__tests__/Application.spec.js.flow +1 -8
  133. package/lib/redux/actions/__tests__/Authorization.spec.js.flow +0 -4
  134. package/lib/redux/connectors/PanelRenderer.js +0 -2
  135. package/lib/redux/connectors/PanelRenderer.js.flow +0 -1
  136. package/lib/redux/connectors/PanelRenderer.js.map +1 -1
  137. package/lib/utils/helpers/checkResource.js +0 -2
  138. package/lib/utils/helpers/checkResource.js.flow +0 -2
  139. package/lib/utils/helpers/checkResource.js.map +1 -1
  140. package/lib/utils/helpers/repositoryResource.js +6 -5
  141. package/lib/utils/helpers/repositoryResource.js.flow +8 -6
  142. package/lib/utils/helpers/repositoryResource.js.map +1 -1
  143. package/package.json +18 -18
  144. package/src/constants/Settings.js +8 -2
  145. package/src/hooks/__tests__/UseModularUIModel.spec.js +11 -4
  146. package/src/hooks/__tests__/useAuthentication.spec.js +2 -8
  147. package/src/hooks/__tests__/useForm.spec.js +14 -12
  148. package/src/hooks/__tests__/useModelCatalog.spec.js +10 -4
  149. package/src/hooks/__tests__/useModels.spec.js +3 -12
  150. package/src/hooks/__tests__/useModularUIBasic.spec.js +9 -8
  151. package/src/hooks/useModularUI.js +31 -16
  152. package/src/hooks/useModularUIBasic.js +66 -50
  153. package/src/models/concepts/ConceptDetailModel.js +2 -7
  154. package/src/models/concepts/ConceptIndexModel.js +7 -1
  155. package/src/models/concepts/ConceptLinkModel.js +14 -9
  156. package/src/models/concepts/ConceptTypeDetailModel.js +3 -25
  157. package/src/models/concepts/SourceReferenceCollection.js +8 -1
  158. package/src/models/concepts/SourceReferenceModel.js +19 -3
  159. package/src/models/concepts/__mock__/conceptindex.js +15 -0
  160. package/src/models/concepts/__mock__/conceptindex_contributions.json +86 -0
  161. package/src/models/concepts/__mock__/conceptindex_data.json +323 -0
  162. package/src/models/concepts/__mock__/concepttype_hierarchy.json +1 -11
  163. package/src/models/concepts/__tests__/ConceptIndexModel.spec.js +30 -2
  164. package/src/models/concepts/__tests__/ConceptTypeDetailModel.spec.js +1 -18
  165. package/src/models/content/ContentLinkModel.js +19 -4
  166. package/src/models/content/SectionModel.js +31 -5
  167. package/src/models/error/ErrorResponse.js +34 -5
  168. package/src/models/href/Href.js +21 -4
  169. package/src/models/href/__tests__/Href.spec.js +9 -3
  170. package/src/models/list/ListItemCollection.js +2 -0
  171. package/src/modularui/CaptchaRequest.js +17 -3
  172. package/src/modularui/ModularUIRequest.js +3 -1
  173. package/src/modularui/UploadRequest.js +12 -2
  174. package/src/redux/_modularui/ModularUIActions.js +20 -10
  175. package/src/redux/_modularui/ModularUIMiddleware.js +6 -3
  176. package/src/redux/_modularui/ModularUIReducer.js +1 -0
  177. package/src/redux/_modularui/ModularUISelectors.js +22 -10
  178. package/src/redux/_modularui/__tests__/actions.spec.js +1 -4
  179. package/src/redux/_modularui/types.js +1 -0
  180. package/src/redux/actions/Application.js +16 -5
  181. package/src/redux/actions/__tests__/Application.spec.js +1 -8
  182. package/src/redux/actions/__tests__/Authorization.spec.js +0 -4
  183. package/src/redux/connectors/PanelRenderer.js +0 -1
  184. package/src/utils/helpers/checkResource.js +0 -2
  185. 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);
@@ -15,7 +15,6 @@ export const connectPanel: ModularUIConnector = modularui(
15
15
  );
16
16
  }
17
17
 
18
- // TODO SBO: origin and context?
19
18
  const panelHref = href ? new Href(href) : new Href(match.url);
20
19
 
21
20
  if (match && match.isExact) {
@@ -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 // TODO SBO: origin and context?\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;EACA,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":[]}
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 // TODO SBO: origin and context?\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 // TODO SBO: origin and context?\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;EACA,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;EACA,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":[]}
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
- const basePath = (0, _constants.getBasePath)();
16
- if ((0, _startsWith.default)(resourceUrl).call(resourceUrl, basePath)) {
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 `${basePath}${resourceUrl}`;
21
+ return `${origin}${contextPath}${resourceUrl}`;
21
22
  }
22
- return `${basePath}${_constants.RESOURCE_PATH}${resourceUrl}`;
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 = (resourceUrl: string): string => {
9
- const basePath = getBasePath();
10
-
11
- if (resourceUrl.startsWith(basePath)) {
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 `${basePath}${resourceUrl}`;
18
+ return `${origin}${contextPath}${resourceUrl}`;
17
19
  }
18
20
 
19
- return `${basePath}${RESOURCE_PATH}${resourceUrl}`;
21
+ return `${origin}${contextPath}${RESOURCE_PATH}${resourceUrl}`;
20
22
  };
@@ -1 +1 @@
1
- {"version":3,"file":"repositoryResource.js","names":["_constants","require","getRepositoryResourceUrl","resourceUrl","basePath","getBasePath","_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 = (resourceUrl: string): string => {\n const basePath = getBasePath();\n\n if (resourceUrl.startsWith(basePath)) {\n return resourceUrl;\n }\n\n if (resourceUrl.startsWith(RESOURCE_PATH)) {\n return `${basePath}${resourceUrl}`;\n }\n\n return `${basePath}${RESOURCE_PATH}${resourceUrl}`;\n};\n"],"mappings":";;;;;;;;AACA,IAAAA,UAAA,GAAAC,OAAA;AAEA;AACA;AACA;AACA;AACO,MAAMC,wBAAwB,GAAIC,WAAmB,IAAa;EACvE,MAAMC,QAAQ,GAAG,IAAAC,sBAAW,EAAC,CAAC;EAE9B,IAAI,IAAAC,WAAA,CAAAC,OAAA,EAAAJ,WAAW,EAAAK,IAAA,CAAXL,WAAW,EAAYC,QAAQ,CAAC,EAAE;IACpC,OAAOD,WAAW;EACpB;EAEA,IAAI,IAAAG,WAAA,CAAAC,OAAA,EAAAJ,WAAW,EAAAK,IAAA,CAAXL,WAAW,EAAYM,wBAAa,CAAC,EAAE;IACzC,OAAO,GAAGL,QAAQ,GAAGD,WAAW,EAAE;EACpC;EAEA,OAAO,GAAGC,QAAQ,GAAGK,wBAAa,GAAGN,WAAW,EAAE;AACpD,CAAC;AAACO,OAAA,CAAAR,wBAAA,GAAAA,wBAAA","ignoreList":[]}
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-contextpath.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.7",
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.7",
102
- "@babel/core": "^7.25.7",
103
- "@babel/eslint-parser": "^7.25.7",
104
- "@babel/eslint-plugin": "^7.25.7",
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.7",
108
- "@babel/preset-env": "^7.25.7",
109
- "@babel/preset-flow": "^7.25.7",
110
- "@babel/preset-react": "^7.25.7",
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.4.4",
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.1",
128
- "eslint-plugin-react": "^7.37.1",
129
- "eslint-plugin-react-hooks": "^4.6.2",
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.24.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.16.1",
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.4",
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 = (): string => `${getBasePath()}${UPLOAD_PATH}`;
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 = (): string => `${getBasePath()}${CAPTCHA_PATH}`;
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(() => xhrMock.setup());
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 `${modelKey}(${url.split("?")[0]})(${locale})`;
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
- if (href !== "" && !isOldReload) {
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
- }, [key, href, options]);
74
+ prevForceReload.current = forceReload;
75
+ }, [key, href, options, forceReload]);
58
76
 
59
- const { removeOnUnmount = false } = options;
60
77
  useEffect(() => {
61
- return () => {
62
- if (removeOnUnmount) {
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
- // retrieve current model from modularui reducer
69
- return useSelector((state) => {
70
- return state.modularui[key];
71
- });
85
+ const selector = useMemo(() => (state) => state.modularui[key], [key]);
86
+ return useSelector(selector);
72
87
  };