@beinformed/ui 1.57.0 → 1.57.2
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 +9 -8
- package/esm/hooks/useModularUI.js.map +1 -1
- package/esm/hooks/useModularUIBasic.js +1 -3
- package/esm/hooks/useModularUIBasic.js.map +1 -1
- package/esm/models/concepts/ConceptLinkModel.js +1 -1
- package/esm/models/concepts/ConceptLinkModel.js.map +1 -1
- package/lib/hooks/useModularUI.js +9 -8
- package/lib/hooks/useModularUI.js.flow +12 -9
- package/lib/hooks/useModularUI.js.map +1 -1
- package/lib/hooks/useModularUIBasic.js +1 -3
- package/lib/hooks/useModularUIBasic.js.flow +2 -3
- package/lib/hooks/useModularUIBasic.js.map +1 -1
- package/lib/models/concepts/ConceptLinkModel.js +1 -1
- package/lib/models/concepts/ConceptLinkModel.js.flow +1 -1
- package/lib/models/concepts/ConceptLinkModel.js.map +1 -1
- package/package.json +1 -1
- package/src/hooks/useModularUI.js +12 -9
- package/src/hooks/useModularUIBasic.js +2 -3
- package/src/models/concepts/ConceptLinkModel.js +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.57.2](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/compare/v1.57.1...v1.57.2) (2024-10-25)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* **usemodularui:** avoid throwing of exception when wrong model ([9e258a9](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/commit/9e258a96bd12593a46a53b6043b78c01f05bb978))
|
|
11
|
+
* **usemodularui:** force load of model when it is removed from the store ([2dc4f12](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/commit/2dc4f124ae0777cea5a9e54201127400f4b4cd0d))
|
|
12
|
+
|
|
13
|
+
## [1.57.1](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/compare/v1.57.0...v1.57.1) (2024-10-23)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
### Bug Fixes
|
|
17
|
+
|
|
18
|
+
* **concept-link:** wrong order of origin and contextpath ([a5696ad](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/commit/a5696adb14999fe132971e0aae61b86f0bf1c327))
|
|
19
|
+
|
|
5
20
|
## [1.57.0](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/compare/v1.56.5...v1.57.0) (2024-10-23)
|
|
6
21
|
|
|
7
22
|
|
|
@@ -24,29 +24,31 @@ export const useModularUI = function (modelKey, url) {
|
|
|
24
24
|
const dispatch = useDispatch();
|
|
25
25
|
const href = useMemo(() => url?.toString() || "", [url]);
|
|
26
26
|
const key = useKeyForHook(modelKey, href);
|
|
27
|
+
const modelSelector = useMemo(() => state => state.modularui[key], [key]);
|
|
28
|
+
const model = useSelector(modelSelector);
|
|
27
29
|
if (url instanceof Href) {
|
|
28
30
|
options.origin = options.origin ?? url.origin;
|
|
29
31
|
options.contextPath = options.contextPath ?? url.contextPath;
|
|
30
32
|
}
|
|
31
33
|
const location = useLocation();
|
|
32
34
|
const redirectLocation = location.state?.redirectLocation;
|
|
33
|
-
const
|
|
35
|
+
const forceLoad = model == null || (redirectLocation instanceof Href ? redirectLocation?.equals(href) : false);
|
|
34
36
|
const prevOptions = useRef(options);
|
|
35
37
|
const prevHref = useRef(href);
|
|
36
|
-
const
|
|
38
|
+
const prevForceLoad = useRef(forceLoad);
|
|
37
39
|
|
|
38
40
|
// dispatch loadModularUI
|
|
39
41
|
useDeepCompareEffect(() => {
|
|
40
42
|
// prevent reloads when previous option had the isReload, but the new options not
|
|
41
43
|
const isOldReload = prevHref.current === href && prevOptions.current.isReload && !options.isReload;
|
|
42
|
-
const
|
|
43
|
-
if (href !== "" && (
|
|
44
|
+
const doForceLoad = forceLoad && !prevForceLoad.current;
|
|
45
|
+
if (href !== "" && (doForceLoad || !isOldReload)) {
|
|
44
46
|
dispatch(loadModularUI(key, href, options));
|
|
45
47
|
}
|
|
46
48
|
prevOptions.current = options;
|
|
47
49
|
prevHref.current = href;
|
|
48
|
-
|
|
49
|
-
}, [key, href, options,
|
|
50
|
+
prevForceLoad.current = forceLoad;
|
|
51
|
+
}, [key, href, options, forceLoad]);
|
|
50
52
|
useEffect(() => {
|
|
51
53
|
if (options.removeOnUnmount) {
|
|
52
54
|
return () => {
|
|
@@ -54,7 +56,6 @@ export const useModularUI = function (modelKey, url) {
|
|
|
54
56
|
};
|
|
55
57
|
}
|
|
56
58
|
}, [dispatch, key, options.removeOnUnmount]);
|
|
57
|
-
|
|
58
|
-
return useSelector(selector);
|
|
59
|
+
return model;
|
|
59
60
|
};
|
|
60
61
|
//# sourceMappingURL=useModularUI.js.map
|
|
@@ -1 +1 @@
|
|
|
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","origin","contextPath","location","redirectLocation","
|
|
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","modelSelector","state","modularui","model","origin","contextPath","location","redirectLocation","forceLoad","equals","prevOptions","prevHref","prevForceLoad","isOldReload","current","isReload","doForceLoad"],"sources":["../../src/hooks/useModularUI.js"],"sourcesContent":["// @flow\nimport { useEffect, useRef, useMemo } from \"react\";\nimport { useDispatch, useSelector } from \"react-redux\";\nimport { useLocation } from \"react-router\";\n\nimport { HTTP_METHODS } from \"../constants\";\nimport {\n loadModularUI,\n removeModelByKey,\n} from \"../redux/_modularui/ModularUIActions\";\n\nimport useDeepCompareEffect from \"./useDeepCompareEffect\";\n\nimport { useLocale } from \"./useI18n\";\nimport Href from \"../models/href/Href\";\n\nimport type { RequestModularUIOptions } from \"../utils\";\n\n/**\n */\nconst useKeyForHook = (modelKey: string, url: string) => {\n const locale = useLocale();\n return useMemo(\n () => `${modelKey}(${url.split(\"?\")[0]})(${locale})`,\n [modelKey, url, locale],\n );\n};\n\n/**\n * Use redux action and selector to retrieve the correct modular ui service model\n */\nexport const useModularUI = (\n modelKey: string,\n url: string | Href,\n options: RequestModularUIOptions = {\n method: HTTP_METHODS.GET,\n removeOnUnmount: false,\n },\n): any => {\n const dispatch = useDispatch();\n const href = useMemo(() => url?.toString() || \"\", [url]);\n const key = useKeyForHook(modelKey, href);\n\n const modelSelector = useMemo(() => (state) => state.modularui[key], [key]);\n const model = useSelector(modelSelector);\n\n if (url instanceof Href) {\n options.origin = options.origin ?? url.origin;\n options.contextPath = options.contextPath ?? url.contextPath;\n }\n\n const location = useLocation();\n const redirectLocation = location.state?.redirectLocation;\n const forceLoad =\n model == null ||\n (redirectLocation instanceof Href ? redirectLocation?.equals(href) : false);\n\n const prevOptions = useRef(options);\n const prevHref = useRef(href);\n const prevForceLoad = useRef(forceLoad);\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 doForceLoad = forceLoad && !prevForceLoad.current;\n\n if (href !== \"\" && (doForceLoad || !isOldReload)) {\n dispatch(loadModularUI(key, href, options));\n }\n\n prevOptions.current = options;\n prevHref.current = href;\n prevForceLoad.current = forceLoad;\n }, [key, href, options, forceLoad]);\n\n useEffect(() => {\n if (options.removeOnUnmount) {\n return () => {\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AACG,OAAO,GAAGjB,IAAI;IACvBe,aAAa,CAACE,OAAO,GAAGN,SAAS;EACnC,CAAC,EAAE,CAACT,GAAG,EAAEF,IAAI,EAAER,OAAO,EAAEmB,SAAS,CAAC,CAAC;EAEnCrC,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,OAAOQ,KAAK;AACd,CAAC","ignoreList":[]}
|
|
@@ -2,7 +2,6 @@ import _startsWithInstanceProperty from "@babel/runtime-corejs3/core-js-stable/i
|
|
|
2
2
|
import { useMemo } from "react";
|
|
3
3
|
import { useModularUI } from "./useModularUI";
|
|
4
4
|
import { useLocation } from "./useRouter";
|
|
5
|
-
import { IllegalStateException } from "../exceptions";
|
|
6
5
|
// Helper to create useModularUI options
|
|
7
6
|
const createUseModularUIOptions = (options, href, location) => {
|
|
8
7
|
var _context;
|
|
@@ -42,8 +41,7 @@ const validateModel = (model, expectedModels) => {
|
|
|
42
41
|
if (expectedModels.length > 0) {
|
|
43
42
|
const isCorrectModel = expectedModels.some(expectedModel => model.type === expectedModel);
|
|
44
43
|
if (!isCorrectModel) {
|
|
45
|
-
console.
|
|
46
|
-
throw new IllegalStateException("Resolved model has incorrect type");
|
|
44
|
+
console.warn(model, "is not of instance", expectedModels);
|
|
47
45
|
}
|
|
48
46
|
}
|
|
49
47
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useModularUIBasic.js","names":["useMemo","useModularUI","useLocation","
|
|
1
|
+
{"version":3,"file":"useModularUIBasic.js","names":["useMemo","useModularUI","useLocation","createUseModularUIOptions","options","href","location","_context","baseOptions","targetModel","undefined","forceTargetModel","isReload","origin","contextPath","cache","state","reload","_startsWithInstanceProperty","pathname","call","validateModel","model","expectedModels","length","isCorrectModel","some","expectedModel","type","console","warn","useModularUIBasic","key","arguments","memoizedHref","toString","useModularUIOptions","modularUI"],"sources":["../../src/hooks/useModularUIBasic.js"],"sourcesContent":["// @flow\nimport { useMemo } from \"react\";\nimport { useModularUI } from \"./useModularUI\";\nimport { useLocation } from \"./useRouter\";\n\nimport type { ModularUIModel, Href } from \"../models\";\n\nexport type UseModularUIBasicOptions<T: ModularUIModel> = {\n expectedModels?: Array<string>,\n targetModel?: Class<T> | Array<Class<T>>,\n forceTargetModel?: boolean,\n origin?: string,\n contextPath?: string,\n cache?: boolean,\n};\n\n// Helper to create useModularUI options\nconst createUseModularUIOptions = <T: ModularUIModel>(\n options: UseModularUIBasicOptions<T>,\n href: string,\n location: any,\n): Object => {\n const baseOptions = {\n targetModel: undefined,\n forceTargetModel: undefined,\n isReload: false,\n origin: undefined,\n contextPath: undefined,\n cache: false,\n };\n\n // Handle targetModel and forceTargetModel\n if (options.targetModel) {\n baseOptions.targetModel = options.targetModel;\n baseOptions.forceTargetModel = options.forceTargetModel;\n }\n\n // Handle cache option\n if (options.cache) {\n baseOptions.cache = options.cache;\n }\n\n // Check for reload if location matches href\n if (location.state?.reload && location.pathname.startsWith(href)) {\n baseOptions.isReload = true;\n }\n\n // Handle origin and contextPath options\n baseOptions.origin = options.origin ?? baseOptions.origin;\n baseOptions.contextPath = options.contextPath ?? baseOptions.contextPath;\n\n return baseOptions;\n};\n\n// Helper to validate the model against expectedModels\nconst validateModel = (model: any, expectedModels: Array<string>) => {\n if (expectedModels.length > 0) {\n const isCorrectModel = expectedModels.some(\n (expectedModel) => model.type === expectedModel,\n );\n if (!isCorrectModel) {\n console.warn(model, \"is not of instance\", expectedModels);\n }\n }\n};\n\n/**\n * useModularUIBasic Hook\n */\nexport const useModularUIBasic = <T: ModularUIModel>(\n key: string,\n href: string | Href,\n options: UseModularUIBasicOptions<T> = {\n expectedModels: [],\n targetModel: undefined,\n forceTargetModel: false,\n origin: undefined,\n contextPath: undefined,\n },\n): T | null => {\n const location = useLocation();\n const memoizedHref = useMemo(() => href.toString(), [href]);\n const useModularUIOptions = useMemo(\n () => createUseModularUIOptions(options, memoizedHref, location),\n [options, memoizedHref, location],\n );\n\n const modularUI = useModularUI(key, memoizedHref, useModularUIOptions);\n const expectedModels = useMemo(\n () => options.expectedModels ?? [],\n [options.expectedModels],\n );\n\n return useMemo((): T | null => {\n if (modularUI?.model) {\n validateModel(modularUI.model, expectedModels);\n return modularUI.model;\n }\n return null;\n }, [expectedModels, modularUI]);\n};\n"],"mappings":";AACA,SAASA,OAAO,QAAQ,OAAO;AAC/B,SAASC,YAAY,QAAQ,gBAAgB;AAC7C,SAASC,WAAW,QAAQ,aAAa;AAazC;AACA,MAAMC,yBAAyB,GAAGA,CAChCC,OAAoC,EACpCC,IAAY,EACZC,QAAa,KACF;EAAA,IAAAC,QAAA;EACX,MAAMC,WAAW,GAAG;IAClBC,WAAW,EAAEC,SAAS;IACtBC,gBAAgB,EAAED,SAAS;IAC3BE,QAAQ,EAAE,KAAK;IACfC,MAAM,EAAEH,SAAS;IACjBI,WAAW,EAAEJ,SAAS;IACtBK,KAAK,EAAE;EACT,CAAC;;EAED;EACA,IAAIX,OAAO,CAACK,WAAW,EAAE;IACvBD,WAAW,CAACC,WAAW,GAAGL,OAAO,CAACK,WAAW;IAC7CD,WAAW,CAACG,gBAAgB,GAAGP,OAAO,CAACO,gBAAgB;EACzD;;EAEA;EACA,IAAIP,OAAO,CAACW,KAAK,EAAE;IACjBP,WAAW,CAACO,KAAK,GAAGX,OAAO,CAACW,KAAK;EACnC;;EAEA;EACA,IAAIT,QAAQ,CAACU,KAAK,EAAEC,MAAM,IAAIC,2BAAA,CAAAX,QAAA,GAAAD,QAAQ,CAACa,QAAQ,EAAAC,IAAA,CAAAb,QAAA,EAAYF,IAAI,CAAC,EAAE;IAChEG,WAAW,CAACI,QAAQ,GAAG,IAAI;EAC7B;;EAEA;EACAJ,WAAW,CAACK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AmB,CAAC;EACtE,MAAMb,cAAc,GAAGvB,OAAO,CAC5B,MAAMI,OAAO,CAACmB,cAAc,IAAI,EAAE,EAClC,CAACnB,OAAO,CAACmB,cAAc,CACzB,CAAC;EAED,OAAOvB,OAAO,CAAC,MAAgB;IAC7B,IAAIqC,SAAS,EAAEf,KAAK,EAAE;MACpBD,aAAa,CAACgB,SAAS,CAACf,KAAK,EAAEC,cAAc,CAAC;MAC9C,OAAOc,SAAS,CAACf,KAAK;IACxB;IACA,OAAO,IAAI;EACb,CAAC,EAAE,CAACC,cAAc,EAAEc,SAAS,CAAC,CAAC;AACjC,CAAC","ignoreList":[]}
|
|
@@ -87,7 +87,7 @@ export default class ConceptLinkModel extends BaseModel {
|
|
|
87
87
|
*/
|
|
88
88
|
get links() {
|
|
89
89
|
if (!this._links) {
|
|
90
|
-
this._links = new LinkCollection(Array.isArray(this.data._links) ? this.data._links[0] : this.data._links, null, this.
|
|
90
|
+
this._links = new LinkCollection(Array.isArray(this.data._links) ? this.data._links[0] : this.data._links, null, this._origin, this._contextPath);
|
|
91
91
|
}
|
|
92
92
|
return this._links;
|
|
93
93
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConceptLinkModel.js","names":["BaseModel","LinkModel","LinkCollection","ConceptTypeDetailModel","TIMEVERSION_FILTER_NAME","getBasePath","ConceptLinkModel","constructor","data","entryDate","arguments","length","undefined","origin","contextPath","_defineProperty","_entryDate","_origin","_contextPath","getInitialChildModelLinks","conceptTypeLink","isCacheable","setChildModels","models","href","conceptTypeModel","_findInstanceProperty","call","model","selfhref","equalsWithParameters","type","conceptType","_conceptType","key","_id","label","getData","links","_links","Array","isArray","selflink","getLinkByKey","Error","addParameter","concepttypeHref","taxonomyType","asLinkModel","link","create","isOfConceptType","conceptTypeId"],"sources":["../../../src/models/concepts/ConceptLinkModel.js"],"sourcesContent":["// @flow\nimport BaseModel from \"../base/BaseModel\";\nimport LinkModel from \"../links/LinkModel\";\nimport LinkCollection from \"../links/LinkCollection\";\nimport ConceptTypeDetailModel from \"./ConceptTypeDetailModel\";\nimport { TIMEVERSION_FILTER_NAME } from \"../../constants/Constants\";\n\nimport type { IModelWithChildModels, ModularUIModel } from \"../types\";\nimport type Href from \"../href/Href\";\nimport { getBasePath } from \"../../constants\";\n/**\n * Link to a concept\n */\nexport default class ConceptLinkModel\n extends BaseModel\n implements IModelWithChildModels\n{\n _links: ?LinkCollection;\n _entryDate: ?ISO_DATE;\n _conceptType: ?ConceptTypeDetailModel;\n _origin: string = \"\";\n _contextPath: string = getBasePath();\n\n /**\n * Construct ConceptLinkModel\n */\n constructor(\n data: Object,\n entryDate: ?ISO_DATE = null,\n origin?: string,\n contextPath?: string,\n ) {\n super(data, {});\n\n this._entryDate = entryDate;\n this._origin = origin || \"\";\n this._contextPath = contextPath || getBasePath();\n }\n\n /**\n */\n getInitialChildModelLinks(): Array<LinkModel> {\n if (this.conceptTypeLink) {\n this.conceptTypeLink.isCacheable = true;\n return [this.conceptTypeLink];\n }\n\n return [];\n }\n\n /**\n */\n setChildModels(models: Array<ModularUIModel>) {\n if (this.conceptTypeLink) {\n const href = this.conceptTypeLink.href;\n const conceptTypeModel = models.find((model) =>\n model.selfhref.equalsWithParameters(href),\n );\n\n if (conceptTypeModel?.type === \"ConceptTypeDetail\") {\n this.conceptType = conceptTypeModel;\n }\n }\n }\n\n /**\n * Retrieve concept type\n */\n get conceptType(): ?ConceptTypeDetailModel {\n return this._conceptType;\n }\n\n /**\n * Set concept type\n */\n set conceptType(conceptType: ?ModularUIModel) {\n this._conceptType =\n conceptType instanceof ConceptTypeDetailModel ? conceptType : null;\n }\n\n /**\n * Retrieve key\n */\n get key(): string {\n return this.data._id;\n }\n\n /**\n * Retrieve label\n */\n get label(): string {\n const label = this.getData(\"label\");\n\n if (label) {\n return label;\n }\n\n return this.getData(\"conceptLabel\", \"\");\n }\n\n /**\n * Getting the links of the resource\n */\n get links(): LinkCollection {\n if (!this._links) {\n this._links = new LinkCollection(\n Array.isArray(this.data._links)\n ? this.data._links[0]\n : this.data._links,\n null,\n this.
|
|
1
|
+
{"version":3,"file":"ConceptLinkModel.js","names":["BaseModel","LinkModel","LinkCollection","ConceptTypeDetailModel","TIMEVERSION_FILTER_NAME","getBasePath","ConceptLinkModel","constructor","data","entryDate","arguments","length","undefined","origin","contextPath","_defineProperty","_entryDate","_origin","_contextPath","getInitialChildModelLinks","conceptTypeLink","isCacheable","setChildModels","models","href","conceptTypeModel","_findInstanceProperty","call","model","selfhref","equalsWithParameters","type","conceptType","_conceptType","key","_id","label","getData","links","_links","Array","isArray","selflink","getLinkByKey","Error","addParameter","concepttypeHref","taxonomyType","asLinkModel","link","create","isOfConceptType","conceptTypeId"],"sources":["../../../src/models/concepts/ConceptLinkModel.js"],"sourcesContent":["// @flow\nimport BaseModel from \"../base/BaseModel\";\nimport LinkModel from \"../links/LinkModel\";\nimport LinkCollection from \"../links/LinkCollection\";\nimport ConceptTypeDetailModel from \"./ConceptTypeDetailModel\";\nimport { TIMEVERSION_FILTER_NAME } from \"../../constants/Constants\";\n\nimport type { IModelWithChildModels, ModularUIModel } from \"../types\";\nimport type Href from \"../href/Href\";\nimport { getBasePath } from \"../../constants\";\n/**\n * Link to a concept\n */\nexport default class ConceptLinkModel\n extends BaseModel\n implements IModelWithChildModels\n{\n _links: ?LinkCollection;\n _entryDate: ?ISO_DATE;\n _conceptType: ?ConceptTypeDetailModel;\n _origin: string = \"\";\n _contextPath: string = getBasePath();\n\n /**\n * Construct ConceptLinkModel\n */\n constructor(\n data: Object,\n entryDate: ?ISO_DATE = null,\n origin?: string,\n contextPath?: string,\n ) {\n super(data, {});\n\n this._entryDate = entryDate;\n this._origin = origin || \"\";\n this._contextPath = contextPath || getBasePath();\n }\n\n /**\n */\n getInitialChildModelLinks(): Array<LinkModel> {\n if (this.conceptTypeLink) {\n this.conceptTypeLink.isCacheable = true;\n return [this.conceptTypeLink];\n }\n\n return [];\n }\n\n /**\n */\n setChildModels(models: Array<ModularUIModel>) {\n if (this.conceptTypeLink) {\n const href = this.conceptTypeLink.href;\n const conceptTypeModel = models.find((model) =>\n model.selfhref.equalsWithParameters(href),\n );\n\n if (conceptTypeModel?.type === \"ConceptTypeDetail\") {\n this.conceptType = conceptTypeModel;\n }\n }\n }\n\n /**\n * Retrieve concept type\n */\n get conceptType(): ?ConceptTypeDetailModel {\n return this._conceptType;\n }\n\n /**\n * Set concept type\n */\n set conceptType(conceptType: ?ModularUIModel) {\n this._conceptType =\n conceptType instanceof ConceptTypeDetailModel ? conceptType : null;\n }\n\n /**\n * Retrieve key\n */\n get key(): string {\n return this.data._id;\n }\n\n /**\n * Retrieve label\n */\n get label(): string {\n const label = this.getData(\"label\");\n\n if (label) {\n return label;\n }\n\n return this.getData(\"conceptLabel\", \"\");\n }\n\n /**\n * Getting the links of the resource\n */\n get links(): LinkCollection {\n if (!this._links) {\n this._links = new LinkCollection(\n Array.isArray(this.data._links)\n ? this.data._links[0]\n : this.data._links,\n null,\n this._origin,\n this._contextPath,\n );\n }\n\n return this._links;\n }\n\n /**\n * Get self link of model\n */\n get selflink(): LinkModel {\n const selflink = this.links.getLinkByKey(\"self\");\n\n if (selflink === null) {\n throw new Error(\n `Could not find self link for ${\n this.key === null ? \"unknown\" : this.key\n }`,\n );\n }\n\n return selflink;\n }\n\n /**\n * Self href of concept\n */\n get selfhref(): Href {\n if (this._entryDate !== null) {\n return this.selflink.href.addParameter(\n TIMEVERSION_FILTER_NAME,\n this._entryDate,\n );\n }\n\n return this.selflink.href;\n }\n\n /**\n */\n get conceptTypeLink(): LinkModel | null {\n return this.links.getLinkByKey(\"concepttype\");\n }\n\n /**\n * Concept type href of concept\n */\n get concepttypeHref(): Href | null {\n return this.conceptTypeLink?.href ?? null;\n }\n\n /**\n */\n get taxonomyType(): string {\n return \"default\";\n }\n\n /**\n */\n asLinkModel(): LinkModel {\n const link = LinkModel.create(this.key, this.selfhref.href, this.label);\n link.href = this.selfhref;\n\n return link;\n }\n\n /**\n * Indicates if the given concept type id or href exists in the hierarchy of concept types for this concept\n */\n isOfConceptType(conceptTypeId: string): boolean {\n return this.conceptType?.isOfConceptType(conceptTypeId) ?? false;\n }\n}\n"],"mappings":";;AACA,OAAOA,SAAS,MAAM,mBAAmB;AACzC,OAAOC,SAAS,MAAM,oBAAoB;AAC1C,OAAOC,cAAc,MAAM,yBAAyB;AACpD,OAAOC,sBAAsB,MAAM,0BAA0B;AAC7D,SAASC,uBAAuB,QAAQ,2BAA2B;AAInE,SAASC,WAAW,QAAQ,iBAAiB;AAC7C;AACA;AACA;AACA,eAAe,MAAMC,gBAAgB,SAC3BN,SAAS,CAEnB;EAOE;AACF;AACA;EACEO,WAAWA,CACTC,IAAY,EAIZ;IAAA,IAHAC,SAAoB,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,IAAI;IAAA,IAC3BG,MAAe,GAAAH,SAAA,CAAAC,MAAA,OAAAD,SAAA,MAAAE,SAAA;IAAA,IACfE,WAAoB,GAAAJ,SAAA,CAAAC,MAAA,OAAAD,SAAA,MAAAE,SAAA;IAEpB,KAAK,CAACJ,IAAI,EAAE,CAAC,CAAC,CAAC;IAACO,eAAA;IAAAA,eAAA;IAAAA,eAAA;IAAAA,eAAA,kBAZA,EAAE;IAAAA,eAAA,uBACGV,WAAW,CAAC,CAAC;IAalC,IAAI,CAACW,UAAU,GAAGP,SAAS;IAC3B,IAAI,CAACQ,OAAO,GAAGJ,MAAM,IAAI,EAAE;IAC3B,IAAI,CAACK,YAAY,GAAGJ,WAAW,IAAIT,WAAW,CAAC,CAAC;EAClD;;EAEA;AACF;EACEc,yBAAyBA,CAAA,EAAqB;IAC5C,IAAI,IAAI,CAACC,eAAe,EAAE;MACxB,IAAI,CAACA,eAAe,CAACC,WAAW,GAAG,IAAI;MACvC,OAAO,CAAC,IAAI,CAACD,eAAe,CAAC;IAC/B;IAEA,OAAO,EAAE;EACX;;EAEA;AACF;EACEE,cAAcA,CAAC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I;EACb;;EAEA;AACF;AACA;EACEE,eAAeA,CAACC,aAAqB,EAAW;IAC9C,OAAO,IAAI,CAACpB,WAAW,EAAEmB,eAAe,CAACC,aAAa,CAAC,IAAI,KAAK;EAClE;AACF","ignoreList":[]}
|
|
@@ -31,29 +31,31 @@ const useModularUI = function (modelKey, url) {
|
|
|
31
31
|
const dispatch = (0, _reactRedux.useDispatch)();
|
|
32
32
|
const href = (0, _react.useMemo)(() => url?.toString() || "", [url]);
|
|
33
33
|
const key = useKeyForHook(modelKey, href);
|
|
34
|
+
const modelSelector = (0, _react.useMemo)(() => state => state.modularui[key], [key]);
|
|
35
|
+
const model = (0, _reactRedux.useSelector)(modelSelector);
|
|
34
36
|
if (url instanceof _Href.default) {
|
|
35
37
|
options.origin = options.origin ?? url.origin;
|
|
36
38
|
options.contextPath = options.contextPath ?? url.contextPath;
|
|
37
39
|
}
|
|
38
40
|
const location = (0, _reactRouter.useLocation)();
|
|
39
41
|
const redirectLocation = location.state?.redirectLocation;
|
|
40
|
-
const
|
|
42
|
+
const forceLoad = model == null || (redirectLocation instanceof _Href.default ? redirectLocation?.equals(href) : false);
|
|
41
43
|
const prevOptions = (0, _react.useRef)(options);
|
|
42
44
|
const prevHref = (0, _react.useRef)(href);
|
|
43
|
-
const
|
|
45
|
+
const prevForceLoad = (0, _react.useRef)(forceLoad);
|
|
44
46
|
|
|
45
47
|
// dispatch loadModularUI
|
|
46
48
|
(0, _useDeepCompareEffect.default)(() => {
|
|
47
49
|
// prevent reloads when previous option had the isReload, but the new options not
|
|
48
50
|
const isOldReload = prevHref.current === href && prevOptions.current.isReload && !options.isReload;
|
|
49
|
-
const
|
|
50
|
-
if (href !== "" && (
|
|
51
|
+
const doForceLoad = forceLoad && !prevForceLoad.current;
|
|
52
|
+
if (href !== "" && (doForceLoad || !isOldReload)) {
|
|
51
53
|
dispatch((0, _ModularUIActions.loadModularUI)(key, href, options));
|
|
52
54
|
}
|
|
53
55
|
prevOptions.current = options;
|
|
54
56
|
prevHref.current = href;
|
|
55
|
-
|
|
56
|
-
}, [key, href, options,
|
|
57
|
+
prevForceLoad.current = forceLoad;
|
|
58
|
+
}, [key, href, options, forceLoad]);
|
|
57
59
|
(0, _react.useEffect)(() => {
|
|
58
60
|
if (options.removeOnUnmount) {
|
|
59
61
|
return () => {
|
|
@@ -61,8 +63,7 @@ const useModularUI = function (modelKey, url) {
|
|
|
61
63
|
};
|
|
62
64
|
}
|
|
63
65
|
}, [dispatch, key, options.removeOnUnmount]);
|
|
64
|
-
|
|
65
|
-
return (0, _reactRedux.useSelector)(selector);
|
|
66
|
+
return model;
|
|
66
67
|
};
|
|
67
68
|
exports.useModularUI = useModularUI;
|
|
68
69
|
//# sourceMappingURL=useModularUI.js.map
|
|
@@ -41,6 +41,9 @@ export const useModularUI = (
|
|
|
41
41
|
const href = useMemo(() => url?.toString() || "", [url]);
|
|
42
42
|
const key = useKeyForHook(modelKey, href);
|
|
43
43
|
|
|
44
|
+
const modelSelector = useMemo(() => (state) => state.modularui[key], [key]);
|
|
45
|
+
const model = useSelector(modelSelector);
|
|
46
|
+
|
|
44
47
|
if (url instanceof Href) {
|
|
45
48
|
options.origin = options.origin ?? url.origin;
|
|
46
49
|
options.contextPath = options.contextPath ?? url.contextPath;
|
|
@@ -48,12 +51,13 @@ export const useModularUI = (
|
|
|
48
51
|
|
|
49
52
|
const location = useLocation();
|
|
50
53
|
const redirectLocation = location.state?.redirectLocation;
|
|
51
|
-
const
|
|
52
|
-
|
|
54
|
+
const forceLoad =
|
|
55
|
+
model == null ||
|
|
56
|
+
(redirectLocation instanceof Href ? redirectLocation?.equals(href) : false);
|
|
53
57
|
|
|
54
58
|
const prevOptions = useRef(options);
|
|
55
59
|
const prevHref = useRef(href);
|
|
56
|
-
const
|
|
60
|
+
const prevForceLoad = useRef(forceLoad);
|
|
57
61
|
|
|
58
62
|
// dispatch loadModularUI
|
|
59
63
|
useDeepCompareEffect(() => {
|
|
@@ -63,16 +67,16 @@ export const useModularUI = (
|
|
|
63
67
|
prevOptions.current.isReload &&
|
|
64
68
|
!options.isReload;
|
|
65
69
|
|
|
66
|
-
const
|
|
70
|
+
const doForceLoad = forceLoad && !prevForceLoad.current;
|
|
67
71
|
|
|
68
|
-
if (href !== "" && (
|
|
72
|
+
if (href !== "" && (doForceLoad || !isOldReload)) {
|
|
69
73
|
dispatch(loadModularUI(key, href, options));
|
|
70
74
|
}
|
|
71
75
|
|
|
72
76
|
prevOptions.current = options;
|
|
73
77
|
prevHref.current = href;
|
|
74
|
-
|
|
75
|
-
}, [key, href, options,
|
|
78
|
+
prevForceLoad.current = forceLoad;
|
|
79
|
+
}, [key, href, options, forceLoad]);
|
|
76
80
|
|
|
77
81
|
useEffect(() => {
|
|
78
82
|
if (options.removeOnUnmount) {
|
|
@@ -82,6 +86,5 @@ export const useModularUI = (
|
|
|
82
86
|
}
|
|
83
87
|
}, [dispatch, key, options.removeOnUnmount]);
|
|
84
88
|
|
|
85
|
-
|
|
86
|
-
return useSelector(selector);
|
|
89
|
+
return model;
|
|
87
90
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useModularUI.js","names":["_react","require","_reactRedux","_reactRouter","_constants","_ModularUIActions","_useDeepCompareEffect","_interopRequireDefault","_useI18n","_Href","useKeyForHook","modelKey","url","locale","useLocale","useMemo","split","useModularUI","options","arguments","length","undefined","method","HTTP_METHODS","GET","removeOnUnmount","dispatch","useDispatch","href","toString","key","Href","origin","contextPath","location","useLocation","redirectLocation","
|
|
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","modelSelector","state","modularui","model","useSelector","Href","origin","contextPath","location","useLocation","redirectLocation","forceLoad","equals","prevOptions","useRef","prevHref","prevForceLoad","useDeepCompareEffect","isOldReload","current","isReload","doForceLoad","loadModularUI","useEffect","removeModelByKey","exports"],"sources":["../../src/hooks/useModularUI.js"],"sourcesContent":["// @flow\nimport { useEffect, useRef, useMemo } from \"react\";\nimport { useDispatch, useSelector } from \"react-redux\";\nimport { useLocation } from \"react-router\";\n\nimport { HTTP_METHODS } from \"../constants\";\nimport {\n loadModularUI,\n removeModelByKey,\n} from \"../redux/_modularui/ModularUIActions\";\n\nimport useDeepCompareEffect from \"./useDeepCompareEffect\";\n\nimport { useLocale } from \"./useI18n\";\nimport Href from \"../models/href/Href\";\n\nimport type { RequestModularUIOptions } from \"../utils\";\n\n/**\n */\nconst useKeyForHook = (modelKey: string, url: string) => {\n const locale = useLocale();\n return useMemo(\n () => `${modelKey}(${url.split(\"?\")[0]})(${locale})`,\n [modelKey, url, locale],\n );\n};\n\n/**\n * Use redux action and selector to retrieve the correct modular ui service model\n */\nexport const useModularUI = (\n modelKey: string,\n url: string | Href,\n options: RequestModularUIOptions = {\n method: HTTP_METHODS.GET,\n removeOnUnmount: false,\n },\n): any => {\n const dispatch = useDispatch();\n const href = useMemo(() => url?.toString() || \"\", [url]);\n const key = useKeyForHook(modelKey, href);\n\n const modelSelector = useMemo(() => (state) => state.modularui[key], [key]);\n const model = useSelector(modelSelector);\n\n if (url instanceof Href) {\n options.origin = options.origin ?? url.origin;\n options.contextPath = options.contextPath ?? url.contextPath;\n }\n\n const location = useLocation();\n const redirectLocation = location.state?.redirectLocation;\n const forceLoad =\n model == null ||\n (redirectLocation instanceof Href ? redirectLocation?.equals(href) : false);\n\n const prevOptions = useRef(options);\n const prevHref = useRef(href);\n const prevForceLoad = useRef(forceLoad);\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 doForceLoad = forceLoad && !prevForceLoad.current;\n\n if (href !== \"\" && (doForceLoad || !isOldReload)) {\n dispatch(loadModularUI(key, href, options));\n }\n\n prevOptions.current = options;\n prevHref.current = href;\n prevForceLoad.current = forceLoad;\n }, [key, href, options, forceLoad]);\n\n useEffect(() => {\n if (options.removeOnUnmount) {\n return () => {\n dispatch(removeModelByKey(key));\n };\n }\n }, [dispatch, key, options.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;AAEA,IAAAO,QAAA,GAAAP,OAAA;AACA,IAAAQ,KAAA,GAAAF,sBAAA,CAAAN,OAAA;AAIA;AACA;AACA,MAAMS,aAAa,GAAGA,CAACC,QAAgB,EAAEC,GAAW,KAAK;EACvD,MAAMC,MAAM,GAAG,IAAAC,kBAAS,EAAC,CAAC;EAC1B,OAAO,IAAAC,cAAO,EACZ,MAAM,GAAGJ,QAAQ,IAAIC,GAAG,CAACI,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,KAAKH,MAAM,GAAG,EACpD,CAACF,QAAQ,EAAEC,GAAG,EAAEC,MAAM,CACxB,CAAC;AACH,CAAC;;AAED;AACA;AACA;AACO,MAAMI,YAAY,GAAG,SAAAA,CAC1BN,QAAgB,EAChBC,GAAkB,EAKV;EAAA,IAJRM,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,GAAG,IAAAb,cAAO,EAAC,MAAMH,GAAG,EAAEiB,QAAQ,CAAC,CAAC,I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AKwB,WAAW,IAAI,CAACH,WAAW,CAAC,EAAE;MAChDvB,QAAQ,CAAC,IAAA2B,+BAAa,EAACvB,GAAG,EAAEF,IAAI,EAAEV,OAAO,CAAC,CAAC;IAC7C;IAEA0B,WAAW,CAACM,OAAO,GAAGhC,OAAO;IAC7B4B,QAAQ,CAACI,OAAO,GAAGtB,IAAI;IACvBmB,aAAa,CAACG,OAAO,GAAGR,SAAS;EACnC,CAAC,EAAE,CAACZ,GAAG,EAAEF,IAAI,EAAEV,OAAO,EAAEwB,SAAS,CAAC,CAAC;EAEnC,IAAAY,gBAAS,EAAC,MAAM;IACd,IAAIpC,OAAO,CAACO,eAAe,EAAE;MAC3B,OAAO,MAAM;QACXC,QAAQ,CAAC,IAAA6B,kCAAgB,EAACzB,GAAG,CAAC,CAAC;MACjC,CAAC;IACH;EACF,CAAC,EAAE,CAACJ,QAAQ,EAAEI,GAAG,EAAEZ,OAAO,CAACO,eAAe,CAAC,CAAC;EAE5C,OAAOS,KAAK;AACd,CAAC;AAACsB,OAAA,CAAAvC,YAAA,GAAAA,YAAA","ignoreList":[]}
|
|
@@ -9,7 +9,6 @@ var _startsWith = _interopRequireDefault(require("@babel/runtime-corejs3/core-js
|
|
|
9
9
|
var _react = require("react");
|
|
10
10
|
var _useModularUI = require("./useModularUI");
|
|
11
11
|
var _useRouter = require("./useRouter");
|
|
12
|
-
var _exceptions = require("../exceptions");
|
|
13
12
|
// Helper to create useModularUI options
|
|
14
13
|
const createUseModularUIOptions = (options, href, location) => {
|
|
15
14
|
var _context;
|
|
@@ -49,8 +48,7 @@ const validateModel = (model, expectedModels) => {
|
|
|
49
48
|
if (expectedModels.length > 0) {
|
|
50
49
|
const isCorrectModel = expectedModels.some(expectedModel => model.type === expectedModel);
|
|
51
50
|
if (!isCorrectModel) {
|
|
52
|
-
console.
|
|
53
|
-
throw new _exceptions.IllegalStateException("Resolved model has incorrect type");
|
|
51
|
+
console.warn(model, "is not of instance", expectedModels);
|
|
54
52
|
}
|
|
55
53
|
}
|
|
56
54
|
};
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { useMemo } from "react";
|
|
3
3
|
import { useModularUI } from "./useModularUI";
|
|
4
4
|
import { useLocation } from "./useRouter";
|
|
5
|
-
|
|
5
|
+
|
|
6
6
|
import type { ModularUIModel, Href } from "../models";
|
|
7
7
|
|
|
8
8
|
export type UseModularUIBasicOptions<T: ModularUIModel> = {
|
|
@@ -59,8 +59,7 @@ const validateModel = (model: any, expectedModels: Array<string>) => {
|
|
|
59
59
|
(expectedModel) => model.type === expectedModel,
|
|
60
60
|
);
|
|
61
61
|
if (!isCorrectModel) {
|
|
62
|
-
console.
|
|
63
|
-
throw new IllegalStateException("Resolved model has incorrect type");
|
|
62
|
+
console.warn(model, "is not of instance", expectedModels);
|
|
64
63
|
}
|
|
65
64
|
}
|
|
66
65
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useModularUIBasic.js","names":["_react","require","_useModularUI","_useRouter","
|
|
1
|
+
{"version":3,"file":"useModularUIBasic.js","names":["_react","require","_useModularUI","_useRouter","createUseModularUIOptions","options","href","location","_context","baseOptions","targetModel","undefined","forceTargetModel","isReload","origin","contextPath","cache","state","reload","_startsWith","default","pathname","call","validateModel","model","expectedModels","length","isCorrectModel","some","expectedModel","type","console","warn","useModularUIBasic","key","arguments","useLocation","memoizedHref","useMemo","toString","useModularUIOptions","modularUI","useModularUI","exports"],"sources":["../../src/hooks/useModularUIBasic.js"],"sourcesContent":["// @flow\nimport { useMemo } from \"react\";\nimport { useModularUI } from \"./useModularUI\";\nimport { useLocation } from \"./useRouter\";\n\nimport type { ModularUIModel, Href } from \"../models\";\n\nexport type UseModularUIBasicOptions<T: ModularUIModel> = {\n expectedModels?: Array<string>,\n targetModel?: Class<T> | Array<Class<T>>,\n forceTargetModel?: boolean,\n origin?: string,\n contextPath?: string,\n cache?: boolean,\n};\n\n// Helper to create useModularUI options\nconst createUseModularUIOptions = <T: ModularUIModel>(\n options: UseModularUIBasicOptions<T>,\n href: string,\n location: any,\n): Object => {\n const baseOptions = {\n targetModel: undefined,\n forceTargetModel: undefined,\n isReload: false,\n origin: undefined,\n contextPath: undefined,\n cache: false,\n };\n\n // Handle targetModel and forceTargetModel\n if (options.targetModel) {\n baseOptions.targetModel = options.targetModel;\n baseOptions.forceTargetModel = options.forceTargetModel;\n }\n\n // Handle cache option\n if (options.cache) {\n baseOptions.cache = options.cache;\n }\n\n // Check for reload if location matches href\n if (location.state?.reload && location.pathname.startsWith(href)) {\n baseOptions.isReload = true;\n }\n\n // Handle origin and contextPath options\n baseOptions.origin = options.origin ?? baseOptions.origin;\n baseOptions.contextPath = options.contextPath ?? baseOptions.contextPath;\n\n return baseOptions;\n};\n\n// Helper to validate the model against expectedModels\nconst validateModel = (model: any, expectedModels: Array<string>) => {\n if (expectedModels.length > 0) {\n const isCorrectModel = expectedModels.some(\n (expectedModel) => model.type === expectedModel,\n );\n if (!isCorrectModel) {\n console.warn(model, \"is not of instance\", expectedModels);\n }\n }\n};\n\n/**\n * useModularUIBasic Hook\n */\nexport const useModularUIBasic = <T: ModularUIModel>(\n key: string,\n href: string | Href,\n options: UseModularUIBasicOptions<T> = {\n expectedModels: [],\n targetModel: undefined,\n forceTargetModel: false,\n origin: undefined,\n contextPath: undefined,\n },\n): T | null => {\n const location = useLocation();\n const memoizedHref = useMemo(() => href.toString(), [href]);\n const useModularUIOptions = useMemo(\n () => createUseModularUIOptions(options, memoizedHref, location),\n [options, memoizedHref, location],\n );\n\n const modularUI = useModularUI(key, memoizedHref, useModularUIOptions);\n const expectedModels = useMemo(\n () => options.expectedModels ?? [],\n [options.expectedModels],\n );\n\n return useMemo((): T | null => {\n if (modularUI?.model) {\n validateModel(modularUI.model, expectedModels);\n return modularUI.model;\n }\n return null;\n }, [expectedModels, modularUI]);\n};\n"],"mappings":";;;;;;;;AACA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,aAAA,GAAAD,OAAA;AACA,IAAAE,U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AAA,CAAAV,iBAAA,GAAAA,iBAAA","ignoreList":[]}
|
|
@@ -94,7 +94,7 @@ class ConceptLinkModel extends _BaseModel.default {
|
|
|
94
94
|
*/
|
|
95
95
|
get links() {
|
|
96
96
|
if (!this._links) {
|
|
97
|
-
this._links = new _LinkCollection.default(Array.isArray(this.data._links) ? this.data._links[0] : this.data._links, null, this.
|
|
97
|
+
this._links = new _LinkCollection.default(Array.isArray(this.data._links) ? this.data._links[0] : this.data._links, null, this._origin, this._contextPath);
|
|
98
98
|
}
|
|
99
99
|
return this._links;
|
|
100
100
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConceptLinkModel.js","names":["_BaseModel","_interopRequireDefault","require","_LinkModel","_LinkCollection","_ConceptTypeDetailModel","_Constants","_constants","ConceptLinkModel","BaseModel","constructor","data","entryDate","arguments","length","undefined","origin","contextPath","_defineProperty2","default","getBasePath","_entryDate","_origin","_contextPath","getInitialChildModelLinks","conceptTypeLink","isCacheable","setChildModels","models","href","conceptTypeModel","_find","call","model","selfhref","equalsWithParameters","type","conceptType","_conceptType","ConceptTypeDetailModel","key","_id","label","getData","links","_links","LinkCollection","Array","isArray","selflink","getLinkByKey","Error","addParameter","TIMEVERSION_FILTER_NAME","concepttypeHref","taxonomyType","asLinkModel","link","LinkModel","create","isOfConceptType","conceptTypeId","exports"],"sources":["../../../src/models/concepts/ConceptLinkModel.js"],"sourcesContent":["// @flow\nimport BaseModel from \"../base/BaseModel\";\nimport LinkModel from \"../links/LinkModel\";\nimport LinkCollection from \"../links/LinkCollection\";\nimport ConceptTypeDetailModel from \"./ConceptTypeDetailModel\";\nimport { TIMEVERSION_FILTER_NAME } from \"../../constants/Constants\";\n\nimport type { IModelWithChildModels, ModularUIModel } from \"../types\";\nimport type Href from \"../href/Href\";\nimport { getBasePath } from \"../../constants\";\n/**\n * Link to a concept\n */\nexport default class ConceptLinkModel\n extends BaseModel\n implements IModelWithChildModels\n{\n _links: ?LinkCollection;\n _entryDate: ?ISO_DATE;\n _conceptType: ?ConceptTypeDetailModel;\n _origin: string = \"\";\n _contextPath: string = getBasePath();\n\n /**\n * Construct ConceptLinkModel\n */\n constructor(\n data: Object,\n entryDate: ?ISO_DATE = null,\n origin?: string,\n contextPath?: string,\n ) {\n super(data, {});\n\n this._entryDate = entryDate;\n this._origin = origin || \"\";\n this._contextPath = contextPath || getBasePath();\n }\n\n /**\n */\n getInitialChildModelLinks(): Array<LinkModel> {\n if (this.conceptTypeLink) {\n this.conceptTypeLink.isCacheable = true;\n return [this.conceptTypeLink];\n }\n\n return [];\n }\n\n /**\n */\n setChildModels(models: Array<ModularUIModel>) {\n if (this.conceptTypeLink) {\n const href = this.conceptTypeLink.href;\n const conceptTypeModel = models.find((model) =>\n model.selfhref.equalsWithParameters(href),\n );\n\n if (conceptTypeModel?.type === \"ConceptTypeDetail\") {\n this.conceptType = conceptTypeModel;\n }\n }\n }\n\n /**\n * Retrieve concept type\n */\n get conceptType(): ?ConceptTypeDetailModel {\n return this._conceptType;\n }\n\n /**\n * Set concept type\n */\n set conceptType(conceptType: ?ModularUIModel) {\n this._conceptType =\n conceptType instanceof ConceptTypeDetailModel ? conceptType : null;\n }\n\n /**\n * Retrieve key\n */\n get key(): string {\n return this.data._id;\n }\n\n /**\n * Retrieve label\n */\n get label(): string {\n const label = this.getData(\"label\");\n\n if (label) {\n return label;\n }\n\n return this.getData(\"conceptLabel\", \"\");\n }\n\n /**\n * Getting the links of the resource\n */\n get links(): LinkCollection {\n if (!this._links) {\n this._links = new LinkCollection(\n Array.isArray(this.data._links)\n ? this.data._links[0]\n : this.data._links,\n null,\n this.
|
|
1
|
+
{"version":3,"file":"ConceptLinkModel.js","names":["_BaseModel","_interopRequireDefault","require","_LinkModel","_LinkCollection","_ConceptTypeDetailModel","_Constants","_constants","ConceptLinkModel","BaseModel","constructor","data","entryDate","arguments","length","undefined","origin","contextPath","_defineProperty2","default","getBasePath","_entryDate","_origin","_contextPath","getInitialChildModelLinks","conceptTypeLink","isCacheable","setChildModels","models","href","conceptTypeModel","_find","call","model","selfhref","equalsWithParameters","type","conceptType","_conceptType","ConceptTypeDetailModel","key","_id","label","getData","links","_links","LinkCollection","Array","isArray","selflink","getLinkByKey","Error","addParameter","TIMEVERSION_FILTER_NAME","concepttypeHref","taxonomyType","asLinkModel","link","LinkModel","create","isOfConceptType","conceptTypeId","exports"],"sources":["../../../src/models/concepts/ConceptLinkModel.js"],"sourcesContent":["// @flow\nimport BaseModel from \"../base/BaseModel\";\nimport LinkModel from \"../links/LinkModel\";\nimport LinkCollection from \"../links/LinkCollection\";\nimport ConceptTypeDetailModel from \"./ConceptTypeDetailModel\";\nimport { TIMEVERSION_FILTER_NAME } from \"../../constants/Constants\";\n\nimport type { IModelWithChildModels, ModularUIModel } from \"../types\";\nimport type Href from \"../href/Href\";\nimport { getBasePath } from \"../../constants\";\n/**\n * Link to a concept\n */\nexport default class ConceptLinkModel\n extends BaseModel\n implements IModelWithChildModels\n{\n _links: ?LinkCollection;\n _entryDate: ?ISO_DATE;\n _conceptType: ?ConceptTypeDetailModel;\n _origin: string = \"\";\n _contextPath: string = getBasePath();\n\n /**\n * Construct ConceptLinkModel\n */\n constructor(\n data: Object,\n entryDate: ?ISO_DATE = null,\n origin?: string,\n contextPath?: string,\n ) {\n super(data, {});\n\n this._entryDate = entryDate;\n this._origin = origin || \"\";\n this._contextPath = contextPath || getBasePath();\n }\n\n /**\n */\n getInitialChildModelLinks(): Array<LinkModel> {\n if (this.conceptTypeLink) {\n this.conceptTypeLink.isCacheable = true;\n return [this.conceptTypeLink];\n }\n\n return [];\n }\n\n /**\n */\n setChildModels(models: Array<ModularUIModel>) {\n if (this.conceptTypeLink) {\n const href = this.conceptTypeLink.href;\n const conceptTypeModel = models.find((model) =>\n model.selfhref.equalsWithParameters(href),\n );\n\n if (conceptTypeModel?.type === \"ConceptTypeDetail\") {\n this.conceptType = conceptTypeModel;\n }\n }\n }\n\n /**\n * Retrieve concept type\n */\n get conceptType(): ?ConceptTypeDetailModel {\n return this._conceptType;\n }\n\n /**\n * Set concept type\n */\n set conceptType(conceptType: ?ModularUIModel) {\n this._conceptType =\n conceptType instanceof ConceptTypeDetailModel ? conceptType : null;\n }\n\n /**\n * Retrieve key\n */\n get key(): string {\n return this.data._id;\n }\n\n /**\n * Retrieve label\n */\n get label(): string {\n const label = this.getData(\"label\");\n\n if (label) {\n return label;\n }\n\n return this.getData(\"conceptLabel\", \"\");\n }\n\n /**\n * Getting the links of the resource\n */\n get links(): LinkCollection {\n if (!this._links) {\n this._links = new LinkCollection(\n Array.isArray(this.data._links)\n ? this.data._links[0]\n : this.data._links,\n null,\n this._origin,\n this._contextPath,\n );\n }\n\n return this._links;\n }\n\n /**\n * Get self link of model\n */\n get selflink(): LinkModel {\n const selflink = this.links.getLinkByKey(\"self\");\n\n if (selflink === null) {\n throw new Error(\n `Could not find self link for ${\n this.key === null ? \"unknown\" : this.key\n }`,\n );\n }\n\n return selflink;\n }\n\n /**\n * Self href of concept\n */\n get selfhref(): Href {\n if (this._entryDate !== null) {\n return this.selflink.href.addParameter(\n TIMEVERSION_FILTER_NAME,\n this._entryDate,\n );\n }\n\n return this.selflink.href;\n }\n\n /**\n */\n get conceptTypeLink(): LinkModel | null {\n return this.links.getLinkByKey(\"concepttype\");\n }\n\n /**\n * Concept type href of concept\n */\n get concepttypeHref(): Href | null {\n return this.conceptTypeLink?.href ?? null;\n }\n\n /**\n */\n get taxonomyType(): string {\n return \"default\";\n }\n\n /**\n */\n asLinkModel(): LinkModel {\n const link = LinkModel.create(this.key, this.selfhref.href, this.label);\n link.href = this.selfhref;\n\n return link;\n }\n\n /**\n * Indicates if the given concept type id or href exists in the hierarchy of concept types for this concept\n */\n isOfConceptType(conceptTypeId: string): boolean {\n return this.conceptType?.isOfConceptType(conceptTypeId) ?? false;\n }\n}\n"],"mappings":";;;;;;;;;AACA,IAAAA,UAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,UAAA,GAAAF,sBAAA,C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B,EAAW;IAC9C,OAAO,IAAI,CAACxB,WAAW,EAAEuB,eAAe,CAACC,aAAa,CAAC,IAAI,KAAK;EAClE;AACF;AAACC,OAAA,CAAA3C,OAAA,GAAAX,gBAAA","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -41,6 +41,9 @@ export const useModularUI = (
|
|
|
41
41
|
const href = useMemo(() => url?.toString() || "", [url]);
|
|
42
42
|
const key = useKeyForHook(modelKey, href);
|
|
43
43
|
|
|
44
|
+
const modelSelector = useMemo(() => (state) => state.modularui[key], [key]);
|
|
45
|
+
const model = useSelector(modelSelector);
|
|
46
|
+
|
|
44
47
|
if (url instanceof Href) {
|
|
45
48
|
options.origin = options.origin ?? url.origin;
|
|
46
49
|
options.contextPath = options.contextPath ?? url.contextPath;
|
|
@@ -48,12 +51,13 @@ export const useModularUI = (
|
|
|
48
51
|
|
|
49
52
|
const location = useLocation();
|
|
50
53
|
const redirectLocation = location.state?.redirectLocation;
|
|
51
|
-
const
|
|
52
|
-
|
|
54
|
+
const forceLoad =
|
|
55
|
+
model == null ||
|
|
56
|
+
(redirectLocation instanceof Href ? redirectLocation?.equals(href) : false);
|
|
53
57
|
|
|
54
58
|
const prevOptions = useRef(options);
|
|
55
59
|
const prevHref = useRef(href);
|
|
56
|
-
const
|
|
60
|
+
const prevForceLoad = useRef(forceLoad);
|
|
57
61
|
|
|
58
62
|
// dispatch loadModularUI
|
|
59
63
|
useDeepCompareEffect(() => {
|
|
@@ -63,16 +67,16 @@ export const useModularUI = (
|
|
|
63
67
|
prevOptions.current.isReload &&
|
|
64
68
|
!options.isReload;
|
|
65
69
|
|
|
66
|
-
const
|
|
70
|
+
const doForceLoad = forceLoad && !prevForceLoad.current;
|
|
67
71
|
|
|
68
|
-
if (href !== "" && (
|
|
72
|
+
if (href !== "" && (doForceLoad || !isOldReload)) {
|
|
69
73
|
dispatch(loadModularUI(key, href, options));
|
|
70
74
|
}
|
|
71
75
|
|
|
72
76
|
prevOptions.current = options;
|
|
73
77
|
prevHref.current = href;
|
|
74
|
-
|
|
75
|
-
}, [key, href, options,
|
|
78
|
+
prevForceLoad.current = forceLoad;
|
|
79
|
+
}, [key, href, options, forceLoad]);
|
|
76
80
|
|
|
77
81
|
useEffect(() => {
|
|
78
82
|
if (options.removeOnUnmount) {
|
|
@@ -82,6 +86,5 @@ export const useModularUI = (
|
|
|
82
86
|
}
|
|
83
87
|
}, [dispatch, key, options.removeOnUnmount]);
|
|
84
88
|
|
|
85
|
-
|
|
86
|
-
return useSelector(selector);
|
|
89
|
+
return model;
|
|
87
90
|
};
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { useMemo } from "react";
|
|
3
3
|
import { useModularUI } from "./useModularUI";
|
|
4
4
|
import { useLocation } from "./useRouter";
|
|
5
|
-
|
|
5
|
+
|
|
6
6
|
import type { ModularUIModel, Href } from "../models";
|
|
7
7
|
|
|
8
8
|
export type UseModularUIBasicOptions<T: ModularUIModel> = {
|
|
@@ -59,8 +59,7 @@ const validateModel = (model: any, expectedModels: Array<string>) => {
|
|
|
59
59
|
(expectedModel) => model.type === expectedModel,
|
|
60
60
|
);
|
|
61
61
|
if (!isCorrectModel) {
|
|
62
|
-
console.
|
|
63
|
-
throw new IllegalStateException("Resolved model has incorrect type");
|
|
62
|
+
console.warn(model, "is not of instance", expectedModels);
|
|
64
63
|
}
|
|
65
64
|
}
|
|
66
65
|
};
|