@beinformed/ui 1.56.2 → 1.56.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,21 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [commit-and-tag-version](https://github.com/absolute-version/commit-and-tag-version) for commit guidelines.
4
4
 
5
+ ## [1.56.4](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/compare/v1.56.3...v1.56.4) (2024-10-16)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * **modularui:** memoize expectedmodels property ([8dac1a6](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/commit/8dac1a6d6cfe4c78c9d67fd7cdab3a3d7cda7ab8))
11
+
12
+ ## [1.56.3](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/compare/v1.56.2...v1.56.3) (2024-10-16)
13
+
14
+
15
+ ### Bug Fixes
16
+
17
+ * **concept-type:** rename name property to kmtId ([c8e8b77](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/commit/c8e8b779fb567747a600c626077201560a2b866e))
18
+ * **modularui:** force reload of existing model when form redirect ([91cfb43](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/commit/91cfb436c1c076e8d424944a181e4599b58eccf4))
19
+
5
20
  ## [1.56.2](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/compare/v1.56.1...v1.56.2) (2024-10-10)
6
21
 
7
22
 
@@ -1,14 +1,16 @@
1
- import { useEffect, useRef } from "react";
1
+ import { useEffect, useRef, useMemo } from "react";
2
2
  import { useDispatch, useSelector } from "react-redux";
3
+ import { useLocation } from "react-router";
3
4
  import { HTTP_METHODS } from "../constants";
4
5
  import { loadModularUI, removeModelByKey } from "../redux/_modularui/ModularUIActions";
5
6
  import useDeepCompareEffect from "./useDeepCompareEffect";
6
7
  import { useLocale } from "./useI18n";
8
+ import Href from "../models/href/Href";
7
9
  /**
8
10
  */
9
11
  const useKeyForHook = (modelKey, url) => {
10
12
  const locale = useLocale();
11
- return `${modelKey}(${url.split("?")[0]})(${locale})`;
13
+ return useMemo(() => `${modelKey}(${url.split("?")[0]})(${locale})`, [modelKey, url, locale]);
12
14
  };
13
15
 
14
16
  /**
@@ -20,35 +22,35 @@ export const useModularUI = function (modelKey, url) {
20
22
  removeOnUnmount: false
21
23
  };
22
24
  const dispatch = useDispatch();
23
- const href = url?.toString() || "";
25
+ const href = useMemo(() => url?.toString() || "", [url]);
24
26
  const key = useKeyForHook(modelKey, href);
27
+ const location = useLocation();
28
+ const redirectLocation = location.state?.redirectLocation;
29
+ const forceReload = redirectLocation instanceof Href ? redirectLocation?.equals(href) : false;
25
30
  const prevOptions = useRef(options);
26
31
  const prevHref = useRef(href);
32
+ const prevForceReload = useRef(forceReload);
27
33
 
28
34
  // dispatch loadModularUI
29
35
  useDeepCompareEffect(() => {
30
36
  // prevent reloads when previous option had the isReload, but the new options not
31
37
  const isOldReload = prevHref.current === href && prevOptions.current.isReload && !options.isReload;
32
- if (href !== "" && !isOldReload) {
38
+ const doForceReload = forceReload && !prevForceReload.current;
39
+ if (href !== "" && (doForceReload || !isOldReload)) {
33
40
  dispatch(loadModularUI(key, href, options));
34
41
  }
35
42
  prevOptions.current = options;
36
43
  prevHref.current = href;
37
- }, [key, href, options]);
38
- const {
39
- removeOnUnmount = false
40
- } = options;
44
+ prevForceReload.current = forceReload;
45
+ }, [key, href, options, forceReload]);
41
46
  useEffect(() => {
42
- return () => {
43
- if (removeOnUnmount) {
47
+ if (options.removeOnUnmount) {
48
+ return () => {
44
49
  dispatch(removeModelByKey(key));
45
- }
46
- };
47
- }, [dispatch, key, removeOnUnmount]);
48
-
49
- // retrieve current model from modularui reducer
50
- return useSelector(state => {
51
- return state.modularui[key];
52
- });
50
+ };
51
+ }
52
+ }, [dispatch, key, options.removeOnUnmount]);
53
+ const selector = useMemo(() => state => state.modularui[key], [key]);
54
+ return useSelector(selector);
53
55
  };
54
56
  //# sourceMappingURL=useModularUI.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useModularUI.js","names":["useEffect","useRef","useDispatch","useSelector","HTTP_METHODS","loadModularUI","removeModelByKey","useDeepCompareEffect","useLocale","useKeyForHook","modelKey","url","locale","split","useModularUI","options","arguments","length","undefined","method","GET","removeOnUnmount","dispatch","href","toString","key","prevOptions","prevHref","isOldReload","current","isReload","state","modularui"],"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,SAASA,SAAS,EAAEC,MAAM,QAAQ,OAAO;AACzC,SAASC,WAAW,EAAEC,WAAW,QAAQ,aAAa;AAEtD,SAASC,YAAY,QAAQ,cAAc;AAC3C,SACEC,aAAa,EACbC,gBAAgB,QACX,sCAAsC;AAE7C,OAAOC,oBAAoB,MAAM,wBAAwB;AAEzD,SAASC,SAAS,QAAQ,WAAW;AAKrC;AACA;AACA,MAAMC,aAAa,GAAGA,CAACC,QAAgB,EAAEC,GAAW,KAAK;EACvD,MAAMC,MAAM,GAAGJ,SAAS,CAAC,CAAC;EAC1B,OAAO,GAAGE,QAAQ,IAAIC,GAAG,CAACE,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,KAAKD,MAAM,GAAG;AACvD,CAAC;;AAED;AACA;AACA;AACA,OAAO,MAAME,YAAY,GAAG,SAAAA,CAC1BJ,QAAgB,EAChBC,GAAkB,EAKV;EAAA,IAJRI,OAAgC,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG;IACjCG,MAAM,EAAEf,YAAY,CAACgB,GAAG;IACxBC,eAAe,EAAE;EACnB,CAAC;EAED,MAAMC,QAAQ,GAAGpB,WAAW,CAAC,CAAC;EAC9B,MAAMqB,IAAI,GAAGZ,GAAG,EAAEa,QAAQ,CAAC,CAAC,IAAI,EAAE;EAClC,MAAMC,GAAG,GAAGhB,aAAa,CAACC,QAAQ,EAAEa,IAAI,CAAC;EAEzC,MAAMG,WAAW,GAAGzB,MAAM,CAACc,OAAO,CAAC;EACnC,MAAMY,QAAQ,GAAG1B,MAAM,CAACsB,IAAI,CAAC;;EAE7B;EACAhB,oBAAoB,CAAC,MAAM;IACzB;IACA,MAAMqB,WAAW,GACfD,QAAQ,CAACE,OAAO,KAAKN,IAAI,IACzBG,WAAW,CAACG,OAAO,CAACC,QAAQ,IAC5B,CAACf,OAAO,CAACe,QAAQ;IAEnB,IAAIP,IAAI,KAAK,EAAE,IAAI,CAACK,WAAW,EAAE;MAC/BN,QAAQ,CAACjB,aAAa,CAACoB,GAAG,EAAEF,IAAI,EAAER,OAAO,CAAC,CAAC;IAC7C;IAEAW,WAAW,CAACG,OAAO,GAAGd,OAAO;IAC7BY,QAAQ,CAACE,OAAO,GAAGN,IAAI;EACzB,CAAC,EAAE,CAACE,GAAG,EAAEF,IAAI,EAAER,OAAO,CAAC,CAAC;EAExB,MAAM;IAAEM,eAAe,GAAG;EAAM,CAAC,GAAGN,OAAO;EAC3Cf,SAAS,CAAC,MAAM;IACd,OAAO,MAAM;MACX,IAAIqB,eAAe,EAAE;QACnBC,QAAQ,CAAChB,gBAAgB,CAACmB,GAAG,CAAC,CAAC;MACjC;IACF,CAAC;EACH,CAAC,EAAE,CAACH,QAAQ,EAAEG,GAAG,EAAEJ,eAAe,CAAC,CAAC;;EAEpC;EACA,OAAOlB,WAAW,CAAE4B,KAAK,IAAK;IAC5B,OAAOA,KAAK,CAACC,SAAS,CAACP,GAAG,CAAC;EAC7B,CAAC,CAAC;AACJ,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"useModularUI.js","names":["useEffect","useRef","useMemo","useDispatch","useSelector","useLocation","HTTP_METHODS","loadModularUI","removeModelByKey","useDeepCompareEffect","useLocale","Href","useKeyForHook","modelKey","url","locale","split","useModularUI","options","arguments","length","undefined","method","GET","removeOnUnmount","dispatch","href","toString","key","location","redirectLocation","state","forceReload","equals","prevOptions","prevHref","prevForceReload","isOldReload","current","isReload","doForceReload","selector","modularui"],"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);\n};\n"],"mappings":"AACA,SAASA,SAAS,EAAEC,MAAM,EAAEC,OAAO,QAAQ,OAAO;AAClD,SAASC,WAAW,EAAEC,WAAW,QAAQ,aAAa;AACtD,SAASC,WAAW,QAAQ,cAAc;AAE1C,SAASC,YAAY,QAAQ,cAAc;AAC3C,SACEC,aAAa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AGlC,MAAM,CAACyB,IAAI,CAAC;EAC7B,MAAMU,eAAe,GAAGnC,MAAM,CAAC+B,WAAW,CAAC;;EAE3C;EACAvB,oBAAoB,CAAC,MAAM;IACzB;IACA,MAAM4B,WAAW,GACfF,QAAQ,CAACG,OAAO,KAAKZ,IAAI,IACzBQ,WAAW,CAACI,OAAO,CAACC,QAAQ,IAC5B,CAACrB,OAAO,CAACqB,QAAQ;IAEnB,MAAMC,aAAa,GAAGR,WAAW,IAAI,CAACI,eAAe,CAACE,OAAO;IAE7D,IAAIZ,IAAI,KAAK,EAAE,KAAKc,aAAa,IAAI,CAACH,WAAW,CAAC,EAAE;MAClDZ,QAAQ,CAAClB,aAAa,CAACqB,GAAG,EAAEF,IAAI,EAAER,OAAO,CAAC,CAAC;IAC7C;IAEAgB,WAAW,CAACI,OAAO,GAAGpB,OAAO;IAC7BiB,QAAQ,CAACG,OAAO,GAAGZ,IAAI;IACvBU,eAAe,CAACE,OAAO,GAAGN,WAAW;EACvC,CAAC,EAAE,CAACJ,GAAG,EAAEF,IAAI,EAAER,OAAO,EAAEc,WAAW,CAAC,CAAC;EAErChC,SAAS,CAAC,MAAM;IACd,IAAIkB,OAAO,CAACM,eAAe,EAAE;MAC3B,OAAO,MAAM;QACXC,QAAQ,CAACjB,gBAAgB,CAACoB,GAAG,CAAC,CAAC;MACjC,CAAC;IACH;EACF,CAAC,EAAE,CAACH,QAAQ,EAAEG,GAAG,EAAEV,OAAO,CAACM,eAAe,CAAC,CAAC;EAE5C,MAAMiB,QAAQ,GAAGvC,OAAO,CAAC,MAAO6B,KAAK,IAAKA,KAAK,CAACW,SAAS,CAACd,GAAG,CAAC,EAAE,CAACA,GAAG,CAAC,CAAC;EACtE,OAAOxB,WAAW,CAACqC,QAAQ,CAAC;AAC9B,CAAC","ignoreList":[]}
@@ -1,4 +1,5 @@
1
1
  import _startsWithInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/starts-with";
2
+ import { useMemo } from "react";
2
3
  import { useModularUI } from "./useModularUI";
3
4
  import { useLocation } from "./useRouter";
4
5
  import { IllegalStateException } from "../exceptions";
@@ -12,6 +13,7 @@ export const useModularUIBasic = function (key, href) {
12
13
  forceTargetModel: false
13
14
  };
14
15
  const location = useLocation();
16
+ const memoizedHref = useMemo(() => href.toString(), [href]);
15
17
  const useModularUIOptions = {
16
18
  targetModel: undefined,
17
19
  forceTargetModel: undefined,
@@ -32,23 +34,23 @@ export const useModularUIBasic = function (key, href) {
32
34
  }
33
35
 
34
36
  // $FlowFixMe[incompatible-call]
35
- const modularUI = useModularUI(key, href, useModularUIOptions);
36
- if (modularUI?.model) {
37
- const {
38
- model
39
- } = modularUI;
40
- const expectedModels = options.expectedModels ?? [];
41
- if (expectedModels.length > 0) {
42
- const isCorrectModel = expectedModels.some(expectedModel => {
43
- return model.type === expectedModel;
44
- });
45
- if (!isCorrectModel) {
46
- console.error(modularUI, "is not of instance", expectedModels);
47
- throw new IllegalStateException("Resolved model has incorrect type");
37
+ const modularUI = useModularUI(key, memoizedHref, useModularUIOptions);
38
+ const expectedModels = useMemo(() => options.expectedModels ?? [], [options.expectedModels]);
39
+ return useMemo(() => {
40
+ if (modularUI?.model) {
41
+ const {
42
+ model
43
+ } = modularUI;
44
+ if (expectedModels.length > 0) {
45
+ const isCorrectModel = expectedModels.some(expectedModel => model.type === expectedModel);
46
+ if (!isCorrectModel) {
47
+ console.error(modularUI, "is not of instance", expectedModels);
48
+ throw new IllegalStateException("Resolved model has incorrect type");
49
+ }
48
50
  }
51
+ return model;
49
52
  }
50
- return model;
51
- }
52
- return null;
53
+ return null;
54
+ }, [expectedModels, modularUI]);
53
55
  };
54
56
  //# sourceMappingURL=useModularUIBasic.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useModularUIBasic.js","names":["useModularUI","useLocation","IllegalStateException","useModularUIBasic","key","href","_context","options","arguments","length","undefined","expectedModels","targetModel","forceTargetModel","location","useModularUIOptions","isReload","cache","state","reload","_startsWithInstanceProperty","pathname","call","toString","modularUI","model","isCorrectModel","some","expectedModel","type","console","error"],"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,SAASA,YAAY,QAAQ,gBAAgB;AAE7C,SAASC,WAAW,QAAQ,aAAa;AAEzC,SAASC,qBAAqB,QAAQ,eAAe;AAWrD;AACA;AACA,OAAO,MAAMC,iBAAiB,GAAG,SAAAA,CAC/BC,GAAW,EACXC,I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5D,OAAOH,KAAK,CAACI,IAAI,KAAKD,aAAa;MACrC,CAAC,CAAC;MAEF,IAAI,CAACF,cAAc,EAAE;QACnBI,OAAO,CAACC,KAAK,CAACP,SAAS,EAAE,oBAAoB,EAAEb,cAAc,CAAC;QAC9D,MAAM,IAAIT,qBAAqB,CAAC,mCAAmC,CAAC;MACtE;IACF;IAEA,OAAOuB,KAAK;EACd;EAEA,OAAO,IAAI;AACb,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"useModularUIBasic.js","names":["useMemo","useModularUI","useLocation","IllegalStateException","useModularUIBasic","key","href","_context","options","arguments","length","undefined","expectedModels","targetModel","forceTargetModel","location","memoizedHref","toString","useModularUIOptions","isReload","cache","state","reload","_startsWithInstanceProperty","pathname","call","modularUI","model","isCorrectModel","some","expectedModel","type","console","error"],"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,SAASA,OAAO,QAAQ,OAAO;AAE/B,SAASC,YAAY,QAAQ,gBAAgB;AAE7C,SAASC,WAAW,QAAQ,aAAa;AAEzC,SAASC,qBAAqB,QAAQ,eAAe;AAWrD;AACA;AACA,OAAO,MAAMC,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,GAAGb,WAAW,CAAC,CAAC;EAC9B,MAAMc,YAAY,GAAGhB,OAAO,CAAC,MAAMM,IAAI,CAACW,QAAQ,CAAC,CAAC,EAAE,CAACX,IAAI,CAAC,CAAC;EAE3D,MAAMY,mBAAmB,GAAG;IAC1BL,WAAW,EAAEF,SAAS;IACtBG,gBAAgB,EAAEH,SAAS;IAC3BQ,QAAQ,EAAE,KAAK;IACfC,KAAK,EAAE;EACT,CAAC;EACD,IAAIZ,OAAO,CAACK,WAAW,EAAE;IACvBK,mBAAmB,CAACL,WAAW,GAAGL,OAAO,CAACK,WAAW;IACrDK,mBAAmB,CAACJ,gBAAgB,GAAGN,OAAO,CAACM,gBAAgB;EACjE;EAEA,IAAIN,OAAO,CAACY,KAAK,EAAE;IACjBF,mBAAmB,CAACE,KAAK,GAAGZ,OAAO,CAACY,KAAK;EAC3C;;EAEA;EACA,IAAIL,QAAQ,CAACM,KAAK,EAAEC,MAAM,IAAIC,2BAAA,CAAAhB,QAAA,GAAAQ,QAAQ,CAACS,QAAQ,EAAAC,IAAA,CAAAlB,QAAA,EAAYD,IAAI,CAACW,QAAQ,CAAC,CAAC,CAAC,EAAE;IAC3EC,mBAAmB,CAACC,QAAQ,GAAG,IAAI;EACrC;;EAEA;EACA,MAAMO,SAAS,GAAGzB,YAAY,CAACI,GAAG,EAAEW,YAAY,EAAEE,mBAAmB,CAAC;EAEtE,MAAMN,cAAc,GAAGZ,OAAO,CAC5B,MAAMQ,OAAO,CAACI,cAAc,IAAI,EAAE,EAClC,CAACJ,OAAO,CAACI,cAAc,CACzB,CAAC;EAED,OAAOZ,OAAO,CAAC,MAAgB;IAC7B,IAAI0B,SAAS,EAAEC,KAAK,EAAE;MACpB,MAAM;QAAEA;MAAM,CAAC,GAAGD,SAAS;MAE3B,IAAId,cAAc,CAACF,MAAM,GAAG,CAAC,EAAE;QAC7B,MAAMkB,cAAc,GAAGhB,cAAc,CAACiB,IAAI,CACvCC,aAAa,IAAKH,KAAK,CAACI,IAAI,KAAKD,aACpC,CAAC;QACD,IAAI,CAACF,cAAc,EAAE;UACnBI,OAAO,CAACC,KAAK,CAACP,SAAS,EAAE,oBAAoB,EAAEd,cAAc,CAAC;UAC9D,MAAM,IAAIT,qBAAqB,CAAC,mCAAmC,CAAC;QACtE;MACF;MAEA,OAAOwB,KAAK;IACd;IACA,OAAO,IAAI;EACb,CAAC,EAAE,CAACf,cAAc,EAAEc,SAAS,CAAC,CAAC;AACjC,CAAC","ignoreList":[]}
@@ -7,8 +7,8 @@ class ConceptTypeDetailModel extends ResourceModel {
7
7
  * 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>
8
8
  * For example BEI_CaseManagement#Case
9
9
  */
10
- get name() {
11
- return this.getData("name", "");
10
+ get kmtId() {
11
+ return this.getData("kmtId", "");
12
12
  }
13
13
 
14
14
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"ConceptTypeDetailModel.js","names":["ResourceModel","ConceptTypeDetailModel","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"],"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,OAAOA,aAAa,MAAM,uBAAuB;AAIjD;AACA;AACA;AACA,MAAMC,sBAAsB,SAASD,aAAa,CAAC;EACjD;AACF;AACA;AACA;EACE,IAAIE,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,E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AAW;IAC9C,OAAO,IAAI,CAACC,QAAQ,CAACC,MAAM,CAACF,aAAa,CAAC;EAC5C;AACF;AAEA,eAAevB,sBAAsB","ignoreList":[]}
1
+ {"version":3,"file":"ConceptTypeDetailModel.js","names":["ResourceModel","ConceptTypeDetailModel","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"],"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,OAAOA,aAAa,MAAM,uBAAuB;AAIjD;AACA;AACA;AACA,MAAMC,sBAAsB,SAASD,aAAa,CAAC;EACjD;AACF;AACA;AACA;EACE,IAAIE,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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,QAAQ,CAACC,MAAM,CAACF,aAAa,CAAC;EAC5C;AACF;AAEA,eAAevB,sBAAsB","ignoreList":[]}
@@ -4,6 +4,8 @@ import { Provider } from "react-redux";
4
4
  import { renderHook } from "@testing-library/react";
5
5
  import xhrMock from "xhr-mock";
6
6
 
7
+ import { useLocation } from "react-router";
8
+
7
9
  import {
8
10
  useApplication,
9
11
  useTab,
@@ -32,6 +34,11 @@ import {
32
34
  const middlewares = [thunk];
33
35
  const mockStore = configureMockStore(middlewares);
34
36
 
37
+ jest.mock("react-router", () => ({
38
+ ...jest.requireActual("react-router"), // Keep other methods from react-router as is
39
+ useLocation: jest.fn(), // Mock useLocation
40
+ }));
41
+
35
42
  const JSON_TYPE = "application/json";
36
43
 
37
44
  describe("modularui hooks", () => {
@@ -83,6 +90,9 @@ describe("modularui hooks", () => {
83
90
  // replace the real XHR object with the mock XHR object before each test
84
91
  // eslint-disable-next-line jest/no-hooks
85
92
  beforeEach(() => {
93
+ useLocation.mockReturnValue({
94
+ state: null,
95
+ });
86
96
  xhrMock.setup();
87
97
  });
88
98
 
@@ -3,6 +3,7 @@ import thunk from "redux-thunk";
3
3
  import { Provider } from "react-redux";
4
4
  import { renderHook } from "@testing-library/react";
5
5
  import xhrMock from "xhr-mock";
6
+ import { useLocation } from "react-router";
6
7
 
7
8
  import {
8
9
  useAttributeSet,
@@ -19,12 +20,22 @@ import { IllegalArgumentException } from "../../exceptions";
19
20
  const middlewares = [thunk];
20
21
  const mockStore = configureMockStore(middlewares);
21
22
 
23
+ jest.mock("react-router", () => ({
24
+ ...jest.requireActual("react-router"), // Keep other methods from react-router as is
25
+ useLocation: jest.fn(), // Mock useLocation
26
+ }));
27
+
22
28
  const JSON_TYPE = "application/json";
23
29
 
24
30
  describe("form hooks", () => {
25
31
  // replace the real XHR object with the mock XHR object before each test
26
32
  // eslint-disable-next-line jest/no-hooks
27
- beforeEach(() => xhrMock.setup());
33
+ beforeEach(() => {
34
+ useLocation.mockReturnValue({
35
+ state: null,
36
+ });
37
+ xhrMock.setup();
38
+ });
28
39
 
29
40
  // put the real XHR object back and clear the mocks after each test
30
41
  // eslint-disable-next-line jest/no-hooks
@@ -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", () => {
@@ -77,6 +83,9 @@ describe("modelcatalog hooks", () => {
77
83
  // replace the real XHR object with the mock XHR object before each test
78
84
  // eslint-disable-next-line jest/no-hooks
79
85
  beforeEach(() => {
86
+ useLocation.mockReturnValue({
87
+ state: null,
88
+ });
80
89
  xhrMock.setup();
81
90
  });
82
91
 
@@ -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
 
@@ -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,IA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B,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);\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;AAEA,IAAAQ,KAAA,GAAAF,sBAAA,CAAAN,OAAA;AAGA;AACA;A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AoB,EAAC,MAAM;IACzB;IACA,MAAMC,WAAW,GACfH,QAAQ,CAACI,OAAO,KAAKhB,IAAI,IACzBU,WAAW,CAACM,OAAO,CAACC,QAAQ,IAC5B,CAAC3B,OAAO,CAAC2B,QAAQ;IAEnB,MAAMC,aAAa,GAAGX,WAAW,IAAI,CAACM,eAAe,CAACG,OAAO;IAE7D,IAAIhB,IAAI,KAAK,EAAE,KAAKkB,aAAa,IAAI,CAACH,WAAW,CAAC,EAAE;MAClDjB,QAAQ,CAAC,IAAAqB,+BAAa,EAACjB,GAAG,EAAEF,IAAI,EAAEV,OAAO,CAAC,CAAC;IAC7C;IAEAoB,WAAW,CAACM,OAAO,GAAG1B,OAAO;IAC7BsB,QAAQ,CAACI,OAAO,GAAGhB,IAAI;IACvBa,eAAe,CAACG,OAAO,GAAGT,WAAW;EACvC,CAAC,EAAE,CAACL,GAAG,EAAEF,IAAI,EAAEV,OAAO,EAAEiB,WAAW,CAAC,CAAC;EAErC,IAAAa,gBAAS,EAAC,MAAM;IACd,IAAI9B,OAAO,CAACO,eAAe,EAAE;MAC3B,OAAO,MAAM;QACXC,QAAQ,CAAC,IAAAuB,kCAAgB,EAACnB,GAAG,CAAC,CAAC;MACjC,CAAC;IACH;EACF,CAAC,EAAE,CAACJ,QAAQ,EAAEI,GAAG,EAAEZ,OAAO,CAACO,eAAe,CAAC,CAAC;EAE5C,MAAMyB,QAAQ,GAAG,IAAAnC,cAAO,EAAC,MAAOmB,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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AC,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,EAAE,EAAE;IAClBC,WAAW,EAAEF,SAAS;IACtBG,gBAAgB,EAAE;EACpB,CAAC;EAED,MAAMC,QAAQ,GAAG,IAAAC,sBAAW,EAAC,CAAC;EAC9B,MAAMC,YAAY,GAAG,IAAAC,cAAO,EAAC,MAAMZ,IAAI,CAACa,QAAQ,CAAC,CAAC,EAAE,CAACb,IAAI,CAAC,CAAC;EAE3D,MAAMc,mBAAmB,GAAG;IAC1BP,WAAW,EAAEF,SAAS;IACtBG,gBAAgB,EAAEH,SAAS;IA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OP,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,CA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AAM,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;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AWA,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":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@beinformed/ui",
3
- "version": "1.56.2",
3
+ "version": "1.56.4",
4
4
  "description": "Toolbox for be informed javascript layouts",
5
5
  "license": "SEE LICENSE IN LICENSE.md",
6
6
  "bugs": "http://support.beinformed.com",
@@ -4,6 +4,8 @@ import { Provider } from "react-redux";
4
4
  import { renderHook } from "@testing-library/react";
5
5
  import xhrMock from "xhr-mock";
6
6
 
7
+ import { useLocation } from "react-router";
8
+
7
9
  import {
8
10
  useApplication,
9
11
  useTab,
@@ -32,6 +34,11 @@ import {
32
34
  const middlewares = [thunk];
33
35
  const mockStore = configureMockStore(middlewares);
34
36
 
37
+ jest.mock("react-router", () => ({
38
+ ...jest.requireActual("react-router"), // Keep other methods from react-router as is
39
+ useLocation: jest.fn(), // Mock useLocation
40
+ }));
41
+
35
42
  const JSON_TYPE = "application/json";
36
43
 
37
44
  describe("modularui hooks", () => {
@@ -83,6 +90,9 @@ describe("modularui hooks", () => {
83
90
  // replace the real XHR object with the mock XHR object before each test
84
91
  // eslint-disable-next-line jest/no-hooks
85
92
  beforeEach(() => {
93
+ useLocation.mockReturnValue({
94
+ state: null,
95
+ });
86
96
  xhrMock.setup();
87
97
  });
88
98
 
@@ -3,6 +3,7 @@ import thunk from "redux-thunk";
3
3
  import { Provider } from "react-redux";
4
4
  import { renderHook } from "@testing-library/react";
5
5
  import xhrMock from "xhr-mock";
6
+ import { useLocation } from "react-router";
6
7
 
7
8
  import {
8
9
  useAttributeSet,
@@ -19,12 +20,22 @@ import { IllegalArgumentException } from "../../exceptions";
19
20
  const middlewares = [thunk];
20
21
  const mockStore = configureMockStore(middlewares);
21
22
 
23
+ jest.mock("react-router", () => ({
24
+ ...jest.requireActual("react-router"), // Keep other methods from react-router as is
25
+ useLocation: jest.fn(), // Mock useLocation
26
+ }));
27
+
22
28
  const JSON_TYPE = "application/json";
23
29
 
24
30
  describe("form hooks", () => {
25
31
  // replace the real XHR object with the mock XHR object before each test
26
32
  // eslint-disable-next-line jest/no-hooks
27
- beforeEach(() => xhrMock.setup());
33
+ beforeEach(() => {
34
+ useLocation.mockReturnValue({
35
+ state: null,
36
+ });
37
+ xhrMock.setup();
38
+ });
28
39
 
29
40
  // put the real XHR object back and clear the mocks after each test
30
41
  // eslint-disable-next-line jest/no-hooks
@@ -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", () => {
@@ -77,6 +83,9 @@ describe("modelcatalog hooks", () => {
77
83
  // replace the real XHR object with the mock XHR object before each test
78
84
  // eslint-disable-next-line jest/no-hooks
79
85
  beforeEach(() => {
86
+ useLocation.mockReturnValue({
87
+ state: null,
88
+ });
80
89
  xhrMock.setup();
81
90
  });
82
91
 
@@ -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
 
@@ -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,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
  };
@@ -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
  /**