@openmrs/esm-react-utils 3.2.1-pre.977 → 3.3.1-pre.1175
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 +16 -0
- package/dist/openmrs-esm-react-utils.js +1 -1
- package/dist/openmrs-esm-react-utils.js.LICENSE.txt +15 -0
- package/dist/openmrs-esm-react-utils.js.map +1 -1
- package/jest.config.js +1 -1
- package/package.json +11 -8
- package/src/ConfigurableLink.tsx +1 -1
- package/src/UserHasAccess.tsx +1 -0
- package/src/createUseStore.ts +2 -0
- package/src/getLifecycle.ts +1 -0
- package/src/index.ts +0 -3
- package/src/public.ts +26 -0
- package/src/useAssignedExtensionIds.ts +1 -0
- package/src/useAssignedExtensions.ts +2 -1
- package/src/useBodyScrollLock.ts +1 -0
- package/src/useConfig.ts +84 -24
- package/src/useConnectedExtensions.ts +1 -0
- package/src/useConnectivity.ts +1 -0
- package/src/useCurrentPatient.ts +1 -0
- package/src/useExtensionInternalStore.ts +3 -1
- package/src/useExtensionSlotMeta.ts +1 -0
- package/src/useExtensionStore.ts +4 -10
- package/src/useLayoutType.ts +1 -0
- package/src/useLocations.tsx +1 -0
- package/src/useOnClickOutside.test.tsx +59 -0
- package/src/useOnClickOutside.tsx +5 -4
- package/src/usePagination.ts +1 -0
- package/src/usePatient.ts +2 -1
- package/src/useSessionUser.tsx +10 -13
- package/src/useStore.ts +53 -5
- package/src/useVisit.ts +33 -40
- package/src/useVisitTypes.ts +1 -0
- package/webpack.config.js +1 -1
- package/.babelrc +0 -8
- package/babel.config.js +0 -3
- package/src/useExtensionSlotConfig.ts +0 -24
- package/src/useNavigationContext.ts +0 -12
- package/src/useStoreState.ts +0 -11
package/src/useVisit.ts
CHANGED
|
@@ -1,49 +1,42 @@
|
|
|
1
|
-
|
|
2
|
-
import dayjs from "dayjs";
|
|
1
|
+
/** @module @category API */
|
|
3
2
|
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
VisitMode,
|
|
7
|
-
VisitStatus,
|
|
3
|
+
defaultVisitCustomRepresentation,
|
|
4
|
+
openmrsFetch,
|
|
8
5
|
Visit,
|
|
9
6
|
} from "@openmrs/esm-api";
|
|
7
|
+
import useSWR from "swr";
|
|
8
|
+
import dayjs from "dayjs";
|
|
9
|
+
import isToday from "dayjs/plugin/isToday";
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
const [currentVisit, setCurrentVisit] = useState<Visit | null>(null);
|
|
13
|
-
const [error, setError] = useState(null);
|
|
14
|
-
|
|
15
|
-
useEffect(() => {
|
|
16
|
-
const sub = getStartedVisit.subscribe((visit) => {
|
|
17
|
-
if (visit) {
|
|
18
|
-
setCurrentVisit(visit?.visitData ?? null);
|
|
19
|
-
} else {
|
|
20
|
-
setCurrentVisit(null);
|
|
21
|
-
}
|
|
22
|
-
});
|
|
11
|
+
dayjs.extend(isToday);
|
|
23
12
|
|
|
24
|
-
|
|
25
|
-
|
|
13
|
+
interface VisitReturnType {
|
|
14
|
+
error: Error;
|
|
15
|
+
mutate: () => void;
|
|
16
|
+
isValidating: boolean;
|
|
17
|
+
currentVisit: Visit | null;
|
|
18
|
+
}
|
|
26
19
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
20
|
+
/**
|
|
21
|
+
* This React hook returns a visit object. If the `patientUuid` is provided
|
|
22
|
+
* as a parameter, then the currentVisit, error and mutate function
|
|
23
|
+
* for that patient visit is returned.
|
|
24
|
+
* @param patientUuid Unique patient identifier `string`
|
|
25
|
+
* @returns Object {`error` `isValidating`, `currentVisit`, `mutate`}
|
|
26
|
+
*/
|
|
27
|
+
export function useVisit(patientUuid: string): VisitReturnType {
|
|
28
|
+
const { data, error, mutate, isValidating } = useSWR<{
|
|
29
|
+
data: { results: Array<Visit> };
|
|
30
|
+
}>(
|
|
31
|
+
`/ws/rest/v1/visit?patient=${patientUuid}&v=${defaultVisitCustomRepresentation}&includeInactive=false`,
|
|
32
|
+
openmrsFetch
|
|
33
|
+
);
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
},
|
|
43
|
-
setError
|
|
44
|
-
);
|
|
45
|
-
return () => sub && sub.unsubscribe();
|
|
46
|
-
}, [patientUuid]);
|
|
35
|
+
const currentVisit =
|
|
36
|
+
data?.data.results.find(
|
|
37
|
+
(visit) =>
|
|
38
|
+
visit.stopDatetime === null && dayjs(visit.startDatetime).isToday()
|
|
39
|
+
) ?? null;
|
|
47
40
|
|
|
48
|
-
return {
|
|
41
|
+
return { error, mutate, isValidating, currentVisit };
|
|
49
42
|
}
|
package/src/useVisitTypes.ts
CHANGED
package/webpack.config.js
CHANGED
package/.babelrc
DELETED
package/babel.config.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { useCallback } from "react";
|
|
2
|
-
import {
|
|
3
|
-
ExtensionSlotConfigObject,
|
|
4
|
-
ExtensionSlotConfigStore,
|
|
5
|
-
getExtensionSlotConfigStore,
|
|
6
|
-
} from "@openmrs/esm-config";
|
|
7
|
-
import { useStoreState } from "./useStoreState";
|
|
8
|
-
|
|
9
|
-
const defaultConfig: ExtensionSlotConfigObject = {
|
|
10
|
-
add: [],
|
|
11
|
-
order: [],
|
|
12
|
-
remove: [],
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
/** @internal */
|
|
16
|
-
export function useExtensionSlotConfig(slotName: string) {
|
|
17
|
-
const store = getExtensionSlotConfigStore(slotName);
|
|
18
|
-
const select = useCallback(
|
|
19
|
-
(s: ExtensionSlotConfigStore) => s.config,
|
|
20
|
-
[slotName]
|
|
21
|
-
);
|
|
22
|
-
const config = useStoreState(store, select);
|
|
23
|
-
return config || defaultConfig;
|
|
24
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { useEffect } from "react";
|
|
2
|
-
import {
|
|
3
|
-
NavigationContext,
|
|
4
|
-
pushNavigationContext,
|
|
5
|
-
} from "@openmrs/esm-extensions";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* @deprecated Don't use this anymore.
|
|
9
|
-
*/
|
|
10
|
-
export function useNavigationContext(context: NavigationContext) {
|
|
11
|
-
useEffect(() => pushNavigationContext(context), []);
|
|
12
|
-
}
|
package/src/useStoreState.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { subscribeTo } from "@openmrs/esm-state";
|
|
2
|
-
import { useEffect, useState } from "react";
|
|
3
|
-
import { Store } from "unistore";
|
|
4
|
-
|
|
5
|
-
export function useStoreState<T, U>(store: Store<T>, select: (state: T) => U) {
|
|
6
|
-
const [state, setState] = useState<U>(() => select(store.getState()));
|
|
7
|
-
|
|
8
|
-
useEffect(() => subscribeTo(store, select, setState), [store, select]);
|
|
9
|
-
|
|
10
|
-
return state;
|
|
11
|
-
}
|