@beinformed/ui 1.56.2 → 1.56.5

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 (60) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/esm/hooks/useModularUI.js +20 -18
  3. package/esm/hooks/useModularUI.js.map +1 -1
  4. package/esm/hooks/useModularUIBasic.js +18 -16
  5. package/esm/hooks/useModularUIBasic.js.map +1 -1
  6. package/esm/models/concepts/ConceptTypeDetailModel.js +2 -2
  7. package/esm/models/concepts/ConceptTypeDetailModel.js.map +1 -1
  8. package/esm/redux/_modularui/ModularUIActions.js +10 -8
  9. package/esm/redux/_modularui/ModularUIActions.js.map +1 -1
  10. package/esm/redux/_modularui/ModularUIMiddleware.js +4 -1
  11. package/esm/redux/_modularui/ModularUIMiddleware.js.map +1 -1
  12. package/esm/redux/_modularui/ModularUIReducer.js +2 -1
  13. package/esm/redux/_modularui/ModularUIReducer.js.map +1 -1
  14. package/esm/redux/_modularui/types.js.map +1 -1
  15. package/lib/hooks/__tests__/UseModularUIModel.spec.js.flow +11 -4
  16. package/lib/hooks/__tests__/useAuthentication.spec.js.flow +2 -8
  17. package/lib/hooks/__tests__/useForm.spec.js.flow +14 -12
  18. package/lib/hooks/__tests__/useModelCatalog.spec.js.flow +10 -4
  19. package/lib/hooks/__tests__/useModels.spec.js.flow +3 -12
  20. package/lib/hooks/__tests__/useModularUIBasic.spec.js.flow +9 -8
  21. package/lib/hooks/useModularUI.js +19 -17
  22. package/lib/hooks/useModularUI.js.flow +26 -16
  23. package/lib/hooks/useModularUI.js.map +1 -1
  24. package/lib/hooks/useModularUIBasic.js +18 -16
  25. package/lib/hooks/useModularUIBasic.js.flow +23 -16
  26. package/lib/hooks/useModularUIBasic.js.map +1 -1
  27. package/lib/models/concepts/ConceptTypeDetailModel.js +2 -2
  28. package/lib/models/concepts/ConceptTypeDetailModel.js.flow +2 -2
  29. package/lib/models/concepts/ConceptTypeDetailModel.js.map +1 -1
  30. package/lib/redux/_modularui/ModularUIActions.js +10 -8
  31. package/lib/redux/_modularui/ModularUIActions.js.flow +14 -9
  32. package/lib/redux/_modularui/ModularUIActions.js.map +1 -1
  33. package/lib/redux/_modularui/ModularUIMiddleware.js +3 -0
  34. package/lib/redux/_modularui/ModularUIMiddleware.js.flow +6 -3
  35. package/lib/redux/_modularui/ModularUIMiddleware.js.map +1 -1
  36. package/lib/redux/_modularui/ModularUIReducer.js +2 -1
  37. package/lib/redux/_modularui/ModularUIReducer.js.flow +1 -0
  38. package/lib/redux/_modularui/ModularUIReducer.js.map +1 -1
  39. package/lib/redux/_modularui/__tests__/actions.spec.js.flow +1 -4
  40. package/lib/redux/_modularui/types.js.flow +1 -0
  41. package/lib/redux/_modularui/types.js.map +1 -1
  42. package/lib/redux/actions/__tests__/Application.spec.js.flow +1 -8
  43. package/lib/redux/actions/__tests__/Authorization.spec.js.flow +0 -4
  44. package/package.json +9 -9
  45. package/src/hooks/__tests__/UseModularUIModel.spec.js +11 -4
  46. package/src/hooks/__tests__/useAuthentication.spec.js +2 -8
  47. package/src/hooks/__tests__/useForm.spec.js +14 -12
  48. package/src/hooks/__tests__/useModelCatalog.spec.js +10 -4
  49. package/src/hooks/__tests__/useModels.spec.js +3 -12
  50. package/src/hooks/__tests__/useModularUIBasic.spec.js +9 -8
  51. package/src/hooks/useModularUI.js +26 -16
  52. package/src/hooks/useModularUIBasic.js +23 -16
  53. package/src/models/concepts/ConceptTypeDetailModel.js +2 -2
  54. package/src/redux/_modularui/ModularUIActions.js +14 -9
  55. package/src/redux/_modularui/ModularUIMiddleware.js +6 -3
  56. package/src/redux/_modularui/ModularUIReducer.js +1 -0
  57. package/src/redux/_modularui/__tests__/actions.spec.js +1 -4
  58. package/src/redux/_modularui/types.js +1 -0
  59. package/src/redux/actions/__tests__/Application.spec.js +1 -8
  60. package/src/redux/actions/__tests__/Authorization.spec.js +0 -4
@@ -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",
@@ -7,15 +7,17 @@ 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"));
13
14
  var _useI18n = require("./useI18n");
15
+ var _Href = _interopRequireDefault(require("../models/href/Href"));
14
16
  /**
15
17
  */
16
18
  const useKeyForHook = (modelKey, url) => {
17
19
  const locale = (0, _useI18n.useLocale)();
18
- return `${modelKey}(${url.split("?")[0]})(${locale})`;
20
+ return (0, _react.useMemo)(() => `${modelKey}(${url.split("?")[0]})(${locale})`, [modelKey, url, locale]);
19
21
  };
20
22
 
21
23
  /**
@@ -27,36 +29,36 @@ const useModularUI = function (modelKey, url) {
27
29
  removeOnUnmount: false
28
30
  };
29
31
  const dispatch = (0, _reactRedux.useDispatch)();
30
- const href = url?.toString() || "";
32
+ const href = (0, _react.useMemo)(() => url?.toString() || "", [url]);
31
33
  const key = useKeyForHook(modelKey, href);
34
+ const location = (0, _reactRouter.useLocation)();
35
+ const redirectLocation = location.state?.redirectLocation;
36
+ const forceReload = redirectLocation instanceof _Href.default ? redirectLocation?.equals(href) : false;
32
37
  const prevOptions = (0, _react.useRef)(options);
33
38
  const prevHref = (0, _react.useRef)(href);
39
+ const prevForceReload = (0, _react.useRef)(forceReload);
34
40
 
35
41
  // dispatch loadModularUI
36
42
  (0, _useDeepCompareEffect.default)(() => {
37
43
  // prevent reloads when previous option had the isReload, but the new options not
38
44
  const isOldReload = prevHref.current === href && prevOptions.current.isReload && !options.isReload;
39
- if (href !== "" && !isOldReload) {
45
+ const doForceReload = forceReload && !prevForceReload.current;
46
+ if (href !== "" && (doForceReload || !isOldReload)) {
40
47
  dispatch((0, _ModularUIActions.loadModularUI)(key, href, options));
41
48
  }
42
49
  prevOptions.current = options;
43
50
  prevHref.current = href;
44
- }, [key, href, options]);
45
- const {
46
- removeOnUnmount = false
47
- } = options;
51
+ prevForceReload.current = forceReload;
52
+ }, [key, href, options, forceReload]);
48
53
  (0, _react.useEffect)(() => {
49
- return () => {
50
- if (removeOnUnmount) {
54
+ if (options.removeOnUnmount) {
55
+ return () => {
51
56
  dispatch((0, _ModularUIActions.removeModelByKey)(key));
52
- }
53
- };
54
- }, [dispatch, key, removeOnUnmount]);
55
-
56
- // retrieve current model from modularui reducer
57
- return (0, _reactRedux.useSelector)(state => {
58
- return state.modularui[key];
59
- });
57
+ };
58
+ }
59
+ }, [dispatch, key, options.removeOnUnmount]);
60
+ const selector = (0, _react.useMemo)(() => state => state.modularui[key], [key]);
61
+ return (0, _reactRedux.useSelector)(selector);
60
62
  };
61
63
  exports.useModularUI = useModularUI;
62
64
  //# 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 {
@@ -12,14 +13,17 @@ import useDeepCompareEffect from "./useDeepCompareEffect";
12
13
 
13
14
  import { useLocale } from "./useI18n";
14
15
 
15
- import type Href from "../models/href/Href";
16
+ import 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,17 @@ 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
+ const location = useLocation();
45
+ const redirectLocation = location.state?.redirectLocation;
46
+ const forceReload =
47
+ redirectLocation instanceof Href ? redirectLocation?.equals(href) : false;
48
+
40
49
  const prevOptions = useRef(options);
41
50
  const prevHref = useRef(href);
51
+ const prevForceReload = useRef(forceReload);
42
52
 
43
53
  // dispatch loadModularUI
44
54
  useDeepCompareEffect(() => {
@@ -48,25 +58,25 @@ export const useModularUI = (
48
58
  prevOptions.current.isReload &&
49
59
  !options.isReload;
50
60
 
51
- if (href !== "" && !isOldReload) {
61
+ const doForceReload = forceReload && !prevForceReload.current;
62
+
63
+ if (href !== "" && (doForceReload || !isOldReload)) {
52
64
  dispatch(loadModularUI(key, href, options));
53
65
  }
54
66
 
55
67
  prevOptions.current = options;
56
68
  prevHref.current = href;
57
- }, [key, href, options]);
69
+ prevForceReload.current = forceReload;
70
+ }, [key, href, options, forceReload]);
58
71
 
59
- const { removeOnUnmount = false } = options;
60
72
  useEffect(() => {
61
- return () => {
62
- if (removeOnUnmount) {
73
+ if (options.removeOnUnmount) {
74
+ return () => {
63
75
  dispatch(removeModelByKey(key));
64
- }
65
- };
66
- }, [dispatch, key, removeOnUnmount]);
76
+ };
77
+ }
78
+ }, [dispatch, key, options.removeOnUnmount]);
67
79
 
68
- // retrieve current model from modularui reducer
69
- return useSelector((state) => {
70
- return state.modularui[key];
71
- });
80
+ const selector = useMemo(() => (state) => state.modularui[key], [key]);
81
+ return useSelector(selector);
72
82
  };
@@ -1 +1 @@
1
- {"version":3,"file":"useModularUI.js","names":["_react","require","_reactRedux","_constants","_ModularUIActions","_useDeepCompareEffect","_interopRequireDefault","_useI18n","useKeyForHook","modelKey","url","locale","useLocale","split","useModularUI","options","arguments","length","undefined","method","HTTP_METHODS","GET","removeOnUnmount","dispatch","useDispatch","href","toString","key","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\";\n\nimport type Href from \"../models/href/Href\";\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 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;AAKA;AACA;AACA,MAAMO,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,EAAE;EACnB,CAAC;EAED,MAAMC,QAAQ,GAAG,IAAAC,uBAAW,EAAC,CAAC;EAC9B,MAAMC,IAAI,GAAGf,GAAG,EAAEgB,QAAQ,CAAC,CAAC,IAAI,EAAE;EAClC,MAAMC,GAAG,GAAGnB,aAAa,CAACC,QAAQ,EAAEgB,IAAI,CAAC;EAEzC,MAAMG,WAAW,GAAG,IAAAC,aAAM,EAACd,OAAO,CAAC;EACnC,MAAMe,QAAQ,GAAG,IAAAD,aAAM,EAACJ,IAAI,CAAC;;EAE7B;EACA,IAAAM,6BAAoB,EAAC,MAAM;IACzB;IACA,MAAMC,WAAW,GACfF,QAAQ,CAACG,OAAO,KAAKR,IAAI,IACzBG,WAAW,CAACK,OAAO,CAACC,QAAQ,IAC5B,CAACnB,OAAO,CAACmB,QAAQ;IAEnB,IAAIT,IAAI,KAAK,EAAE,IAAI,CAACO,WAAW,EAAE;MAC/BT,QAAQ,CAAC,IAAAY,+BAAa,EAACR,GAAG,EAAEF,IAAI,EAAEV,OAAO,CAAC,CAAC;IAC7C;IAEAa,WAAW,CAACK,OAAO,GAAGlB,OAAO;IAC7Be,QAAQ,CAACG,OAAO,GAAGR,IAAI;EACzB,CAAC,EAAE,CAACE,GAAG,EAAEF,IAAI,EAAEV,OAAO,CAAC,CAAC;EAExB,MAAM;IAAEO,eAAe,GAAG;EAAM,CAAC,GAAGP,OAAO;EAC3C,IAAAqB,gBAAS,EAAC,MAAM;IACd,OAAO,MAAM;MACX,IAAId,eAAe,EAAE;QACnBC,QAAQ,CAAC,IAAAc,kCAAgB,EAACV,GAAG,CAAC,CAAC;MACjC;IACF,CAAC;EACH,CAAC,EAAE,CAACJ,QAAQ,EAAEI,GAAG,EAAEL,eAAe,CAAC,CAAC;;EAEpC;EACA,OAAO,IAAAgB,uBAAW,EAAEC,KAAK,IAAK;IAC5B,OAAOA,KAAK,CAACC,SAAS,CAACb,GAAG,CAAC;EAC7B,CAAC,CAAC;AACJ,CAAC;AAACc,OAAA,CAAA3B,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","location","useLocation","redirectLocation","state","forceReload","Href","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\";\n\nimport Href from \"../models/href/Href\";\nimport type { RequestModularUIOptions } from \"../utils\";\n\n/**\n */\nconst useKeyForHook = (modelKey: string, url: string) => {\n const locale = useLocale();\n return useMemo(\n () => `${modelKey}(${url.split(\"?\")[0]})(${locale})`,\n [modelKey, url, locale],\n );\n};\n\n/**\n * Use redux action and selector to retrieve the correct modular ui service model\n */\nexport const useModularUI = (\n modelKey: string,\n url: string | Href,\n options: RequestModularUIOptions = {\n method: HTTP_METHODS.GET,\n removeOnUnmount: false,\n },\n): any => {\n const dispatch = useDispatch();\n const href = useMemo(() => url?.toString() || \"\", [url]);\n const key = useKeyForHook(modelKey, href);\n\n const 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);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KAAK,IAAKA,KAAK,CAACiB,SAAS,CAACrB,GAAG,CAAC,EAAE,CAACA,GAAG,CAAC,CAAC;EACtE,OAAO,IAAAsB,uBAAW,EAACF,QAAQ,CAAC;AAC9B,CAAC;AAACG,OAAA,CAAApC,YAAA,GAAAA,YAAA","ignoreList":[]}
@@ -6,6 +6,7 @@ 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");
@@ -19,6 +20,7 @@ const useModularUIBasic = function (key, href) {
19
20
  forceTargetModel: false
20
21
  };
21
22
  const location = (0, _useRouter.useLocation)();
23
+ const memoizedHref = (0, _react.useMemo)(() => href.toString(), [href]);
22
24
  const useModularUIOptions = {
23
25
  targetModel: undefined,
24
26
  forceTargetModel: undefined,
@@ -39,24 +41,24 @@ const useModularUIBasic = function (key, href) {
39
41
  }
40
42
 
41
43
  // $FlowFixMe[incompatible-call]
42
- const modularUI = (0, _useModularUI.useModularUI)(key, href, useModularUIOptions);
43
- if (modularUI?.model) {
44
- const {
45
- model
46
- } = modularUI;
47
- const expectedModels = options.expectedModels ?? [];
48
- if (expectedModels.length > 0) {
49
- const isCorrectModel = expectedModels.some(expectedModel => {
50
- return model.type === expectedModel;
51
- });
52
- if (!isCorrectModel) {
53
- console.error(modularUI, "is not of instance", expectedModels);
54
- throw new _exceptions.IllegalStateException("Resolved model has incorrect type");
44
+ const modularUI = (0, _useModularUI.useModularUI)(key, memoizedHref, useModularUIOptions);
45
+ const expectedModels = (0, _react.useMemo)(() => options.expectedModels ?? [], [options.expectedModels]);
46
+ return (0, _react.useMemo)(() => {
47
+ if (modularUI?.model) {
48
+ const {
49
+ model
50
+ } = modularUI;
51
+ if (expectedModels.length > 0) {
52
+ const isCorrectModel = expectedModels.some(expectedModel => model.type === expectedModel);
53
+ if (!isCorrectModel) {
54
+ console.error(modularUI, "is not of instance", expectedModels);
55
+ throw new _exceptions.IllegalStateException("Resolved model has incorrect type");
56
+ }
55
57
  }
58
+ return model;
56
59
  }
57
- return model;
58
- }
59
- return null;
60
+ return null;
61
+ }, [expectedModels, modularUI]);
60
62
  };
61
63
  exports.useModularUIBasic = useModularUIBasic;
62
64
  //# sourceMappingURL=useModularUIBasic.js.map
@@ -1,4 +1,6 @@
1
1
  // @flow
2
+ import { useMemo } from "react";
3
+
2
4
  import { useModularUI } from "./useModularUI";
3
5
 
4
6
  import { useLocation } from "./useRouter";
@@ -26,6 +28,7 @@ export const useModularUIBasic = <T: ModularUIModel>(
26
28
  },
27
29
  ): T | null => {
28
30
  const location = useLocation();
31
+ const memoizedHref = useMemo(() => href.toString(), [href]);
29
32
 
30
33
  const useModularUIOptions = {
31
34
  targetModel: undefined,
@@ -48,25 +51,29 @@ export const useModularUIBasic = <T: ModularUIModel>(
48
51
  }
49
52
 
50
53
  // $FlowFixMe[incompatible-call]
51
- const modularUI = useModularUI(key, href, useModularUIOptions);
54
+ const modularUI = useModularUI(key, memoizedHref, useModularUIOptions);
52
55
 
53
- if (modularUI?.model) {
54
- const { model } = modularUI;
56
+ const expectedModels = useMemo(
57
+ () => options.expectedModels ?? [],
58
+ [options.expectedModels],
59
+ );
55
60
 
56
- const expectedModels = options.expectedModels ?? [];
57
- if (expectedModels.length > 0) {
58
- const isCorrectModel = expectedModels.some((expectedModel) => {
59
- return model.type === expectedModel;
60
- });
61
+ return useMemo((): T | null => {
62
+ if (modularUI?.model) {
63
+ const { model } = modularUI;
61
64
 
62
- if (!isCorrectModel) {
63
- console.error(modularUI, "is not of instance", expectedModels);
64
- throw new IllegalStateException("Resolved model has incorrect type");
65
+ if (expectedModels.length > 0) {
66
+ const isCorrectModel = expectedModels.some(
67
+ (expectedModel) => model.type === expectedModel,
68
+ );
69
+ if (!isCorrectModel) {
70
+ console.error(modularUI, "is not of instance", expectedModels);
71
+ throw new IllegalStateException("Resolved model has incorrect type");
72
+ }
65
73
  }
66
- }
67
74
 
68
- return model;
69
- }
70
-
71
- return null;
75
+ return model;
76
+ }
77
+ return null;
78
+ }, [expectedModels, modularUI]);
72
79
  };
@@ -1 +1 @@
1
- {"version":3,"file":"useModularUIBasic.js","names":["_useModularUI","require","_useRouter","_exceptions","useModularUIBasic","key","href","_context","options","arguments","length","undefined","expectedModels","targetModel","forceTargetModel","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 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 },\n): T | null => {\n const location = useLocation();\n\n const useModularUIOptions = {\n targetModel: undefined,\n forceTargetModel: undefined,\n isReload: false,\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 // $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;AAWA;AACA;AACO,MAAMG,iBAAiB,GAAG,SAAAA,CAC/BC,GAAW,EACXC,IAAmB,EAMN;EAAA,IAAAC,QAAA;EAAA,IALbC,OAAoC,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG;IACrCG,cAAc,EAAE,EAAE;IAClBC,WAAW,EAAEF,SAAS;IACtBG,gBAAgB,EAAE;EACpB,CAAC;EAED,MAAMC,QAAQ,GAAG,IAAAC,sBAAW,EAAC,CAAC;EAE9B,MAAMC,mBAAmB,GAAG;IAC1BJ,WAAW,EAAEF,SAAS;IACtBG,gBAAgB,EAAEH,SAAS;IAC3BO,QAAQ,EAAE,KAAK;IACfC,KAAK,EAAE;EACT,CAAC;EACD,IAAIX,OAAO,CAACK,WAAW,EAAE;IACvBI,mBAAmB,CAACJ,WAAW,GAAGL,OAAO,CAACK,WAAW;IACrDI,mBAAmB,CAACH,gBAAgB,GAAGN,OAAO,CAACM,gBAAgB;EACjE;EAEA,IAAIN,OAAO,CAACW,KAAK,EAAE;IACjBF,mBAAmB,CAACE,KAAK,GAAGX,OAAO,CAACW,KAAK;EAC3C;;EAEA;EACA,IAAIJ,QAAQ,CAACK,KAAK,EAAEC,MAAM,IAAI,IAAAC,WAAA,CAAAC,OAAA,EAAAhB,QAAA,GAAAQ,QAAQ,CAACS,QAAQ,EAAAC,IAAA,CAAAlB,QAAA,EAAYD,IAAI,CAACoB,QAAQ,CAAC,CAAC,CAAC,EAAE;IAC3ET,mBAAmB,CAACC,QAAQ,GAAG,IAAI;EACrC;;EAEA;EACA,MAAMS,SAAS,GAAG,IAAAC,0BAAY,EAACvB,GAAG,EAAEC,IAAI,EAAEW,mBAAmB,CAAC;EAE9D,IAAIU,SAAS,EAAEE,KAAK,EAAE;IACpB,MAAM;MAAEA;IAAM,CAAC,GAAGF,SAAS;IAE3B,MAAMf,cAAc,GAAGJ,OAAO,CAACI,cAAc,IAAI,EAAE;IACnD,IAAIA,cAAc,CAACF,MAAM,GAAG,CAAC,EAAE;MAC7B,MAAMoB,cAAc,GAAGlB,cAAc,CAACmB,IAAI,CAAEC,aAAa,IAAK;QAC5D,OAAOH,KAAK,CAACI,IAAI,KAAKD,aAAa;MACrC,CAAC,CAAC;MAEF,IAAI,CAACF,cAAc,EAAE;QACnBI,OAAO,CAACC,KAAK,CAACR,SAAS,EAAE,oBAAoB,EAAEf,cAAc,CAAC;QAC9D,MAAM,IAAIwB,iCAAqB,CAAC,mCAAmC,CAAC;MACtE;IACF;IAEA,OAAOP,KAAK;EACd;EAEA,OAAO,IAAI;AACb,CAAC;AAACQ,OAAA,CAAAjC,iBAAA,GAAAA,iBAAA","ignoreList":[]}
1
+ {"version":3,"file":"useModularUIBasic.js","names":["_react","require","_useModularUI","_useRouter","_exceptions","useModularUIBasic","key","href","_context","options","arguments","length","undefined","expectedModels","targetModel","forceTargetModel","location","useLocation","memoizedHref","useMemo","toString","useModularUIOptions","isReload","cache","state","reload","_startsWith","default","pathname","call","modularUI","useModularUI","model","isCorrectModel","some","expectedModel","type","console","error","IllegalStateException","exports"],"sources":["../../src/hooks/useModularUIBasic.js"],"sourcesContent":["// @flow\nimport { useMemo } from \"react\";\n\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 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 },\n): T | null => {\n const location = useLocation();\n const memoizedHref = useMemo(() => href.toString(), [href]);\n\n const useModularUIOptions = {\n targetModel: undefined,\n forceTargetModel: undefined,\n isReload: false,\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 // $FlowFixMe[incompatible-call]\n const modularUI = useModularUI(key, memoizedHref, useModularUIOptions);\n\n const expectedModels = useMemo(\n () => options.expectedModels ?? [],\n [options.expectedModels],\n );\n\n return useMemo((): T | null => {\n if (modularUI?.model) {\n const { model } = modularUI;\n\n if (expectedModels.length > 0) {\n const isCorrectModel = expectedModels.some(\n (expectedModel) => model.type === expectedModel,\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 return null;\n }, [expectedModels, modularUI]);\n};\n"],"mappings":";;;;;;;;AACA,IAAAA,MAAA,GAAAC,OAAA;AAEA,IAAAC,aAAA,GAAAD,OAAA;AAEA,IAAAE,UAAA,GAAAF,OAAA;AAEA,IAAAG,WAAA,GAAAH,OAAA;AAWA;AACA;AACO,MAAMI,iBAAiB,GAAG,SAAAA,CAC/BC,GAAW,EACXC,IAAmB,EAMN;EAAA,IAAAC,QAAA;EAAA,IALbC,OAAoC,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG;IACrCG,cAAc,EAA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IAAIjB,cAAc,CAACF,MAAM,GAAG,CAAC,EAAE;QAC7B,MAAMsB,cAAc,GAAGpB,cAAc,CAACqB,IAAI,CACvCC,aAAa,IAAKH,KAAK,CAACI,IAAI,KAAKD,aACpC,CAAC;QACD,IAAI,CAACF,cAAc,EAAE;UACnBI,OAAO,CAACC,KAAK,CAACR,SAAS,EAAE,oBAAoB,EAAEjB,cAAc,CAAC;UAC9D,MAAM,IAAI0B,iCAAqB,CAAC,mCAAmC,CAAC;QACtE;MACF;MAEA,OAAOP,KAAK;IACd;IACA,OAAO,IAAI;EACb,CAAC,EAAE,CAACnB,cAAc,EAAEiB,SAAS,CAAC,CAAC;AACjC,CAAC;AAACU,OAAA,CAAAnC,iBAAA,GAAAA,iBAAA","ignoreList":[]}
@@ -14,8 +14,8 @@ class ConceptTypeDetailModel extends _ResourceModel.default {
14
14
  * The name of the concept type consists of the functional id of the kmt and the functional id of the concept type separated by a #.<br>
15
15
  * For example BEI_CaseManagement#Case
16
16
  */
17
- get name() {
18
- return this.getData("name", "");
17
+ get kmtId() {
18
+ return this.getData("kmtId", "");
19
19
  }
20
20
 
21
21
  /**
@@ -11,8 +11,8 @@ class ConceptTypeDetailModel extends ResourceModel {
11
11
  * The name of the concept type consists of the functional id of the kmt and the functional id of the concept type separated by a #.<br>
12
12
  * For example BEI_CaseManagement#Case
13
13
  */
14
- get name(): string {
15
- return this.getData("name", "");
14
+ get kmtId(): string {
15
+ return this.getData("kmtId", "");
16
16
  }
17
17
 
18
18
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"ConceptTypeDetailModel.js","names":["_ResourceModel","_interopRequireDefault","require","ConceptTypeDetailModel","ResourceModel","name","getData","type","modelName","isApplicableModel","data","contributions","resourcetype","key","_id","label","modelCategory","isCoreTaxonomy","icon","textColor","backgroundColor","borderColor","labelTypes","propertyTypes","textFragmentTypes","sectionReferenceTypes","isOfConceptType","conceptTypeId","selfhref","equals","_default","exports","default"],"sources":["../../../src/models/concepts/ConceptTypeDetailModel.js"],"sourcesContent":["// @flow\nimport ResourceModel from \"../base/ResourceModel\";\n\nimport type ModularUIResponse from \"../../modularui/ModularUIResponse\";\n\n/**\n * Model for concept details, available through modelcatalog\n */\nclass ConceptTypeDetailModel extends ResourceModel {\n /**\n * The name of the concept type consists of the functional id of the kmt and the functional id of the concept type separated by a #.<br>\n * For example BEI_CaseManagement#Case\n */\n get name(): string {\n return this.getData(\"name\", \"\");\n }\n\n /**\n */\n get type(): string {\n return \"ConceptTypeDetail\";\n }\n\n /**\n */\n static get modelName(): string {\n return \"ConceptTypeDetailModel\";\n }\n\n /**\n */\n static isApplicableModel(data: ModularUIResponse): boolean {\n return (\n data.contributions.resourcetype &&\n data.contributions.resourcetype === \"ConceptTypeDetail\"\n );\n }\n\n /**\n */\n get key(): string {\n return this.data._id;\n }\n\n /**\n * Get concept type label\n */\n get label(): string {\n return this.getData(\"label\", \"\");\n }\n\n /**\n * Get model category of the concept type\n */\n get modelCategory(): string {\n return this.getData(\"modelCategory\", \"\");\n }\n\n /**\n */\n get isCoreTaxonomy(): boolean {\n return this.getData(\"coreTaxonomy\", \"false\") === \"true\";\n }\n\n /**\n * Get concept type icon\n */\n get icon(): string {\n return this.getData(\"icon\", \"\");\n }\n\n /**\n * Get concept type text color\n */\n get textColor(): string {\n return this.getData(\"textColor\", \"#000\");\n }\n\n /**\n * Get concept type background color\n */\n get backgroundColor(): string {\n return this.getData(\"backgroundColor\", \"#fff\");\n }\n\n /**\n * Get concept line color\n */\n get borderColor(): string {\n return this.getData(\"lineColor\", \"#000\");\n }\n\n /**\n * Get label types\n */\n get labelTypes(): ?Array<Object> {\n return this.data.labelTypes;\n }\n\n /**\n * Get propertyTypes\n */\n get propertyTypes(): Array<Object> {\n return this.getData(\"propertyTypes\", []);\n }\n\n /**\n * Get textFragmentTypes\n */\n get textFragmentTypes(): Array<Object> {\n return this.getData(\"textFragmentTypes\", []);\n }\n\n /**\n * Get sectionReferenceTypes\n */\n get sectionReferenceTypes(): Array<Object> {\n return this.getData(\"sectionReferenceTypes\", []);\n }\n\n /**\n */\n isOfConceptType(conceptTypeId: string): boolean {\n return this.selfhref.equals(conceptTypeId);\n }\n}\n\nexport default ConceptTypeDetailModel;\n"],"mappings":";;;;;;;AACA,IAAAA,cAAA,GAAAC,sBAAA,CAAAC,OAAA;AAIA;AACA;AACA;AACA,MAAMC,sBAAsB,SAASC,sBAAa,CAAC;EACjD;AACF;AACA;AACA;EACE,IAAIC,IAAIA,CAAA,EAAW;IACjB,OAAO,IAAI,CAACC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC;EACjC;;EAEA;AACF;EACE,IAAIC,IAAIA,CAAA,EAAW;IACjB,OAAO,mBAAmB;EAC5B;;EAEA;AACF;EACE,WAAWC,SAASA,CAAA,EAAW;IAC7B,OAAO,wBAAwB;EACjC;;EAEA;AACF;EACE,OAAOC,iBAAiBA,CAACC,IAAuB,EAAW;IACzD,OACEA,IAAI,CAACC,aAAa,CAACC,YAAY,IAC/BF,IAAI,CAACC,aAAa,CAACC,YAAY,KAAK,mBAAmB;EAE3D;;EAEA;AACF;EACE,IAAIC,GAAGA,CAAA,EAAW;IAChB,OAAO,IAAI,CAACH,IAAI,CAACI,GAAG;EACtB;;EAEA;AACF;AACA;EACE,IAAIC,KAAKA,CAAA,EAAW;IAClB,OAAO,IAAI,CAACT,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC;EAClC;;EAEA;AACF;AACA;EACE,IAAIU,aAAaA,CAAA,EAAW;IAC1B,OAAO,IAAI,CAACV,OAAO,CAAC,eAAe,EAAE,EAAE,CAAC;EAC1C;;EAEA;AACF;EACE,IAAIW,cAAcA,CAAA,EAAY;IAC5B,OAAO,IAAI,CAACX,OAAO,CAAC,cAAc,EAAE,OAAO,CAAC,KAAK,MAAM;EACzD;;EAEA;AACF;AACA;EACE,IAAIY,IAAIA,CAAA,EAAW;IACjB,OAAO,IAAI,CAACZ,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC;EACjC;;EAEA;AACF;AACA;EACE,IAAIa,SAASA,CAAA,EAAW;IACtB,OAAO,IAAI,CAACb,OAAO,CAAC,WAAW,EAAE,MAAM,CAAC;EAC1C;;EAEA;AACF;AACA;EACE,IAAIc,eAAeA,CAAA,EAAW;IAC5B,OAAO,IAAI,CAACd,OAAO,CAAC,iBAAiB,EAAE,MAAM,CAAC;EAChD;;EAEA;AACF;AACA;EACE,IAAIe,WAAWA,CAAA,EAAW;IACxB,OAAO,IAAI,CAACf,OAAO,CAAC,WAAW,EAAE,MAAM,CAAC;EAC1C;;EAEA;AACF;AACA;EACE,IAAIgB,UAAUA,CAAA,EAAmB;IAC/B,OAAO,IAAI,CAACZ,IAAI,CAACY,UAAU;EAC7B;;EAEA;AACF;AACA;EACE,IAAIC,aAAaA,CAAA,EAAkB;IACjC,OAAO,IAAI,CAACjB,OAAO,CAAC,eAAe,EAAE,EAAE,CAAC;EAC1C;;EAEA;AACF;AACA;EACE,IAAIkB,iBAAiBA,CAAA,EAAkB;IACrC,OAAO,IAAI,CAAClB,OAAO,CAAC,mBAAmB,EAAE,EAAE,CAAC;EAC9C;;EAEA;AACF;AACA;EACE,IAAImB,qBAAqBA,CAAA,EAAkB;IACzC,OAAO,IAAI,CAACnB,OAAO,CAAC,uBAAuB,EAAE,EAAE,CAAC;EAClD;;EAEA;AACF;EACEoB,eAAeA,CAACC,aAAqB,EAAW;IAC9C,OAAO,IAAI,CAACC,QAAQ,CAACC,MAAM,CAACF,aAAa,CAAC;EAC5C;AACF;AAAC,IAAAG,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEc7B,sBAAsB","ignoreList":[]}
1
+ {"version":3,"file":"ConceptTypeDetailModel.js","names":["_ResourceModel","_interopRequireDefault","require","ConceptTypeDetailModel","ResourceModel","kmtId","getData","type","modelName","isApplicableModel","data","contributions","resourcetype","key","_id","label","modelCategory","isCoreTaxonomy","icon","textColor","backgroundColor","borderColor","labelTypes","propertyTypes","textFragmentTypes","sectionReferenceTypes","isOfConceptType","conceptTypeId","selfhref","equals","_default","exports","default"],"sources":["../../../src/models/concepts/ConceptTypeDetailModel.js"],"sourcesContent":["// @flow\nimport ResourceModel from \"../base/ResourceModel\";\n\nimport type ModularUIResponse from \"../../modularui/ModularUIResponse\";\n\n/**\n * Model for concept details, available through modelcatalog\n */\nclass ConceptTypeDetailModel extends ResourceModel {\n /**\n * The name of the concept type consists of the functional id of the kmt and the functional id of the concept type separated by a #.<br>\n * For example BEI_CaseManagement#Case\n */\n get kmtId(): string {\n return this.getData(\"kmtId\", \"\");\n }\n\n /**\n */\n get type(): string {\n return \"ConceptTypeDetail\";\n }\n\n /**\n */\n static get modelName(): string {\n return \"ConceptTypeDetailModel\";\n }\n\n /**\n */\n static isApplicableModel(data: ModularUIResponse): boolean {\n return (\n data.contributions.resourcetype &&\n data.contributions.resourcetype === \"ConceptTypeDetail\"\n );\n }\n\n /**\n */\n get key(): string {\n return this.data._id;\n }\n\n /**\n * Get concept type label\n */\n get label(): string {\n return this.getData(\"label\", \"\");\n }\n\n /**\n * Get model category of the concept type\n */\n get modelCategory(): string {\n return this.getData(\"modelCategory\", \"\");\n }\n\n /**\n */\n get isCoreTaxonomy(): boolean {\n return this.getData(\"coreTaxonomy\", \"false\") === \"true\";\n }\n\n /**\n * Get concept type icon\n */\n get icon(): string {\n return this.getData(\"icon\", \"\");\n }\n\n /**\n * Get concept type text color\n */\n get textColor(): string {\n return this.getData(\"textColor\", \"#000\");\n }\n\n /**\n * Get concept type background color\n */\n get backgroundColor(): string {\n return this.getData(\"backgroundColor\", \"#fff\");\n }\n\n /**\n * Get concept line color\n */\n get borderColor(): string {\n return this.getData(\"lineColor\", \"#000\");\n }\n\n /**\n * Get label types\n */\n get labelTypes(): ?Array<Object> {\n return this.data.labelTypes;\n }\n\n /**\n * Get propertyTypes\n */\n get propertyTypes(): Array<Object> {\n return this.getData(\"propertyTypes\", []);\n }\n\n /**\n * Get textFragmentTypes\n */\n get textFragmentTypes(): Array<Object> {\n return this.getData(\"textFragmentTypes\", []);\n }\n\n /**\n * Get sectionReferenceTypes\n */\n get sectionReferenceTypes(): Array<Object> {\n return this.getData(\"sectionReferenceTypes\", []);\n }\n\n /**\n */\n isOfConceptType(conceptTypeId: string): boolean {\n return this.selfhref.equals(conceptTypeId);\n }\n}\n\nexport default ConceptTypeDetailModel;\n"],"mappings":";;;;;;;AACA,IAAAA,cAAA,GAAAC,sBAAA,CAAAC,OAAA;AAIA;AACA;AACA;AACA,MAAMC,sBAAsB,SAASC,sBAAa,CAAC;EACjD;AACF;AACA;AACA;EACE,IAAIC,KAAKA,CAAA,EAAW;IAClB,OAAO,IAAI,CAACC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC;EAClC;;EAEA;AACF;EACE,IAAIC,IAAIA,CAAA,EAAW;IACjB,OAAO,mBAAmB;EAC5B;;EAEA;AACF;EACE,WAAWC,SAASA,CAAA,EAAW;IAC7B,OAAO,wBAAwB;EACjC;;EAEA;AACF;EACE,OAAOC,iBAAiBA,CAACC,IAAuB,EAAW;IACzD,OACEA,IAAI,CAACC,aAAa,CAACC,YAAY,IAC/BF,IAAI,CAACC,aAAa,CAACC,YAAY,KAAK,mBAAmB;EAE3D;;EAEA;AACF;EACE,IAAIC,GAAGA,CAAA,EAAW;IAChB,OAAO,IAAI,CAACH,IAAI,CAACI,GAAG;EACtB;;EAEA;AACF;AACA;EACE,IAAIC,KAAKA,CAAA,EAAW;IAClB,OAAO,IAAI,CAACT,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC;EAClC;;EAEA;AACF;AACA;EACE,IAAIU,aAAaA,CAAA,EAAW;IAC1B,OAAO,IAAI,CAACV,OAAO,CAAC,eAAe,EAAE,EAAE,CAAC;EAC1C;;EAEA;AACF;EACE,IAAIW,cAAcA,CAAA,EAAY;IAC5B,OAAO,IAAI,CAACX,OAAO,CAAC,cAAc,EAAE,OAAO,CAAC,KAAK,MAAM;EACzD;;EAEA;AACF;AACA;EACE,IAAIY,IAAIA,CAAA,EAAW;IACjB,OAAO,IAAI,CAACZ,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC;EACjC;;EAEA;AACF;AACA;EACE,IAAIa,SAASA,CAAA,EAAW;IACtB,OAAO,IAAI,CAACb,OAAO,CAAC,WAAW,EAAE,MAAM,CAAC;EAC1C;;EAEA;AACF;AACA;EACE,IAAIc,eAAeA,CAAA,EAAW;IAC5B,OAAO,IAAI,CAACd,OAAO,CAAC,iBAAiB,EAAE,MAAM,CAAC;EAChD;;EAEA;AACF;AACA;EACE,IAAIe,WAAWA,CAAA,EAAW;IACxB,OAAO,IAAI,CAACf,OAAO,CAAC,WAAW,EAAE,MAAM,CAAC;EAC1C;;EAEA;AACF;AACA;EACE,IAAIgB,UAAUA,CAAA,EAAmB;IAC/B,OAAO,IAAI,CAACZ,IAAI,CAACY,UAAU;EAC7B;;EAEA;AACF;AACA;EACE,IAAIC,aAAaA,CAAA,EAAkB;IACjC,OAAO,IAAI,CAACjB,OAAO,CAAC,eAAe,EAAE,EAAE,CAAC;EAC1C;;EAEA;AACF;AACA;EACE,IAAIkB,iBAAiBA,CAAA,EAAkB;IACrC,OAAO,IAAI,CAAClB,OAAO,CAAC,mBAAmB,EAAE,EAAE,CAAC;EAC9C;;EAEA;AACF;AACA;EACE,IAAImB,qBAAqBA,CAAA,EAAkB;IACzC,OAAO,IAAI,CAACnB,OAAO,CAAC,uBAAuB,EAAE,EAAE,CAAC;EAClD;;EAEA;AACF;EACEoB,eAAeA,CAACC,aAAqB,EAAW;IAC9C,OAAO,IAAI,CAACC,QAAQ,CAACC,MAAM,CAACF,aAAa,CAAC;EAC5C;AACF;AAAC,IAAAG,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEc7B,sBAAsB","ignoreList":[]}
@@ -92,6 +92,7 @@ const loadModelSuccessAction = (key, model, updateHandler) => {
92
92
  const loadModel = (key, href, options) => ({
93
93
  type: "MODULARUI/FETCH",
94
94
  payload: {
95
+ key,
95
96
  href: href instanceof _Href.default ? href : new _Href.default(href),
96
97
  method: options?.method ?? _Constants.HTTP_METHODS.GET,
97
98
  data: options?.data,
@@ -122,16 +123,17 @@ const loadModel = (key, href, options) => ({
122
123
  /**
123
124
  */
124
125
  exports.loadModel = loadModel;
125
- const loadModularUI = (key, href, options) => dispatch => {
126
- dispatch(updateStatus(key, _Constants.MODULARUI_STATUS.LOADING));
126
+ const loadModularUI = (key, href, options) => (dispatch, getState) => {
127
+ const modularuiStore = getState()?.modularui;
128
+ if (modularuiStore && modularuiStore[key]?.status === _Constants.MODULARUI_STATUS.LOADING) {
129
+ // don't create duplicate requests during loading
130
+ return dispatch({
131
+ type: "NO_ACTION"
132
+ });
133
+ }
127
134
  dispatch((0, _ProgressIndicator.startProgress)());
128
135
  const loadModelPromise = dispatch(loadModel(key, href, options));
129
- return _promise.default.resolve(loadModelPromise).then(response => {
130
- if (response?.type === "FINISH_PROGRESS") {
131
- dispatch(updateStatus(key, _Constants.MODULARUI_STATUS.FINISHED));
132
- }
133
- return dispatch((0, _ProgressIndicator.finishProgress)());
134
- }).catch(error => dispatch((0, _Error.handleError)(error)));
136
+ return _promise.default.resolve(loadModelPromise).then(() => dispatch((0, _ProgressIndicator.finishProgress)())).catch(error => dispatch((0, _Error.handleError)(error)));
135
137
  };
136
138
 
137
139
  /**
@@ -109,6 +109,7 @@ export const loadModel = (
109
109
  ): ModularUIAction => ({
110
110
  type: "MODULARUI/FETCH",
111
111
  payload: {
112
+ key,
112
113
  href: href instanceof Href ? href : new Href(href),
113
114
  method: options?.method ?? HTTP_METHODS.GET,
114
115
  data: options?.data,
@@ -146,20 +147,24 @@ export const loadModularUI =
146
147
  href: Href | string,
147
148
  options?: RequestModularUIOptions,
148
149
  ): ThunkAction =>
149
- (dispatch: Dispatch) => {
150
- dispatch(updateStatus(key, MODULARUI_STATUS.LOADING));
150
+ (dispatch: Dispatch, getState) => {
151
+ const modularuiStore = getState()?.modularui;
152
+ if (
153
+ modularuiStore &&
154
+ modularuiStore[key]?.status === MODULARUI_STATUS.LOADING
155
+ ) {
156
+ // don't create duplicate requests during loading
157
+ return dispatch({
158
+ type: "NO_ACTION",
159
+ });
160
+ }
161
+
151
162
  dispatch(startProgress());
152
163
 
153
164
  const loadModelPromise = dispatch(loadModel(key, href, options));
154
165
 
155
166
  return Promise.resolve(loadModelPromise)
156
- .then((response) => {
157
- if (response?.type === "FINISH_PROGRESS") {
158
- dispatch(updateStatus(key, MODULARUI_STATUS.FINISHED));
159
- }
160
-
161
- return dispatch(finishProgress());
162
- })
167
+ .then(() => dispatch(finishProgress()))
163
168
  .catch((error) => dispatch(handleError(error)));
164
169
  };
165
170