@beinformed/ui 1.65.15 → 1.65.17
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 +15 -0
- package/esm/hooks/useModularUI.js +2 -2
- package/esm/hooks/useModularUI.js.flow +3 -2
- package/esm/hooks/useModularUI.js.map +1 -1
- package/esm/hooks/useModularUIBasic.js.flow +1 -1
- package/esm/hooks/useModularUIBasic.js.map +1 -1
- package/lib/hooks/useModularUI.js +1 -1
- package/lib/hooks/useModularUI.js.map +1 -1
- package/lib/hooks/useModularUIBasic.js.map +1 -1
- package/package.json +1 -1
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.65.17](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/compare/v1.65.15...v1.65.17) (2026-01-15)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* **hooks:** handle error status in `useModularUI` reload logic ([8cec2b7](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/commit/8cec2b706a06bfafd7f070b644ca47e5434e595d))
|
|
11
|
+
* **types:** refine default options typing in `useModularUI` and `useModularUIBasic` hooks ([f994795](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/commit/f99479540fc2c71efbe6772bb76a99fa855844ef))
|
|
12
|
+
|
|
13
|
+
## [1.65.16](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/compare/v1.65.15...v1.65.16) (2026-01-15)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
### Bug Fixes
|
|
17
|
+
|
|
18
|
+
* **types:** refine default options typing in `useModularUI` and `useModularUIBasic` hooks ([f994795](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/commit/f99479540fc2c71efbe6772bb76a99fa855844ef))
|
|
19
|
+
|
|
5
20
|
## [1.65.15](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/compare/v1.65.14...v1.65.15) (2026-01-15)
|
|
6
21
|
|
|
7
22
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useEffect, useMemo } from "react";
|
|
2
2
|
import { useDispatch, useSelector } from "react-redux";
|
|
3
3
|
import { useLocation } from "react-router";
|
|
4
|
-
import { HTTP_METHODS } from "../constants";
|
|
4
|
+
import { HTTP_METHODS, MODULARUI_STATUS } from "../constants";
|
|
5
5
|
import { loadModularUI, removeModelByKey } from "../redux/_modularui/ModularUIActions";
|
|
6
6
|
import useDeepCompareEffect from "./useDeepCompareEffect";
|
|
7
7
|
import { useModularUIKey } from "./useModularUIKey";
|
|
@@ -28,7 +28,7 @@ export const useModularUI = (modelKey, url, options = {}) => {
|
|
|
28
28
|
}, [options, url]);
|
|
29
29
|
const location = useLocation();
|
|
30
30
|
const redirectLocation = location.state?.redirectLocation;
|
|
31
|
-
const shouldLoad = model == null || (redirectLocation instanceof Href ? redirectLocation?.equals(href) : false) || requestOptions.isReload === true;
|
|
31
|
+
const shouldLoad = model == null || model.status === MODULARUI_STATUS.ERROR || (redirectLocation instanceof Href ? redirectLocation?.equals(href) : false) || requestOptions.isReload === true;
|
|
32
32
|
|
|
33
33
|
// dispatch loadModularUI
|
|
34
34
|
useDeepCompareEffect(() => {
|
|
@@ -3,7 +3,7 @@ import { useEffect, useMemo } from "react";
|
|
|
3
3
|
import { useDispatch, useSelector } from "react-redux";
|
|
4
4
|
import { useLocation } from "react-router";
|
|
5
5
|
|
|
6
|
-
import { HTTP_METHODS } from "../constants";
|
|
6
|
+
import { HTTP_METHODS, MODULARUI_STATUS } from "../constants";
|
|
7
7
|
import {
|
|
8
8
|
loadModularUI,
|
|
9
9
|
removeModelByKey,
|
|
@@ -21,7 +21,7 @@ import type { RequestModularUIOptions } from "../utils";
|
|
|
21
21
|
export const useModularUI = (
|
|
22
22
|
modelKey: string,
|
|
23
23
|
url: string | Href,
|
|
24
|
-
options: RequestModularUIOptions = {},
|
|
24
|
+
options: RequestModularUIOptions = (({}: any): RequestModularUIOptions),
|
|
25
25
|
): any => {
|
|
26
26
|
const dispatch = useDispatch();
|
|
27
27
|
|
|
@@ -49,6 +49,7 @@ export const useModularUI = (
|
|
|
49
49
|
|
|
50
50
|
const shouldLoad =
|
|
51
51
|
model == null ||
|
|
52
|
+
model.status === MODULARUI_STATUS.ERROR ||
|
|
52
53
|
(redirectLocation instanceof Href
|
|
53
54
|
? redirectLocation?.equals(href)
|
|
54
55
|
: false) ||
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useModularUI.js","names":["useEffect","useMemo","useDispatch","useSelector","useLocation","HTTP_METHODS","loadModularUI","removeModelByKey","useDeepCompareEffect","useModularUIKey","Href","useModularUI","modelKey","url","options","dispatch","href","toString","key","model","state","modularui","requestOptions","merged","method","GET","removeOnUnmount","origin","contextPath","location","redirectLocation","shouldLoad","equals","isReload"],"sources":["../../src/hooks/useModularUI.js"],"sourcesContent":["// @flow\nimport { useEffect, 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\";\nimport { useModularUIKey } from \"./useModularUIKey\";\n\nimport Href from \"../models/href/Href\";\nimport type { RequestModularUIOptions } from \"../utils\";\n\n/**\n * Core hook to retrieve information for a Be Informed modular ui resource\n */\nexport const useModularUI = (\n modelKey: string,\n url: string | Href,\n options: RequestModularUIOptions = {},\n): any => {\n const dispatch = useDispatch();\n\n const href = useMemo(() => url?.toString() || \"\", [url]);\n const key = useModularUIKey(modelKey, href);\n\n const model = useSelector((state) => state.modularui[key]);\n\n const requestOptions = useMemo(() => {\n const merged = {\n method: HTTP_METHODS.GET,\n removeOnUnmount: false,\n ...options,\n };\n\n if (url instanceof Href) {\n merged.origin = merged.origin ?? url.origin;\n merged.contextPath = merged.contextPath ?? url.contextPath;\n }\n return merged;\n }, [options, url]);\n\n const location = useLocation();\n const redirectLocation = location.state?.redirectLocation;\n\n const shouldLoad =\n model == null ||\n (redirectLocation instanceof Href\n ? redirectLocation?.equals(href)\n : false) ||\n requestOptions.isReload === true;\n\n // dispatch loadModularUI\n useDeepCompareEffect(() => {\n if (href !== \"\" && shouldLoad) {\n dispatch(loadModularUI(key, href, requestOptions));\n }\n }, [key, href, requestOptions, shouldLoad]);\n\n useEffect(() => {\n if (requestOptions.removeOnUnmount) {\n return () => {\n dispatch(removeModelByKey(key));\n };\n }\n }, [dispatch, key, requestOptions.removeOnUnmount]);\n\n return model;\n};\n"],"mappings":"AACA,SAASA,SAAS,EAAEC,OAAO,QAAQ,OAAO;AAC1C,SAASC,WAAW,EAAEC,WAAW,QAAQ,aAAa;AACtD,SAASC,WAAW,QAAQ,cAAc;AAE1C,SAASC,YAAY,QAAQ,cAAc;
|
|
1
|
+
{"version":3,"file":"useModularUI.js","names":["useEffect","useMemo","useDispatch","useSelector","useLocation","HTTP_METHODS","MODULARUI_STATUS","loadModularUI","removeModelByKey","useDeepCompareEffect","useModularUIKey","Href","useModularUI","modelKey","url","options","dispatch","href","toString","key","model","state","modularui","requestOptions","merged","method","GET","removeOnUnmount","origin","contextPath","location","redirectLocation","shouldLoad","status","ERROR","equals","isReload"],"sources":["../../src/hooks/useModularUI.js"],"sourcesContent":["// @flow\nimport { useEffect, useMemo } from \"react\";\nimport { useDispatch, useSelector } from \"react-redux\";\nimport { useLocation } from \"react-router\";\n\nimport { HTTP_METHODS, MODULARUI_STATUS } from \"../constants\";\nimport {\n loadModularUI,\n removeModelByKey,\n} from \"../redux/_modularui/ModularUIActions\";\n\nimport useDeepCompareEffect from \"./useDeepCompareEffect\";\nimport { useModularUIKey } from \"./useModularUIKey\";\n\nimport Href from \"../models/href/Href\";\nimport type { RequestModularUIOptions } from \"../utils\";\n\n/**\n * Core hook to retrieve information for a Be Informed modular ui resource\n */\nexport const useModularUI = (\n modelKey: string,\n url: string | Href,\n options: RequestModularUIOptions = (({}: any): RequestModularUIOptions),\n): any => {\n const dispatch = useDispatch();\n\n const href = useMemo(() => url?.toString() || \"\", [url]);\n const key = useModularUIKey(modelKey, href);\n\n const model = useSelector((state) => state.modularui[key]);\n\n const requestOptions = useMemo(() => {\n const merged = {\n method: HTTP_METHODS.GET,\n removeOnUnmount: false,\n ...options,\n };\n\n if (url instanceof Href) {\n merged.origin = merged.origin ?? url.origin;\n merged.contextPath = merged.contextPath ?? url.contextPath;\n }\n return merged;\n }, [options, url]);\n\n const location = useLocation();\n const redirectLocation = location.state?.redirectLocation;\n\n const shouldLoad =\n model == null ||\n model.status === MODULARUI_STATUS.ERROR ||\n (redirectLocation instanceof Href\n ? redirectLocation?.equals(href)\n : false) ||\n requestOptions.isReload === true;\n\n // dispatch loadModularUI\n useDeepCompareEffect(() => {\n if (href !== \"\" && shouldLoad) {\n dispatch(loadModularUI(key, href, requestOptions));\n }\n }, [key, href, requestOptions, shouldLoad]);\n\n useEffect(() => {\n if (requestOptions.removeOnUnmount) {\n return () => {\n dispatch(removeModelByKey(key));\n };\n }\n }, [dispatch, key, requestOptions.removeOnUnmount]);\n\n return model;\n};\n"],"mappings":"AACA,SAASA,SAAS,EAAEC,OAAO,QAAQ,OAAO;AAC1C,SAASC,WAAW,EAAEC,WAAW,QAAQ,aAAa;AACtD,SAASC,WAAW,QAAQ,cAAc;AAE1C,SAASC,YAAY,EAAEC,gBAAgB,QAAQ,cAAc;AAC7D,SACEC,aAAa,EACbC,gBAAgB,QACX,sCAAsC;AAE7C,OAAOC,oBAAoB,MAAM,wBAAwB;AACzD,SAASC,eAAe,QAAQ,mBAAmB;AAEnD,OAAOC,IAAI,MAAM,qBAAqB;AAGtC;AACA;AACA;AACA,OAAO,MAAMC,YAAY,GAAGA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AIQ,IAAI,KAAK,EAAE,IAAIe,UAAU,EAAE;MAC7BhB,QAAQ,CAACT,aAAa,CAACY,GAAG,EAAEF,IAAI,EAAEM,cAAc,CAAC,CAAC;IACpD;EACF,CAAC,EAAE,CAACJ,GAAG,EAAEF,IAAI,EAAEM,cAAc,EAAES,UAAU,CAAC,CAAC;EAE3ChC,SAAS,CAAC,MAAM;IACd,IAAIuB,cAAc,CAACI,eAAe,EAAE;MAClC,OAAO,MAAM;QACXX,QAAQ,CAACR,gBAAgB,CAACW,GAAG,CAAC,CAAC;MACjC,CAAC;IACH;EACF,CAAC,EAAE,CAACH,QAAQ,EAAEG,GAAG,EAAEI,cAAc,CAACI,eAAe,CAAC,CAAC;EAEnD,OAAOP,KAAK;AACd,CAAC","ignoreList":[]}
|
|
@@ -68,7 +68,7 @@ const validateModel = (model: any, expectedModels: Array<string>) => {
|
|
|
68
68
|
export const useModularUIBasic = <T: ModularUIModel>(
|
|
69
69
|
defaultKey: string,
|
|
70
70
|
href: string | Href,
|
|
71
|
-
options: UseModularUIBasicOptions<T> = {},
|
|
71
|
+
options: UseModularUIBasicOptions<T> = (({}: any): UseModularUIBasicOptions<T>),
|
|
72
72
|
): T | null => {
|
|
73
73
|
const memoizedHref = useMemo(() => href.toString(), [href]);
|
|
74
74
|
const key = options.key ?? defaultKey;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useModularUIBasic.js","names":["useLocation","useSelector","useMemo","useModularUI","HTTP_METHODS","MODULARUI_STATUS","useModularUIKey","createUseModularUIOptions","options","href","mustReload","baseOptions","expectedModels","method","GET","data","undefined","removeOnUnmount","isReload","formdata","POST","validateModel","model","length","isCorrectModel","_includesInstanceProperty","call","type","console","warn","useModularUIBasic","defaultKey","memoizedHref","toString","key","useReload","modularUIOptions","modularUI","modelKey","url","location","modelEntry","state","modularui","reload","isFullyLoaded","status","FINISHED","lastModification"],"sources":["../../src/hooks/useModularUIBasic.js"],"sourcesContent":["// @flow\nimport { useLocation } from \"react-router\";\nimport { useSelector } from \"react-redux\";\nimport { useMemo } from \"react\";\nimport { useModularUI } from \"./useModularUI\";\n\nimport { HTTP_METHODS, MODULARUI_STATUS } from \"../constants\";\nimport { useModularUIKey } from \"./useModularUIKey\";\n\nimport type { ModularUIModel, Href } from \"../models\";\nexport type HookOptions = {\n key?: string,\n origin?: string,\n contextPath?: string,\n removeOnUnmount?: boolean,\n formdata?: any,\n};\n\nexport type UseModularUIBasicOptions<T: ModularUIModel> = {\n expectedModels?: Array<string>,\n targetModel?: Class<T> | Array<Class<T>>,\n forceTargetModel?: boolean,\n origin?: string,\n contextPath?: string,\n cache?: boolean,\n key?: string,\n isReload?: boolean,\n removeOnUnmount?: boolean,\n formdata?: any,\n};\n\n// Helper to create useModularUI options\nconst createUseModularUIOptions = <T: ModularUIModel>(\n options: UseModularUIBasicOptions<T>,\n href: string,\n mustReload: boolean,\n): Object => {\n const baseOptions = {\n expectedModels: [],\n method: HTTP_METHODS.GET,\n data: undefined,\n removeOnUnmount: false,\n ...options,\n isReload: mustReload || options.isReload,\n };\n\n if (options.formdata != null) {\n baseOptions.method = HTTP_METHODS.POST;\n baseOptions.data = options.formdata;\n }\n\n return baseOptions;\n};\n\n// Helper to validate the model against expectedModels\nconst validateModel = (model: any, expectedModels: Array<string>) => {\n if (expectedModels.length > 0) {\n const isCorrectModel = expectedModels.includes(model.type);\n if (!isCorrectModel) {\n console.warn(model, \"is not of instance\", expectedModels);\n }\n }\n};\n\n/**\n * useModularUIBasic Hook\n */\nexport const useModularUIBasic = <T: ModularUIModel>(\n defaultKey: string,\n href: string | Href,\n options: UseModularUIBasicOptions<T> = {},\n): T | null => {\n const memoizedHref = useMemo(() => href.toString(), [href]);\n const key = options.key ?? defaultKey;\n\n const mustReload = useReload(key, memoizedHref);\n const modularUIOptions = useMemo(\n () => createUseModularUIOptions(options, memoizedHref, mustReload),\n [options, memoizedHref, mustReload],\n );\n\n const modularUI = useModularUI(key, href, modularUIOptions);\n const expectedModels = useMemo(\n () => options.expectedModels ?? [],\n [options.expectedModels],\n );\n\n return useMemo((): T | null => {\n if (modularUI?.model) {\n validateModel(modularUI.model, expectedModels);\n return modularUI.model;\n }\n return null;\n }, [expectedModels, modularUI]);\n};\n\n/**\n * Check if the model corresponding to a modular ui service should be reloaded\n */\nexport const useReload = (modelKey: string, url: string): boolean => {\n const location = useLocation();\n const key = useModularUIKey(modelKey, url);\n const modelEntry = useSelector((state) => state.modularui[key]);\n\n if (modelEntry) {\n const reload = location.state?.reload || 0;\n if (reload > 0) {\n const isFullyLoaded = modelEntry?.status === MODULARUI_STATUS.FINISHED;\n const lastModification = modelEntry?.lastModification ?? 0;\n if (isFullyLoaded && lastModification < reload) {\n return true;\n }\n }\n }\n return false;\n};\n"],"mappings":";AACA,SAASA,WAAW,QAAQ,cAAc;AAC1C,SAASC,WAAW,QAAQ,aAAa;AACzC,SAASC,OAAO,QAAQ,OAAO;AAC/B,SAASC,YAAY,QAAQ,gBAAgB;AAE7C,SAASC,YAAY,EAAEC,gBAAgB,QAAQ,cAAc;AAC7D,SAASC,eAAe,QAAQ,mBAAmB;AAwBnD;AACA,MAAMC,yBAAyB,GAAGA,CAChCC,OAAoC,EACpCC,IAAY,EACZC,UAAmB,KACR;EACX,MAAMC,WAAW,GAAG;IAClBC,cAAc,EAAE,EAAE;IAClBC,MAAM,EAAET,YAAY,CAACU,GAAG;IACxBC,IAAI,EAAEC,SAAS;IACfC,eAAe,EAAE,KAAK;IACtB,GAAGT,OAAO;IACVU,QAAQ,EAAER,UAAU,IAAIF,OAAO,CAACU;EAClC,CAAC;EAED,IAAIV,OAAO,CAACW,QAAQ,IAAI,IAAI,EAAE;IAC5BR,WAAW,CAACE,MAAM,GAAGT,YAAY,CAACgB,IAAI;IACtCT,WAAW,CAACI,IAAI,GAAGP,OAAO,CAACW,QAAQ;EACrC;EAEA,OAAOR,WAAW;AACpB,CAAC;;AAED;AACA,MAAMU,aAAa,GAAGA,CAACC,KAAU,EAAEV,cAA6B,KAAK;EACnE,IAAIA,cAAc,CAACW,MAAM,GAAG,CAAC,EAAE;IAC7B,MAAMC,cAAc,GAAGC,yBAAA,CAAAb,cAAc,EAAAc,IAAA,CAAdd,cAAc,EAAUU,KAAK,CAACK,IAAI,CAAC;IAC1D,IAAI,CAACH,cAAc,EAAE;MACnBI,OAAO,CAACC,IAAI,CAACP,KAAK,EAAE,oBAAoB,EAAEV,cAAc,CAAC;IAC3D;EACF;AACF,CAAC;;AAED;AACA;AACA;AACA,OAAO,MAAMkB,iBAAiB,GAAGA,CAC/BC,UAAkB,EAClBtB,IAAmB,EACnBD,OAAoC,
|
|
1
|
+
{"version":3,"file":"useModularUIBasic.js","names":["useLocation","useSelector","useMemo","useModularUI","HTTP_METHODS","MODULARUI_STATUS","useModularUIKey","createUseModularUIOptions","options","href","mustReload","baseOptions","expectedModels","method","GET","data","undefined","removeOnUnmount","isReload","formdata","POST","validateModel","model","length","isCorrectModel","_includesInstanceProperty","call","type","console","warn","useModularUIBasic","defaultKey","memoizedHref","toString","key","useReload","modularUIOptions","modularUI","modelKey","url","location","modelEntry","state","modularui","reload","isFullyLoaded","status","FINISHED","lastModification"],"sources":["../../src/hooks/useModularUIBasic.js"],"sourcesContent":["// @flow\nimport { useLocation } from \"react-router\";\nimport { useSelector } from \"react-redux\";\nimport { useMemo } from \"react\";\nimport { useModularUI } from \"./useModularUI\";\n\nimport { HTTP_METHODS, MODULARUI_STATUS } from \"../constants\";\nimport { useModularUIKey } from \"./useModularUIKey\";\n\nimport type { ModularUIModel, Href } from \"../models\";\nexport type HookOptions = {\n key?: string,\n origin?: string,\n contextPath?: string,\n removeOnUnmount?: boolean,\n formdata?: any,\n};\n\nexport type UseModularUIBasicOptions<T: ModularUIModel> = {\n expectedModels?: Array<string>,\n targetModel?: Class<T> | Array<Class<T>>,\n forceTargetModel?: boolean,\n origin?: string,\n contextPath?: string,\n cache?: boolean,\n key?: string,\n isReload?: boolean,\n removeOnUnmount?: boolean,\n formdata?: any,\n};\n\n// Helper to create useModularUI options\nconst createUseModularUIOptions = <T: ModularUIModel>(\n options: UseModularUIBasicOptions<T>,\n href: string,\n mustReload: boolean,\n): Object => {\n const baseOptions = {\n expectedModels: [],\n method: HTTP_METHODS.GET,\n data: undefined,\n removeOnUnmount: false,\n ...options,\n isReload: mustReload || options.isReload,\n };\n\n if (options.formdata != null) {\n baseOptions.method = HTTP_METHODS.POST;\n baseOptions.data = options.formdata;\n }\n\n return baseOptions;\n};\n\n// Helper to validate the model against expectedModels\nconst validateModel = (model: any, expectedModels: Array<string>) => {\n if (expectedModels.length > 0) {\n const isCorrectModel = expectedModels.includes(model.type);\n if (!isCorrectModel) {\n console.warn(model, \"is not of instance\", expectedModels);\n }\n }\n};\n\n/**\n * useModularUIBasic Hook\n */\nexport const useModularUIBasic = <T: ModularUIModel>(\n defaultKey: string,\n href: string | Href,\n options: UseModularUIBasicOptions<T> = (({}: any): UseModularUIBasicOptions<T>),\n): T | null => {\n const memoizedHref = useMemo(() => href.toString(), [href]);\n const key = options.key ?? defaultKey;\n\n const mustReload = useReload(key, memoizedHref);\n const modularUIOptions = useMemo(\n () => createUseModularUIOptions(options, memoizedHref, mustReload),\n [options, memoizedHref, mustReload],\n );\n\n const modularUI = useModularUI(key, href, modularUIOptions);\n const expectedModels = useMemo(\n () => options.expectedModels ?? [],\n [options.expectedModels],\n );\n\n return useMemo((): T | null => {\n if (modularUI?.model) {\n validateModel(modularUI.model, expectedModels);\n return modularUI.model;\n }\n return null;\n }, [expectedModels, modularUI]);\n};\n\n/**\n * Check if the model corresponding to a modular ui service should be reloaded\n */\nexport const useReload = (modelKey: string, url: string): boolean => {\n const location = useLocation();\n const key = useModularUIKey(modelKey, url);\n const modelEntry = useSelector((state) => state.modularui[key]);\n\n if (modelEntry) {\n const reload = location.state?.reload || 0;\n if (reload > 0) {\n const isFullyLoaded = modelEntry?.status === MODULARUI_STATUS.FINISHED;\n const lastModification = modelEntry?.lastModification ?? 0;\n if (isFullyLoaded && lastModification < reload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AC1C,IAAIA,MAAM,GAAG,CAAC,EAAE;MACd,MAAMC,aAAa,GAAGJ,UAAU,EAAEK,MAAM,KAAKzC,gBAAgB,CAAC0C,QAAQ;MACtE,MAAMC,gBAAgB,GAAGP,UAAU,EAAEO,gBAAgB,IAAI,CAAC;MAC1D,IAAIH,aAAa,IAAIG,gBAAgB,GAAGJ,MAAM,EAAE;QAC9C,OAAO,IAAI;MACb;IACF;EACF;EACA,OAAO,KAAK;AACd,CAAC","ignoreList":[]}
|
|
@@ -35,7 +35,7 @@ const useModularUI = (modelKey, url, options = {}) => {
|
|
|
35
35
|
}, [options, url]);
|
|
36
36
|
const location = (0, _reactRouter.useLocation)();
|
|
37
37
|
const redirectLocation = location.state?.redirectLocation;
|
|
38
|
-
const shouldLoad = model == null || (redirectLocation instanceof _Href.default ? redirectLocation?.equals(href) : false) || requestOptions.isReload === true;
|
|
38
|
+
const shouldLoad = model == null || model.status === _constants.MODULARUI_STATUS.ERROR || (redirectLocation instanceof _Href.default ? redirectLocation?.equals(href) : false) || requestOptions.isReload === true;
|
|
39
39
|
|
|
40
40
|
// dispatch loadModularUI
|
|
41
41
|
(0, _useDeepCompareEffect.default)(() => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useModularUI.js","names":["_react","require","_reactRedux","_reactRouter","_constants","_ModularUIActions","_useDeepCompareEffect","_interopRequireDefault","_useModularUIKey","_Href","useModularUI","modelKey","url","options","dispatch","useDispatch","href","useMemo","toString","key","useModularUIKey","model","useSelector","state","modularui","requestOptions","merged","method","HTTP_METHODS","GET","removeOnUnmount","Href","origin","contextPath","location","useLocation","redirectLocation","shouldLoad","equals","isReload","useDeepCompareEffect","loadModularUI","useEffect","removeModelByKey","exports"],"sources":["../../src/hooks/useModularUI.js"],"sourcesContent":["// @flow\nimport { useEffect, 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\";\nimport { useModularUIKey } from \"./useModularUIKey\";\n\nimport Href from \"../models/href/Href\";\nimport type { RequestModularUIOptions } from \"../utils\";\n\n/**\n * Core hook to retrieve information for a Be Informed modular ui resource\n */\nexport const useModularUI = (\n modelKey: string,\n url: string | Href,\n options: RequestModularUIOptions = {},\n): any => {\n const dispatch = useDispatch();\n\n const href = useMemo(() => url?.toString() || \"\", [url]);\n const key = useModularUIKey(modelKey, href);\n\n const model = useSelector((state) => state.modularui[key]);\n\n const requestOptions = useMemo(() => {\n const merged = {\n method: HTTP_METHODS.GET,\n removeOnUnmount: false,\n ...options,\n };\n\n if (url instanceof Href) {\n merged.origin = merged.origin ?? url.origin;\n merged.contextPath = merged.contextPath ?? url.contextPath;\n }\n return merged;\n }, [options, url]);\n\n const location = useLocation();\n const redirectLocation = location.state?.redirectLocation;\n\n const shouldLoad =\n model == null ||\n (redirectLocation instanceof Href\n ? redirectLocation?.equals(href)\n : false) ||\n requestOptions.isReload === true;\n\n // dispatch loadModularUI\n useDeepCompareEffect(() => {\n if (href !== \"\" && shouldLoad) {\n dispatch(loadModularUI(key, href, requestOptions));\n }\n }, [key, href, requestOptions, shouldLoad]);\n\n useEffect(() => {\n if (requestOptions.removeOnUnmount) {\n return () => {\n dispatch(removeModelByKey(key));\n };\n }\n }, [dispatch, key, requestOptions.removeOnUnmount]);\n\n return model;\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;AACA,IAAAO,gBAAA,GAAAP,OAAA;AAEA,IAAAQ,KAAA,GAAAF,sBAAA,CAAAN,OAAA;AAGA;AACA;AACA;AACO,MAAMS,YAAY,GAAGA,CAC1BC,QAAgB,EAChBC,GAAkB,EAClBC,OAAgC,
|
|
1
|
+
{"version":3,"file":"useModularUI.js","names":["_react","require","_reactRedux","_reactRouter","_constants","_ModularUIActions","_useDeepCompareEffect","_interopRequireDefault","_useModularUIKey","_Href","useModularUI","modelKey","url","options","dispatch","useDispatch","href","useMemo","toString","key","useModularUIKey","model","useSelector","state","modularui","requestOptions","merged","method","HTTP_METHODS","GET","removeOnUnmount","Href","origin","contextPath","location","useLocation","redirectLocation","shouldLoad","status","MODULARUI_STATUS","ERROR","equals","isReload","useDeepCompareEffect","loadModularUI","useEffect","removeModelByKey","exports"],"sources":["../../src/hooks/useModularUI.js"],"sourcesContent":["// @flow\nimport { useEffect, useMemo } from \"react\";\nimport { useDispatch, useSelector } from \"react-redux\";\nimport { useLocation } from \"react-router\";\n\nimport { HTTP_METHODS, MODULARUI_STATUS } from \"../constants\";\nimport {\n loadModularUI,\n removeModelByKey,\n} from \"../redux/_modularui/ModularUIActions\";\n\nimport useDeepCompareEffect from \"./useDeepCompareEffect\";\nimport { useModularUIKey } from \"./useModularUIKey\";\n\nimport Href from \"../models/href/Href\";\nimport type { RequestModularUIOptions } from \"../utils\";\n\n/**\n * Core hook to retrieve information for a Be Informed modular ui resource\n */\nexport const useModularUI = (\n modelKey: string,\n url: string | Href,\n options: RequestModularUIOptions = (({}: any): RequestModularUIOptions),\n): any => {\n const dispatch = useDispatch();\n\n const href = useMemo(() => url?.toString() || \"\", [url]);\n const key = useModularUIKey(modelKey, href);\n\n const model = useSelector((state) => state.modularui[key]);\n\n const requestOptions = useMemo(() => {\n const merged = {\n method: HTTP_METHODS.GET,\n removeOnUnmount: false,\n ...options,\n };\n\n if (url instanceof Href) {\n merged.origin = merged.origin ?? url.origin;\n merged.contextPath = merged.contextPath ?? url.contextPath;\n }\n return merged;\n }, [options, url]);\n\n const location = useLocation();\n const redirectLocation = location.state?.redirectLocation;\n\n const shouldLoad =\n model == null ||\n model.status === MODULARUI_STATUS.ERROR ||\n (redirectLocation instanceof Href\n ? redirectLocation?.equals(href)\n : false) ||\n requestOptions.isReload === true;\n\n // dispatch loadModularUI\n useDeepCompareEffect(() => {\n if (href !== \"\" && shouldLoad) {\n dispatch(loadModularUI(key, href, requestOptions));\n }\n }, [key, href, requestOptions, shouldLoad]);\n\n useEffect(() => {\n if (requestOptions.removeOnUnmount) {\n return () => {\n dispatch(removeModelByKey(key));\n };\n }\n }, [dispatch, key, requestOptions.removeOnUnmount]);\n\n return model;\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;AACA,IAAAO,gBAAA,GAAAP,OAAA;AAEA,IAAAQ,KAAA,GAAAF,sBAAA,CAAAN,OAAA;AAGA;AACA;AACA;AACO,MAAMS,YAAY,GAAGA,CAC1BC,QAAgB,EAChBC,GAAkB,EAClBC,OAAgC,GAAK,CAAC,CAAiC,KAC/D;EACR,MAAMC,QAAQ,GAAG,IAAAC,uBAAW,EAAC,CAAC;EAE9B,MAAMC,IAAI,GAAG,IAAAC,cAAO,EAAC,MAAML,GAAG,EAAEM,QAAQ,CAAC,CAAC,IAAI,EAAE,EAAE,CAACN,GAAG,CAAC,CAAC;EACxD,MAAMO,GAAG,GAAG,IAAAC,gCAAe,EAACT,QAAQ,EAAEK,IAAI,CAAC;EAE3C,MAAMK,KAAK,GAAG,IAAAC,uBAAW,EAAEC,KAAK,IAAKA,KAAK,CAACC,SAAS,CAACL,GAAG,CAAC,CAAC;EAE1D,MAAMM,cAAc,GAAG,IAAAR,cAAO,EAAC,MAAM;IACnC,MAAMS,MAAM,GAAG;MACbC,MAAM,EAAEC,uBAAY,CAACC,GA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AAAC0B,OAAA,CAAArC,YAAA,GAAAA,YAAA","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useModularUIBasic.js","names":["_reactRouter","require","_reactRedux","_react","_useModularUI","_constants","_useModularUIKey","createUseModularUIOptions","options","href","mustReload","baseOptions","expectedModels","method","HTTP_METHODS","GET","data","undefined","removeOnUnmount","isReload","formdata","POST","validateModel","model","length","isCorrectModel","_includes","default","call","type","console","warn","useModularUIBasic","defaultKey","memoizedHref","useMemo","toString","key","useReload","modularUIOptions","modularUI","useModularUI","exports","modelKey","url","location","useLocation","useModularUIKey","modelEntry","useSelector","state","modularui","reload","isFullyLoaded","status","MODULARUI_STATUS","FINISHED","lastModification"],"sources":["../../src/hooks/useModularUIBasic.js"],"sourcesContent":["// @flow\nimport { useLocation } from \"react-router\";\nimport { useSelector } from \"react-redux\";\nimport { useMemo } from \"react\";\nimport { useModularUI } from \"./useModularUI\";\n\nimport { HTTP_METHODS, MODULARUI_STATUS } from \"../constants\";\nimport { useModularUIKey } from \"./useModularUIKey\";\n\nimport type { ModularUIModel, Href } from \"../models\";\nexport type HookOptions = {\n key?: string,\n origin?: string,\n contextPath?: string,\n removeOnUnmount?: boolean,\n formdata?: any,\n};\n\nexport type UseModularUIBasicOptions<T: ModularUIModel> = {\n expectedModels?: Array<string>,\n targetModel?: Class<T> | Array<Class<T>>,\n forceTargetModel?: boolean,\n origin?: string,\n contextPath?: string,\n cache?: boolean,\n key?: string,\n isReload?: boolean,\n removeOnUnmount?: boolean,\n formdata?: any,\n};\n\n// Helper to create useModularUI options\nconst createUseModularUIOptions = <T: ModularUIModel>(\n options: UseModularUIBasicOptions<T>,\n href: string,\n mustReload: boolean,\n): Object => {\n const baseOptions = {\n expectedModels: [],\n method: HTTP_METHODS.GET,\n data: undefined,\n removeOnUnmount: false,\n ...options,\n isReload: mustReload || options.isReload,\n };\n\n if (options.formdata != null) {\n baseOptions.method = HTTP_METHODS.POST;\n baseOptions.data = options.formdata;\n }\n\n return baseOptions;\n};\n\n// Helper to validate the model against expectedModels\nconst validateModel = (model: any, expectedModels: Array<string>) => {\n if (expectedModels.length > 0) {\n const isCorrectModel = expectedModels.includes(model.type);\n if (!isCorrectModel) {\n console.warn(model, \"is not of instance\", expectedModels);\n }\n }\n};\n\n/**\n * useModularUIBasic Hook\n */\nexport const useModularUIBasic = <T: ModularUIModel>(\n defaultKey: string,\n href: string | Href,\n options: UseModularUIBasicOptions<T> = {},\n): T | null => {\n const memoizedHref = useMemo(() => href.toString(), [href]);\n const key = options.key ?? defaultKey;\n\n const mustReload = useReload(key, memoizedHref);\n const modularUIOptions = useMemo(\n () => createUseModularUIOptions(options, memoizedHref, mustReload),\n [options, memoizedHref, mustReload],\n );\n\n const modularUI = useModularUI(key, href, modularUIOptions);\n const expectedModels = useMemo(\n () => options.expectedModels ?? [],\n [options.expectedModels],\n );\n\n return useMemo((): T | null => {\n if (modularUI?.model) {\n validateModel(modularUI.model, expectedModels);\n return modularUI.model;\n }\n return null;\n }, [expectedModels, modularUI]);\n};\n\n/**\n * Check if the model corresponding to a modular ui service should be reloaded\n */\nexport const useReload = (modelKey: string, url: string): boolean => {\n const location = useLocation();\n const key = useModularUIKey(modelKey, url);\n const modelEntry = useSelector((state) => state.modularui[key]);\n\n if (modelEntry) {\n const reload = location.state?.reload || 0;\n if (reload > 0) {\n const isFullyLoaded = modelEntry?.status === MODULARUI_STATUS.FINISHED;\n const lastModification = modelEntry?.lastModification ?? 0;\n if (isFullyLoaded && lastModification < reload) {\n return true;\n }\n }\n }\n return false;\n};\n"],"mappings":";;;;;;;;AACA,IAAAA,YAAA,GAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AACA,IAAAG,aAAA,GAAAH,OAAA;AAEA,IAAAI,UAAA,GAAAJ,OAAA;AACA,IAAAK,gBAAA,GAAAL,OAAA;AAwBA;AACA,MAAMM,yBAAyB,GAAGA,CAChCC,OAAoC,EACpCC,IAAY,EACZC,UAAmB,KACR;EACX,MAAMC,WAAW,GAAG;IAClBC,cAAc,EAAE,EAAE;IAClBC,MAAM,EAAEC,uBAAY,CAACC,GAAG;IACxBC,IAAI,EAAEC,SAAS;IACfC,eAAe,EAAE,KAAK;IACtB,GAAGV,OAAO;IACVW,QAAQ,EAAET,UAAU,IAAIF,OAAO,CAACW;EAClC,CAAC;EAED,IAAIX,OAAO,CAACY,QAAQ,IAAI,IAAI,EAAE;IAC5BT,WAAW,CAACE,MAAM,GAAGC,uBAAY,CAACO,IAAI;IACtCV,WAAW,CAACK,IAAI,GAAGR,OAAO,CAACY,QAAQ;EACrC;EAEA,OAAOT,WAAW;AACpB,CAAC;;AAED;AACA,MAAMW,aAAa,GAAGA,CAACC,KAAU,EAAEX,cAA6B,KAAK;EACnE,IAAIA,cAAc,CAACY,MAAM,GAAG,CAAC,EAAE;IAC7B,MAAMC,cAAc,GAAG,IAAAC,SAAA,CAAAC,OAAA,EAAAf,cAAc,EAAAgB,IAAA,CAAdhB,cAAc,EAAUW,KAAK,CAACM,IAAI,CAAC;IAC1D,IAAI,CAACJ,cAAc,EAAE;MACnBK,OAAO,CAACC,IAAI,CAACR,KAAK,EAAE,oBAAoB,EAAEX,cAAc,CAAC;IAC3D;EACF;AACF,CAAC;;AAED;AACA;AACA;AACO,MAAMoB,iBAAiB,GAAGA,CAC/BC,UAAkB,EAClBxB,IAAmB,EACnBD,OAAoC,
|
|
1
|
+
{"version":3,"file":"useModularUIBasic.js","names":["_reactRouter","require","_reactRedux","_react","_useModularUI","_constants","_useModularUIKey","createUseModularUIOptions","options","href","mustReload","baseOptions","expectedModels","method","HTTP_METHODS","GET","data","undefined","removeOnUnmount","isReload","formdata","POST","validateModel","model","length","isCorrectModel","_includes","default","call","type","console","warn","useModularUIBasic","defaultKey","memoizedHref","useMemo","toString","key","useReload","modularUIOptions","modularUI","useModularUI","exports","modelKey","url","location","useLocation","useModularUIKey","modelEntry","useSelector","state","modularui","reload","isFullyLoaded","status","MODULARUI_STATUS","FINISHED","lastModification"],"sources":["../../src/hooks/useModularUIBasic.js"],"sourcesContent":["// @flow\nimport { useLocation } from \"react-router\";\nimport { useSelector } from \"react-redux\";\nimport { useMemo } from \"react\";\nimport { useModularUI } from \"./useModularUI\";\n\nimport { HTTP_METHODS, MODULARUI_STATUS } from \"../constants\";\nimport { useModularUIKey } from \"./useModularUIKey\";\n\nimport type { ModularUIModel, Href } from \"../models\";\nexport type HookOptions = {\n key?: string,\n origin?: string,\n contextPath?: string,\n removeOnUnmount?: boolean,\n formdata?: any,\n};\n\nexport type UseModularUIBasicOptions<T: ModularUIModel> = {\n expectedModels?: Array<string>,\n targetModel?: Class<T> | Array<Class<T>>,\n forceTargetModel?: boolean,\n origin?: string,\n contextPath?: string,\n cache?: boolean,\n key?: string,\n isReload?: boolean,\n removeOnUnmount?: boolean,\n formdata?: any,\n};\n\n// Helper to create useModularUI options\nconst createUseModularUIOptions = <T: ModularUIModel>(\n options: UseModularUIBasicOptions<T>,\n href: string,\n mustReload: boolean,\n): Object => {\n const baseOptions = {\n expectedModels: [],\n method: HTTP_METHODS.GET,\n data: undefined,\n removeOnUnmount: false,\n ...options,\n isReload: mustReload || options.isReload,\n };\n\n if (options.formdata != null) {\n baseOptions.method = HTTP_METHODS.POST;\n baseOptions.data = options.formdata;\n }\n\n return baseOptions;\n};\n\n// Helper to validate the model against expectedModels\nconst validateModel = (model: any, expectedModels: Array<string>) => {\n if (expectedModels.length > 0) {\n const isCorrectModel = expectedModels.includes(model.type);\n if (!isCorrectModel) {\n console.warn(model, \"is not of instance\", expectedModels);\n }\n }\n};\n\n/**\n * useModularUIBasic Hook\n */\nexport const useModularUIBasic = <T: ModularUIModel>(\n defaultKey: string,\n href: string | Href,\n options: UseModularUIBasicOptions<T> = (({}: any): UseModularUIBasicOptions<T>),\n): T | null => {\n const memoizedHref = useMemo(() => href.toString(), [href]);\n const key = options.key ?? defaultKey;\n\n const mustReload = useReload(key, memoizedHref);\n const modularUIOptions = useMemo(\n () => createUseModularUIOptions(options, memoizedHref, mustReload),\n [options, memoizedHref, mustReload],\n );\n\n const modularUI = useModularUI(key, href, modularUIOptions);\n const expectedModels = useMemo(\n () => options.expectedModels ?? [],\n [options.expectedModels],\n );\n\n return useMemo((): T | null => {\n if (modularUI?.model) {\n validateModel(modularUI.model, expectedModels);\n return modularUI.model;\n }\n return null;\n }, [expectedModels, modularUI]);\n};\n\n/**\n * Check if the model corresponding to a modular ui service should be reloaded\n */\nexport const useReload = (modelKey: string, url: string): boolean => {\n const location = useLocation();\n const key = useModularUIKey(modelKey, url);\n const modelEntry = useSelector((state) => state.modularui[key]);\n\n if (modelEntry) {\n const reload = location.state?.reload || 0;\n if (reload > 0) {\n const isFullyLoaded = modelEntry?.status === MODULARUI_STATUS.FINISHED;\n const lastModification = modelEntry?.lastModification ?? 0;\n if (isFullyLoaded && lastModification < reload) {\n return true;\n }\n }\n }\n return false;\n};\n"],"mappings":";;;;;;;;AACA,IAAAA,YAAA,GAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AACA,IAAAG,aAAA,GAAAH,OAAA;AAEA,IAAAI,UAAA,GAAAJ,OAAA;AACA,IAAAK,gBAAA,GAAAL,OAAA;AAwBA;AACA,MAAMM,yBAAyB,GAAGA,CAChCC,OAAoC,EACpCC,IAAY,EACZC,UAAmB,KACR;EACX,MAAMC,WAAW,GAAG;IAClBC,cAAc,EAAE,EAAE;IAClBC,MAAM,EAAEC,uBAAY,CAACC,GAAG;IACxBC,IAAI,EAAEC,SAAS;IACfC,eAAe,EAAE,KAAK;IACtB,GAAGV,OAAO;IACVW,QAAQ,EAAET,UAAU,IAAIF,OAAO,CAACW;EAClC,CAAC;EAED,IAAIX,OAAO,CAACY,QAAQ,IAAI,IAAI,EAAE;IAC5BT,WAAW,CAACE,MAAM,GAAGC,uBAAY,CAACO,IAAI;IACtCV,WAAW,CAACK,IAAI,GAAGR,OAA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