@beinformed/ui 1.65.10 → 1.65.12
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 +23 -0
- package/esm/hooks/useDeepCompareEffect.js +22 -8
- package/esm/hooks/useDeepCompareEffect.js.flow +26 -10
- package/esm/hooks/useDeepCompareEffect.js.map +1 -1
- package/esm/hooks/useList.js +12 -6
- package/esm/hooks/useList.js.flow +9 -6
- package/esm/hooks/useList.js.map +1 -1
- package/esm/hooks/useLookup.js +1 -1
- package/esm/hooks/useLookup.js.flow +1 -1
- package/esm/hooks/useLookup.js.map +1 -1
- package/esm/hooks/useModularUIBasic.js +10 -3
- package/esm/hooks/useModularUIBasic.js.flow +11 -1
- package/esm/hooks/useModularUIBasic.js.map +1 -1
- package/esm/hooks/usePanel.js.flow +1 -1
- package/esm/hooks/usePanel.js.map +1 -1
- package/esm/hooks/useRouter.js +12 -6
- package/esm/hooks/useRouter.js.flow +29 -23
- package/esm/hooks/useRouter.js.map +1 -1
- package/esm/models/href/Href.js +26 -1
- package/esm/models/href/Href.js.flow +28 -1
- package/esm/models/href/Href.js.map +1 -1
- package/esm/models/href/ListHref.js +12 -2
- package/esm/models/href/ListHref.js.flow +14 -2
- package/esm/models/href/ListHref.js.map +1 -1
- package/esm/models/list/ListModel.js +42 -16
- package/esm/models/list/ListModel.js.flow +33 -2
- package/esm/models/list/ListModel.js.map +1 -1
- package/esm/models/parameter/Parameter.js +6 -6
- package/esm/models/parameter/Parameter.js.flow +6 -6
- package/esm/models/parameter/Parameter.js.map +1 -1
- package/lib/hooks/useDeepCompareEffect.js +22 -11
- package/lib/hooks/useDeepCompareEffect.js.map +1 -1
- package/lib/hooks/useList.js +12 -6
- package/lib/hooks/useList.js.map +1 -1
- package/lib/hooks/useLookup.js +1 -1
- package/lib/hooks/useLookup.js.map +1 -1
- package/lib/hooks/useModularUIBasic.js +9 -2
- package/lib/hooks/useModularUIBasic.js.map +1 -1
- package/lib/hooks/usePanel.js.map +1 -1
- package/lib/hooks/useRouter.js +12 -6
- package/lib/hooks/useRouter.js.map +1 -1
- package/lib/models/href/Href.js +26 -1
- package/lib/models/href/Href.js.map +1 -1
- package/lib/models/href/ListHref.js +12 -2
- package/lib/models/href/ListHref.js.map +1 -1
- package/lib/models/list/ListModel.js +42 -16
- package/lib/models/list/ListModel.js.map +1 -1
- package/lib/models/parameter/Parameter.js +6 -6
- package/lib/models/parameter/Parameter.js.map +1 -1
- package/package.json +10 -10
- package/src/hooks/useDeepCompareEffect.js +26 -10
- package/src/hooks/useList.js +9 -6
- package/src/hooks/useLookup.js +1 -1
- package/src/hooks/useModularUIBasic.js +11 -1
- package/src/hooks/usePanel.js +1 -1
- package/src/hooks/useRouter.js +29 -23
- package/src/models/href/Href.js +28 -1
- package/src/models/href/ListHref.js +14 -2
- package/src/models/list/ListModel.js +33 -2
- package/src/models/parameter/Parameter.js +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,29 @@
|
|
|
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.12](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/compare/v1.65.10...v1.65.12) (2026-01-13)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* **hooks:** enhance `useRouter` hooks with memoization and type improvements ([b24ebb3](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/commit/b24ebb30c541c7736ba750bd059de107fce7b559))
|
|
11
|
+
* **hooks:** improve `useDeepCompareEffect` with validation and cleanup logic ([90fb49d](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/commit/90fb49d9cd7731f81c6bb319d1c3865d19500d1b))
|
|
12
|
+
* **hooks:** make it possible to post formdata using the basic modular ui hooks ([4a49624](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/commit/4a4962419497bf7300839be791a22d0a84158159))
|
|
13
|
+
* **href:** add support for formdata and public querystring handling ([2978cda](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/commit/2978cdac3d22eff45e217aa39910b10afb8f9abb))
|
|
14
|
+
* **models:** add `lookupToken` support for `ListHref` and `ListModel` ([0fd6d4a](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/commit/0fd6d4a866764e7dca57fa45a5c85116f936d395))
|
|
15
|
+
* **parameter:** decode parameter name to retrieve prefix ([a0b89a0](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/commit/a0b89a0121eb6bf46de1e695ff09cffa8df8e224))
|
|
16
|
+
|
|
17
|
+
## [1.65.11](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/compare/v1.65.10...v1.65.11) (2026-01-12)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Bug Fixes
|
|
21
|
+
|
|
22
|
+
* **hooks:** enhance `useRouter` hooks with memoization and type improvements ([b24ebb3](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/commit/b24ebb30c541c7736ba750bd059de107fce7b559))
|
|
23
|
+
* **hooks:** improve `useDeepCompareEffect` with validation and cleanup logic ([90fb49d](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/commit/90fb49d9cd7731f81c6bb319d1c3865d19500d1b))
|
|
24
|
+
* **hooks:** make it possible to post formdata using the basic modular ui hooks ([4a49624](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/commit/4a4962419497bf7300839be791a22d0a84158159))
|
|
25
|
+
* **href:** add support for formdata and public querystring handling ([2978cda](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/commit/2978cdac3d22eff45e217aa39910b10afb8f9abb))
|
|
26
|
+
* **parameter:** decode parameter name to retrieve prefix ([a0b89a0](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/commit/a0b89a0121eb6bf46de1e695ff09cffa8df8e224))
|
|
27
|
+
|
|
5
28
|
## [1.65.10](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/compare/v1.65.9...v1.65.10) (2026-01-09)
|
|
6
29
|
|
|
7
30
|
|
|
@@ -1,24 +1,38 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { useRef, useEffect } from "react";
|
|
2
2
|
import { dequal as deepEqual } from "dequal/lite";
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* Validates that dependencies are used correctly.
|
|
5
|
+
* Deep compare should not be used with empty arrays or no dependencies.
|
|
6
6
|
*/
|
|
7
|
+
function checkDeps(deps) {
|
|
8
|
+
if (process.env.NODE_ENV !== "production") {
|
|
9
|
+
if (!deps || deps.length === 0) {
|
|
10
|
+
console.warn("useDeepCompareEffect should not be used with no dependencies. Use React.useEffect instead.");
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}
|
|
7
14
|
const useDeepCompareMemoize = value => {
|
|
8
|
-
const ref =
|
|
9
|
-
|
|
15
|
+
const ref = useRef(value);
|
|
16
|
+
|
|
17
|
+
// Only update the ref if the deep equality check fails
|
|
10
18
|
if (!deepEqual(value, ref.current)) {
|
|
11
19
|
ref.current = value;
|
|
12
|
-
signalRef.current += 1;
|
|
13
20
|
}
|
|
14
|
-
return
|
|
21
|
+
return ref.current;
|
|
15
22
|
};
|
|
16
23
|
|
|
17
24
|
/**
|
|
25
|
+
* A version of useEffect that accepts a deep comparison of dependencies.
|
|
18
26
|
*/
|
|
19
27
|
export function useDeepCompareEffect(callback, dependencies) {
|
|
28
|
+
if (process.env.NODE_ENV !== "production") {
|
|
29
|
+
checkDeps(dependencies);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// We use the memoized ref as the dependency.
|
|
33
|
+
// React's shallow check will only trigger when the ref object itself changes.
|
|
20
34
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
21
|
-
|
|
35
|
+
useEffect(callback, useDeepCompareMemoize(dependencies));
|
|
22
36
|
}
|
|
23
37
|
export default useDeepCompareEffect;
|
|
24
38
|
//# sourceMappingURL=useDeepCompareEffect.js.map
|
|
@@ -1,34 +1,50 @@
|
|
|
1
1
|
// @flow
|
|
2
|
-
import
|
|
2
|
+
import { useRef, useEffect } from "react";
|
|
3
3
|
import { dequal as deepEqual } from "dequal/lite";
|
|
4
4
|
|
|
5
5
|
type Callback = () => void | (() => void);
|
|
6
|
-
type DependencyList =
|
|
6
|
+
type DependencyList = $ReadOnlyArray<any>;
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
10
|
-
*
|
|
9
|
+
* Validates that dependencies are used correctly.
|
|
10
|
+
* Deep compare should not be used with empty arrays or no dependencies.
|
|
11
11
|
*/
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
function checkDeps(deps: DependencyList) {
|
|
13
|
+
if (process.env.NODE_ENV !== "production") {
|
|
14
|
+
if (!deps || deps.length === 0) {
|
|
15
|
+
console.warn(
|
|
16
|
+
"useDeepCompareEffect should not be used with no dependencies. Use React.useEffect instead.",
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const useDeepCompareMemoize = (value: DependencyList): DependencyList => {
|
|
23
|
+
const ref = useRef<DependencyList>(value);
|
|
15
24
|
|
|
25
|
+
// Only update the ref if the deep equality check fails
|
|
16
26
|
if (!deepEqual(value, ref.current)) {
|
|
17
27
|
ref.current = value;
|
|
18
|
-
signalRef.current += 1;
|
|
19
28
|
}
|
|
20
29
|
|
|
21
|
-
return
|
|
30
|
+
return ref.current;
|
|
22
31
|
};
|
|
23
32
|
|
|
24
33
|
/**
|
|
34
|
+
* A version of useEffect that accepts a deep comparison of dependencies.
|
|
25
35
|
*/
|
|
26
36
|
export function useDeepCompareEffect(
|
|
27
37
|
callback: Callback,
|
|
28
38
|
dependencies: DependencyList,
|
|
29
39
|
): void {
|
|
40
|
+
if (process.env.NODE_ENV !== "production") {
|
|
41
|
+
checkDeps(dependencies);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// We use the memoized ref as the dependency.
|
|
45
|
+
// React's shallow check will only trigger when the ref object itself changes.
|
|
30
46
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
31
|
-
|
|
47
|
+
useEffect(callback, useDeepCompareMemoize(dependencies));
|
|
32
48
|
}
|
|
33
49
|
|
|
34
50
|
export default useDeepCompareEffect;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDeepCompareEffect.js","names":["
|
|
1
|
+
{"version":3,"file":"useDeepCompareEffect.js","names":["useRef","useEffect","dequal","deepEqual","checkDeps","deps","process","env","NODE_ENV","length","console","warn","useDeepCompareMemoize","value","ref","current","useDeepCompareEffect","callback","dependencies"],"sources":["../../src/hooks/useDeepCompareEffect.js"],"sourcesContent":["// @flow\nimport { useRef, useEffect } from \"react\";\nimport { dequal as deepEqual } from \"dequal/lite\";\n\ntype Callback = () => void | (() => void);\ntype DependencyList = $ReadOnlyArray<any>;\n\n/**\n * Validates that dependencies are used correctly.\n * Deep compare should not be used with empty arrays or no dependencies.\n */\nfunction checkDeps(deps: DependencyList) {\n if (process.env.NODE_ENV !== \"production\") {\n if (!deps || deps.length === 0) {\n console.warn(\n \"useDeepCompareEffect should not be used with no dependencies. Use React.useEffect instead.\",\n );\n }\n }\n}\n\nconst useDeepCompareMemoize = (value: DependencyList): DependencyList => {\n const ref = useRef<DependencyList>(value);\n\n // Only update the ref if the deep equality check fails\n if (!deepEqual(value, ref.current)) {\n ref.current = value;\n }\n\n return ref.current;\n};\n\n/**\n * A version of useEffect that accepts a deep comparison of dependencies.\n */\nexport function useDeepCompareEffect(\n callback: Callback,\n dependencies: DependencyList,\n): void {\n if (process.env.NODE_ENV !== \"production\") {\n checkDeps(dependencies);\n }\n\n // We use the memoized ref as the dependency.\n // React's shallow check will only trigger when the ref object itself changes.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n useEffect(callback, useDeepCompareMemoize(dependencies));\n}\n\nexport default useDeepCompareEffect;\n"],"mappings":"AACA,SAASA,MAAM,EAAEC,SAAS,QAAQ,OAAO;AACzC,SAASC,MAAM,IAAIC,SAAS,QAAQ,aAAa;AAKjD;AACA;AACA;AACA;AACA,SAASC,SAASA,CAACC,IAAoB,EAAE;EACvC,IAAIC,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,YAAY,EAAE;IACzC,IAAI,CAACH,IAAI,IAAIA,IAAI,CAACI,MAAM,KAAK,CAAC,EAAE;MAC9BC,OAAO,CAACC,IAAI,CACV,4FACF,CAAC;IACH;EACF;AACF;AAEA,MAAMC,qBAAqB,GAAIC,KAAqB,IAAqB;EACvE,MAAMC,GAAG,GAAGd,MAAM,CAAiBa,KAAK,CAAC;;EAEzC;EACA,IAAI,CAACV,SAAS,CAACU,KAAK,EAAEC,GAAG,CAACC,OAAO,CAAC,EAAE;IAClCD,GAAG,CAACC,OAAO,GAAGF,KAAK;EACrB;EAEA,OAAOC,GAAG,CAACC,OAAO;AACpB,CAAC;;AAED;AACA;AACA;AACA,OAAO,SAASC,oBAAoBA,CAClCC,QAAkB,EAClBC,YAA4B,EACtB;EACN,IAAIZ,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,YAAY,EAAE;IACzCJ,SAAS,CAACc,YAAY,CAAC;EACzB;;EAEA;EACA;EACA;EACAjB,SAAS,CAACgB,QAAQ,EAAEL,qBAAqB,CAACM,YAAY,CAAC,CAAC;AAC1D;AAEA,eAAeF,oBAAoB","ignoreList":[]}
|
package/esm/hooks/useList.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { useHistory } from "react-router";
|
|
2
1
|
import { useDispatch } from "react-redux";
|
|
3
2
|
import { useModularUIBasic } from "./useModularUIBasic";
|
|
4
3
|
import { HTTP_METHODS } from "../constants/Constants";
|
|
5
4
|
import { loadModularUI } from "../redux";
|
|
5
|
+
import { useNavigation } from "./useRouter";
|
|
6
6
|
import DetailModel from "../models/detail/DetailModel";
|
|
7
7
|
import ListModel from "../models/list/ListModel";
|
|
8
8
|
import CaseSearchModel from "../models/search/CaseSearchModel";
|
|
@@ -43,8 +43,12 @@ export const useListNavigation = ({
|
|
|
43
43
|
syncLocation = true,
|
|
44
44
|
historyAction = "push"
|
|
45
45
|
} = {}) => {
|
|
46
|
-
const
|
|
46
|
+
const {
|
|
47
|
+
push,
|
|
48
|
+
replace
|
|
49
|
+
} = useNavigation();
|
|
47
50
|
const dispatch = useDispatch();
|
|
51
|
+
const navigate = historyAction === "push" ? push : replace;
|
|
48
52
|
const update = useCallback((list, resetPage = false) => {
|
|
49
53
|
const listHref = list.selfhref;
|
|
50
54
|
if (resetPage) {
|
|
@@ -52,9 +56,11 @@ export const useListNavigation = ({
|
|
|
52
56
|
}
|
|
53
57
|
if (list.requestMethod === HTTP_METHODS.POST) {
|
|
54
58
|
if (syncLocation) {
|
|
55
|
-
|
|
59
|
+
navigate({
|
|
56
60
|
search: listHref.getQuerystring(true),
|
|
57
|
-
state:
|
|
61
|
+
state: {
|
|
62
|
+
formdata: list.formdata
|
|
63
|
+
}
|
|
58
64
|
});
|
|
59
65
|
}
|
|
60
66
|
dispatch(loadModularUI(list.connectKey, listHref, {
|
|
@@ -64,7 +70,7 @@ export const useListNavigation = ({
|
|
|
64
70
|
}));
|
|
65
71
|
} else {
|
|
66
72
|
if (syncLocation) {
|
|
67
|
-
|
|
73
|
+
navigate({
|
|
68
74
|
search: listHref.getQuerystring(true)
|
|
69
75
|
});
|
|
70
76
|
}
|
|
@@ -73,7 +79,7 @@ export const useListNavigation = ({
|
|
|
73
79
|
targetModel: [ListModel, CaseSearchModel]
|
|
74
80
|
}));
|
|
75
81
|
}
|
|
76
|
-
}, [dispatch,
|
|
82
|
+
}, [dispatch, navigate, syncLocation]);
|
|
77
83
|
const updateFilters = useCallback((list, filters) => {
|
|
78
84
|
list.filterCollection = filters;
|
|
79
85
|
update(list, true);
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
// @flow
|
|
2
|
-
import { useHistory } from "react-router";
|
|
3
2
|
import { useDispatch } from "react-redux";
|
|
4
3
|
|
|
5
4
|
import { useModularUIBasic } from "./useModularUIBasic";
|
|
@@ -7,6 +6,8 @@ import { HTTP_METHODS } from "../constants/Constants";
|
|
|
7
6
|
|
|
8
7
|
import { loadModularUI } from "../redux";
|
|
9
8
|
|
|
9
|
+
import { useNavigation } from "./useRouter";
|
|
10
|
+
|
|
10
11
|
import DetailModel from "../models/detail/DetailModel";
|
|
11
12
|
import ListModel from "../models/list/ListModel";
|
|
12
13
|
import CaseSearchModel from "../models/search/CaseSearchModel";
|
|
@@ -84,9 +85,11 @@ export const useListNavigation = ({
|
|
|
84
85
|
syncLocation = true,
|
|
85
86
|
historyAction = "push",
|
|
86
87
|
}: ListNavigationOptions = {}): ListNavigationHook => {
|
|
87
|
-
const
|
|
88
|
+
const { push, replace } = useNavigation();
|
|
88
89
|
const dispatch = useDispatch();
|
|
89
90
|
|
|
91
|
+
const navigate = historyAction === "push" ? push : replace;
|
|
92
|
+
|
|
90
93
|
const update = useCallback(
|
|
91
94
|
(list: ListModel, resetPage: boolean = false) => {
|
|
92
95
|
const listHref = list.selfhref;
|
|
@@ -96,9 +99,9 @@ export const useListNavigation = ({
|
|
|
96
99
|
|
|
97
100
|
if (list.requestMethod === HTTP_METHODS.POST) {
|
|
98
101
|
if (syncLocation) {
|
|
99
|
-
|
|
102
|
+
navigate({
|
|
100
103
|
search: listHref.getQuerystring(true),
|
|
101
|
-
state: list.formdata,
|
|
104
|
+
state: { formdata: list.formdata },
|
|
102
105
|
});
|
|
103
106
|
}
|
|
104
107
|
|
|
@@ -111,7 +114,7 @@ export const useListNavigation = ({
|
|
|
111
114
|
);
|
|
112
115
|
} else {
|
|
113
116
|
if (syncLocation) {
|
|
114
|
-
|
|
117
|
+
navigate({ search: listHref.getQuerystring(true) });
|
|
115
118
|
}
|
|
116
119
|
dispatch(
|
|
117
120
|
loadModularUI(list.connectKey, listHref, {
|
|
@@ -121,7 +124,7 @@ export const useListNavigation = ({
|
|
|
121
124
|
);
|
|
122
125
|
}
|
|
123
126
|
},
|
|
124
|
-
[dispatch,
|
|
127
|
+
[dispatch, navigate, syncLocation],
|
|
125
128
|
);
|
|
126
129
|
|
|
127
130
|
const updateFilters = useCallback(
|
package/esm/hooks/useList.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useList.js","names":["useHistory","useDispatch","useModularUIBasic","HTTP_METHODS","loadModularUI","DetailModel","ListModel","CaseSearchModel","ListDetailModel","Href","FilterCollection","AssignmentFilterModel","FilterModel","useCallback","useMemo","useList","href","options","expectedModels","targetModel","useListOrDetail","useListDetail","forceTargetModel","useListNavigation","syncLocation","historyAction","history","dispatch","update","list","resetPage","listHref","selfhref","page","requestMethod","POST","search","getQuerystring","state","formdata","connectKey","method","data","GET","updateFilters","filters","filterCollection","updateFilter","filter","value","attribute","Error","resetFilters","reset","removeFilter","getFilterByName","name","updateSort","sortOption","sorting","updatePage","paging","updatePageSize","pagesize"],"sources":["../../src/hooks/useList.js"],"sourcesContent":["// @flow\nimport { useHistory } from \"react-router\";\nimport { useDispatch } from \"react-redux\";\n\nimport { useModularUIBasic } from \"./useModularUIBasic\";\nimport { HTTP_METHODS } from \"../constants/Constants\";\n\nimport { loadModularUI } from \"../redux\";\n\nimport DetailModel from \"../models/detail/DetailModel\";\nimport ListModel from \"../models/list/ListModel\";\nimport CaseSearchModel from \"../models/search/CaseSearchModel\";\nimport ListDetailModel from \"../models/list/ListDetailModel\";\nimport Href from \"../models/href/Href\";\nimport FilterCollection from \"../models/filters/FilterCollection\";\nimport AssignmentFilterModel from \"../models/filters/AssignmentFilterModel\";\nimport FilterModel from \"../models/filters/FilterModel\";\n\nimport type { HookOptions } from \"./useModularUIBasic\";\nimport type { AttributeType, IFilter } from \"../models/types\";\nimport { useCallback, useMemo } from \"react\";\n\ntype ListNavigationHook = {\n update: (list: ListModel, resetPage?: boolean) => void,\n updateFilters: (list: ListModel, filters: FilterCollection) => void,\n updateFilter: (\n list: ListModel,\n filter: IFilter,\n value: string,\n attribute?: AttributeType,\n ) => void,\n updateSort: (list: ListModel, sortOption: string) => void,\n updatePage: (list: ListModel, page: number) => void,\n updatePageSize: (list: ListModel, pagesize: number) => void,\n resetFilters: (list: ListModel) => void,\n removeFilter: (list: ListModel, filter: IFilter) => void,\n};\n\ntype ListNavigationOptions = {\n syncLocation?: boolean,\n historyAction?: \"push\" | \"replace\",\n};\n\n/**\n */\nexport const useList = (\n href: string | Href,\n options?: HookOptions,\n): ListModel | null =>\n useModularUIBasic(\"list\", href, {\n expectedModels: [\"List\", \"CaseSearch\"],\n targetModel: [ListModel, CaseSearchModel],\n ...options,\n });\n\n/**\n */\nexport const useListOrDetail = (\n href: string | Href,\n options?: HookOptions,\n): ListModel | DetailModel | null =>\n useModularUIBasic(\"list\", href, {\n expectedModels: [\"List\", \"CaseSearch\", \"Detail\"],\n targetModel: [ListModel, CaseSearchModel, DetailModel],\n ...options,\n });\n\n/**\n */\nexport const useListDetail = (\n href: string | Href,\n options?: HookOptions,\n): ListDetailModel | null =>\n useModularUIBasic(\"listdetail\", href, {\n expectedModels: [\"ListDetail\"],\n targetModel: ListDetailModel,\n forceTargetModel: true,\n ...options,\n });\n\n/**\n */\nexport const useListNavigation = ({\n syncLocation = true,\n historyAction = \"push\",\n}: ListNavigationOptions = {}): ListNavigationHook => {\n const history = useHistory();\n const dispatch = useDispatch();\n\n const update = useCallback(\n (list: ListModel, resetPage: boolean = false) => {\n const listHref = list.selfhref;\n if (resetPage) {\n listHref.page = null;\n }\n\n if (list.requestMethod === HTTP_METHODS.POST) {\n if (syncLocation) {\n history[historyAction]({\n search: listHref.getQuerystring(true),\n state: list.formdata,\n });\n }\n\n dispatch(\n loadModularUI(list.connectKey, listHref, {\n method: HTTP_METHODS.POST,\n data: list.formdata,\n targetModel: [ListModel, CaseSearchModel],\n }),\n );\n } else {\n if (syncLocation) {\n history[historyAction]({ search: listHref.getQuerystring(true) });\n }\n dispatch(\n loadModularUI(list.connectKey, listHref, {\n method: HTTP_METHODS.GET,\n targetModel: [ListModel, CaseSearchModel],\n }),\n );\n }\n },\n [dispatch, history, historyAction, syncLocation],\n );\n\n const updateFilters = useCallback(\n (list: ListModel, filters: FilterCollection) => {\n list.filterCollection = filters;\n update(list, true);\n },\n [update],\n );\n\n const updateFilter = useCallback(\n (\n list: ListModel,\n filter: IFilter,\n value: string,\n attribute?: AttributeType,\n ) => {\n if (attribute) {\n filter.update(attribute, value);\n } else if (filter instanceof AssignmentFilterModel) {\n throw new Error(\n \"Need the attribute to update for AssigmentFilterModel\",\n );\n } else if (filter instanceof FilterModel) {\n filter.update(filter.attribute, value);\n }\n update(list, true);\n },\n [update],\n );\n\n const resetFilters = useCallback(\n (list: ListModel) => {\n list.filterCollection.reset();\n update(list, true);\n },\n [update],\n );\n\n const removeFilter = useCallback(\n (list: ListModel, filter: IFilter) => {\n list.filterCollection.getFilterByName(filter.name)?.reset();\n update(list, true);\n },\n [update],\n );\n\n const updateSort = useCallback(\n (list: ListModel, sortOption: string) => {\n list.sorting.value = sortOption;\n update(list, true);\n },\n [update],\n );\n\n const updatePage = useCallback(\n (list: ListModel, page: number) => {\n list.paging.page = page;\n update(list);\n },\n [update],\n );\n\n const updatePageSize = useCallback(\n (list: ListModel, pagesize: number) => {\n list.paging.pagesize.value = pagesize;\n update(list, true);\n },\n [update],\n );\n\n return useMemo(\n () => ({\n update,\n updateFilters,\n updateFilter,\n updateSort,\n updatePage,\n updatePageSize,\n resetFilters,\n removeFilter,\n }),\n [\n removeFilter,\n resetFilters,\n update,\n updateFilter,\n updateFilters,\n updatePage,\n updatePageSize,\n updateSort,\n ],\n );\n};\n"],"mappings":"AACA,SAASA,UAAU,QAAQ,cAAc;AACzC,SAASC,WAAW,QAAQ,aAAa;AAEzC,SAASC,iBAAiB,QAAQ,qBAAqB;AACvD,SAASC,YAAY,QAAQ,wBAAwB;AAErD,SAASC,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AK,GAAGS,UAAU;IAC/B9B,MAAM,CAACC,IAAI,EAAE,IAAI,CAAC;EACpB,CAAC,EACD,CAACD,MAAM,CACT,CAAC;EAED,MAAMgC,UAAU,GAAG/C,WAAW,CAC5B,CAACgB,IAAe,EAAEI,IAAY,KAAK;IACjCJ,IAAI,CAACgC,MAAM,CAAC5B,IAAI,GAAGA,IAAI;IACvBL,MAAM,CAACC,IAAI,CAAC;EACd,CAAC,EACD,CAACD,MAAM,CACT,CAAC;EAED,MAAMkC,cAAc,GAAGjD,WAAW,CAChC,CAACgB,IAAe,EAAEkC,QAAgB,KAAK;IACrClC,IAAI,CAACgC,MAAM,CAACE,QAAQ,CAACd,KAAK,GAAGc,QAAQ;IACrCnC,MAAM,CAACC,IAAI,EAAE,IAAI,CAAC;EACpB,CAAC,EACD,CAACD,MAAM,CACT,CAAC;EAED,OAAOd,OAAO,CACZ,OAAO;IACLc,MAAM;IACNgB,aAAa;IACbG,YAAY;IACZU,UAAU;IACVG,UAAU;IACVE,cAAc;IACdV,YAAY;IACZE;EACF,CAAC,CAAC,EACF,CACEA,YAAY,EACZF,YAAY,EACZxB,MAAM,EACNmB,YAAY,EACZH,aAAa,EACbgB,UAAU,EACVE,cAAc,EACdL,UAAU,CAEd,CAAC;AACH,CAAC","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"useList.js","names":["useDispatch","useModularUIBasic","HTTP_METHODS","loadModularUI","useNavigation","DetailModel","ListModel","CaseSearchModel","ListDetailModel","Href","FilterCollection","AssignmentFilterModel","FilterModel","useCallback","useMemo","useList","href","options","expectedModels","targetModel","useListOrDetail","useListDetail","forceTargetModel","useListNavigation","syncLocation","historyAction","push","replace","dispatch","navigate","update","list","resetPage","listHref","selfhref","page","requestMethod","POST","search","getQuerystring","state","formdata","connectKey","method","data","GET","updateFilters","filters","filterCollection","updateFilter","filter","value","attribute","Error","resetFilters","reset","removeFilter","getFilterByName","name","updateSort","sortOption","sorting","updatePage","paging","updatePageSize","pagesize"],"sources":["../../src/hooks/useList.js"],"sourcesContent":["// @flow\nimport { useDispatch } from \"react-redux\";\n\nimport { useModularUIBasic } from \"./useModularUIBasic\";\nimport { HTTP_METHODS } from \"../constants/Constants\";\n\nimport { loadModularUI } from \"../redux\";\n\nimport { useNavigation } from \"./useRouter\";\n\nimport DetailModel from \"../models/detail/DetailModel\";\nimport ListModel from \"../models/list/ListModel\";\nimport CaseSearchModel from \"../models/search/CaseSearchModel\";\nimport ListDetailModel from \"../models/list/ListDetailModel\";\nimport Href from \"../models/href/Href\";\nimport FilterCollection from \"../models/filters/FilterCollection\";\nimport AssignmentFilterModel from \"../models/filters/AssignmentFilterModel\";\nimport FilterModel from \"../models/filters/FilterModel\";\n\nimport type { HookOptions } from \"./useModularUIBasic\";\nimport type { AttributeType, IFilter } from \"../models/types\";\nimport { useCallback, useMemo } from \"react\";\n\ntype ListNavigationHook = {\n update: (list: ListModel, resetPage?: boolean) => void,\n updateFilters: (list: ListModel, filters: FilterCollection) => void,\n updateFilter: (\n list: ListModel,\n filter: IFilter,\n value: string,\n attribute?: AttributeType,\n ) => void,\n updateSort: (list: ListModel, sortOption: string) => void,\n updatePage: (list: ListModel, page: number) => void,\n updatePageSize: (list: ListModel, pagesize: number) => void,\n resetFilters: (list: ListModel) => void,\n removeFilter: (list: ListModel, filter: IFilter) => void,\n};\n\ntype ListNavigationOptions = {\n syncLocation?: boolean,\n historyAction?: \"push\" | \"replace\",\n};\n\n/**\n */\nexport const useList = (\n href: string | Href,\n options?: HookOptions,\n): ListModel | null =>\n useModularUIBasic(\"list\", href, {\n expectedModels: [\"List\", \"CaseSearch\"],\n targetModel: [ListModel, CaseSearchModel],\n ...options,\n });\n\n/**\n */\nexport const useListOrDetail = (\n href: string | Href,\n options?: HookOptions,\n): ListModel | DetailModel | null =>\n useModularUIBasic(\"list\", href, {\n expectedModels: [\"List\", \"CaseSearch\", \"Detail\"],\n targetModel: [ListModel, CaseSearchModel, DetailModel],\n ...options,\n });\n\n/**\n */\nexport const useListDetail = (\n href: string | Href,\n options?: HookOptions,\n): ListDetailModel | null =>\n useModularUIBasic(\"listdetail\", href, {\n expectedModels: [\"ListDetail\"],\n targetModel: ListDetailModel,\n forceTargetModel: true,\n ...options,\n });\n\n/**\n */\nexport const useListNavigation = ({\n syncLocation = true,\n historyAction = \"push\",\n}: ListNavigationOptions = {}): ListNavigationHook => {\n const { push, replace } = useNavigation();\n const dispatch = useDispatch();\n\n const navigate = historyAction === \"push\" ? push : replace;\n\n const update = useCallback(\n (list: ListModel, resetPage: boolean = false) => {\n const listHref = list.selfhref;\n if (resetPage) {\n listHref.page = null;\n }\n\n if (list.requestMethod === HTTP_METHODS.POST) {\n if (syncLocation) {\n navigate({\n search: listHref.getQuerystring(true),\n state: { formdata: list.formdata },\n });\n }\n\n dispatch(\n loadModularUI(list.connectKey, listHref, {\n method: HTTP_METHODS.POST,\n data: list.formdata,\n targetModel: [ListModel, CaseSearchModel],\n }),\n );\n } else {\n if (syncLocation) {\n navigate({ search: listHref.getQuerystring(true) });\n }\n dispatch(\n loadModularUI(list.connectKey, listHref, {\n method: HTTP_METHODS.GET,\n targetModel: [ListModel, CaseSearchModel],\n }),\n );\n }\n },\n [dispatch, navigate, syncLocation],\n );\n\n const updateFilters = useCallback(\n (list: ListModel, filters: FilterCollection) => {\n list.filterCollection = filters;\n update(list, true);\n },\n [update],\n );\n\n const updateFilter = useCallback(\n (\n list: ListModel,\n filter: IFilter,\n value: string,\n attribute?: AttributeType,\n ) => {\n if (attribute) {\n filter.update(attribute, value);\n } else if (filter instanceof AssignmentFilterModel) {\n throw new Error(\n \"Need the attribute to update for AssigmentFilterModel\",\n );\n } else if (filter instanceof FilterModel) {\n filter.update(filter.attribute, value);\n }\n update(list, true);\n },\n [update],\n );\n\n const resetFilters = useCallback(\n (list: ListModel) => {\n list.filterCollection.reset();\n update(list, true);\n },\n [update],\n );\n\n const removeFilter = useCallback(\n (list: ListModel, filter: IFilter) => {\n list.filterCollection.getFilterByName(filter.name)?.reset();\n update(list, true);\n },\n [update],\n );\n\n const updateSort = useCallback(\n (list: ListModel, sortOption: string) => {\n list.sorting.value = sortOption;\n update(list, true);\n },\n [update],\n );\n\n const updatePage = useCallback(\n (list: ListModel, page: number) => {\n list.paging.page = page;\n update(list);\n },\n [update],\n );\n\n const updatePageSize = useCallback(\n (list: ListModel, pagesize: number) => {\n list.paging.pagesize.value = pagesize;\n update(list, true);\n },\n [update],\n );\n\n return useMemo(\n () => ({\n update,\n updateFilters,\n updateFilter,\n updateSort,\n updatePage,\n updatePageSize,\n resetFilters,\n removeFilter,\n }),\n [\n removeFilter,\n resetFilters,\n update,\n updateFilter,\n updateFilters,\n updatePage,\n updatePageSize,\n updateSort,\n ],\n );\n};\n"],"mappings":"AACA,SAASA,WAAW,QAAQ,aAAa;AAEzC,SAASC,iBAAiB,QAAQ,qBAAqB;AACvD,SAASC,YAAY,QAAQ,wBAAwB;AAErD,SAASC,aAAa,QAAQ,UAAU;AAExC,SAASC,aAAa,QAAQ,aAAa;AAE3C,OAAOC,WAAW,MAAM,8BAA8B;AACtD,OAAOC,SAAS,MAAM,0BAA0B;AAChD,OAAOC,eAAe,MAAM,kCAAkC;AAC9D,OAAOC,eAAe,MAAM,gCAAgC;AAC5D,OAAOC,IAAI,MAAM,qBAAqB;AACtC,OAAOC,gBAAgB,MAAM,oCAAoC;AACjE,OAAOC,qBAAqB,MAAM,yCAAyC;AAC3E,OAAOC,WAAW,MAAM,+BAA+B;AAIvD,SAASC,WAAW,EAAEC,OAAO,QAAQ,OAAO;AAuB5C;AACA;AACA,OAAO,MAAMC,OAAO,GAAGA,CACrBC,IAAmB,EACnBC,OAAqB,KAErBhB,iBAAiB,CAAC,MAAM,EAAEe,IAAI,EAAE;EAC9BE,cAAc,EAAE,CAAC,MAAM,EAAE,YAAY,CAAC;EACtCC,WAAW,EAAE,CAACb,SAAS,EAAEC,eAAe,CAAC;EACzC,GAAGU;AACL,CAAC,CAAC;;AAEJ;AACA;AACA,OAAO,MAAMG,eA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,OAAO,CACZ,OAAO;IACLgB,MAAM;IACNgB,aAAa;IACbG,YAAY;IACZU,UAAU;IACVG,UAAU;IACVE,cAAc;IACdV,YAAY;IACZE;EACF,CAAC,CAAC,EACF,CACEA,YAAY,EACZF,YAAY,EACZxB,MAAM,EACNmB,YAAY,EACZH,aAAa,EACbgB,UAAU,EACVE,cAAc,EACdL,UAAU,CAEd,CAAC;AACH,CAAC","ignoreList":[]}
|
package/esm/hooks/useLookup.js
CHANGED
|
@@ -8,7 +8,7 @@ import { useProgressIndicator } from "./useProgressIndicator";
|
|
|
8
8
|
/**
|
|
9
9
|
* Lookup options call
|
|
10
10
|
*/
|
|
11
|
-
export const useLookup = (lookupLink, filterInput = "", minLength =
|
|
11
|
+
export const useLookup = (lookupLink, filterInput = "", minLength = 1, debounceMs = 300) => {
|
|
12
12
|
const {
|
|
13
13
|
start,
|
|
14
14
|
finish
|
|
@@ -21,7 +21,7 @@ type UseLookupHook = {
|
|
|
21
21
|
export const useLookup = (
|
|
22
22
|
lookupLink: LinkModel,
|
|
23
23
|
filterInput: string = "",
|
|
24
|
-
minLength: number =
|
|
24
|
+
minLength: number = 1,
|
|
25
25
|
debounceMs: number = 300,
|
|
26
26
|
): UseLookupHook => {
|
|
27
27
|
const { start, finish } = useProgressIndicator();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLookup.js","names":["useEffect","useState","HTTP_METHODS","Href","LinkModel","LookupOptionsModel","useModularUIRequest","useProgressIndicator","useLookup","lookupLink","filterInput","minLength","debounceMs","start","finish","modularuiRequest","lookupOptions","setLookupOptions","lookupLoading","setLookupLoading","href","filterName","method","length","timeoutId","setTimeout","lookupHref","requestOptions","data","undefined","POST","addParameter","fetch","then","lookupResponse","finally","clearTimeout"],"sources":["../../src/hooks/useLookup.js"],"sourcesContent":["// @flow\nimport { useEffect, useState } from \"react\";\n\nimport { HTTP_METHODS } from \"../constants\";\n\nimport Href from \"../models/href/Href\";\nimport LinkModel from \"../models/links/LinkModel\";\nimport LookupOptionsModel from \"../models/lookup/LookupOptionsModel\";\n\nimport { useModularUIRequest } from \"./useModularUIRequest\";\nimport { useProgressIndicator } from \"./useProgressIndicator\";\n\ntype UseLookupHook = {\n lookupOptions: LookupOptionsModel | null,\n lookupLoading: boolean,\n};\n\n/**\n * Lookup options call\n */\nexport const useLookup = (\n lookupLink: LinkModel,\n filterInput: string = \"\",\n minLength: number =
|
|
1
|
+
{"version":3,"file":"useLookup.js","names":["useEffect","useState","HTTP_METHODS","Href","LinkModel","LookupOptionsModel","useModularUIRequest","useProgressIndicator","useLookup","lookupLink","filterInput","minLength","debounceMs","start","finish","modularuiRequest","lookupOptions","setLookupOptions","lookupLoading","setLookupLoading","href","filterName","method","length","timeoutId","setTimeout","lookupHref","requestOptions","data","undefined","POST","addParameter","fetch","then","lookupResponse","finally","clearTimeout"],"sources":["../../src/hooks/useLookup.js"],"sourcesContent":["// @flow\nimport { useEffect, useState } from \"react\";\n\nimport { HTTP_METHODS } from \"../constants\";\n\nimport Href from \"../models/href/Href\";\nimport LinkModel from \"../models/links/LinkModel\";\nimport LookupOptionsModel from \"../models/lookup/LookupOptionsModel\";\n\nimport { useModularUIRequest } from \"./useModularUIRequest\";\nimport { useProgressIndicator } from \"./useProgressIndicator\";\n\ntype UseLookupHook = {\n lookupOptions: LookupOptionsModel | null,\n lookupLoading: boolean,\n};\n\n/**\n * Lookup options call\n */\nexport const useLookup = (\n lookupLink: LinkModel,\n filterInput: string = \"\",\n minLength: number = 1,\n debounceMs: number = 300,\n): UseLookupHook => {\n const { start, finish } = useProgressIndicator();\n const modularuiRequest = useModularUIRequest();\n\n const [lookupOptions, setLookupOptions] = useState(null);\n const [lookupLoading, setLookupLoading] = useState(false);\n\n const { href, filterName, method } = lookupLink;\n\n useEffect(() => {\n if (filterInput.length < minLength) {\n setLookupOptions(null);\n return;\n }\n\n const timeoutId = setTimeout(async () => {\n setLookupLoading(true);\n start();\n\n const lookupHref = new Href(href);\n const requestOptions = { method, data: undefined };\n if (method === HTTP_METHODS.POST) {\n requestOptions.data = { [filterName]: filterInput };\n } else {\n lookupHref.addParameter(filterName, filterInput);\n }\n\n modularuiRequest(lookupHref, requestOptions)\n .fetch()\n .then((lookupResponse) => {\n if (lookupResponse instanceof LookupOptionsModel) {\n setLookupOptions(lookupResponse);\n }\n })\n .finally(() => {\n finish();\n setLookupLoading(false);\n });\n }, debounceMs);\n\n return () => {\n clearTimeout(timeoutId);\n };\n }, [\n debounceMs,\n filterInput,\n filterName,\n finish,\n href,\n method,\n minLength,\n modularuiRequest,\n start,\n ]);\n\n return { lookupOptions, lookupLoading };\n};\n"],"mappings":"AACA,SAASA,SAAS,EAAEC,QAAQ,QAAQ,OAAO;AAE3C,SAASC,YAAY,QAAQ,cAAc;AAE3C,OAAOC,IAAI,MAAM,qBAAqB;AACtC,OAAOC,SAAS,MAAM,2BAA2B;AACjD,OAAOC,kBAAkB,MAAM,qCAAqC;AAEpE,SAASC,mBAAmB,QAAQ,uBAAuB;AAC3D,SAASC,oBAAoB,QAAQ,wBAAwB;AAO7D;AACA;AACA;AACA,OAAO,MAAMC,SAAS,GAAGA,CACvBC,UAAqB,EACrBC,WAAmB,GAAG,EAAE,EACxBC,SAAiB,GAAG,CAAC,EACrBC,UAAkB,GAAG,GAAG,KACN;EAClB,MAAM;IAAEC,KAAK;IAAEC;EAAO,CAAC,GAAGP,oBAAoB,CAAC,CAAC;EAChD,MAAMQ,gBAAgB,GAAGT,mBAAmB,CAAC,CAAC;EAE9C,MAAM,CAACU,aAAa,EAAEC,gBAAgB,CAAC,GAAGhB,QAAQ,CAAC,IAAI,CAAC;EACxD,MAAM,CAACiB,aAAa,EAAEC,gBAAgB,CAAC,GAAGlB,QAAQ,CAAC,KAAK,CAAC;EAEzD,MAAM;IAAEmB,IAAI;IAAEC,UAAU;IAAEC;EAAO,CAAC,GAAGb,UAAU;EAE/CT,SAAS,CAAC,MAAM;IACd,IAAIU,WAAW,CAACa,MAAM,GAAGZ,SAAS,EAAE;MAClCM,gBAAgB,CAAC,IAAI,CAAC;MACtB;IACF;IAEA,MAAMO,SAAS,GAAGC,UAAU,CAAC,YAAY;MACvCN,gBAAgB,CAAC,IAAI,CAAC;MACtBN,KAAK,CAAC,CAAC;MAEP,MAAMa,UAAU,GAAG,IAAIvB,IAAI,CAACiB,IAAI,CAAC;MACjC,MAAMO,cAAc,GAAG;QAAEL,MAAM;QAAEM,IAAI,EAAEC;MAAU,CAAC;MAClD,IAAIP,MAAM,KAAKpB,YAAY,CAAC4B,IAAI,EAAE;QAChCH,cAAc,CAACC,IAAI,GAAG;UAAE,CAACP,UAAU,GAAGX;QAAY,CAAC;MACrD,CAAC,MAAM;QACLgB,UAAU,CAACK,YAAY,CAACV,UAAU,EAAEX,WAAW,CAAC;MAClD;MAEAK,gBAAgB,CAACW,UAAU,EAAEC,cAAc,CAAC,CACzCK,KAAK,CAAC,CAAC,CACPC,IAAI,CAAEC,cAAc,IAAK;QACxB,IAAIA,cAAc,YAAY7B,kBAAkB,EAAE;UAChDY,gBAAgB,CAACiB,cAAc,CAAC;QAClC;MACF,CAAC,CAAC,CACDC,OAAO,CAAC,MAAM;QACbrB,MAAM,CAAC,CAAC;QACRK,gBAAgB,CAAC,KAAK,CAAC;MACzB,CAAC,CAAC;IACN,CAAC,EAAEP,UAAU,CAAC;IAEd,OAAO,MAAM;MACXwB,YAAY,CAACZ,SAAS,CAAC;IACzB,CAAC;EACH,CAAC,EAAE,CACDZ,UAAU,EACVF,WAAW,EACXW,UAAU,EACVP,MAAM,EACNM,IAAI,EACJE,MAAM,EACNX,SAAS,EACTI,gBAAgB,EAChBF,KAAK,CACN,CAAC;EAEF,OAAO;IAAEG,aAAa;IAAEE;EAAc,CAAC;AACzC,CAAC","ignoreList":[]}
|
|
@@ -2,7 +2,7 @@ import { useLocation } from "react-router";
|
|
|
2
2
|
import { useSelector } from "react-redux";
|
|
3
3
|
import { useMemo } from "react";
|
|
4
4
|
import { useModularUI } from "./useModularUI";
|
|
5
|
-
import { MODULARUI_STATUS } from "../constants";
|
|
5
|
+
import { HTTP_METHODS, MODULARUI_STATUS } from "../constants";
|
|
6
6
|
import { useModularUIKey } from "./useModularUIKey";
|
|
7
7
|
// Helper to create useModularUI options
|
|
8
8
|
const createUseModularUIOptions = (options, href, mustReload) => {
|
|
@@ -13,7 +13,9 @@ const createUseModularUIOptions = (options, href, mustReload) => {
|
|
|
13
13
|
origin: undefined,
|
|
14
14
|
contextPath: undefined,
|
|
15
15
|
cache: false,
|
|
16
|
-
removeOnUnmount: false
|
|
16
|
+
removeOnUnmount: false,
|
|
17
|
+
method: HTTP_METHODS.GET,
|
|
18
|
+
data: undefined
|
|
17
19
|
};
|
|
18
20
|
|
|
19
21
|
// Handle targetModel and forceTargetModel
|
|
@@ -32,6 +34,10 @@ const createUseModularUIOptions = (options, href, mustReload) => {
|
|
|
32
34
|
if (options.removeOnUnmount) {
|
|
33
35
|
baseOptions.removeOnUnmount = true;
|
|
34
36
|
}
|
|
37
|
+
if (options.formdata != null) {
|
|
38
|
+
baseOptions.method = HTTP_METHODS.POST;
|
|
39
|
+
baseOptions.data = options.formdata;
|
|
40
|
+
}
|
|
35
41
|
|
|
36
42
|
// Handle origin and contextPath options
|
|
37
43
|
baseOptions.origin = options.origin ?? baseOptions.origin;
|
|
@@ -58,7 +64,8 @@ export const useModularUIBasic = (defaultKey, href, options = {
|
|
|
58
64
|
forceTargetModel: false,
|
|
59
65
|
origin: undefined,
|
|
60
66
|
contextPath: undefined,
|
|
61
|
-
key: undefined
|
|
67
|
+
key: undefined,
|
|
68
|
+
formdata: undefined
|
|
62
69
|
}) => {
|
|
63
70
|
const memoizedHref = useMemo(() => href.toString(), [href]);
|
|
64
71
|
const key = options.key ?? defaultKey;
|
|
@@ -4,7 +4,7 @@ import { useSelector } from "react-redux";
|
|
|
4
4
|
import { useMemo } from "react";
|
|
5
5
|
import { useModularUI } from "./useModularUI";
|
|
6
6
|
|
|
7
|
-
import { MODULARUI_STATUS } from "../constants";
|
|
7
|
+
import { HTTP_METHODS, MODULARUI_STATUS } from "../constants";
|
|
8
8
|
import { useModularUIKey } from "./useModularUIKey";
|
|
9
9
|
|
|
10
10
|
import type { ModularUIModel, Href } from "../models";
|
|
@@ -13,6 +13,7 @@ export type HookOptions = {
|
|
|
13
13
|
origin?: string,
|
|
14
14
|
contextPath?: string,
|
|
15
15
|
removeOnUnmount?: boolean,
|
|
16
|
+
formdata?: any,
|
|
16
17
|
};
|
|
17
18
|
|
|
18
19
|
export type UseModularUIBasicOptions<T: ModularUIModel> = {
|
|
@@ -25,6 +26,7 @@ export type UseModularUIBasicOptions<T: ModularUIModel> = {
|
|
|
25
26
|
key?: string,
|
|
26
27
|
isReload?: boolean,
|
|
27
28
|
removeOnUnmount?: boolean,
|
|
29
|
+
formdata?: any,
|
|
28
30
|
};
|
|
29
31
|
|
|
30
32
|
// Helper to create useModularUI options
|
|
@@ -41,6 +43,8 @@ const createUseModularUIOptions = <T: ModularUIModel>(
|
|
|
41
43
|
contextPath: undefined,
|
|
42
44
|
cache: false,
|
|
43
45
|
removeOnUnmount: false,
|
|
46
|
+
method: HTTP_METHODS.GET,
|
|
47
|
+
data: undefined,
|
|
44
48
|
};
|
|
45
49
|
|
|
46
50
|
// Handle targetModel and forceTargetModel
|
|
@@ -62,6 +66,11 @@ const createUseModularUIOptions = <T: ModularUIModel>(
|
|
|
62
66
|
baseOptions.removeOnUnmount = true;
|
|
63
67
|
}
|
|
64
68
|
|
|
69
|
+
if (options.formdata != null) {
|
|
70
|
+
baseOptions.method = HTTP_METHODS.POST;
|
|
71
|
+
baseOptions.data = options.formdata;
|
|
72
|
+
}
|
|
73
|
+
|
|
65
74
|
// Handle origin and contextPath options
|
|
66
75
|
baseOptions.origin = options.origin ?? baseOptions.origin;
|
|
67
76
|
baseOptions.contextPath = options.contextPath ?? baseOptions.contextPath;
|
|
@@ -94,6 +103,7 @@ export const useModularUIBasic = <T: ModularUIModel>(
|
|
|
94
103
|
origin: undefined,
|
|
95
104
|
contextPath: undefined,
|
|
96
105
|
key: undefined,
|
|
106
|
+
formdata: undefined,
|
|
97
107
|
},
|
|
98
108
|
): T | null => {
|
|
99
109
|
const memoizedHref = useMemo(() => href.toString(), [href]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useModularUIBasic.js","names":["useLocation","useSelector","useMemo","useModularUI","MODULARUI_STATUS","useModularUIKey","createUseModularUIOptions","options","href","mustReload","baseOptions","targetModel","undefined","forceTargetModel","isReload","origin","contextPath","cache","removeOnUnmount","validateModel","model","expectedModels","length","isCorrectModel","some","expectedModel","type","console","warn","useModularUIBasic","defaultKey","key","memoizedHref","toString","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 { 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};\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};\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 targetModel: undefined,\n forceTargetModel: undefined,\n isReload: false,\n origin: undefined,\n contextPath: undefined,\n cache: false,\n removeOnUnmount: 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 if (mustReload) {\n baseOptions.isReload = true;\n }\n\n if (options.removeOnUnmount) {\n baseOptions.removeOnUnmount = 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 defaultKey: string,\n href: string | Href,\n options: UseModularUIBasicOptions<T> = {\n expectedModels: [],\n targetModel: undefined,\n forceTargetModel: false,\n origin: undefined,\n contextPath: undefined,\n key: undefined,\n },\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,gBAAgB,QAAQ,cAAc;
|
|
1
|
+
{"version":3,"file":"useModularUIBasic.js","names":["useLocation","useSelector","useMemo","useModularUI","HTTP_METHODS","MODULARUI_STATUS","useModularUIKey","createUseModularUIOptions","options","href","mustReload","baseOptions","targetModel","undefined","forceTargetModel","isReload","origin","contextPath","cache","removeOnUnmount","method","GET","data","formdata","POST","validateModel","model","expectedModels","length","isCorrectModel","some","expectedModel","type","console","warn","useModularUIBasic","defaultKey","key","memoizedHref","toString","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 targetModel: undefined,\n forceTargetModel: undefined,\n isReload: false,\n origin: undefined,\n contextPath: undefined,\n cache: false,\n removeOnUnmount: false,\n method: HTTP_METHODS.GET,\n data: undefined,\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 if (mustReload) {\n baseOptions.isReload = true;\n }\n\n if (options.removeOnUnmount) {\n baseOptions.removeOnUnmount = true;\n }\n\n if (options.formdata != null) {\n baseOptions.method = HTTP_METHODS.POST;\n baseOptions.data = options.formdata;\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 defaultKey: string,\n href: string | Href,\n options: UseModularUIBasicOptions<T> = {\n expectedModels: [],\n targetModel: undefined,\n forceTargetModel: false,\n origin: undefined,\n contextPath: undefined,\n key: undefined,\n formdata: undefined,\n },\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,WAAW,EAAEC,SAAS;IACtBC,gBAAgB,EAAED,SAAS;IAC3BE,QAAQ,EAAE,KAAK;IACfC,MAAM,EAAEH,SAAS;IACjBI,WAAW,EAAEJ,SAAS;IACtBK,KAAK,EAAE,KAAK;IACZC,eAAe,EAAE,KAAK;IACtBC,MAAM,EAAEhB,YAAY,CAACiB,GAAG;IACxBC,IAAI,EAAET;EACR,CAAC;;EAED;EACA,IAAIL,OAAO,CAACI,WAAW,EAAE;IACvBD,WAAW,CAACC,WAAW,GAAGJ,OAAO,CAACI,WAAW;IAC7CD,WAAW,CAACG,gBAAgB,GAAGN,OAAO,CAACM,gBAAgB;EACzD;;EAEA;EACA,IAAIN,OAAO,CAACU,KAAK,EAAE;IACjBP,WAAW,CAACO,KAAK,GAAGV,OAAO,CAACU,KAAK;EACnC;EAEA,IAAIR,UA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AU,EAAEK,MAAM,KAAK9C,gBAAgB,CAAC+C,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":[]}
|
|
@@ -64,7 +64,7 @@ const useUrl = (href?: string | Href, fromRoute: boolean = false) => {
|
|
|
64
64
|
*/
|
|
65
65
|
export const usePanel = (
|
|
66
66
|
href?: string | Href,
|
|
67
|
-
options?: HookOptions
|
|
67
|
+
options?: { ...HookOptions, fromRoute?: boolean },
|
|
68
68
|
): ListModel | GroupingPanelModel | DetailModel | null => {
|
|
69
69
|
const { fromRoute, ...hookOptions } = options || { fromRoute: false };
|
|
70
70
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePanel.js","names":["useState","useMemo","useLocation","useRouteMatch","Href","useModularUIBasic","GroupingPanelModel","ListModel","DetailModel","CaseSearchModel","useUrl","href","fromRoute","previousUrl","setPreviousUrl","previousExact","setPreviousExact","match","location","_context","url","isExact","addParametersFromString","search","equalsWithParameters","shouldUpdate","Function","call","bind","_startsWithInstanceProperty","usePanel","options","hookOptions","basicOptions","expectedModels","targetModel"],"sources":["../../src/hooks/usePanel.js"],"sourcesContent":["// @flow\nimport { useState, useMemo } from \"react\";\nimport { useLocation, useRouteMatch } from \"react-router\";\nimport Href from \"../models/href/Href\";\nimport { useModularUIBasic } from \"./useModularUIBasic\";\n\nimport type { HookOptions } from \"./useModularUIBasic\";\nimport GroupingPanelModel from \"../models/panels/GroupingPanelModel\";\nimport ListModel from \"../models/list/ListModel\";\nimport DetailModel from \"../models/detail/DetailModel\";\nimport CaseSearchModel from \"../models/search/CaseSearchModel\";\n\nconst useUrl = (href?: string | Href, fromRoute: boolean = false) => {\n const [previousUrl, setPreviousUrl] = useState(null);\n const [previousExact, setPreviousExact] = useState(false);\n\n const match = useRouteMatch();\n const location = useLocation();\n\n return useMemo(() => {\n if (href == null && previousUrl == null) {\n return new Href(\"\");\n }\n\n const url = href instanceof Href ? href : new Href(href);\n\n if (!fromRoute) {\n return url;\n }\n\n if (match.isExact) {\n url.addParametersFromString(location.search);\n }\n\n // Check equality to prevent unnecessary state updates\n if (url.equalsWithParameters(previousUrl)) {\n return previousUrl || url;\n }\n\n const shouldUpdate =\n match.isExact === true ||\n previousExact === match.isExact ||\n !previousUrl?.startsWith(match.url);\n\n if (shouldUpdate) {\n setPreviousUrl(url);\n setPreviousExact(match.isExact);\n return url;\n }\n\n return previousUrl || new Href(\"\");\n }, [\n href,\n previousUrl,\n fromRoute,\n match.isExact,\n match.url,\n previousExact,\n location.search,\n ]);\n};\n\n/**\n */\nexport const usePanel = (\n href?: string | Href,\n options?: HookOptions
|
|
1
|
+
{"version":3,"file":"usePanel.js","names":["useState","useMemo","useLocation","useRouteMatch","Href","useModularUIBasic","GroupingPanelModel","ListModel","DetailModel","CaseSearchModel","useUrl","href","fromRoute","previousUrl","setPreviousUrl","previousExact","setPreviousExact","match","location","_context","url","isExact","addParametersFromString","search","equalsWithParameters","shouldUpdate","Function","call","bind","_startsWithInstanceProperty","usePanel","options","hookOptions","basicOptions","expectedModels","targetModel"],"sources":["../../src/hooks/usePanel.js"],"sourcesContent":["// @flow\nimport { useState, useMemo } from \"react\";\nimport { useLocation, useRouteMatch } from \"react-router\";\nimport Href from \"../models/href/Href\";\nimport { useModularUIBasic } from \"./useModularUIBasic\";\n\nimport type { HookOptions } from \"./useModularUIBasic\";\nimport GroupingPanelModel from \"../models/panels/GroupingPanelModel\";\nimport ListModel from \"../models/list/ListModel\";\nimport DetailModel from \"../models/detail/DetailModel\";\nimport CaseSearchModel from \"../models/search/CaseSearchModel\";\n\nconst useUrl = (href?: string | Href, fromRoute: boolean = false) => {\n const [previousUrl, setPreviousUrl] = useState(null);\n const [previousExact, setPreviousExact] = useState(false);\n\n const match = useRouteMatch();\n const location = useLocation();\n\n return useMemo(() => {\n if (href == null && previousUrl == null) {\n return new Href(\"\");\n }\n\n const url = href instanceof Href ? href : new Href(href);\n\n if (!fromRoute) {\n return url;\n }\n\n if (match.isExact) {\n url.addParametersFromString(location.search);\n }\n\n // Check equality to prevent unnecessary state updates\n if (url.equalsWithParameters(previousUrl)) {\n return previousUrl || url;\n }\n\n const shouldUpdate =\n match.isExact === true ||\n previousExact === match.isExact ||\n !previousUrl?.startsWith(match.url);\n\n if (shouldUpdate) {\n setPreviousUrl(url);\n setPreviousExact(match.isExact);\n return url;\n }\n\n return previousUrl || new Href(\"\");\n }, [\n href,\n previousUrl,\n fromRoute,\n match.isExact,\n match.url,\n previousExact,\n location.search,\n ]);\n};\n\n/**\n */\nexport const usePanel = (\n href?: string | Href,\n options?: { ...HookOptions, fromRoute?: boolean },\n): ListModel | GroupingPanelModel | DetailModel | null => {\n const { fromRoute, ...hookOptions } = options || { fromRoute: false };\n\n const url = useUrl(href, fromRoute || false);\n const basicOptions = {\n expectedModels: [\"List\", \"GroupingPanel\", \"Detail\", \"CaseSearch\"],\n targetModel: [ListModel, GroupingPanelModel, DetailModel, CaseSearchModel],\n ...(hookOptions: HookOptions),\n };\n\n return useModularUIBasic(\"panel\", url, basicOptions);\n};\n"],"mappings":";AACA,SAASA,QAAQ,EAAEC,OAAO,QAAQ,OAAO;AACzC,SAASC,WAAW,EAAEC,aAAa,QAAQ,cAAc;AACzD,OAAOC,IAAI,MAAM,qBAAqB;AACtC,SAASC,iBAAiB,QAAQ,qBAAqB;AAGvD,OAAOC,kBAAkB,MAAM,qCAAqC;AACpE,OAAOC,SAAS,MAAM,0BAA0B;AAChD,OAAOC,WAAW,MAAM,8BAA8B;AACtD,OAAOC,eAAe,MAAM,kCAAkC;AAE9D,MAAMC,MAAM,GAAGA,CAACC,IAAoB,EAAEC,SAAkB,GAAG,KAAK,KAAK;EACnE,MAAM,CAACC,WAAW,EAAEC,cAAc,CAAC,GAAGd,QAAQ,C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bJ,KAAK,CAACG,GAAG,EACTL,aAAa,EACbG,QAAQ,CAACK,MAAM,CAChB,CAAC;AACJ,CAAC;;AAED;AACA;AACA,OAAO,MAAMO,QAAQ,GAAGA,CACtBnB,IAAoB,EACpBoB,OAAiD,KACO;EACxD,MAAM;IAAEnB,SAAS;IAAE,GAAGoB;EAAY,CAAC,GAAGD,OAAO,IAAI;IAAEnB,SAAS,EAAE;EAAM,CAAC;EAErE,MAAMQ,GAAG,GAAGV,MAAM,CAACC,IAAI,EAAEC,SAAS,IAAI,KAAK,CAAC;EAC5C,MAAMqB,YAAY,GAAG;IACnBC,cAAc,EAAE,CAAC,MAAM,EAAE,eAAe,EAAE,QAAQ,EAAE,YAAY,CAAC;IACjEC,WAAW,EAAE,CAAC5B,SAAS,EAAED,kBAAkB,EAAEE,WAAW,EAAEC,eAAe,CAAC;IAC1E,GAAIuB;EACN,CAAC;EAED,OAAO3B,iBAAiB,CAAC,OAAO,EAAEe,GAAG,EAAEa,YAAY,CAAC;AACtD,CAAC","ignoreList":[]}
|
package/esm/hooks/useRouter.js
CHANGED
|
@@ -1,31 +1,37 @@
|
|
|
1
|
+
import { useMemo } from "react";
|
|
1
2
|
import { useDispatch, useSelector } from "react-redux";
|
|
2
3
|
import { push, replace, go, goBack, goForward } from "../redux/_router/RouterActions";
|
|
3
4
|
/**
|
|
5
|
+
* Returns the full location object from the router state.
|
|
4
6
|
*/
|
|
5
|
-
export const useLocation = () => useSelector(state => state.router
|
|
7
|
+
export const useLocation = () => useSelector(state => state.router?.location || {});
|
|
6
8
|
|
|
7
9
|
/**
|
|
10
|
+
* Returns the unique key of the current location.
|
|
8
11
|
*/
|
|
9
|
-
export const useLocationKey = () =>
|
|
12
|
+
export const useLocationKey = () => useSelector(state => state.router?.location?.key ?? "");
|
|
10
13
|
|
|
11
14
|
/**
|
|
15
|
+
* Returns the current search (querystring) portion of the URL.
|
|
12
16
|
*/
|
|
13
|
-
export const useQuerystring = () =>
|
|
17
|
+
export const useQuerystring = () => useSelector(state => state.router?.location?.search ?? "");
|
|
14
18
|
|
|
15
19
|
/**
|
|
20
|
+
* Returns the current URL pathname.
|
|
16
21
|
*/
|
|
17
|
-
export const usePathname = () =>
|
|
22
|
+
export const usePathname = () => useSelector(state => state.router?.location?.pathname ?? "");
|
|
18
23
|
|
|
19
24
|
/**
|
|
25
|
+
* Provides navigation methods.
|
|
20
26
|
*/
|
|
21
27
|
export const useNavigation = () => {
|
|
22
28
|
const dispatch = useDispatch();
|
|
23
|
-
return {
|
|
29
|
+
return useMemo(() => ({
|
|
24
30
|
push: (location, state) => dispatch(push(location, state)),
|
|
25
31
|
replace: (location, state) => dispatch(replace(location, state)),
|
|
26
32
|
go: delta => dispatch(go(delta)),
|
|
27
33
|
goBack: () => dispatch(goBack()),
|
|
28
34
|
goForward: () => dispatch(goForward())
|
|
29
|
-
};
|
|
35
|
+
}), [dispatch]);
|
|
30
36
|
};
|
|
31
37
|
//# sourceMappingURL=useRouter.js.map
|