@beinformed/ui 1.57.0-contextpath.1 → 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 (159) hide show
  1. package/CHANGELOG.md +53 -0
  2. package/esm/constants/Settings.js +10 -2
  3. package/esm/constants/Settings.js.map +1 -1
  4. package/esm/hooks/useModularUI.js +19 -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/modularui/CaptchaRequest.js +12 -3
  27. package/esm/modularui/CaptchaRequest.js.map +1 -1
  28. package/esm/modularui/ModularUIRequest.js +1 -1
  29. package/esm/modularui/ModularUIRequest.js.map +1 -1
  30. package/esm/modularui/UploadRequest.js +7 -3
  31. package/esm/modularui/UploadRequest.js.map +1 -1
  32. package/esm/redux/_modularui/ModularUIActions.js +11 -9
  33. package/esm/redux/_modularui/ModularUIActions.js.map +1 -1
  34. package/esm/redux/_modularui/ModularUIMiddleware.js +4 -1
  35. package/esm/redux/_modularui/ModularUIMiddleware.js.map +1 -1
  36. package/esm/redux/_modularui/ModularUIReducer.js +2 -1
  37. package/esm/redux/_modularui/ModularUIReducer.js.map +1 -1
  38. package/esm/redux/_modularui/ModularUISelectors.js +7 -6
  39. package/esm/redux/_modularui/ModularUISelectors.js.map +1 -1
  40. package/esm/redux/_modularui/types.js.map +1 -1
  41. package/esm/redux/connectors/PanelRenderer.js +0 -2
  42. package/esm/redux/connectors/PanelRenderer.js.map +1 -1
  43. package/esm/utils/helpers/repositoryResource.js +6 -5
  44. package/esm/utils/helpers/repositoryResource.js.map +1 -1
  45. package/lib/constants/Settings.js +10 -2
  46. package/lib/constants/Settings.js.flow +8 -2
  47. package/lib/constants/Settings.js.map +1 -1
  48. package/lib/hooks/__tests__/UseModularUIModel.spec.js.flow +11 -4
  49. package/lib/hooks/__tests__/useAuthentication.spec.js.flow +2 -8
  50. package/lib/hooks/__tests__/useForm.spec.js.flow +14 -12
  51. package/lib/hooks/__tests__/useModelCatalog.spec.js.flow +10 -4
  52. package/lib/hooks/__tests__/useModels.spec.js.flow +3 -12
  53. package/lib/hooks/__tests__/useModularUIBasic.spec.js.flow +9 -8
  54. package/lib/hooks/useModularUI.js +18 -17
  55. package/lib/hooks/useModularUI.js.flow +25 -15
  56. package/lib/hooks/useModularUI.js.map +1 -1
  57. package/lib/hooks/useModularUIBasic.js +52 -41
  58. package/lib/hooks/useModularUIBasic.js.flow +66 -50
  59. package/lib/hooks/useModularUIBasic.js.map +1 -1
  60. package/lib/models/concepts/ConceptDetailModel.js +1 -8
  61. package/lib/models/concepts/ConceptDetailModel.js.flow +2 -7
  62. package/lib/models/concepts/ConceptDetailModel.js.map +1 -1
  63. package/lib/models/concepts/ConceptIndexModel.js +1 -1
  64. package/lib/models/concepts/ConceptIndexModel.js.flow +7 -1
  65. package/lib/models/concepts/ConceptIndexModel.js.map +1 -1
  66. package/lib/models/concepts/ConceptLinkModel.js +8 -9
  67. package/lib/models/concepts/ConceptLinkModel.js.flow +14 -9
  68. package/lib/models/concepts/ConceptLinkModel.js.map +1 -1
  69. package/lib/models/concepts/ConceptTypeDetailModel.js +3 -20
  70. package/lib/models/concepts/ConceptTypeDetailModel.js.flow +3 -25
  71. package/lib/models/concepts/ConceptTypeDetailModel.js.map +1 -1
  72. package/lib/models/concepts/SourceReferenceCollection.js +3 -1
  73. package/lib/models/concepts/SourceReferenceCollection.js.flow +8 -1
  74. package/lib/models/concepts/SourceReferenceCollection.js.map +1 -1
  75. package/lib/models/concepts/SourceReferenceModel.js +9 -3
  76. package/lib/models/concepts/SourceReferenceModel.js.flow +19 -3
  77. package/lib/models/concepts/SourceReferenceModel.js.map +1 -1
  78. package/lib/models/concepts/__mock__/conceptindex.js.flow +15 -0
  79. package/lib/models/concepts/__tests__/ConceptIndexModel.spec.js.flow +30 -2
  80. package/lib/models/concepts/__tests__/ConceptTypeDetailModel.spec.js.flow +1 -18
  81. package/lib/models/content/ContentLinkModel.js +9 -4
  82. package/lib/models/content/ContentLinkModel.js.flow +19 -4
  83. package/lib/models/content/ContentLinkModel.js.map +1 -1
  84. package/lib/models/content/SectionModel.js +10 -6
  85. package/lib/models/content/SectionModel.js.flow +31 -5
  86. package/lib/models/content/SectionModel.js.map +1 -1
  87. package/lib/models/error/ErrorResponse.js +20 -5
  88. package/lib/models/error/ErrorResponse.js.flow +34 -5
  89. package/lib/models/error/ErrorResponse.js.map +1 -1
  90. package/lib/modularui/CaptchaRequest.js +11 -2
  91. package/lib/modularui/CaptchaRequest.js.flow +17 -3
  92. package/lib/modularui/CaptchaRequest.js.map +1 -1
  93. package/lib/modularui/ModularUIRequest.js +1 -1
  94. package/lib/modularui/ModularUIRequest.js.flow +3 -1
  95. package/lib/modularui/ModularUIRequest.js.map +1 -1
  96. package/lib/modularui/UploadRequest.js +6 -2
  97. package/lib/modularui/UploadRequest.js.flow +12 -2
  98. package/lib/modularui/UploadRequest.js.map +1 -1
  99. package/lib/redux/_modularui/ModularUIActions.js +11 -9
  100. package/lib/redux/_modularui/ModularUIActions.js.flow +20 -10
  101. package/lib/redux/_modularui/ModularUIActions.js.map +1 -1
  102. package/lib/redux/_modularui/ModularUIMiddleware.js +3 -0
  103. package/lib/redux/_modularui/ModularUIMiddleware.js.flow +6 -3
  104. package/lib/redux/_modularui/ModularUIMiddleware.js.map +1 -1
  105. package/lib/redux/_modularui/ModularUIReducer.js +2 -1
  106. package/lib/redux/_modularui/ModularUIReducer.js.flow +1 -0
  107. package/lib/redux/_modularui/ModularUIReducer.js.map +1 -1
  108. package/lib/redux/_modularui/ModularUISelectors.js +5 -6
  109. package/lib/redux/_modularui/ModularUISelectors.js.flow +22 -10
  110. package/lib/redux/_modularui/ModularUISelectors.js.map +1 -1
  111. package/lib/redux/_modularui/__tests__/actions.spec.js.flow +1 -4
  112. package/lib/redux/_modularui/types.js.flow +1 -0
  113. package/lib/redux/_modularui/types.js.map +1 -1
  114. package/lib/redux/actions/__tests__/Application.spec.js.flow +1 -8
  115. package/lib/redux/actions/__tests__/Authorization.spec.js.flow +0 -4
  116. package/lib/redux/connectors/PanelRenderer.js +0 -2
  117. package/lib/redux/connectors/PanelRenderer.js.flow +0 -1
  118. package/lib/redux/connectors/PanelRenderer.js.map +1 -1
  119. package/lib/utils/helpers/repositoryResource.js +6 -5
  120. package/lib/utils/helpers/repositoryResource.js.flow +8 -6
  121. package/lib/utils/helpers/repositoryResource.js.map +1 -1
  122. package/package.json +18 -18
  123. package/src/constants/Settings.js +8 -2
  124. package/src/hooks/__tests__/UseModularUIModel.spec.js +11 -4
  125. package/src/hooks/__tests__/useAuthentication.spec.js +2 -8
  126. package/src/hooks/__tests__/useForm.spec.js +14 -12
  127. package/src/hooks/__tests__/useModelCatalog.spec.js +10 -4
  128. package/src/hooks/__tests__/useModels.spec.js +3 -12
  129. package/src/hooks/__tests__/useModularUIBasic.spec.js +9 -8
  130. package/src/hooks/useModularUI.js +25 -15
  131. package/src/hooks/useModularUIBasic.js +66 -50
  132. package/src/models/concepts/ConceptDetailModel.js +2 -7
  133. package/src/models/concepts/ConceptIndexModel.js +7 -1
  134. package/src/models/concepts/ConceptLinkModel.js +14 -9
  135. package/src/models/concepts/ConceptTypeDetailModel.js +3 -25
  136. package/src/models/concepts/SourceReferenceCollection.js +8 -1
  137. package/src/models/concepts/SourceReferenceModel.js +19 -3
  138. package/src/models/concepts/__mock__/conceptindex.js +15 -0
  139. package/src/models/concepts/__mock__/conceptindex_contributions.json +86 -0
  140. package/src/models/concepts/__mock__/conceptindex_data.json +323 -0
  141. package/src/models/concepts/__mock__/concepttype_hierarchy.json +1 -11
  142. package/src/models/concepts/__tests__/ConceptIndexModel.spec.js +30 -2
  143. package/src/models/concepts/__tests__/ConceptTypeDetailModel.spec.js +1 -18
  144. package/src/models/content/ContentLinkModel.js +19 -4
  145. package/src/models/content/SectionModel.js +31 -5
  146. package/src/models/error/ErrorResponse.js +34 -5
  147. package/src/modularui/CaptchaRequest.js +17 -3
  148. package/src/modularui/ModularUIRequest.js +3 -1
  149. package/src/modularui/UploadRequest.js +12 -2
  150. package/src/redux/_modularui/ModularUIActions.js +20 -10
  151. package/src/redux/_modularui/ModularUIMiddleware.js +6 -3
  152. package/src/redux/_modularui/ModularUIReducer.js +1 -0
  153. package/src/redux/_modularui/ModularUISelectors.js +22 -10
  154. package/src/redux/_modularui/__tests__/actions.spec.js +1 -4
  155. package/src/redux/_modularui/types.js +1 -0
  156. package/src/redux/actions/__tests__/Application.spec.js +1 -8
  157. package/src/redux/actions/__tests__/Authorization.spec.js +0 -4
  158. package/src/redux/connectors/PanelRenderer.js +0 -1
  159. package/src/utils/helpers/repositoryResource.js +8 -6
@@ -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",
@@ -7,6 +7,7 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports.useModularUI = void 0;
8
8
  var _react = require("react");
9
9
  var _reactRedux = require("react-redux");
10
+ var _reactRouter = require("react-router");
10
11
  var _constants = require("../constants");
11
12
  var _ModularUIActions = require("../redux/_modularui/ModularUIActions");
12
13
  var _useDeepCompareEffect = _interopRequireDefault(require("./useDeepCompareEffect"));
@@ -16,7 +17,7 @@ var _Href = _interopRequireDefault(require("../models/href/Href"));
16
17
  */
17
18
  const useKeyForHook = (modelKey, url) => {
18
19
  const locale = (0, _useI18n.useLocale)();
19
- return `${modelKey}(${url.split("?")[0]})(${locale})`;
20
+ return (0, _react.useMemo)(() => `${modelKey}(${url.split("?")[0]})(${locale})`, [modelKey, url, locale]);
20
21
  };
21
22
 
22
23
  /**
@@ -28,40 +29,40 @@ const useModularUI = function (modelKey, url) {
28
29
  removeOnUnmount: false
29
30
  };
30
31
  const dispatch = (0, _reactRedux.useDispatch)();
31
- const href = url?.toString() || "";
32
+ const href = (0, _react.useMemo)(() => url?.toString() || "", [url]);
32
33
  const key = useKeyForHook(modelKey, href);
33
34
  if (url instanceof _Href.default) {
34
35
  options.origin = options.origin ?? url.origin;
35
36
  options.contextPath = options.contextPath ?? url.contextPath;
36
37
  }
38
+ const location = (0, _reactRouter.useLocation)();
39
+ const redirectLocation = location.state?.redirectLocation;
40
+ const forceReload = redirectLocation instanceof _Href.default ? redirectLocation?.equals(href) : false;
37
41
  const prevOptions = (0, _react.useRef)(options);
38
42
  const prevHref = (0, _react.useRef)(href);
43
+ const prevForceReload = (0, _react.useRef)(forceReload);
39
44
 
40
45
  // dispatch loadModularUI
41
46
  (0, _useDeepCompareEffect.default)(() => {
42
47
  // prevent reloads when previous option had the isReload, but the new options not
43
48
  const isOldReload = prevHref.current === href && prevOptions.current.isReload && !options.isReload;
44
- if (href !== "" && !isOldReload) {
49
+ const doForceReload = forceReload && !prevForceReload.current;
50
+ if (href !== "" && (doForceReload || !isOldReload)) {
45
51
  dispatch((0, _ModularUIActions.loadModularUI)(key, href, options));
46
52
  }
47
53
  prevOptions.current = options;
48
54
  prevHref.current = href;
49
- }, [key, href, options]);
50
- const {
51
- removeOnUnmount = false
52
- } = options;
55
+ prevForceReload.current = forceReload;
56
+ }, [key, href, options, forceReload]);
53
57
  (0, _react.useEffect)(() => {
54
- return () => {
55
- if (removeOnUnmount) {
58
+ if (options.removeOnUnmount) {
59
+ return () => {
56
60
  dispatch((0, _ModularUIActions.removeModelByKey)(key));
57
- }
58
- };
59
- }, [dispatch, key, removeOnUnmount]);
60
-
61
- // retrieve current model from modularui reducer
62
- return (0, _reactRedux.useSelector)(state => {
63
- return state.modularui[key];
64
- });
61
+ };
62
+ }
63
+ }, [dispatch, key, options.removeOnUnmount]);
64
+ const selector = (0, _react.useMemo)(() => state => state.modularui[key], [key]);
65
+ return (0, _reactRedux.useSelector)(selector);
65
66
  };
66
67
  exports.useModularUI = useModularUI;
67
68
  //# sourceMappingURL=useModularUI.js.map
@@ -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 {
@@ -19,7 +20,10 @@ import type { RequestModularUIOptions } from "../utils";
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,7 +38,7 @@ 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
 
40
44
  if (url instanceof Href) {
@@ -42,8 +46,14 @@ export const useModularUI = (
42
46
  options.contextPath = options.contextPath ?? url.contextPath;
43
47
  }
44
48
 
49
+ const location = useLocation();
50
+ const redirectLocation = location.state?.redirectLocation;
51
+ const forceReload =
52
+ redirectLocation instanceof Href ? redirectLocation?.equals(href) : false;
53
+
45
54
  const prevOptions = useRef(options);
46
55
  const prevHref = useRef(href);
56
+ const prevForceReload = useRef(forceReload);
47
57
 
48
58
  // dispatch loadModularUI
49
59
  useDeepCompareEffect(() => {
@@ -53,25 +63,25 @@ export const useModularUI = (
53
63
  prevOptions.current.isReload &&
54
64
  !options.isReload;
55
65
 
56
- if (href !== "" && !isOldReload) {
66
+ const doForceReload = forceReload && !prevForceReload.current;
67
+
68
+ if (href !== "" && (doForceReload || !isOldReload)) {
57
69
  dispatch(loadModularUI(key, href, options));
58
70
  }
59
71
 
60
72
  prevOptions.current = options;
61
73
  prevHref.current = href;
62
- }, [key, href, options]);
74
+ prevForceReload.current = forceReload;
75
+ }, [key, href, options, forceReload]);
63
76
 
64
- const { removeOnUnmount = false } = options;
65
77
  useEffect(() => {
66
- return () => {
67
- if (removeOnUnmount) {
78
+ if (options.removeOnUnmount) {
79
+ return () => {
68
80
  dispatch(removeModelByKey(key));
69
- }
70
- };
71
- }, [dispatch, key, removeOnUnmount]);
81
+ };
82
+ }
83
+ }, [dispatch, key, options.removeOnUnmount]);
72
84
 
73
- // retrieve current model from modularui reducer
74
- return useSelector((state) => {
75
- return state.modularui[key];
76
- });
85
+ const selector = useMemo(() => (state) => state.modularui[key], [key]);
86
+ return useSelector(selector);
77
87
  };
@@ -1 +1 @@
1
- {"version":3,"file":"useModularUI.js","names":["_react","require","_reactRedux","_constants","_ModularUIActions","_useDeepCompareEffect","_interopRequireDefault","_useI18n","_Href","useKeyForHook","modelKey","url","locale","useLocale","split","useModularUI","options","arguments","length","undefined","method","HTTP_METHODS","GET","removeOnUnmount","dispatch","useDispatch","href","toString","key","Href","origin","contextPath","prevOptions","useRef","prevHref","useDeepCompareEffect","isOldReload","current","isReload","loadModularUI","useEffect","removeModelByKey","useSelector","state","modularui","exports"],"sources":["../../src/hooks/useModularUI.js"],"sourcesContent":["// @flow\nimport { useEffect, useRef } from \"react\";\nimport { useDispatch, useSelector } from \"react-redux\";\n\nimport { HTTP_METHODS } from \"../constants\";\nimport {\n loadModularUI,\n removeModelByKey,\n} from \"../redux/_modularui/ModularUIActions\";\n\nimport useDeepCompareEffect from \"./useDeepCompareEffect\";\n\nimport { useLocale } from \"./useI18n\";\nimport Href from \"../models/href/Href\";\n\nimport type { RequestModularUIOptions } from \"../utils\";\n\n/**\n */\nconst useKeyForHook = (modelKey: string, url: string) => {\n const locale = useLocale();\n return `${modelKey}(${url.split(\"?\")[0]})(${locale})`;\n};\n\n/**\n * Use redux action and selector to retrieve the correct modular ui service model\n */\nexport const useModularUI = (\n modelKey: string,\n url: string | Href,\n options: RequestModularUIOptions = {\n method: HTTP_METHODS.GET,\n removeOnUnmount: false,\n },\n): any => {\n const dispatch = useDispatch();\n const href = url?.toString() || \"\";\n const key = useKeyForHook(modelKey, href);\n\n if (url instanceof Href) {\n options.origin = options.origin ?? url.origin;\n options.contextPath = options.contextPath ?? url.contextPath;\n }\n\n const prevOptions = useRef(options);\n const prevHref = useRef(href);\n\n // dispatch loadModularUI\n useDeepCompareEffect(() => {\n // prevent reloads when previous option had the isReload, but the new options not\n const isOldReload =\n prevHref.current === href &&\n prevOptions.current.isReload &&\n !options.isReload;\n\n if (href !== \"\" && !isOldReload) {\n dispatch(loadModularUI(key, href, options));\n }\n\n prevOptions.current = options;\n prevHref.current = href;\n }, [key, href, options]);\n\n const { removeOnUnmount = false } = options;\n useEffect(() => {\n return () => {\n if (removeOnUnmount) {\n dispatch(removeModelByKey(key));\n }\n };\n }, [dispatch, key, removeOnUnmount]);\n\n // retrieve current model from modularui reducer\n return useSelector((state) => {\n return state.modularui[key];\n });\n};\n"],"mappings":";;;;;;;AACA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AAEA,IAAAE,UAAA,GAAAF,OAAA;AACA,IAAAG,iBAAA,GAAAH,OAAA;AAKA,IAAAI,qBAAA,GAAAC,sBAAA,CAAAL,OAAA;AAEA,IAAAM,QAAA,GAAAN,OAAA;AACA,IAAAO,KAAA,GAAAF,sBAAA,CAAAL,OAAA;AAIA;AACA;AACA,MAAMQ,aAAa,GAAGA,CAACC,QAAgB,EAAEC,GAAW,KAAK;EACvD,MAAMC,MAAM,GAAG,IAAAC,kBAAS,EAAC,CAAC;EAC1B,OAAO,GAAGH,QAAQ,IAAIC,GAAG,CAACG,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,KAAKF,MAAM,GAAG;AACvD,CAAC;;AAED;AACA;AACA;AACO,MAAMG,YAAY,GAAG,SAAAA,CAC1BL,QAAgB,EAChBC,GAAkB,EAKV;EAAA,IAJRK,OAAgC,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG;IACjCG,MAAM,EAAEC,uBAAY,CAACC,GAAG;IACxBC,eAAe,E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AC,EAAE,CAACJ,QAAQ,EAAEI,GAAG,EAAEL,eAAe,CAAC,CAAC;;EAEpC;EACA,OAAO,IAAAmB,uBAAW,EAAEC,KAAK,IAAK;IAC5B,OAAOA,KAAK,CAACC,SAAS,CAAChB,GAAG,CAAC;EAC7B,CAAC,CAAC;AACJ,CAAC;AAACiB,OAAA,CAAA9B,YAAA,GAAAA,YAAA","ignoreList":[]}
1
+ {"version":3,"file":"useModularUI.js","names":["_react","require","_reactRedux","_reactRouter","_constants","_ModularUIActions","_useDeepCompareEffect","_interopRequireDefault","_useI18n","_Href","useKeyForHook","modelKey","url","locale","useLocale","useMemo","split","useModularUI","options","arguments","length","undefined","method","HTTP_METHODS","GET","removeOnUnmount","dispatch","useDispatch","href","toString","key","Href","origin","contextPath","location","useLocation","redirectLocation","state","forceReload","equals","prevOptions","useRef","prevHref","prevForceReload","useDeepCompareEffect","isOldReload","current","isReload","doForceReload","loadModularUI","useEffect","removeModelByKey","selector","modularui","useSelector","exports"],"sources":["../../src/hooks/useModularUI.js"],"sourcesContent":["// @flow\nimport { useEffect, useRef, useMemo } from \"react\";\nimport { useDispatch, useSelector } from \"react-redux\";\nimport { useLocation } from \"react-router\";\n\nimport { HTTP_METHODS } from \"../constants\";\nimport {\n loadModularUI,\n removeModelByKey,\n} from \"../redux/_modularui/ModularUIActions\";\n\nimport useDeepCompareEffect from \"./useDeepCompareEffect\";\n\nimport { useLocale } from \"./useI18n\";\nimport Href from \"../models/href/Href\";\n\nimport type { RequestModularUIOptions } from \"../utils\";\n\n/**\n */\nconst useKeyForHook = (modelKey: string, url: string) => {\n const locale = useLocale();\n return useMemo(\n () => `${modelKey}(${url.split(\"?\")[0]})(${locale})`,\n [modelKey, url, locale],\n );\n};\n\n/**\n * Use redux action and selector to retrieve the correct modular ui service model\n */\nexport const useModularUI = (\n modelKey: string,\n url: string | Href,\n options: RequestModularUIOptions = {\n method: HTTP_METHODS.GET,\n removeOnUnmount: false,\n },\n): any => {\n const dispatch = useDispatch();\n const href = useMemo(() => url?.toString() || \"\", [url]);\n const key = useKeyForHook(modelKey, href);\n\n if (url instanceof Href) {\n options.origin = options.origin ?? url.origin;\n options.contextPath = options.contextPath ?? url.contextPath;\n }\n\n const location = useLocation();\n const redirectLocation = location.state?.redirectLocation;\n const forceReload =\n redirectLocation instanceof Href ? redirectLocation?.equals(href) : false;\n\n const prevOptions = useRef(options);\n const prevHref = useRef(href);\n const prevForceReload = useRef(forceReload);\n\n // dispatch loadModularUI\n useDeepCompareEffect(() => {\n // prevent reloads when previous option had the isReload, but the new options not\n const isOldReload =\n prevHref.current === href &&\n prevOptions.current.isReload &&\n !options.isReload;\n\n const doForceReload = forceReload && !prevForceReload.current;\n\n if (href !== \"\" && (doForceReload || !isOldReload)) {\n dispatch(loadModularUI(key, href, options));\n }\n\n prevOptions.current = options;\n prevHref.current = href;\n prevForceReload.current = forceReload;\n }, [key, href, options, forceReload]);\n\n useEffect(() => {\n if (options.removeOnUnmount) {\n return () => {\n dispatch(removeModelByKey(key));\n };\n }\n }, [dispatch, key, options.removeOnUnmount]);\n\n const selector = useMemo(() => (state) => state.modularui[key], [key]);\n return useSelector(selector);\n};\n"],"mappings":";;;;;;;AACA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AACA,IAAAE,YAAA,GAAAF,OAAA;AAEA,IAAAG,UAAA,GAAAH,OAAA;AACA,IAAAI,iBAAA,GAAAJ,OAAA;AAKA,IAAAK,qBAAA,GAAAC,sBAAA,CAAAN,OAAA;AAEA,IAAAO,QAAA,GAAAP,OAAA;AACA,IAAAQ,KAAA,GAAAF,sBAAA,CAAAN,OAAA;AAIA;AACA;AACA,MAAMS,aAAa,GAAGA,CAACC,QAAgB,EAAEC,GAAW,KAAK;EACvD,MAAMC,MAAM,GAAG,IAAAC,kBAAS,EAAC,CAAC;EAC1B,OAAO,IAAAC,cAAO,EACZ,MAAM,GAAGJ,QAAQ,IAAIC,GAAG,CAACI,KAAK,CAAC,G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IAAAM,6BAAoB,EAAC,MAAM;IACzB;IACA,MAAMC,WAAW,GACfH,QAAQ,CAACI,OAAO,KAAKlB,IAAI,IACzBY,WAAW,CAACM,OAAO,CAACC,QAAQ,IAC5B,CAAC7B,OAAO,CAAC6B,QAAQ;IAEnB,MAAMC,aAAa,GAAGV,WAAW,IAAI,CAACK,eAAe,CAACG,OAAO;IAE7D,IAAIlB,IAAI,KAAK,EAAE,KAAKoB,aAAa,IAAI,CAACH,WAAW,CAAC,EAAE;MAClDnB,QAAQ,CAAC,IAAAuB,+BAAa,EAACnB,GAAG,EAAEF,IAAI,EAAEV,OAAO,CAAC,CAAC;IAC7C;IAEAsB,WAAW,CAACM,OAAO,GAAG5B,OAAO;IAC7BwB,QAAQ,CAACI,OAAO,GAAGlB,IAAI;IACvBe,eAAe,CAACG,OAAO,GAAGR,WAAW;EACvC,CAAC,EAAE,CAACR,GAAG,EAAEF,IAAI,EAAEV,OAAO,EAAEoB,WAAW,CAAC,CAAC;EAErC,IAAAY,gBAAS,EAAC,MAAM;IACd,IAAIhC,OAAO,CAACO,eAAe,EAAE;MAC3B,OAAO,MAAM;QACXC,QAAQ,CAAC,IAAAyB,kCAAgB,EAACrB,GAAG,CAAC,CAAC;MACjC,CAAC;IACH;EACF,CAAC,EAAE,CAACJ,QAAQ,EAAEI,GAAG,EAAEZ,OAAO,CAACO,eAAe,CAAC,CAAC;EAE5C,MAAM2B,QAAQ,GAAG,IAAArC,cAAO,EAAC,MAAOsB,KAAK,IAAKA,KAAK,CAACgB,SAAS,CAACvB,GAAG,CAAC,EAAE,CAACA,GAAG,CAAC,CAAC;EACtE,OAAO,IAAAwB,uBAAW,EAACF,QAAQ,CAAC;AAC9B,CAAC;AAACG,OAAA,CAAAtC,YAAA,GAAAA,YAAA","ignoreList":[]}
@@ -6,22 +6,14 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.useModularUIBasic = void 0;
8
8
  var _startsWith = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/starts-with"));
9
+ var _react = require("react");
9
10
  var _useModularUI = require("./useModularUI");
10
11
  var _useRouter = require("./useRouter");
11
12
  var _exceptions = require("../exceptions");
12
- /**
13
- */
14
- const useModularUIBasic = function (key, href) {
13
+ // Helper to create useModularUI options
14
+ const createUseModularUIOptions = (options, href, location) => {
15
15
  var _context;
16
- let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {
17
- expectedModels: [],
18
- targetModel: undefined,
19
- forceTargetModel: false,
20
- origin: undefined,
21
- contextPath: undefined
22
- };
23
- const location = (0, _useRouter.useLocation)();
24
- const useModularUIOptions = {
16
+ const baseOptions = {
25
17
  targetModel: undefined,
26
18
  forceTargetModel: undefined,
27
19
  isReload: false,
@@ -29,44 +21,63 @@ const useModularUIBasic = function (key, href) {
29
21
  contextPath: undefined,
30
22
  cache: false
31
23
  };
24
+
25
+ // Handle targetModel and forceTargetModel
32
26
  if (options.targetModel) {
33
- useModularUIOptions.targetModel = options.targetModel;
34
- useModularUIOptions.forceTargetModel = options.forceTargetModel;
27
+ baseOptions.targetModel = options.targetModel;
28
+ baseOptions.forceTargetModel = options.forceTargetModel;
35
29
  }
30
+
31
+ // Handle cache option
36
32
  if (options.cache) {
37
- useModularUIOptions.cache = options.cache;
33
+ baseOptions.cache = options.cache;
38
34
  }
39
35
 
40
- // reload when the modular service starts with the current location
41
- if (location.state?.reload && (0, _startsWith.default)(_context = location.pathname).call(_context, href.toString())) {
42
- useModularUIOptions.isReload = true;
43
- }
44
- if (options.origin) {
45
- useModularUIOptions.origin = options.origin;
46
- }
47
- if (options.contextPath) {
48
- useModularUIOptions.contextPath = options.contextPath;
36
+ // Check for reload if location matches href
37
+ if (location.state?.reload && (0, _startsWith.default)(_context = location.pathname).call(_context, href)) {
38
+ baseOptions.isReload = true;
49
39
  }
50
40
 
51
- // $FlowFixMe[incompatible-call]
52
- const modularUI = (0, _useModularUI.useModularUI)(key, href, useModularUIOptions);
53
- if (modularUI?.model) {
54
- const {
55
- model
56
- } = modularUI;
57
- const expectedModels = options.expectedModels ?? [];
58
- if (expectedModels.length > 0) {
59
- const isCorrectModel = expectedModels.some(expectedModel => {
60
- return model.type === expectedModel;
61
- });
62
- if (!isCorrectModel) {
63
- console.error(modularUI, "is not of instance", expectedModels);
64
- throw new _exceptions.IllegalStateException("Resolved model has incorrect type");
65
- }
41
+ // Handle origin and contextPath options
42
+ baseOptions.origin = options.origin ?? baseOptions.origin;
43
+ baseOptions.contextPath = options.contextPath ?? baseOptions.contextPath;
44
+ return baseOptions;
45
+ };
46
+
47
+ // Helper to validate the model against expectedModels
48
+ const validateModel = (model, expectedModels) => {
49
+ if (expectedModels.length > 0) {
50
+ const isCorrectModel = expectedModels.some(expectedModel => model.type === expectedModel);
51
+ if (!isCorrectModel) {
52
+ console.error(model, "is not of instance", expectedModels);
53
+ throw new _exceptions.IllegalStateException("Resolved model has incorrect type");
66
54
  }
67
- return model;
68
55
  }
69
- return null;
56
+ };
57
+
58
+ /**
59
+ * useModularUIBasic Hook
60
+ */
61
+ const useModularUIBasic = function (key, href) {
62
+ let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {
63
+ expectedModels: [],
64
+ targetModel: undefined,
65
+ forceTargetModel: false,
66
+ origin: undefined,
67
+ contextPath: undefined
68
+ };
69
+ const location = (0, _useRouter.useLocation)();
70
+ const memoizedHref = (0, _react.useMemo)(() => href.toString(), [href]);
71
+ const useModularUIOptions = (0, _react.useMemo)(() => createUseModularUIOptions(options, memoizedHref, location), [options, memoizedHref, location]);
72
+ const modularUI = (0, _useModularUI.useModularUI)(key, memoizedHref, useModularUIOptions);
73
+ const expectedModels = (0, _react.useMemo)(() => options.expectedModels ?? [], [options.expectedModels]);
74
+ return (0, _react.useMemo)(() => {
75
+ if (modularUI?.model) {
76
+ validateModel(modularUI.model, expectedModels);
77
+ return modularUI.model;
78
+ }
79
+ return null;
80
+ }, [expectedModels, modularUI]);
70
81
  };
71
82
  exports.useModularUIBasic = useModularUIBasic;
72
83
  //# sourceMappingURL=useModularUIBasic.js.map
@@ -1,10 +1,8 @@
1
1
  // @flow
2
+ import { useMemo } from "react";
2
3
  import { useModularUI } from "./useModularUI";
3
-
4
4
  import { useLocation } from "./useRouter";
5
-
6
5
  import { IllegalStateException } from "../exceptions";
7
-
8
6
  import type { ModularUIModel, Href } from "../models";
9
7
 
10
8
  export type UseModularUIBasicOptions<T: ModularUIModel> = {
@@ -16,22 +14,13 @@ export type UseModularUIBasicOptions<T: ModularUIModel> = {
16
14
  cache?: boolean,
17
15
  };
18
16
 
19
- /**
20
- */
21
- export const useModularUIBasic = <T: ModularUIModel>(
22
- key: string,
23
- href: string | Href,
24
- options: UseModularUIBasicOptions<T> = {
25
- expectedModels: [],
26
- targetModel: undefined,
27
- forceTargetModel: false,
28
- origin: undefined,
29
- contextPath: undefined,
30
- },
31
- ): T | null => {
32
- const location = useLocation();
33
-
34
- const useModularUIOptions = {
17
+ // Helper to create useModularUI options
18
+ const createUseModularUIOptions = <T: ModularUIModel>(
19
+ options: UseModularUIBasicOptions<T>,
20
+ href: string,
21
+ location: any,
22
+ ): Object => {
23
+ const baseOptions = {
35
24
  targetModel: undefined,
36
25
  forceTargetModel: undefined,
37
26
  isReload: false,
@@ -39,48 +28,75 @@ export const useModularUIBasic = <T: ModularUIModel>(
39
28
  contextPath: undefined,
40
29
  cache: false,
41
30
  };
31
+
32
+ // Handle targetModel and forceTargetModel
42
33
  if (options.targetModel) {
43
- useModularUIOptions.targetModel = options.targetModel;
44
- useModularUIOptions.forceTargetModel = options.forceTargetModel;
34
+ baseOptions.targetModel = options.targetModel;
35
+ baseOptions.forceTargetModel = options.forceTargetModel;
45
36
  }
46
37
 
38
+ // Handle cache option
47
39
  if (options.cache) {
48
- useModularUIOptions.cache = options.cache;
49
- }
50
-
51
- // reload when the modular service starts with the current location
52
- if (location.state?.reload && location.pathname.startsWith(href.toString())) {
53
- useModularUIOptions.isReload = true;
40
+ baseOptions.cache = options.cache;
54
41
  }
55
42
 
56
- if (options.origin) {
57
- useModularUIOptions.origin = options.origin;
43
+ // Check for reload if location matches href
44
+ if (location.state?.reload && location.pathname.startsWith(href)) {
45
+ baseOptions.isReload = true;
58
46
  }
59
47
 
60
- if (options.contextPath) {
61
- useModularUIOptions.contextPath = options.contextPath;
62
- }
63
-
64
- // $FlowFixMe[incompatible-call]
65
- const modularUI = useModularUI(key, href, useModularUIOptions);
66
-
67
- if (modularUI?.model) {
68
- const { model } = modularUI;
48
+ // Handle origin and contextPath options
49
+ baseOptions.origin = options.origin ?? baseOptions.origin;
50
+ baseOptions.contextPath = options.contextPath ?? baseOptions.contextPath;
69
51
 
70
- const expectedModels = options.expectedModels ?? [];
71
- if (expectedModels.length > 0) {
72
- const isCorrectModel = expectedModels.some((expectedModel) => {
73
- return model.type === expectedModel;
74
- });
52
+ return baseOptions;
53
+ };
75
54
 
76
- if (!isCorrectModel) {
77
- console.error(modularUI, "is not of instance", expectedModels);
78
- throw new IllegalStateException("Resolved model has incorrect type");
79
- }
55
+ // Helper to validate the model against expectedModels
56
+ const validateModel = (model: any, expectedModels: Array<string>) => {
57
+ if (expectedModels.length > 0) {
58
+ const isCorrectModel = expectedModels.some(
59
+ (expectedModel) => model.type === expectedModel,
60
+ );
61
+ if (!isCorrectModel) {
62
+ console.error(model, "is not of instance", expectedModels);
63
+ throw new IllegalStateException("Resolved model has incorrect type");
80
64
  }
81
-
82
- return model;
83
65
  }
66
+ };
84
67
 
85
- return null;
68
+ /**
69
+ * useModularUIBasic Hook
70
+ */
71
+ export const useModularUIBasic = <T: ModularUIModel>(
72
+ key: string,
73
+ href: string | Href,
74
+ options: UseModularUIBasicOptions<T> = {
75
+ expectedModels: [],
76
+ targetModel: undefined,
77
+ forceTargetModel: false,
78
+ origin: undefined,
79
+ contextPath: undefined,
80
+ },
81
+ ): T | null => {
82
+ const location = useLocation();
83
+ const memoizedHref = useMemo(() => href.toString(), [href]);
84
+ const useModularUIOptions = useMemo(
85
+ () => createUseModularUIOptions(options, memoizedHref, location),
86
+ [options, memoizedHref, location],
87
+ );
88
+
89
+ const modularUI = useModularUI(key, memoizedHref, useModularUIOptions);
90
+ const expectedModels = useMemo(
91
+ () => options.expectedModels ?? [],
92
+ [options.expectedModels],
93
+ );
94
+
95
+ return useMemo((): T | null => {
96
+ if (modularUI?.model) {
97
+ validateModel(modularUI.model, expectedModels);
98
+ return modularUI.model;
99
+ }
100
+ return null;
101
+ }, [expectedModels, modularUI]);
86
102
  };
@@ -1 +1 @@
1
- {"version":3,"file":"useModularUIBasic.js","names":["_useModularUI","require","_useRouter","_exceptions","useModularUIBasic","key","href","_context","options","arguments","length","undefined","expectedModels","targetModel","forceTargetModel","origin","contextPath","location","useLocation","useModularUIOptions","isReload","cache","state","reload","_startsWith","default","pathname","call","toString","modularUI","useModularUI","model","isCorrectModel","some","expectedModel","type","console","error","IllegalStateException","exports"],"sources":["../../src/hooks/useModularUIBasic.js"],"sourcesContent":["// @flow\nimport { useModularUI } from \"./useModularUI\";\n\nimport { useLocation } from \"./useRouter\";\n\nimport { IllegalStateException } from \"../exceptions\";\n\nimport type { ModularUIModel, Href } from \"../models\";\n\nexport type UseModularUIBasicOptions<T: ModularUIModel> = {\n expectedModels?: Array<string>,\n targetModel?: Class<T> | Array<Class<T>>,\n forceTargetModel?: boolean,\n origin?: string,\n contextPath?: string,\n cache?: boolean,\n};\n\n/**\n */\nexport const useModularUIBasic = <T: ModularUIModel>(\n key: string,\n href: string | Href,\n options: UseModularUIBasicOptions<T> = {\n expectedModels: [],\n targetModel: undefined,\n forceTargetModel: false,\n origin: undefined,\n contextPath: undefined,\n },\n): T | null => {\n const location = useLocation();\n\n const useModularUIOptions = {\n targetModel: undefined,\n forceTargetModel: undefined,\n isReload: false,\n origin: undefined,\n contextPath: undefined,\n cache: false,\n };\n if (options.targetModel) {\n useModularUIOptions.targetModel = options.targetModel;\n useModularUIOptions.forceTargetModel = options.forceTargetModel;\n }\n\n if (options.cache) {\n useModularUIOptions.cache = options.cache;\n }\n\n // reload when the modular service starts with the current location\n if (location.state?.reload && location.pathname.startsWith(href.toString())) {\n useModularUIOptions.isReload = true;\n }\n\n if (options.origin) {\n useModularUIOptions.origin = options.origin;\n }\n\n if (options.contextPath) {\n useModularUIOptions.contextPath = options.contextPath;\n }\n\n // $FlowFixMe[incompatible-call]\n const modularUI = useModularUI(key, href, useModularUIOptions);\n\n if (modularUI?.model) {\n const { model } = modularUI;\n\n const expectedModels = options.expectedModels ?? [];\n if (expectedModels.length > 0) {\n const isCorrectModel = expectedModels.some((expectedModel) => {\n return model.type === expectedModel;\n });\n\n if (!isCorrectModel) {\n console.error(modularUI, \"is not of instance\", expectedModels);\n throw new IllegalStateException(\"Resolved model has incorrect type\");\n }\n }\n\n return model;\n }\n\n return null;\n};\n"],"mappings":";;;;;;;;AACA,IAAAA,aAAA,GAAAC,OAAA;AAEA,IAAAC,UAAA,GAAAD,OAAA;AAEA,IAAAE,WAAA,GAAAF,OAAA;AAaA;AACA;AACO,MAAMG,iBAAiB,GAAG,SAAAA,CAC/BC,GAAW,EACXC,IAAmB,EAQN;EAAA,IAAAC,QAAA;EAAA,IAPbC,OAAoC,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG;IACrCG,cAAc,EAAE,EAAE;IAClBC,WAAW,EAAEF,SAAS;IACtBG,gBAAgB,EAAE,KAAK;IACvBC,MAAM,EAAEJ,SAAS;IACjBK,WAAW,EAAEL;EACf,CAAC;EAED,MAAMM,QAAQ,GAAG,IAAAC,sBAAW,EAAC,CAAC;EAE9B,MAAMC,mBAAmB,GAAG;IAC1BN,WAAW,EAAEF,SAAS;IACtBG,gBAAgB,EAAEH,SAAS;IAC3BS,QAAQ,EAAE,KAAK;IACfL,MAAM,EAAEJ,SAAS;IACjBK,WAAW,EAAEL,SAAS;IACtBU,KAAK,EAAE;EACT,CAAC;EACD,IAAIb,OAAO,CAACK,WAAW,EAAE;IACvBM,mBAAmB,CAACN,WAAW,G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P,KAAK;EACd;EAEA,OAAO,IAAI;AACb,CAAC;AAACQ,OAAA,CAAAnC,iBAAA,GAAAA,iBAAA","ignoreList":[]}
1
+ {"version":3,"file":"useModularUIBasic.js","names":["_react","require","_useModularUI","_useRouter","_exceptions","createUseModularUIOptions","options","href","location","_context","baseOptions","targetModel","undefined","forceTargetModel","isReload","origin","contextPath","cache","state","reload","_startsWith","default","pathname","call","validateModel","model","expectedModels","length","isCorrectModel","some","expectedModel","type","console","error","IllegalStateException","useModularUIBasic","key","arguments","useLocation","memoizedHref","useMemo","toString","useModularUIOptions","modularUI","useModularUI","exports"],"sources":["../../src/hooks/useModularUIBasic.js"],"sourcesContent":["// @flow\nimport { useMemo } from \"react\";\nimport { useModularUI } from \"./useModularUI\";\nimport { useLocation } from \"./useRouter\";\nimport { IllegalStateException } from \"../exceptions\";\nimport type { ModularUIModel, Href } from \"../models\";\n\nexport type UseModularUIBasicOptions<T: ModularUIModel> = {\n expectedModels?: Array<string>,\n targetModel?: Class<T> | Array<Class<T>>,\n forceTargetModel?: boolean,\n origin?: string,\n contextPath?: string,\n cache?: boolean,\n};\n\n// Helper to create useModularUI options\nconst createUseModularUIOptions = <T: ModularUIModel>(\n options: UseModularUIBasicOptions<T>,\n href: string,\n location: any,\n): Object => {\n const baseOptions = {\n targetModel: undefined,\n forceTargetModel: undefined,\n isReload: false,\n origin: undefined,\n contextPath: undefined,\n cache: false,\n };\n\n // Handle targetModel and forceTargetModel\n if (options.targetModel) {\n baseOptions.targetModel = options.targetModel;\n baseOptions.forceTargetModel = options.forceTargetModel;\n }\n\n // Handle cache option\n if (options.cache) {\n baseOptions.cache = options.cache;\n }\n\n // Check for reload if location matches href\n if (location.state?.reload && location.pathname.startsWith(href)) {\n baseOptions.isReload = true;\n }\n\n // Handle origin and contextPath options\n baseOptions.origin = options.origin ?? baseOptions.origin;\n baseOptions.contextPath = options.contextPath ?? baseOptions.contextPath;\n\n return baseOptions;\n};\n\n// Helper to validate the model against expectedModels\nconst validateModel = (model: any, expectedModels: Array<string>) => {\n if (expectedModels.length > 0) {\n const isCorrectModel = expectedModels.some(\n (expectedModel) => model.type === expectedModel,\n );\n if (!isCorrectModel) {\n console.error(model, \"is not of instance\", expectedModels);\n throw new IllegalStateException(\"Resolved model has incorrect type\");\n }\n }\n};\n\n/**\n * useModularUIBasic Hook\n */\nexport const useModularUIBasic = <T: ModularUIModel>(\n key: string,\n href: string | Href,\n options: UseModularUIBasicOptions<T> = {\n expectedModels: [],\n targetModel: undefined,\n forceTargetModel: false,\n origin: undefined,\n contextPath: undefined,\n },\n): T | null => {\n const location = useLocation();\n const memoizedHref = useMemo(() => href.toString(), [href]);\n const useModularUIOptions = useMemo(\n () => createUseModularUIOptions(options, memoizedHref, location),\n [options, memoizedHref, location],\n );\n\n const modularUI = useModularUI(key, memoizedHref, useModularUIOptions);\n const expectedModels = useMemo(\n () => options.expectedModels ?? [],\n [options.expectedModels],\n );\n\n return useMemo((): T | null => {\n if (modularUI?.model) {\n validateModel(modularUI.model, expectedModels);\n return modularUI.model;\n }\n return null;\n }, [expectedModels, modularUI]);\n};\n"],"mappings":";;;;;;;;AACA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,aAAA,GAAAD,OAAA;AACA,IAAAE,UAAA,GAAAF,OAAA;AACA,IAAAG,WAAA,GAAAH,OAAA;AAYA;AACA,MAAMI,yBAAyB,GAAGA,CAChCC,OAAoC,EACpCC,IAAY,EACZC,QAAa,KACF;EAAA,IAAAC,QAAA;EACX,MAAMC,WAAW,GAAG;IAClBC,WAAW,EAAEC,SAAS;IACtBC,gBAAgB,EAAED,SAAS;IAC3BE,QAAQ,EAAE,KAAK;IACfC,MAAM,EAAEH,SAAS;IACjBI,WAAW,EAAEJ,SAAS;IACtBK,KAAK,EAAE;EACT,CAAC;;EAED;EACA,IAAIX,OAAO,CAACK,WAAW,EAAE;IACvBD,WAAW,CAACC,WAAW,GAAGL,OAAO,CAACK,WAAW;IAC7CD,WAAW,CAACG,gBAAgB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AW,EAAEJ;EACf,CAAC;EAED,MAAMJ,QAAQ,GAAG,IAAA8B,sBAAW,EAAC,CAAC;EAC9B,MAAMC,YAAY,GAAG,IAAAC,cAAO,EAAC,MAAMjC,IAAI,CAACkC,QAAQ,CAAC,CAAC,EAAE,CAAClC,IAAI,CAAC,CAAC;EAC3D,MAAMmC,mBAAmB,GAAG,IAAAF,cAAO,EACjC,MAAMnC,yBAAyB,CAACC,OAAO,EAAEiC,YAAY,EAAE/B,QAAQ,CAAC,EAChE,CAACF,OAAO,EAAEiC,YAAY,EAAE/B,QAAQ,CAClC,CAAC;EAED,MAAMmC,SAAS,GAAG,IAAAC,0BAAY,EAACR,GAAG,EAAEG,YAAY,EAAEG,mBAAmB,CAAC;EACtE,MAAMhB,cAAc,GAAG,IAAAc,cAAO,EAC5B,MAAMlC,OAAO,CAACoB,cAAc,IAAI,EAAE,EAClC,CAACpB,OAAO,CAACoB,cAAc,CACzB,CAAC;EAED,OAAO,IAAAc,cAAO,EAAC,MAAgB;IAC7B,IAAIG,SAAS,EAAElB,KAAK,EAAE;MACpBD,aAAa,CAACmB,SAAS,CAAClB,KAAK,EAAEC,cAAc,CAAC;MAC9C,OAAOiB,SAAS,CAAClB,KAAK;IACxB;IACA,OAAO,IAAI;EACb,CAAC,EAAE,CAACC,cAAc,EAAEiB,SAAS,CAAC,CAAC;AACjC,CAAC;AAACE,OAAA,CAAAV,iBAAA,GAAAA,iBAAA","ignoreList":[]}
@@ -230,7 +230,7 @@ class ConceptDetailModel extends _ResourceModel.default {
230
230
  getSourceReferenceCollection() {
231
231
  let availableLocales = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
232
232
  if (!this._sourceReferences) {
233
- this._sourceReferences = new _SourceReferenceCollection.default(this.getSourceReferencesForCurrentLanguage(availableLocales), this.entryDate);
233
+ this._sourceReferences = new _SourceReferenceCollection.default(this.getSourceReferencesForCurrentLanguage(availableLocales), this.entryDate, this.origin, this.contextPath);
234
234
  }
235
235
  return this._sourceReferences;
236
236
  }
@@ -276,13 +276,6 @@ class ConceptDetailModel extends _ResourceModel.default {
276
276
  isOfConceptType(conceptTypeId) {
277
277
  return this.conceptType?.isOfConceptType(conceptTypeId) ?? false;
278
278
  }
279
-
280
- /**
281
- * Indicates if the given metamodel functional identifier exists in the hierarchy of concept types for this concept
282
- */
283
- hasMetamodelIdInConceptTypeHierarchy(metamodelId) {
284
- return this.conceptType?.hasMetamodelIdInHierarchy(metamodelId) ?? false;
285
- }
286
279
  }
287
280
  exports.default = ConceptDetailModel;
288
281
  //# sourceMappingURL=ConceptDetailModel.js.map
@@ -273,6 +273,8 @@ export default class ConceptDetailModel extends ResourceModel {
273
273
  this._sourceReferences = new SourceReferenceCollection(
274
274
  this.getSourceReferencesForCurrentLanguage(availableLocales),
275
275
  this.entryDate,
276
+ this.origin,
277
+ this.contextPath,
276
278
  );
277
279
  }
278
280
 
@@ -338,11 +340,4 @@ export default class ConceptDetailModel extends ResourceModel {
338
340
  isOfConceptType(conceptTypeId: string): boolean {
339
341
  return this.conceptType?.isOfConceptType(conceptTypeId) ?? false;
340
342
  }
341
-
342
- /**
343
- * Indicates if the given metamodel functional identifier exists in the hierarchy of concept types for this concept
344
- */
345
- hasMetamodelIdInConceptTypeHierarchy(metamodelId: string): boolean {
346
- return this.conceptType?.hasMetamodelIdInHierarchy(metamodelId) ?? false;
347
- }
348
343
  }