@beinformed/ui 1.50.4 → 1.51.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,13 @@
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.51.0](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/compare/v1.50.4...v1.51.0) (2024-08-01)
6
+
7
+
8
+ ### Features
9
+
10
+ * **modularui:** make it possible to call useModularUI with null or empty href ([0546de5](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/commit/0546de599f10d7d5ec2cb2746083f3c644b84379))
11
+
5
12
  ## [1.50.4](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/compare/v1.50.3...v1.50.4) (2024-07-23)
6
13
 
7
14
 
@@ -20,7 +20,7 @@ export const useModularUI = function (modelKey, url) {
20
20
  removeOnUnmount: false
21
21
  };
22
22
  const dispatch = useDispatch();
23
- const href = url.toString();
23
+ const href = url?.toString() || "";
24
24
  const key = useKeyForHook(modelKey, href);
25
25
  const prevOptions = useRef(options);
26
26
  const prevHref = useRef(href);
@@ -29,7 +29,7 @@ export const useModularUI = function (modelKey, url) {
29
29
  useDeepCompareEffect(() => {
30
30
  // prevent reloads when previous option had the isReload, but the new options not
31
31
  const isOldReload = prevHref.current === href && prevOptions.current.isReload && !options.isReload;
32
- if (!isOldReload) {
32
+ if (href !== "" && !isOldReload) {
33
33
  dispatch(loadModularUI(key, href, options));
34
34
  }
35
35
  prevOptions.current = options;
@@ -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 (!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,CAACa,QAAQ,CAAC,CAAC;EAC3B,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,IAAI,CAACF,WAAW,EAAE;MAChBN,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","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,7 +1,7 @@
1
1
  import _startsWithInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/starts-with";
2
2
  import { useModularUI } from "./useModularUI";
3
3
  import { useLocation } from "./useRouter";
4
- import { IllegalArgumentException, IllegalStateException } from "../exceptions";
4
+ import { IllegalStateException } from "../exceptions";
5
5
  /**
6
6
  */
7
7
  export const useModularUIBasic = function (key, href) {
@@ -12,9 +12,6 @@ export const useModularUIBasic = function (key, href) {
12
12
  forceTargetModel: false
13
13
  };
14
14
  const location = useLocation();
15
- if (!href) {
16
- throw new IllegalArgumentException("Missing href");
17
- }
18
15
  const useModularUIOptions = {
19
16
  targetModel: undefined,
20
17
  forceTargetModel: undefined,
@@ -1 +1 @@
1
- {"version":3,"file":"useModularUIBasic.js","names":["useModularUI","useLocation","IllegalArgumentException","IllegalStateException","useModularUIBasic","key","href","_context","options","arguments","length","undefined","expectedModels","targetModel","forceTargetModel","location","useModularUIOptions","isReload","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 { IllegalArgumentException, IllegalStateException } from \"../exceptions\";\n\nimport type { ModularUIModel, Href } from \"../models\";\n\ntype UseModularUIBasicOptions<T: ModularUIModel> = {\n expectedModels: Array<string>,\n targetModel?: Class<T> | Array<Class<T>>,\n forceTargetModel?: 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 if (!href) {\n throw new IllegalArgumentException(\"Missing href\");\n }\n\n const useModularUIOptions = {\n targetModel: undefined,\n forceTargetModel: undefined,\n isReload: false,\n };\n if (options.targetModel) {\n useModularUIOptions.targetModel = options.targetModel;\n useModularUIOptions.forceTargetModel = options.forceTargetModel;\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 if (options.expectedModels.length > 0) {\n const isCorrectModel = options.expectedModels.some((expectedModel) => {\n return model.type === expectedModel;\n });\n\n if (!isCorrectModel) {\n console.error(modularUI, \"is not of instance\", options.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,wBAAwB,EAAEC,qBAAqB,QAAQ,eAAe;AAU/E;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,GAAGd,WAAW,CAAC,CAAC;EAC9B,IAAI,CAACK,IAAI,EAAE;IACT,MAAM,IAAIJ,wBAAwB,CAAC,cAAc,CAAC;EACpD;EAEA,MAAMc,mBAAmB,GAAG;IAC1BH,WAAW,EAAEF,SAAS;IACtBG,gBAAgB,EAAEH,SAAS;IAC3BM,QAAQ,EAAE;EACZ,CAAC;EACD,IAAIT,OAAO,CAACK,WAAW,EAAE;IACvBG,mBAAmB,CAACH,WAAW,GAAGL,OAAO,CAACK,WAAW;IACrDG,mBAAmB,CAACF,gBAAgB,GAAGN,OAAO,CAACM,gBAAgB;EACjE;;EAEA;EACA,IAAIC,QAAQ,CAACG,KAAK,EAAEC,MAAM,IAAIC,2BAAA,CAAAb,QAAA,GAAAQ,QAAQ,CAACM,QAAQ,EAAAC,IAAA,CAAAf,QAAA,EAAYD,IAAI,CAACiB,QAAQ,CAAC,CAAC,CAAC,EAAE;IAC3EP,mBAAmB,CAACC,QAAQ,GAAG,IAAI;EACrC;;EAEA;EACA,MAAMO,SAAS,GAAGxB,YAAY,CAACK,GAAG,EAAEC,IAAI,EAAEU,mBAAmB,CAAC;EAE9D,IAAIQ,SAAS,EAAEC,KAAK,EAAE;IACpB,MAAM;MAAEA;IAAM,CAAC,GAAGD,SAAS;IAC3B,IAAIhB,OAAO,CAACI,cAAc,CAACF,MAAM,GAAG,CAAC,EAAE;MACrC,MAAMgB,cAAc,GAAGlB,OAAO,CAACI,cAAc,CAACe,IAAI,CAAEC,aAAa,IAAK;QACpE,OAAOH,KAAK,CAACI,IAAI,KAAKD,aAAa;MACrC,CAAC,CAAC;MAEF,IAAI,CAACF,cAAc,EAAE;QACnBI,OAAO,CAACC,KAAK,CAACP,SAAS,EAAE,oBAAoB,EAAEhB,OAAO,CAACI,cAAc,CAAC;QACtE,MAAM,IAAIT,qBAAqB,CAAC,mCAAmC,CAAC;MACtE;IACF;IAEA,OAAOsB,KAAK;EACd;EAEA,OAAO,IAAI;AACb,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"useModularUIBasic.js","names":["useModularUI","useLocation","IllegalStateException","useModularUIBasic","key","href","_context","options","arguments","length","undefined","expectedModels","targetModel","forceTargetModel","location","useModularUIOptions","isReload","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\ntype UseModularUIBasicOptions<T: ModularUIModel> = {\n expectedModels: Array<string>,\n targetModel?: Class<T> | Array<Class<T>>,\n forceTargetModel?: 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 };\n if (options.targetModel) {\n useModularUIOptions.targetModel = options.targetModel;\n useModularUIOptions.forceTargetModel = options.forceTargetModel;\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 if (options.expectedModels.length > 0) {\n const isCorrectModel = options.expectedModels.some((expectedModel) => {\n return model.type === expectedModel;\n });\n\n if (!isCorrectModel) {\n console.error(modularUI, \"is not of instance\", options.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;AAUrD;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;EAE9B,MAAMc,mBAAmB,GAAG;IAC1BH,WAAW,EAAEF,SAAS;IACtBG,gBAAgB,EAAEH,SAAS;IAC3BM,QAAQ,EAAE;EACZ,CAAC;EACD,IAAIT,OAAO,CAACK,WAAW,EAAE;IACvBG,mBAAmB,CAACH,WAAW,GAAGL,OAAO,CAACK,WAAW;IACrDG,mBAAmB,CAACF,gBAAgB,GAAGN,OAAO,CAACM,gBAAgB;EACjE;;EAEA;EACA,IAAIC,QAAQ,CAACG,KAAK,EAAEC,MAAM,IAAIC,2BAAA,CAAAb,QAAA,GAAAQ,QAAQ,CAACM,QAAQ,EAAAC,IAAA,CAAAf,QAAA,EAAYD,IAAI,CAACiB,QAAQ,CAAC,CAAC,CAAC,EAAE;IAC3EP,mBAAmB,CAACC,QAAQ,GAAG,IAAI;EACrC;;EAEA;EACA,MAAMO,SAAS,GAAGvB,YAAY,CAACI,GAAG,EAAEC,IAAI,EAAEU,mBAAmB,CAAC;EAE9D,IAAIQ,SAAS,EAAEC,KAAK,EAAE;IACpB,MAAM;MAAEA;IAAM,CAAC,GAAGD,SAAS;IAC3B,IAAIhB,OAAO,CAACI,cAAc,CAACF,MAAM,GAAG,CAAC,EAAE;MACrC,MAAMgB,cAAc,GAAGlB,OAAO,CAACI,cAAc,CAACe,IAAI,CAAEC,aAAa,IAAK;QACpE,OAAOH,KAAK,CAACI,IAAI,KAAKD,aAAa;MACrC,CAAC,CAAC;MAEF,IAAI,CAACF,cAAc,EAAE;QACnBI,OAAO,CAACC,KAAK,CAACP,SAAS,EAAE,oBAAoB,EAAEhB,OAAO,CAACI,cAAc,CAAC;QACtE,MAAM,IAAIT,qBAAqB,CAAC,mCAAmC,CAAC;MACtE;IACF;IAEA,OAAOsB,KAAK;EACd;EAEA,OAAO,IAAI;AACb,CAAC","ignoreList":[]}
@@ -27,7 +27,7 @@ const useModularUI = function (modelKey, url) {
27
27
  removeOnUnmount: false
28
28
  };
29
29
  const dispatch = (0, _reactRedux.useDispatch)();
30
- const href = url.toString();
30
+ const href = url?.toString() || "";
31
31
  const key = useKeyForHook(modelKey, href);
32
32
  const prevOptions = (0, _react.useRef)(options);
33
33
  const prevHref = (0, _react.useRef)(href);
@@ -36,7 +36,7 @@ const useModularUI = function (modelKey, url) {
36
36
  (0, _useDeepCompareEffect.default)(() => {
37
37
  // prevent reloads when previous option had the isReload, but the new options not
38
38
  const isOldReload = prevHref.current === href && prevOptions.current.isReload && !options.isReload;
39
- if (!isOldReload) {
39
+ if (href !== "" && !isOldReload) {
40
40
  dispatch((0, _ModularUIActions.loadModularUI)(key, href, options));
41
41
  }
42
42
  prevOptions.current = options;
@@ -34,7 +34,7 @@ export const useModularUI = (
34
34
  },
35
35
  ): any => {
36
36
  const dispatch = useDispatch();
37
- const href = url.toString();
37
+ const href = url?.toString() || "";
38
38
  const key = useKeyForHook(modelKey, href);
39
39
 
40
40
  const prevOptions = useRef(options);
@@ -48,7 +48,7 @@ export const useModularUI = (
48
48
  prevOptions.current.isReload &&
49
49
  !options.isReload;
50
50
 
51
- if (!isOldReload) {
51
+ if (href !== "" && !isOldReload) {
52
52
  dispatch(loadModularUI(key, href, options));
53
53
  }
54
54
 
@@ -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 (!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,CAACgB,QAAQ,CAAC,CAAC;EAC3B,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,IAAI,CAACF,WAAW,EAAE;MAChBT,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","_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":[]}
@@ -19,9 +19,6 @@ const useModularUIBasic = function (key, href) {
19
19
  forceTargetModel: false
20
20
  };
21
21
  const location = (0, _useRouter.useLocation)();
22
- if (!href) {
23
- throw new _exceptions.IllegalArgumentException("Missing href");
24
- }
25
22
  const useModularUIOptions = {
26
23
  targetModel: undefined,
27
24
  forceTargetModel: undefined,
@@ -3,7 +3,7 @@ import { useModularUI } from "./useModularUI";
3
3
 
4
4
  import { useLocation } from "./useRouter";
5
5
 
6
- import { IllegalArgumentException, IllegalStateException } from "../exceptions";
6
+ import { IllegalStateException } from "../exceptions";
7
7
 
8
8
  import type { ModularUIModel, Href } from "../models";
9
9
 
@@ -25,9 +25,6 @@ export const useModularUIBasic = <T: ModularUIModel>(
25
25
  },
26
26
  ): T | null => {
27
27
  const location = useLocation();
28
- if (!href) {
29
- throw new IllegalArgumentException("Missing href");
30
- }
31
28
 
32
29
  const useModularUIOptions = {
33
30
  targetModel: undefined,
@@ -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","IllegalArgumentException","useModularUIOptions","isReload","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 { IllegalArgumentException, IllegalStateException } from \"../exceptions\";\n\nimport type { ModularUIModel, Href } from \"../models\";\n\ntype UseModularUIBasicOptions<T: ModularUIModel> = {\n expectedModels: Array<string>,\n targetModel?: Class<T> | Array<Class<T>>,\n forceTargetModel?: 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 if (!href) {\n throw new IllegalArgumentException(\"Missing href\");\n }\n\n const useModularUIOptions = {\n targetModel: undefined,\n forceTargetModel: undefined,\n isReload: false,\n };\n if (options.targetModel) {\n useModularUIOptions.targetModel = options.targetModel;\n useModularUIOptions.forceTargetModel = options.forceTargetModel;\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 if (options.expectedModels.length > 0) {\n const isCorrectModel = options.expectedModels.some((expectedModel) => {\n return model.type === expectedModel;\n });\n\n if (!isCorrectModel) {\n console.error(modularUI, \"is not of instance\", options.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;AAUA;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;EAC9B,IAAI,CAACV,IAAI,EAAE;IACT,MAAM,IAAIW,oCAAwB,CAAC,cAAc,CAAC;EACpD;EAEA,MAAMC,mBAAmB,GAAG;IAC1BL,WAAW,EAAEF,SAAS;IACtBG,gBAAgB,EAAEH,SAAS;IAC3BQ,QAAQ,EAAE;EACZ,CAAC;EACD,IAAIX,OAAO,CAACK,WAAW,EAAE;IACvBK,mBAAmB,CAACL,WAAW,GAAGL,OAAO,CAACK,WAAW;IACrDK,mBAAmB,CAACJ,gBAAgB,GAAGN,OAAO,CAACM,gBAAgB;EACjE;;EAEA;EACA,IAAIC,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;IAC3ER,mBAAmB,CAACC,QAAQ,GAAG,IAAI;EACrC;;EAEA;EACA,MAAMQ,SAAS,GAAG,IAAAC,0BAAY,EAACvB,GAAG,EAAEC,IAAI,EAAEY,mBAAmB,CAAC;EAE9D,IAAIS,SAAS,EAAEE,KAAK,EAAE;IACpB,MAAM;MAAEA;IAAM,CAAC,GAAGF,SAAS;IAC3B,IAAInB,OAAO,CAACI,cAAc,CAACF,MAAM,GAAG,CAAC,EAAE;MACrC,MAAMoB,cAAc,GAAGtB,OAAO,CAACI,cAAc,CAACmB,IAAI,CAAEC,aAAa,IAAK;QACpE,OAAOH,KAAK,CAACI,IAAI,KAAKD,aAAa;MACrC,CAAC,CAAC;MAEF,IAAI,CAACF,cAAc,EAAE;QACnBI,OAAO,CAACC,KAAK,CAACR,SAAS,EAAE,oBAAoB,EAAEnB,OAAO,CAACI,cAAc,CAAC;QACtE,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":["_useModularUI","require","_useRouter","_exceptions","useModularUIBasic","key","href","_context","options","arguments","length","undefined","expectedModels","targetModel","forceTargetModel","location","useLocation","useModularUIOptions","isReload","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\ntype UseModularUIBasicOptions<T: ModularUIModel> = {\n expectedModels: Array<string>,\n targetModel?: Class<T> | Array<Class<T>>,\n forceTargetModel?: 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 };\n if (options.targetModel) {\n useModularUIOptions.targetModel = options.targetModel;\n useModularUIOptions.forceTargetModel = options.forceTargetModel;\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 if (options.expectedModels.length > 0) {\n const isCorrectModel = options.expectedModels.some((expectedModel) => {\n return model.type === expectedModel;\n });\n\n if (!isCorrectModel) {\n console.error(modularUI, \"is not of instance\", options.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;AAUA;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;EACZ,CAAC;EACD,IAAIV,OAAO,CAACK,WAAW,EAAE;IACvBI,mBAAmB,CAACJ,WAAW,GAAGL,OAAO,CAACK,WAAW;IACrDI,mBAAmB,CAACH,gBAAgB,GAAGN,OAAO,CAACM,gBAAgB;EACjE;;EAEA;EACA,IAAIC,QAAQ,CAACI,KAAK,EAAEC,MAAM,IAAI,IAAAC,WAAA,CAAAC,OAAA,EAAAf,QAAA,GAAAQ,QAAQ,CAACQ,QAAQ,EAAAC,IAAA,CAAAjB,QAAA,EAAYD,IAAI,CAACmB,QAAQ,CAAC,CAAC,CAAC,EAAE;IAC3ER,mBAAmB,CAACC,QAAQ,GAAG,IAAI;EACrC;;EAEA;EACA,MAAMQ,SAAS,GAAG,IAAAC,0BAAY,EAACtB,GAAG,EAAEC,IAAI,EAAEW,mBAAmB,CAAC;EAE9D,IAAIS,SAAS,EAAEE,KAAK,EAAE;IACpB,MAAM;MAAEA;IAAM,CAAC,GAAGF,SAAS;IAC3B,IAAIlB,OAAO,CAACI,cAAc,CAACF,MAAM,GAAG,CAAC,EAAE;MACrC,MAAMmB,cAAc,GAAGrB,OAAO,CAACI,cAAc,CAACkB,IAAI,CAAEC,aAAa,IAAK;QACpE,OAAOH,KAAK,CAACI,IAAI,KAAKD,aAAa;MACrC,CAAC,CAAC;MAEF,IAAI,CAACF,cAAc,EAAE;QACnBI,OAAO,CAACC,KAAK,CAACR,SAAS,EAAE,oBAAoB,EAAElB,OAAO,CAACI,cAAc,CAAC;QACtE,MAAM,IAAIuB,iCAAqB,CAAC,mCAAmC,CAAC;MACtE;IACF;IAEA,OAAOP,KAAK;EACd;EAEA,OAAO,IAAI;AACb,CAAC;AAACQ,OAAA,CAAAhC,iBAAA,GAAAA,iBAAA","ignoreList":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@beinformed/ui",
3
- "version": "1.50.4",
3
+ "version": "1.51.0",
4
4
  "description": "Toolbox for be informed javascript layouts",
5
5
  "license": "SEE LICENSE IN LICENSE.md",
6
6
  "bugs": "http://support.beinformed.com",
@@ -82,7 +82,7 @@
82
82
  "styled-components": "^5.0.0"
83
83
  },
84
84
  "dependencies": {
85
- "@babel/runtime-corejs3": "^7.24.7",
85
+ "@babel/runtime-corejs3": "^7.25.0",
86
86
  "big.js": "^6.2.1",
87
87
  "date-fns": "^3.6.0",
88
88
  "deepmerge": "^4.3.1",
@@ -98,14 +98,14 @@
98
98
  "setimmediate": "^1.0.5"
99
99
  },
100
100
  "devDependencies": {
101
- "@babel/cli": "^7.24.7",
102
- "@babel/core": "^7.24.7",
103
- "@babel/eslint-parser": "^7.24.7",
104
- "@babel/eslint-plugin": "^7.24.7",
101
+ "@babel/cli": "^7.24.8",
102
+ "@babel/core": "^7.25.2",
103
+ "@babel/eslint-parser": "^7.25.1",
104
+ "@babel/eslint-plugin": "^7.25.1",
105
105
  "@babel/plugin-proposal-class-properties": "^7.18.6",
106
106
  "@babel/plugin-syntax-dynamic-import": "^7.8.3",
107
107
  "@babel/plugin-transform-runtime": "^7.24.7",
108
- "@babel/preset-env": "^7.24.7",
108
+ "@babel/preset-env": "^7.25.3",
109
109
  "@babel/preset-flow": "^7.24.7",
110
110
  "@babel/preset-react": "^7.24.7",
111
111
  "@commitlint/cli": "^19.3.0",
@@ -121,27 +121,27 @@
121
121
  "eslint": "^8.57.0",
122
122
  "eslint-config-prettier": "^9.1.0",
123
123
  "eslint-plugin-babel": "^5.3.1",
124
- "eslint-plugin-ft-flow": "^3.0.9",
124
+ "eslint-plugin-ft-flow": "^3.0.11",
125
125
  "eslint-plugin-import": "^2.29.1",
126
126
  "eslint-plugin-jest": "^27.9.0",
127
- "eslint-plugin-jsdoc": "^48.5.0",
128
- "eslint-plugin-react": "^7.34.3",
127
+ "eslint-plugin-jsdoc": "^48.10.2",
128
+ "eslint-plugin-react": "^7.35.0",
129
129
  "eslint-plugin-react-hooks": "^4.6.2",
130
130
  "eslint-plugin-you-dont-need-lodash-underscore": "^6.14.0",
131
131
  "flow-bin": "^0.200.1",
132
132
  "flow-copy-source": "^2.0.9",
133
133
  "flow-typed": "^3.9.0",
134
- "hermes-eslint": "^0.22.0",
134
+ "hermes-eslint": "^0.23.1",
135
135
  "history": "^4.0.0",
136
- "husky": "^9.0.11",
136
+ "husky": "^9.1.4",
137
137
  "jest": "^29.7.0",
138
138
  "jest-environment-jsdom": "^29.7.0",
139
139
  "jest-junit": "^16.0.0",
140
140
  "jest-sonar-reporter": "^2.0.0",
141
- "jscodeshift": "^0.15.1",
141
+ "jscodeshift": "^0.16.1",
142
142
  "lint-staged": "^15.2.7",
143
143
  "polished": "^4.0.0",
144
- "prettier": "^3.3.2",
144
+ "prettier": "^3.3.3",
145
145
  "react": "^18.3.1",
146
146
  "react-dom": "^18.3.1",
147
147
  "react-helmet-async": "^2.0.5",
@@ -34,7 +34,7 @@ export const useModularUI = (
34
34
  },
35
35
  ): any => {
36
36
  const dispatch = useDispatch();
37
- const href = url.toString();
37
+ const href = url?.toString() || "";
38
38
  const key = useKeyForHook(modelKey, href);
39
39
 
40
40
  const prevOptions = useRef(options);
@@ -48,7 +48,7 @@ export const useModularUI = (
48
48
  prevOptions.current.isReload &&
49
49
  !options.isReload;
50
50
 
51
- if (!isOldReload) {
51
+ if (href !== "" && !isOldReload) {
52
52
  dispatch(loadModularUI(key, href, options));
53
53
  }
54
54
 
@@ -3,7 +3,7 @@ import { useModularUI } from "./useModularUI";
3
3
 
4
4
  import { useLocation } from "./useRouter";
5
5
 
6
- import { IllegalArgumentException, IllegalStateException } from "../exceptions";
6
+ import { IllegalStateException } from "../exceptions";
7
7
 
8
8
  import type { ModularUIModel, Href } from "../models";
9
9
 
@@ -25,9 +25,6 @@ export const useModularUIBasic = <T: ModularUIModel>(
25
25
  },
26
26
  ): T | null => {
27
27
  const location = useLocation();
28
- if (!href) {
29
- throw new IllegalArgumentException("Missing href");
30
- }
31
28
 
32
29
  const useModularUIOptions = {
33
30
  targetModel: undefined,