@openmrs/esm-react-utils 4.3.2-pre.661 → 4.3.2-pre.666
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/.turbo/turbo-build.log +7 -7
- package/dist/openmrs-esm-react-utils.js +1 -1
- package/dist/openmrs-esm-react-utils.js.map +1 -1
- package/jest.config.js +1 -0
- package/package.json +7 -7
- package/src/index.ts +0 -1
- package/src/public.ts +0 -1
- package/src/usePagination.ts +5 -1
- package/src/usePatient.ts +1 -1
- package/src/useCurrentPatient.ts +0 -117
package/jest.config.js
CHANGED
|
@@ -10,6 +10,7 @@ module.exports = {
|
|
|
10
10
|
"@openmrs/esm-state": "<rootDir>/__mocks__/openmrs-esm-state.mock.ts",
|
|
11
11
|
"@openmrs/esm-styleguide":
|
|
12
12
|
"<rootDir>/__mocks__/openmrs-esm-styleguide.mock.tsx",
|
|
13
|
+
dexie: require.resolve("dexie"),
|
|
13
14
|
},
|
|
14
15
|
testEnvironment: "jsdom",
|
|
15
16
|
testEnvironmentOptions: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openmrs/esm-react-utils",
|
|
3
|
-
"version": "4.3.2-pre.
|
|
3
|
+
"version": "4.3.2-pre.666",
|
|
4
4
|
"license": "MPL-2.0",
|
|
5
5
|
"description": "React utilities for OpenMRS.",
|
|
6
6
|
"browser": "dist/openmrs-esm-react-utils.js",
|
|
@@ -55,11 +55,11 @@
|
|
|
55
55
|
"react-i18next": "11.x"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
|
-
"@openmrs/esm-api": "^4.3.2-pre.
|
|
59
|
-
"@openmrs/esm-config": "^4.3.2-pre.
|
|
60
|
-
"@openmrs/esm-error-handling": "^4.3.2-pre.
|
|
61
|
-
"@openmrs/esm-extensions": "^4.3.2-pre.
|
|
62
|
-
"@openmrs/esm-globals": "^4.3.2-pre.
|
|
58
|
+
"@openmrs/esm-api": "^4.3.2-pre.666",
|
|
59
|
+
"@openmrs/esm-config": "^4.3.2-pre.666",
|
|
60
|
+
"@openmrs/esm-error-handling": "^4.3.2-pre.666",
|
|
61
|
+
"@openmrs/esm-extensions": "^4.3.2-pre.666",
|
|
62
|
+
"@openmrs/esm-globals": "^4.3.2-pre.666",
|
|
63
63
|
"dayjs": "^1.10.8",
|
|
64
64
|
"i18next": "^19.6.0",
|
|
65
65
|
"react": "^18.1.0",
|
|
@@ -68,5 +68,5 @@
|
|
|
68
68
|
"rxjs": "^6.5.3",
|
|
69
69
|
"unistore": "^3.5.2"
|
|
70
70
|
},
|
|
71
|
-
"gitHead": "
|
|
71
|
+
"gitHead": "c224f96451732d2bc86c4b8b3f1994b92931b8d9"
|
|
72
72
|
}
|
package/src/index.ts
CHANGED
|
@@ -12,7 +12,6 @@ export * from "./useConfig";
|
|
|
12
12
|
export * from "./useConnectedExtensions";
|
|
13
13
|
export * from "./useConnectivity";
|
|
14
14
|
export * from "./usePatient";
|
|
15
|
-
export * from "./useCurrentPatient";
|
|
16
15
|
export * from "./useExtensionInternalStore";
|
|
17
16
|
export * from "./useExtensionSlot";
|
|
18
17
|
export * from "./useExtensionSlotMeta";
|
package/src/public.ts
CHANGED
|
@@ -11,7 +11,6 @@ export * from "./useConfig";
|
|
|
11
11
|
export * from "./useConnectedExtensions";
|
|
12
12
|
export * from "./useConnectivity";
|
|
13
13
|
export * from "./usePatient";
|
|
14
|
-
export * from "./useCurrentPatient";
|
|
15
14
|
export * from "./useExtensionSlotMeta";
|
|
16
15
|
export * from "./useExtensionStore";
|
|
17
16
|
export * from "./useLayoutType";
|
package/src/usePagination.ts
CHANGED
|
@@ -9,9 +9,13 @@ export function usePagination<T>(
|
|
|
9
9
|
) {
|
|
10
10
|
const [page, setPage] = useState(1);
|
|
11
11
|
const totalPages = useMemo(
|
|
12
|
-
() =>
|
|
12
|
+
() =>
|
|
13
|
+
typeof resultsPerPage === "number" && resultsPerPage > 0
|
|
14
|
+
? Math.max(1, Math.ceil(data.length / resultsPerPage))
|
|
15
|
+
: 1,
|
|
13
16
|
[data.length, resultsPerPage]
|
|
14
17
|
);
|
|
18
|
+
|
|
15
19
|
const results = useMemo(() => {
|
|
16
20
|
const lowerBound = (page - 1) * resultsPerPage;
|
|
17
21
|
const upperBound = (page + 0) * resultsPerPage;
|
package/src/usePatient.ts
CHANGED
package/src/useCurrentPatient.ts
DELETED
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
/** @module @category API */
|
|
2
|
-
import { useEffect, useReducer } from "react";
|
|
3
|
-
import { fetchCurrentPatient, PatientUuid } from "@openmrs/esm-api";
|
|
4
|
-
|
|
5
|
-
type NullablePatient = fhir.Patient | null;
|
|
6
|
-
|
|
7
|
-
interface CurrentPatientState {
|
|
8
|
-
patient: NullablePatient;
|
|
9
|
-
isLoadingPatient: boolean;
|
|
10
|
-
err: Error | null;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
interface LoadPatient {
|
|
14
|
-
type: ActionTypes.loadPatient;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
interface NewPatient {
|
|
18
|
-
type: ActionTypes.newPatient;
|
|
19
|
-
patient: NullablePatient;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
interface PatientLoadError {
|
|
23
|
-
type: ActionTypes.loadError;
|
|
24
|
-
err: Error | null;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
type Action = LoadPatient | NewPatient | PatientLoadError;
|
|
28
|
-
|
|
29
|
-
enum ActionTypes {
|
|
30
|
-
loadPatient = "loadPatient",
|
|
31
|
-
newPatient = "newPatient",
|
|
32
|
-
loadError = "patientLloadErroroadError",
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const initialState: CurrentPatientState = {
|
|
36
|
-
patient: null,
|
|
37
|
-
isLoadingPatient: true,
|
|
38
|
-
err: null,
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
function getPatientUuidFromUrl(): PatientUuid {
|
|
42
|
-
const match = /\/patient\/([a-zA-Z0-9\-]+)\/?/.exec(location.pathname);
|
|
43
|
-
return match && match[1];
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
function reducer(
|
|
47
|
-
state: CurrentPatientState,
|
|
48
|
-
action: Action
|
|
49
|
-
): CurrentPatientState {
|
|
50
|
-
switch (action.type) {
|
|
51
|
-
case ActionTypes.loadPatient:
|
|
52
|
-
return {
|
|
53
|
-
...state,
|
|
54
|
-
patient: null,
|
|
55
|
-
isLoadingPatient: true,
|
|
56
|
-
err: null,
|
|
57
|
-
};
|
|
58
|
-
case ActionTypes.newPatient:
|
|
59
|
-
return {
|
|
60
|
-
...state,
|
|
61
|
-
patient: action.patient,
|
|
62
|
-
isLoadingPatient: false,
|
|
63
|
-
err: null,
|
|
64
|
-
};
|
|
65
|
-
case ActionTypes.loadError:
|
|
66
|
-
return {
|
|
67
|
-
...state,
|
|
68
|
-
patient: null,
|
|
69
|
-
isLoadingPatient: false,
|
|
70
|
-
err: action.err,
|
|
71
|
-
};
|
|
72
|
-
default:
|
|
73
|
-
return state;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* This React hook returns the current patient, as specified by the current route. It returns
|
|
79
|
-
* all the information needed to render a loading state, error state, and normal/success state.
|
|
80
|
-
*
|
|
81
|
-
* @deprecated Use {@link usePatient} instead.
|
|
82
|
-
*/
|
|
83
|
-
export function useCurrentPatient(
|
|
84
|
-
patientUuid = getPatientUuidFromUrl()
|
|
85
|
-
): [boolean, NullablePatient, PatientUuid, Error | null] {
|
|
86
|
-
const [state, dispatch] = useReducer(reducer, initialState);
|
|
87
|
-
|
|
88
|
-
useEffect(() => {
|
|
89
|
-
let active = true;
|
|
90
|
-
|
|
91
|
-
if (patientUuid) {
|
|
92
|
-
fetchCurrentPatient(patientUuid).then(
|
|
93
|
-
(patient) =>
|
|
94
|
-
active &&
|
|
95
|
-
dispatch({
|
|
96
|
-
patient: patient.data,
|
|
97
|
-
type: ActionTypes.newPatient,
|
|
98
|
-
}),
|
|
99
|
-
(err) =>
|
|
100
|
-
active &&
|
|
101
|
-
dispatch({
|
|
102
|
-
err,
|
|
103
|
-
type: ActionTypes.loadError,
|
|
104
|
-
})
|
|
105
|
-
);
|
|
106
|
-
dispatch({ type: ActionTypes.loadPatient });
|
|
107
|
-
} else {
|
|
108
|
-
dispatch({ type: ActionTypes.newPatient, patient: null });
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
return () => {
|
|
112
|
-
active = false;
|
|
113
|
-
};
|
|
114
|
-
}, [patientUuid]);
|
|
115
|
-
|
|
116
|
-
return [state.isLoadingPatient, state.patient, patientUuid, state.err];
|
|
117
|
-
}
|