@openmrs/esm-react-utils 8.0.1-pre.3783 → 8.0.1-pre.3786
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 +1 -1
- package/dist/ConfigurableLink.d.ts +2 -4
- package/dist/ConfigurableLink.d.ts.map +1 -1
- package/dist/ConfigurableLink.js +1 -1
- package/dist/getLifecycle.d.ts +52 -0
- package/dist/getLifecycle.d.ts.map +1 -1
- package/dist/getLifecycle.js +52 -3
- package/dist/useAttachments.d.ts +25 -0
- package/dist/useAttachments.d.ts.map +1 -1
- package/dist/useAttachments.js +25 -1
- package/dist/useBodyScrollLock.d.ts +18 -0
- package/dist/useBodyScrollLock.d.ts.map +1 -1
- package/dist/useBodyScrollLock.js +18 -1
- package/dist/useConnectivity.d.ts +16 -0
- package/dist/useConnectivity.d.ts.map +1 -1
- package/dist/useConnectivity.js +16 -1
- package/dist/useLeftNav.d.ts +20 -0
- package/dist/useLeftNav.d.ts.map +1 -1
- package/dist/useLeftNav.js +21 -2
- package/dist/useLeftNavStore.d.ts +15 -0
- package/dist/useLeftNavStore.d.ts.map +1 -1
- package/dist/useLeftNavStore.js +16 -2
- package/dist/useLocations.d.ts +24 -0
- package/dist/useLocations.d.ts.map +1 -1
- package/dist/useLocations.js +24 -1
- package/dist/useOnClickOutside.d.ts +27 -0
- package/dist/useOnClickOutside.d.ts.map +1 -1
- package/dist/useOnClickOutside.js +27 -1
- package/dist/usePatient.d.ts +5 -0
- package/dist/usePatient.d.ts.map +1 -1
- package/dist/usePatient.js +5 -0
- package/dist/usePrimaryIdentifierResource.d.ts +8 -0
- package/dist/usePrimaryIdentifierResource.d.ts.map +1 -1
- package/dist/usePrimaryIdentifierResource.js +8 -1
- package/dist/useVisitTypes.d.ts +22 -0
- package/dist/useVisitTypes.d.ts.map +1 -1
- package/dist/useVisitTypes.js +22 -1
- package/package.json +12 -12
- package/src/ConfigurableLink.tsx +2 -4
- package/src/getLifecycle.ts +52 -0
- package/src/useAttachments.ts +25 -0
- package/src/useBodyScrollLock.ts +18 -0
- package/src/useConnectivity.ts +16 -0
- package/src/useLeftNav.ts +21 -0
- package/src/useLeftNavStore.ts +16 -0
- package/src/useLocations.tsx +24 -0
- package/src/useOnClickOutside.ts +27 -0
- package/src/usePatient.ts +5 -0
- package/src/usePrimaryIdentifierResource.ts +8 -0
- package/src/useVisitTypes.ts +22 -0
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
/** @module @category Navigation */
|
|
2
2
|
import React, { type MouseEvent, type AnchorHTMLAttributes, type PropsWithChildren } from 'react';
|
|
3
3
|
import { type TemplateParams } from '@openmrs/esm-navigation';
|
|
4
|
-
/**
|
|
5
|
-
* @noInheritDoc
|
|
6
|
-
*/
|
|
4
|
+
/** @noInheritDoc */
|
|
7
5
|
export interface ConfigurableLinkProps extends AnchorHTMLAttributes<HTMLAnchorElement> {
|
|
8
6
|
/** The target path or URL. Supports interpolation. See [[navigate]] */
|
|
9
7
|
to: string;
|
|
@@ -13,7 +11,7 @@ export interface ConfigurableLinkProps extends AnchorHTMLAttributes<HTMLAnchorEl
|
|
|
13
11
|
onBeforeNavigate?: (event: MouseEvent) => void;
|
|
14
12
|
}
|
|
15
13
|
/**
|
|
16
|
-
* A React link component which calls
|
|
14
|
+
* A React link component which calls {@link navigate} when clicked
|
|
17
15
|
*/
|
|
18
16
|
export declare function ConfigurableLink({ to, templateParams, onBeforeNavigate, children, ...otherProps }: PropsWithChildren<ConfigurableLinkProps>): React.JSX.Element;
|
|
19
17
|
//# sourceMappingURL=ConfigurableLink.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConfigurableLink.d.ts","sourceRoot":"","sources":["../src/ConfigurableLink.tsx"],"names":[],"mappings":"AAAA,mCAAmC;AACnC,OAAO,KAAK,EAAE,EAAE,KAAK,UAAU,EAAE,KAAK,oBAAoB,EAAE,KAAK,iBAAiB,EAAa,MAAM,OAAO,CAAC;AAC7G,OAAO,EAA4B,KAAK,cAAc,EAAE,MAAM,yBAAyB,CAAC;AA+BxF
|
|
1
|
+
{"version":3,"file":"ConfigurableLink.d.ts","sourceRoot":"","sources":["../src/ConfigurableLink.tsx"],"names":[],"mappings":"AAAA,mCAAmC;AACnC,OAAO,KAAK,EAAE,EAAE,KAAK,UAAU,EAAE,KAAK,oBAAoB,EAAE,KAAK,iBAAiB,EAAa,MAAM,OAAO,CAAC;AAC7G,OAAO,EAA4B,KAAK,cAAc,EAAE,MAAM,yBAAyB,CAAC;AA+BxF,oBAAoB;AACpB,MAAM,WAAW,qBAAsB,SAAQ,oBAAoB,CAAC,iBAAiB,CAAC;IACpF,uEAAuE;IACvE,EAAE,EAAE,MAAM,CAAC;IACX,8HAA8H;IAC9H,cAAc,CAAC,EAAE,cAAc,CAAC;IAChC,4DAA4D;IAC5D,gBAAgB,CAAC,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI,CAAC;CAChD;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,EAC/B,EAAE,EACF,cAAc,EACd,gBAAgB,EAChB,QAAQ,EACR,GAAG,UAAU,EACd,EAAE,iBAAiB,CAAC,qBAAqB,CAAC,qBAsB1C"}
|
package/dist/ConfigurableLink.js
CHANGED
|
@@ -24,7 +24,7 @@ function handleClick(event, to, templateParams, onBeforeNavigate) {
|
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
/**
|
|
27
|
-
* A React link component which calls
|
|
27
|
+
* A React link component which calls {@link navigate} when clicked
|
|
28
28
|
*/ export function ConfigurableLink({ to, templateParams, onBeforeNavigate, children, ...otherProps }) {
|
|
29
29
|
useEffect(()=>{
|
|
30
30
|
if (otherProps.href) {
|
package/dist/getLifecycle.d.ts
CHANGED
|
@@ -2,10 +2,62 @@
|
|
|
2
2
|
import type { ComponentType } from 'react';
|
|
3
3
|
import singleSpaReact from 'single-spa-react';
|
|
4
4
|
import type { ComponentDecoratorOptions } from './openmrsComponentDecorator';
|
|
5
|
+
/**
|
|
6
|
+
* Creates a single-spa lifecycle object for a React component. The component is
|
|
7
|
+
* wrapped with the OpenMRS component decorator which provides standard functionality
|
|
8
|
+
* like error boundaries, configuration, and extension support.
|
|
9
|
+
*
|
|
10
|
+
* @param Component The React component to create a lifecycle for.
|
|
11
|
+
* @param options Configuration options for the OpenMRS component decorator.
|
|
12
|
+
* @returns A single-spa lifecycle object with bootstrap, mount, and unmount functions.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* import { getLifecycle } from '@openmrs/esm-framework';
|
|
17
|
+
* import MyComponent from './MyComponent';
|
|
18
|
+
* export const lifecycle = getLifecycle(MyComponent, { featureName: 'my-feature', moduleName: '@openmrs/esm-my-app' });
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
5
21
|
export declare function getLifecycle<T>(Component: ComponentType<T>, options: ComponentDecoratorOptions): singleSpaReact.ReactAppOrParcel<T>;
|
|
22
|
+
/**
|
|
23
|
+
* Creates a lazy-loading single-spa lifecycle for a React component. The component
|
|
24
|
+
* is loaded asynchronously via dynamic import only when it's needed, which helps
|
|
25
|
+
* reduce initial bundle size. This is the recommended way to define lifecycles
|
|
26
|
+
* for most modules.
|
|
27
|
+
*
|
|
28
|
+
* @param lazy A function that returns a Promise resolving to a module with the
|
|
29
|
+
* component as its default export (i.e., a dynamic import).
|
|
30
|
+
* @param options Configuration options for the OpenMRS component decorator.
|
|
31
|
+
* @returns A function that returns a Promise resolving to a single-spa lifecycle object.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* import { getAsyncLifecycle } from '@openmrs/esm-framework';
|
|
36
|
+
* const options = { featureName: 'my-feature', moduleName: '@openmrs/esm-my-app' };
|
|
37
|
+
* export const root = getAsyncLifecycle(() => import('./root.component'), options);
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
6
40
|
export declare function getAsyncLifecycle<T>(lazy: () => Promise<{
|
|
7
41
|
default: ComponentType<T>;
|
|
8
42
|
}>, options: ComponentDecoratorOptions): () => Promise<singleSpaReact.ReactAppOrParcel<T>>;
|
|
43
|
+
/**
|
|
44
|
+
* Creates a single-spa lifecycle for a React component that is already loaded.
|
|
45
|
+
* Unlike {@link getAsyncLifecycle}, this wraps a synchronously-available component
|
|
46
|
+
* in a Promise to match the expected lifecycle interface. Use this when the
|
|
47
|
+
* component doesn't need lazy loading.
|
|
48
|
+
*
|
|
49
|
+
* @param Component The React component to create a lifecycle for.
|
|
50
|
+
* @param options Configuration options for the OpenMRS component decorator.
|
|
51
|
+
* @returns A function that returns a Promise resolving to a single-spa lifecycle object.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```ts
|
|
55
|
+
* import { getSyncLifecycle } from '@openmrs/esm-framework';
|
|
56
|
+
* import MyComponent from './MyComponent';
|
|
57
|
+
* const options = { featureName: 'my-feature', moduleName: '@openmrs/esm-my-app' };
|
|
58
|
+
* export const myExtension = getSyncLifecycle(MyComponent, options);
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
9
61
|
export declare function getSyncLifecycle<T>(Component: ComponentType<T>, options: ComponentDecoratorOptions): () => Promise<singleSpaReact.ReactAppOrParcel<T>>;
|
|
10
62
|
/**
|
|
11
63
|
* @deprecated Use getAsyncLifecycle instead.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getLifecycle.d.ts","sourceRoot":"","sources":["../src/getLifecycle.ts"],"names":[],"mappings":"AAAA,kCAAkC;AAClC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAI3C,OAAO,cAAyC,MAAM,kBAAkB,CAAC;AACzE,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AAG7E,wBAAgB,YAAY,CAAC,CAAC,EAAE,SAAS,EAAE,aAAa,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,yBAAyB,sCAM9F;AAED,wBAAgB,iBAAiB,CAAC,CAAC,EACjC,IAAI,EAAE,MAAM,OAAO,CAAC;IAAE,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC,CAAA;CAAE,CAAC,EAClD,OAAO,EAAE,yBAAyB,qDAGnC;AAED,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,SAAS,EAAE,aAAa,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,yBAAyB,qDAElG;AAED;;GAEG;AACH,eAAO,MAAM,0BAA0B,0BAAoB,CAAC"}
|
|
1
|
+
{"version":3,"file":"getLifecycle.d.ts","sourceRoot":"","sources":["../src/getLifecycle.ts"],"names":[],"mappings":"AAAA,kCAAkC;AAClC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAI3C,OAAO,cAAyC,MAAM,kBAAkB,CAAC;AACzE,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AAG7E;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,SAAS,EAAE,aAAa,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,yBAAyB,sCAM9F;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EACjC,IAAI,EAAE,MAAM,OAAO,CAAC;IAAE,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC,CAAA;CAAE,CAAC,EAClD,OAAO,EAAE,yBAAyB,qDAGnC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,SAAS,EAAE,aAAa,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,yBAAyB,qDAElG;AAED;;GAEG;AACH,eAAO,MAAM,0BAA0B,0BAAoB,CAAC"}
|
package/dist/getLifecycle.js
CHANGED
|
@@ -2,17 +2,66 @@
|
|
|
2
2
|
import ReactDOMClient from "react-dom/client";
|
|
3
3
|
import singleSpaReact from "single-spa-react";
|
|
4
4
|
import { openmrsComponentDecorator } from "./openmrsComponentDecorator.js";
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Creates a single-spa lifecycle object for a React component. The component is
|
|
7
|
+
* wrapped with the OpenMRS component decorator which provides standard functionality
|
|
8
|
+
* like error boundaries, configuration, and extension support.
|
|
9
|
+
*
|
|
10
|
+
* @param Component The React component to create a lifecycle for.
|
|
11
|
+
* @param options Configuration options for the OpenMRS component decorator.
|
|
12
|
+
* @returns A single-spa lifecycle object with bootstrap, mount, and unmount functions.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* import { getLifecycle } from '@openmrs/esm-framework';
|
|
17
|
+
* import MyComponent from './MyComponent';
|
|
18
|
+
* export const lifecycle = getLifecycle(MyComponent, { featureName: 'my-feature', moduleName: '@openmrs/esm-my-app' });
|
|
19
|
+
* ```
|
|
20
|
+
*/ export function getLifecycle(Component, options) {
|
|
6
21
|
return singleSpaReact({
|
|
7
22
|
React,
|
|
8
23
|
ReactDOMClient,
|
|
9
24
|
rootComponent: openmrsComponentDecorator(options)(Component)
|
|
10
25
|
});
|
|
11
26
|
}
|
|
12
|
-
|
|
27
|
+
/**
|
|
28
|
+
* Creates a lazy-loading single-spa lifecycle for a React component. The component
|
|
29
|
+
* is loaded asynchronously via dynamic import only when it's needed, which helps
|
|
30
|
+
* reduce initial bundle size. This is the recommended way to define lifecycles
|
|
31
|
+
* for most modules.
|
|
32
|
+
*
|
|
33
|
+
* @param lazy A function that returns a Promise resolving to a module with the
|
|
34
|
+
* component as its default export (i.e., a dynamic import).
|
|
35
|
+
* @param options Configuration options for the OpenMRS component decorator.
|
|
36
|
+
* @returns A function that returns a Promise resolving to a single-spa lifecycle object.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```ts
|
|
40
|
+
* import { getAsyncLifecycle } from '@openmrs/esm-framework';
|
|
41
|
+
* const options = { featureName: 'my-feature', moduleName: '@openmrs/esm-my-app' };
|
|
42
|
+
* export const root = getAsyncLifecycle(() => import('./root.component'), options);
|
|
43
|
+
* ```
|
|
44
|
+
*/ export function getAsyncLifecycle(lazy, options) {
|
|
13
45
|
return ()=>lazy().then(({ default: Component })=>getLifecycle(Component, options));
|
|
14
46
|
}
|
|
15
|
-
|
|
47
|
+
/**
|
|
48
|
+
* Creates a single-spa lifecycle for a React component that is already loaded.
|
|
49
|
+
* Unlike {@link getAsyncLifecycle}, this wraps a synchronously-available component
|
|
50
|
+
* in a Promise to match the expected lifecycle interface. Use this when the
|
|
51
|
+
* component doesn't need lazy loading.
|
|
52
|
+
*
|
|
53
|
+
* @param Component The React component to create a lifecycle for.
|
|
54
|
+
* @param options Configuration options for the OpenMRS component decorator.
|
|
55
|
+
* @returns A function that returns a Promise resolving to a single-spa lifecycle object.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```ts
|
|
59
|
+
* import { getSyncLifecycle } from '@openmrs/esm-framework';
|
|
60
|
+
* import MyComponent from './MyComponent';
|
|
61
|
+
* const options = { featureName: 'my-feature', moduleName: '@openmrs/esm-my-app' };
|
|
62
|
+
* export const myExtension = getSyncLifecycle(MyComponent, options);
|
|
63
|
+
* ```
|
|
64
|
+
*/ export function getSyncLifecycle(Component, options) {
|
|
16
65
|
return ()=>Promise.resolve(getLifecycle(Component, options));
|
|
17
66
|
}
|
|
18
67
|
/**
|
package/dist/useAttachments.d.ts
CHANGED
|
@@ -1,5 +1,30 @@
|
|
|
1
1
|
import { type FetchResponse } from '@openmrs/esm-api';
|
|
2
2
|
import { type AttachmentResponse } from '@openmrs/esm-emr-api';
|
|
3
|
+
/**
|
|
4
|
+
* A React hook that fetches attachments for a patient using SWR for caching
|
|
5
|
+
* and automatic revalidation.
|
|
6
|
+
*
|
|
7
|
+
* @param patientUuid The UUID of the patient whose attachments should be fetched.
|
|
8
|
+
* @param includeEncounterless Whether to include attachments that are not
|
|
9
|
+
* associated with any encounter.
|
|
10
|
+
* @returns An object containing:
|
|
11
|
+
* - `data`: Array of attachment objects (empty array while loading)
|
|
12
|
+
* - `isLoading`: Whether the initial fetch is in progress
|
|
13
|
+
* - `isValidating`: Whether any request (initial or revalidation) is in progress
|
|
14
|
+
* - `error`: Any error that occurred during fetching
|
|
15
|
+
* - `mutate`: Function to trigger a revalidation of the data
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```tsx
|
|
19
|
+
* import { useAttachments } from '@openmrs/esm-framework';
|
|
20
|
+
* function PatientAttachments({ patientUuid }) {
|
|
21
|
+
* const { data, isLoading, error } = useAttachments(patientUuid, true);
|
|
22
|
+
* if (isLoading) return <span>Loading...</span>;
|
|
23
|
+
* if (error) return <span>Error loading attachments</span>;
|
|
24
|
+
* return <AttachmentList attachments={data} />;
|
|
25
|
+
* }
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
3
28
|
export declare function useAttachments(patientUuid: string, includeEncounterless: boolean): {
|
|
4
29
|
isLoading: boolean;
|
|
5
30
|
data: AttachmentResponse[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAttachments.d.ts","sourceRoot":"","sources":["../src/useAttachments.ts"],"names":[],"mappings":"AAGA,OAAO,EAAgB,KAAK,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACpE,OAAO,EAAiB,KAAK,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE9E,wBAAgB,cAAc,CAAC,WAAW,EAAE,MAAM,EAAE,oBAAoB,EAAE,OAAO;;;;;iBAEpD,KAAK,CAAC,kBAAkB,CAAC;;;EAerD"}
|
|
1
|
+
{"version":3,"file":"useAttachments.d.ts","sourceRoot":"","sources":["../src/useAttachments.ts"],"names":[],"mappings":"AAGA,OAAO,EAAgB,KAAK,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACpE,OAAO,EAAiB,KAAK,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE9E;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,cAAc,CAAC,WAAW,EAAE,MAAM,EAAE,oBAAoB,EAAE,OAAO;;;;;iBAEpD,KAAK,CAAC,kBAAkB,CAAC;;;EAerD"}
|
package/dist/useAttachments.js
CHANGED
|
@@ -2,7 +2,31 @@
|
|
|
2
2
|
import useSWR from "swr";
|
|
3
3
|
import { openmrsFetch } from "@openmrs/esm-api";
|
|
4
4
|
import { attachmentUrl } from "@openmrs/esm-emr-api";
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* A React hook that fetches attachments for a patient using SWR for caching
|
|
7
|
+
* and automatic revalidation.
|
|
8
|
+
*
|
|
9
|
+
* @param patientUuid The UUID of the patient whose attachments should be fetched.
|
|
10
|
+
* @param includeEncounterless Whether to include attachments that are not
|
|
11
|
+
* associated with any encounter.
|
|
12
|
+
* @returns An object containing:
|
|
13
|
+
* - `data`: Array of attachment objects (empty array while loading)
|
|
14
|
+
* - `isLoading`: Whether the initial fetch is in progress
|
|
15
|
+
* - `isValidating`: Whether any request (initial or revalidation) is in progress
|
|
16
|
+
* - `error`: Any error that occurred during fetching
|
|
17
|
+
* - `mutate`: Function to trigger a revalidation of the data
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```tsx
|
|
21
|
+
* import { useAttachments } from '@openmrs/esm-framework';
|
|
22
|
+
* function PatientAttachments({ patientUuid }) {
|
|
23
|
+
* const { data, isLoading, error } = useAttachments(patientUuid, true);
|
|
24
|
+
* if (isLoading) return <span>Loading...</span>;
|
|
25
|
+
* if (error) return <span>Error loading attachments</span>;
|
|
26
|
+
* return <AttachmentList attachments={data} />;
|
|
27
|
+
* }
|
|
28
|
+
* ```
|
|
29
|
+
*/ export function useAttachments(patientUuid, includeEncounterless) {
|
|
6
30
|
const { data, error, mutate, isLoading, isValidating } = useSWR(`${attachmentUrl}?patient=${patientUuid}&includeEncounterless=${includeEncounterless}`, openmrsFetch);
|
|
7
31
|
const results = useMemo(()=>({
|
|
8
32
|
isLoading,
|
|
@@ -1,2 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A React hook that prevents scrolling on the document body when active.
|
|
3
|
+
* Useful for modals, overlays, or any full-screen UI that should prevent
|
|
4
|
+
* background scrolling. The original overflow style is restored when the
|
|
5
|
+
* hook becomes inactive or the component unmounts.
|
|
6
|
+
*
|
|
7
|
+
* @param active Whether to lock the body scroll. When `true`, sets
|
|
8
|
+
* `document.body.style.overflow` to 'hidden'.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```tsx
|
|
12
|
+
* import { useBodyScrollLock } from '@openmrs/esm-framework';
|
|
13
|
+
* function Modal({ isOpen }) {
|
|
14
|
+
* useBodyScrollLock(isOpen);
|
|
15
|
+
* return isOpen ? <div className="modal">...</div> : null;
|
|
16
|
+
* }
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
1
19
|
export declare function useBodyScrollLock(active: boolean): void;
|
|
2
20
|
//# sourceMappingURL=useBodyScrollLock.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useBodyScrollLock.d.ts","sourceRoot":"","sources":["../src/useBodyScrollLock.ts"],"names":[],"mappings":"AAGA,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,OAAO,QAUhD"}
|
|
1
|
+
{"version":3,"file":"useBodyScrollLock.d.ts","sourceRoot":"","sources":["../src/useBodyScrollLock.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,OAAO,QAUhD"}
|
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
/** @module @category UI */ import { useEffect } from "react";
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* A React hook that prevents scrolling on the document body when active.
|
|
4
|
+
* Useful for modals, overlays, or any full-screen UI that should prevent
|
|
5
|
+
* background scrolling. The original overflow style is restored when the
|
|
6
|
+
* hook becomes inactive or the component unmounts.
|
|
7
|
+
*
|
|
8
|
+
* @param active Whether to lock the body scroll. When `true`, sets
|
|
9
|
+
* `document.body.style.overflow` to 'hidden'.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```tsx
|
|
13
|
+
* import { useBodyScrollLock } from '@openmrs/esm-framework';
|
|
14
|
+
* function Modal({ isOpen }) {
|
|
15
|
+
* useBodyScrollLock(isOpen);
|
|
16
|
+
* return isOpen ? <div className="modal">...</div> : null;
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
19
|
+
*/ export function useBodyScrollLock(active) {
|
|
3
20
|
useEffect(()=>{
|
|
4
21
|
if (active) {
|
|
5
22
|
const original = window.getComputedStyle(document.body).overflow;
|
|
@@ -1,2 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A React hook that returns the current online/offline status and automatically
|
|
3
|
+
* updates when connectivity changes. Useful for showing offline indicators or
|
|
4
|
+
* conditionally rendering UI based on network availability.
|
|
5
|
+
*
|
|
6
|
+
* @returns `true` if the browser is online, `false` if offline.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```tsx
|
|
10
|
+
* import { useConnectivity } from '@openmrs/esm-framework';
|
|
11
|
+
* function NetworkStatus() {
|
|
12
|
+
* const isOnline = useConnectivity();
|
|
13
|
+
* return <span>{isOnline ? 'Online' : 'Offline'}</span>;
|
|
14
|
+
* }
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
1
17
|
export declare function useConnectivity(): boolean;
|
|
2
18
|
//# sourceMappingURL=useConnectivity.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useConnectivity.d.ts","sourceRoot":"","sources":["../src/useConnectivity.ts"],"names":[],"mappings":"AAKA,wBAAgB,eAAe,YAM9B"}
|
|
1
|
+
{"version":3,"file":"useConnectivity.d.ts","sourceRoot":"","sources":["../src/useConnectivity.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,eAAe,YAM9B"}
|
package/dist/useConnectivity.js
CHANGED
|
@@ -1,7 +1,22 @@
|
|
|
1
1
|
/** @module @category Offline */ import { subscribeConnectivityChanged } from "@openmrs/esm-globals";
|
|
2
2
|
import { isOnline as isOnlineFn } from "@openmrs/esm-utils";
|
|
3
3
|
import { useEffect, useState } from "react";
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* A React hook that returns the current online/offline status and automatically
|
|
6
|
+
* updates when connectivity changes. Useful for showing offline indicators or
|
|
7
|
+
* conditionally rendering UI based on network availability.
|
|
8
|
+
*
|
|
9
|
+
* @returns `true` if the browser is online, `false` if offline.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```tsx
|
|
13
|
+
* import { useConnectivity } from '@openmrs/esm-framework';
|
|
14
|
+
* function NetworkStatus() {
|
|
15
|
+
* const isOnline = useConnectivity();
|
|
16
|
+
* return <span>{isOnline ? 'Online' : 'Offline'}</span>;
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
19
|
+
*/ export function useConnectivity() {
|
|
5
20
|
let [isOnline, setIsOnline] = useState(isOnlineFn());
|
|
6
21
|
useEffect(()=>subscribeConnectivityChanged(({ online })=>setIsOnline(online)), []);
|
|
7
22
|
return isOnline;
|
package/dist/useLeftNav.d.ts
CHANGED
|
@@ -1,3 +1,23 @@
|
|
|
1
1
|
import { type SetLeftNavParams } from '@openmrs/esm-extensions';
|
|
2
|
+
/**
|
|
3
|
+
* A React hook that registers a left navigation menu for the current component.
|
|
4
|
+
* The navigation is automatically registered when the component mounts and
|
|
5
|
+
* unregistered when it unmounts.
|
|
6
|
+
*
|
|
7
|
+
* **Important:** This hook should only be used in "page" components, not in
|
|
8
|
+
* "extension" components. Extensions should not control the left navigation.
|
|
9
|
+
*
|
|
10
|
+
* @param params Configuration parameters for the left navigation, excluding the
|
|
11
|
+
* module name which is automatically determined from the component context.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```tsx
|
|
15
|
+
* import { useLeftNav } from '@openmrs/esm-framework';
|
|
16
|
+
* function MyPageComponent() {
|
|
17
|
+
* useLeftNav({ name: 'my-nav', slots: ['nav-slot-1', 'nav-slot-2'] });
|
|
18
|
+
* return <div>My Page</div>;
|
|
19
|
+
* }
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
2
22
|
export declare function useLeftNav(params: Omit<SetLeftNavParams, 'module'>): void;
|
|
3
23
|
//# sourceMappingURL=useLeftNav.d.ts.map
|
package/dist/useLeftNav.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLeftNav.d.ts","sourceRoot":"","sources":["../src/useLeftNav.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useLeftNav.d.ts","sourceRoot":"","sources":["../src/useLeftNav.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,gBAAgB,EAA4B,MAAM,yBAAyB,CAAC;AAG1F;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,IAAI,CAAC,gBAAgB,EAAE,QAAQ,CAAC,QAclE"}
|
package/dist/useLeftNav.js
CHANGED
|
@@ -1,7 +1,26 @@
|
|
|
1
|
-
import { useContext, useEffect } from "react";
|
|
1
|
+
/** @module @category UI */ import { useContext, useEffect } from "react";
|
|
2
2
|
import { setLeftNav, unsetLeftNav } from "@openmrs/esm-extensions";
|
|
3
3
|
import { ComponentContext } from "./ComponentContext.js";
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* A React hook that registers a left navigation menu for the current component.
|
|
6
|
+
* The navigation is automatically registered when the component mounts and
|
|
7
|
+
* unregistered when it unmounts.
|
|
8
|
+
*
|
|
9
|
+
* **Important:** This hook should only be used in "page" components, not in
|
|
10
|
+
* "extension" components. Extensions should not control the left navigation.
|
|
11
|
+
*
|
|
12
|
+
* @param params Configuration parameters for the left navigation, excluding the
|
|
13
|
+
* module name which is automatically determined from the component context.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```tsx
|
|
17
|
+
* import { useLeftNav } from '@openmrs/esm-framework';
|
|
18
|
+
* function MyPageComponent() {
|
|
19
|
+
* useLeftNav({ name: 'my-nav', slots: ['nav-slot-1', 'nav-slot-2'] });
|
|
20
|
+
* return <div>My Page</div>;
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
*/ export function useLeftNav(params) {
|
|
5
24
|
const componentContext = useContext(ComponentContext);
|
|
6
25
|
useEffect(()=>{
|
|
7
26
|
if (componentContext && componentContext.moduleName) {
|
|
@@ -1,2 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A React hook that provides access to the left navigation store state.
|
|
3
|
+
* The component will re-render whenever the left navigation state changes.
|
|
4
|
+
*
|
|
5
|
+
* @returns The current state of the left navigation store.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```tsx
|
|
9
|
+
* import { useLeftNavStore } from '@openmrs/esm-framework';
|
|
10
|
+
* function MyComponent() {
|
|
11
|
+
* const leftNavState = useLeftNavStore();
|
|
12
|
+
* return <div>Current nav: {leftNavState.activeNavName}</div>;
|
|
13
|
+
* }
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
1
16
|
export declare function useLeftNavStore(): import("@openmrs/esm-extensions").LeftNavStore;
|
|
2
17
|
//# sourceMappingURL=useLeftNavStore.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLeftNavStore.d.ts","sourceRoot":"","sources":["../src/useLeftNavStore.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useLeftNavStore.d.ts","sourceRoot":"","sources":["../src/useLeftNavStore.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,eAAe,mDAE9B"}
|
package/dist/useLeftNavStore.js
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
|
-
import { leftNavStore } from "@openmrs/esm-extensions";
|
|
1
|
+
/** @module @category UI */ import { leftNavStore } from "@openmrs/esm-extensions";
|
|
2
2
|
import { useStore } from "./useStore.js";
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* A React hook that provides access to the left navigation store state.
|
|
5
|
+
* The component will re-render whenever the left navigation state changes.
|
|
6
|
+
*
|
|
7
|
+
* @returns The current state of the left navigation store.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```tsx
|
|
11
|
+
* import { useLeftNavStore } from '@openmrs/esm-framework';
|
|
12
|
+
* function MyComponent() {
|
|
13
|
+
* const leftNavState = useLeftNavStore();
|
|
14
|
+
* return <div>Current nav: {leftNavState.activeNavName}</div>;
|
|
15
|
+
* }
|
|
16
|
+
* ```
|
|
17
|
+
*/ export function useLeftNavStore() {
|
|
4
18
|
return useStore(leftNavStore);
|
|
5
19
|
}
|
package/dist/useLocations.d.ts
CHANGED
|
@@ -1,3 +1,27 @@
|
|
|
1
1
|
import { type Location } from '@openmrs/esm-emr-api';
|
|
2
|
+
/**
|
|
3
|
+
* A React hook that fetches and returns locations from the OpenMRS server.
|
|
4
|
+
* Locations can be filtered by a tag UUID/name and/or a search query string.
|
|
5
|
+
*
|
|
6
|
+
* @param tagUuidOrName Optional tag UUID or name to filter locations by.
|
|
7
|
+
* Pass `null` to not filter by tag.
|
|
8
|
+
* @param query Optional search query string to filter locations. Pass `null`
|
|
9
|
+
* to not filter by query.
|
|
10
|
+
* @returns An array of Location objects. Returns an empty array while loading
|
|
11
|
+
* or if an error occurs.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```tsx
|
|
15
|
+
* import { useLocations } from '@openmrs/esm-framework';
|
|
16
|
+
* function LocationList() {
|
|
17
|
+
* const locations = useLocations('Login Location');
|
|
18
|
+
* return (
|
|
19
|
+
* <ul>
|
|
20
|
+
* {locations.map((loc) => <li key={loc.uuid}>{loc.display}</li>)}
|
|
21
|
+
* </ul>
|
|
22
|
+
* );
|
|
23
|
+
* }
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
2
26
|
export declare function useLocations(tagUuidOrName?: string | null, query?: string | null): Array<Location>;
|
|
3
27
|
//# sourceMappingURL=useLocations.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLocations.d.ts","sourceRoot":"","sources":["../src/useLocations.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAgB,KAAK,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAEnE,wBAAgB,YAAY,CAAC,aAAa,GAAE,MAAM,GAAG,IAAW,EAAE,KAAK,GAAE,MAAM,GAAG,IAAW,GAAG,KAAK,CAAC,QAAQ,CAAC,CAgB9G"}
|
|
1
|
+
{"version":3,"file":"useLocations.d.ts","sourceRoot":"","sources":["../src/useLocations.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAgB,KAAK,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAEnE;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,YAAY,CAAC,aAAa,GAAE,MAAM,GAAG,IAAW,EAAE,KAAK,GAAE,MAAM,GAAG,IAAW,GAAG,KAAK,CAAC,QAAQ,CAAC,CAgB9G"}
|
package/dist/useLocations.js
CHANGED
|
@@ -1,6 +1,29 @@
|
|
|
1
1
|
/** @module @category API */ import { useState, useEffect } from "react";
|
|
2
2
|
import { getLocations } from "@openmrs/esm-emr-api";
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* A React hook that fetches and returns locations from the OpenMRS server.
|
|
5
|
+
* Locations can be filtered by a tag UUID/name and/or a search query string.
|
|
6
|
+
*
|
|
7
|
+
* @param tagUuidOrName Optional tag UUID or name to filter locations by.
|
|
8
|
+
* Pass `null` to not filter by tag.
|
|
9
|
+
* @param query Optional search query string to filter locations. Pass `null`
|
|
10
|
+
* to not filter by query.
|
|
11
|
+
* @returns An array of Location objects. Returns an empty array while loading
|
|
12
|
+
* or if an error occurs.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```tsx
|
|
16
|
+
* import { useLocations } from '@openmrs/esm-framework';
|
|
17
|
+
* function LocationList() {
|
|
18
|
+
* const locations = useLocations('Login Location');
|
|
19
|
+
* return (
|
|
20
|
+
* <ul>
|
|
21
|
+
* {locations.map((loc) => <li key={loc.uuid}>{loc.display}</li>)}
|
|
22
|
+
* </ul>
|
|
23
|
+
* );
|
|
24
|
+
* }
|
|
25
|
+
* ```
|
|
26
|
+
*/ export function useLocations(tagUuidOrName = null, query = null) {
|
|
4
27
|
const [locations, setLocations] = useState([]);
|
|
5
28
|
useEffect(()=>{
|
|
6
29
|
const locationSub = getLocations(tagUuidOrName, query).subscribe((locations)=>{
|
|
@@ -1,2 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A React hook that detects clicks outside of a referenced element. Useful for
|
|
3
|
+
* implementing dropdown menus, modals, or any component that should close when
|
|
4
|
+
* clicking outside of it.
|
|
5
|
+
*
|
|
6
|
+
* @typeParam T The type of HTML element the ref will be attached to.
|
|
7
|
+
* @param handler A callback function invoked when a click occurs outside the
|
|
8
|
+
* referenced element.
|
|
9
|
+
* @param active Whether the outside click detection is active. Defaults to `true`.
|
|
10
|
+
* Set to `false` to temporarily disable the detection.
|
|
11
|
+
* @returns A React ref object to attach to the element you want to detect
|
|
12
|
+
* outside clicks for.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```tsx
|
|
16
|
+
* import { useOnClickOutside } from '@openmrs/esm-framework';
|
|
17
|
+
* function Dropdown() {
|
|
18
|
+
* const [isOpen, setIsOpen] = useState(false);
|
|
19
|
+
* const ref = useOnClickOutside<HTMLDivElement>(() => setIsOpen(false), isOpen);
|
|
20
|
+
* return (
|
|
21
|
+
* <div ref={ref}>
|
|
22
|
+
* {isOpen && <ul>...</ul>}
|
|
23
|
+
* </div>
|
|
24
|
+
* );
|
|
25
|
+
* }
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
1
28
|
export declare function useOnClickOutside<T extends HTMLElement = HTMLElement>(handler: (event: MouseEvent) => void, active?: boolean): import("react").RefObject<T>;
|
|
2
29
|
//# sourceMappingURL=useOnClickOutside.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useOnClickOutside.d.ts","sourceRoot":"","sources":["../src/useOnClickOutside.ts"],"names":[],"mappings":"AAGA,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,WAAW,GAAG,WAAW,EACnE,OAAO,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI,EACpC,MAAM,UAAO,gCA0Bd"}
|
|
1
|
+
{"version":3,"file":"useOnClickOutside.d.ts","sourceRoot":"","sources":["../src/useOnClickOutside.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,WAAW,GAAG,WAAW,EACnE,OAAO,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI,EACpC,MAAM,UAAO,gCA0Bd"}
|
|
@@ -1,5 +1,31 @@
|
|
|
1
1
|
/** @module @category UI */ import { useRef, useEffect } from "react";
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* A React hook that detects clicks outside of a referenced element. Useful for
|
|
4
|
+
* implementing dropdown menus, modals, or any component that should close when
|
|
5
|
+
* clicking outside of it.
|
|
6
|
+
*
|
|
7
|
+
* @typeParam T The type of HTML element the ref will be attached to.
|
|
8
|
+
* @param handler A callback function invoked when a click occurs outside the
|
|
9
|
+
* referenced element.
|
|
10
|
+
* @param active Whether the outside click detection is active. Defaults to `true`.
|
|
11
|
+
* Set to `false` to temporarily disable the detection.
|
|
12
|
+
* @returns A React ref object to attach to the element you want to detect
|
|
13
|
+
* outside clicks for.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```tsx
|
|
17
|
+
* import { useOnClickOutside } from '@openmrs/esm-framework';
|
|
18
|
+
* function Dropdown() {
|
|
19
|
+
* const [isOpen, setIsOpen] = useState(false);
|
|
20
|
+
* const ref = useOnClickOutside<HTMLDivElement>(() => setIsOpen(false), isOpen);
|
|
21
|
+
* return (
|
|
22
|
+
* <div ref={ref}>
|
|
23
|
+
* {isOpen && <ul>...</ul>}
|
|
24
|
+
* </div>
|
|
25
|
+
* );
|
|
26
|
+
* }
|
|
27
|
+
* ```
|
|
28
|
+
*/ export function useOnClickOutside(handler, active = true) {
|
|
3
29
|
const ref = useRef(null);
|
|
4
30
|
useEffect(()=>{
|
|
5
31
|
const listener = (event)=>{
|
package/dist/usePatient.d.ts
CHANGED
|
@@ -4,6 +4,11 @@ export type NullablePatient = fhir.Patient | null;
|
|
|
4
4
|
* as a parameter, then the patient for that UUID is returned. If the parameter
|
|
5
5
|
* is not provided, the patient UUID is obtained from the current route, and
|
|
6
6
|
* a route listener is set up to update the patient whenever the route changes.
|
|
7
|
+
*
|
|
8
|
+
* @param patientUuid Optional UUID of the patient to fetch. If not provided,
|
|
9
|
+
* the UUID is extracted from the current URL path.
|
|
10
|
+
* @returns An object containing the patient data, loading state, current patient UUID, and any error.
|
|
11
|
+
*
|
|
7
12
|
*/
|
|
8
13
|
export declare function usePatient(patientUuid?: string): {
|
|
9
14
|
isLoading: boolean;
|
package/dist/usePatient.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePatient.d.ts","sourceRoot":"","sources":["../src/usePatient.ts"],"names":[],"mappings":"AAKA,MAAM,MAAM,eAAe,GAAG,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;AAOlD
|
|
1
|
+
{"version":3,"file":"usePatient.d.ts","sourceRoot":"","sources":["../src/usePatient.ts"],"names":[],"mappings":"AAKA,MAAM,MAAM,eAAe,GAAG,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;AAOlD;;;;;;;;;;GAUG;AACH,wBAAgB,UAAU,CAAC,WAAW,CAAC,EAAE,MAAM;;;;;EAgC9C"}
|
package/dist/usePatient.js
CHANGED
|
@@ -10,6 +10,11 @@ function getPatientUuidFromUrl() {
|
|
|
10
10
|
* as a parameter, then the patient for that UUID is returned. If the parameter
|
|
11
11
|
* is not provided, the patient UUID is obtained from the current route, and
|
|
12
12
|
* a route listener is set up to update the patient whenever the route changes.
|
|
13
|
+
*
|
|
14
|
+
* @param patientUuid Optional UUID of the patient to fetch. If not provided,
|
|
15
|
+
* the UUID is extracted from the current URL path.
|
|
16
|
+
* @returns An object containing the patient data, loading state, current patient UUID, and any error.
|
|
17
|
+
*
|
|
13
18
|
*/ export function usePatient(patientUuid) {
|
|
14
19
|
const [currentPatientUuid, setCurrentPatientUuid] = useState(patientUuid ?? getPatientUuidFromUrl());
|
|
15
20
|
const { data: patient, error, isValidating } = useSWR(currentPatientUuid ? [
|
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
export interface PrimaryIdentifier {
|
|
2
2
|
metadataUuid: string;
|
|
3
3
|
}
|
|
4
|
+
/**
|
|
5
|
+
* A React hook that retrieves the UUID of the primary patient identifier type
|
|
6
|
+
* from the metadata mapping configuration. This identifier type is commonly used
|
|
7
|
+
* to display the main identifier for a patient, such as their medical record number.
|
|
8
|
+
*
|
|
9
|
+
* @returns An object containing the primary identifier type UUID, loading state, and any error.
|
|
10
|
+
*
|
|
11
|
+
*/
|
|
4
12
|
export declare function usePrimaryIdentifierCode(): {
|
|
5
13
|
primaryIdentifierCode: string | undefined;
|
|
6
14
|
isLoading: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePrimaryIdentifierResource.d.ts","sourceRoot":"","sources":["../src/usePrimaryIdentifierResource.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,iBAAiB;IAChC,YAAY,EAAE,MAAM,CAAC;CACtB;AAKD,wBAAgB,wBAAwB,IAAI;IAC1C,qBAAqB,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1C,SAAS,EAAE,OAAO,CAAC;IACnB,KAAK,EAAE,KAAK,GAAG,SAAS,CAAC;CAC1B,CAcA"}
|
|
1
|
+
{"version":3,"file":"usePrimaryIdentifierResource.d.ts","sourceRoot":"","sources":["../src/usePrimaryIdentifierResource.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,iBAAiB;IAChC,YAAY,EAAE,MAAM,CAAC;CACtB;AAKD;;;;;;;GAOG;AACH,wBAAgB,wBAAwB,IAAI;IAC1C,qBAAqB,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1C,SAAS,EAAE,OAAO,CAAC;IACnB,KAAK,EAAE,KAAK,GAAG,SAAS,CAAC;CAC1B,CAcA"}
|
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
/** @module @category API */ import { useMemo } from "react";
|
|
2
2
|
import useSWR from "swr";
|
|
3
3
|
import { openmrsFetch, restBaseUrl } from "@openmrs/esm-api";
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* A React hook that retrieves the UUID of the primary patient identifier type
|
|
6
|
+
* from the metadata mapping configuration. This identifier type is commonly used
|
|
7
|
+
* to display the main identifier for a patient, such as their medical record number.
|
|
8
|
+
*
|
|
9
|
+
* @returns An object containing the primary identifier type UUID, loading state, and any error.
|
|
10
|
+
*
|
|
11
|
+
*/ export function usePrimaryIdentifierCode() {
|
|
5
12
|
const url = `${restBaseUrl}/metadatamapping/termmapping?v=custom:(metadataUuid)&code=emr.primaryIdentifierType`;
|
|
6
13
|
const { data, error, isLoading } = useSWR(url, openmrsFetch);
|
|
7
14
|
const results = useMemo(()=>({
|
package/dist/useVisitTypes.d.ts
CHANGED
|
@@ -1,4 +1,26 @@
|
|
|
1
1
|
/** @module @category API */
|
|
2
2
|
import { type VisitType } from '@openmrs/esm-emr-api';
|
|
3
|
+
/**
|
|
4
|
+
* A React hook that fetches and returns all available visit types from the
|
|
5
|
+
* OpenMRS server. The data is fetched once when the component mounts.
|
|
6
|
+
*
|
|
7
|
+
* @returns An array of VisitType objects. Returns an empty array while loading
|
|
8
|
+
* or if an error occurs.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```tsx
|
|
12
|
+
* import { useVisitTypes } from '@openmrs/esm-framework';
|
|
13
|
+
* function VisitTypeSelector() {
|
|
14
|
+
* const visitTypes = useVisitTypes();
|
|
15
|
+
* return (
|
|
16
|
+
* <select>
|
|
17
|
+
* {visitTypes.map((vt) => (
|
|
18
|
+
* <option key={vt.uuid} value={vt.uuid}>{vt.display}</option>
|
|
19
|
+
* ))}
|
|
20
|
+
* </select>
|
|
21
|
+
* );
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
3
25
|
export declare function useVisitTypes(): VisitType[];
|
|
4
26
|
//# sourceMappingURL=useVisitTypes.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useVisitTypes.d.ts","sourceRoot":"","sources":["../src/useVisitTypes.ts"],"names":[],"mappings":"AAAA,4BAA4B;AAC5B,OAAO,EAAiB,KAAK,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAGrE,wBAAgB,aAAa,gBAe5B"}
|
|
1
|
+
{"version":3,"file":"useVisitTypes.d.ts","sourceRoot":"","sources":["../src/useVisitTypes.ts"],"names":[],"mappings":"AAAA,4BAA4B;AAC5B,OAAO,EAAiB,KAAK,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAGrE;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,aAAa,gBAe5B"}
|
package/dist/useVisitTypes.js
CHANGED
|
@@ -1,6 +1,27 @@
|
|
|
1
1
|
/** @module @category API */ import { getVisitTypes } from "@openmrs/esm-emr-api";
|
|
2
2
|
import { useEffect, useState } from "react";
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* A React hook that fetches and returns all available visit types from the
|
|
5
|
+
* OpenMRS server. The data is fetched once when the component mounts.
|
|
6
|
+
*
|
|
7
|
+
* @returns An array of VisitType objects. Returns an empty array while loading
|
|
8
|
+
* or if an error occurs.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```tsx
|
|
12
|
+
* import { useVisitTypes } from '@openmrs/esm-framework';
|
|
13
|
+
* function VisitTypeSelector() {
|
|
14
|
+
* const visitTypes = useVisitTypes();
|
|
15
|
+
* return (
|
|
16
|
+
* <select>
|
|
17
|
+
* {visitTypes.map((vt) => (
|
|
18
|
+
* <option key={vt.uuid} value={vt.uuid}>{vt.display}</option>
|
|
19
|
+
* ))}
|
|
20
|
+
* </select>
|
|
21
|
+
* );
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
*/ export function useVisitTypes() {
|
|
4
25
|
const [visitTypes, setVisitTypes] = useState([]);
|
|
5
26
|
useEffect(()=>{
|
|
6
27
|
const visitTypesSub = getVisitTypes().subscribe((visitTypes)=>{
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openmrs/esm-react-utils",
|
|
3
|
-
"version": "8.0.1-pre.
|
|
3
|
+
"version": "8.0.1-pre.3786",
|
|
4
4
|
"license": "MPL-2.0",
|
|
5
5
|
"description": "React utilities for OpenMRS.",
|
|
6
6
|
"type": "module",
|
|
@@ -79,17 +79,17 @@
|
|
|
79
79
|
"swr": "2.x"
|
|
80
80
|
},
|
|
81
81
|
"devDependencies": {
|
|
82
|
-
"@openmrs/esm-api": "8.0.1-pre.
|
|
83
|
-
"@openmrs/esm-config": "8.0.1-pre.
|
|
84
|
-
"@openmrs/esm-context": "8.0.1-pre.
|
|
85
|
-
"@openmrs/esm-emr-api": "8.0.1-pre.
|
|
86
|
-
"@openmrs/esm-error-handling": "8.0.1-pre.
|
|
87
|
-
"@openmrs/esm-extensions": "8.0.1-pre.
|
|
88
|
-
"@openmrs/esm-feature-flags": "8.0.1-pre.
|
|
89
|
-
"@openmrs/esm-globals": "8.0.1-pre.
|
|
90
|
-
"@openmrs/esm-navigation": "8.0.1-pre.
|
|
91
|
-
"@openmrs/esm-state": "8.0.1-pre.
|
|
92
|
-
"@openmrs/esm-utils": "8.0.1-pre.
|
|
82
|
+
"@openmrs/esm-api": "8.0.1-pre.3786",
|
|
83
|
+
"@openmrs/esm-config": "8.0.1-pre.3786",
|
|
84
|
+
"@openmrs/esm-context": "8.0.1-pre.3786",
|
|
85
|
+
"@openmrs/esm-emr-api": "8.0.1-pre.3786",
|
|
86
|
+
"@openmrs/esm-error-handling": "8.0.1-pre.3786",
|
|
87
|
+
"@openmrs/esm-extensions": "8.0.1-pre.3786",
|
|
88
|
+
"@openmrs/esm-feature-flags": "8.0.1-pre.3786",
|
|
89
|
+
"@openmrs/esm-globals": "8.0.1-pre.3786",
|
|
90
|
+
"@openmrs/esm-navigation": "8.0.1-pre.3786",
|
|
91
|
+
"@openmrs/esm-state": "8.0.1-pre.3786",
|
|
92
|
+
"@openmrs/esm-utils": "8.0.1-pre.3786",
|
|
93
93
|
"@swc/cli": "^0.7.7",
|
|
94
94
|
"@swc/core": "^1.11.29",
|
|
95
95
|
"@vitest/coverage-v8": "^4.0.7",
|
package/src/ConfigurableLink.tsx
CHANGED
|
@@ -31,9 +31,7 @@ function handleClick(
|
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
/**
|
|
35
|
-
* @noInheritDoc
|
|
36
|
-
*/
|
|
34
|
+
/** @noInheritDoc */
|
|
37
35
|
export interface ConfigurableLinkProps extends AnchorHTMLAttributes<HTMLAnchorElement> {
|
|
38
36
|
/** The target path or URL. Supports interpolation. See [[navigate]] */
|
|
39
37
|
to: string;
|
|
@@ -44,7 +42,7 @@ export interface ConfigurableLinkProps extends AnchorHTMLAttributes<HTMLAnchorEl
|
|
|
44
42
|
}
|
|
45
43
|
|
|
46
44
|
/**
|
|
47
|
-
* A React link component which calls
|
|
45
|
+
* A React link component which calls {@link navigate} when clicked
|
|
48
46
|
*/
|
|
49
47
|
export function ConfigurableLink({
|
|
50
48
|
to,
|
package/src/getLifecycle.ts
CHANGED
|
@@ -7,6 +7,22 @@ import singleSpaReact, { type ReactAppOrParcel } from 'single-spa-react';
|
|
|
7
7
|
import type { ComponentDecoratorOptions } from './openmrsComponentDecorator';
|
|
8
8
|
import { openmrsComponentDecorator } from './openmrsComponentDecorator';
|
|
9
9
|
|
|
10
|
+
/**
|
|
11
|
+
* Creates a single-spa lifecycle object for a React component. The component is
|
|
12
|
+
* wrapped with the OpenMRS component decorator which provides standard functionality
|
|
13
|
+
* like error boundaries, configuration, and extension support.
|
|
14
|
+
*
|
|
15
|
+
* @param Component The React component to create a lifecycle for.
|
|
16
|
+
* @param options Configuration options for the OpenMRS component decorator.
|
|
17
|
+
* @returns A single-spa lifecycle object with bootstrap, mount, and unmount functions.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* import { getLifecycle } from '@openmrs/esm-framework';
|
|
22
|
+
* import MyComponent from './MyComponent';
|
|
23
|
+
* export const lifecycle = getLifecycle(MyComponent, { featureName: 'my-feature', moduleName: '@openmrs/esm-my-app' });
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
10
26
|
export function getLifecycle<T>(Component: ComponentType<T>, options: ComponentDecoratorOptions) {
|
|
11
27
|
return singleSpaReact<T>({
|
|
12
28
|
React,
|
|
@@ -15,6 +31,24 @@ export function getLifecycle<T>(Component: ComponentType<T>, options: ComponentD
|
|
|
15
31
|
});
|
|
16
32
|
}
|
|
17
33
|
|
|
34
|
+
/**
|
|
35
|
+
* Creates a lazy-loading single-spa lifecycle for a React component. The component
|
|
36
|
+
* is loaded asynchronously via dynamic import only when it's needed, which helps
|
|
37
|
+
* reduce initial bundle size. This is the recommended way to define lifecycles
|
|
38
|
+
* for most modules.
|
|
39
|
+
*
|
|
40
|
+
* @param lazy A function that returns a Promise resolving to a module with the
|
|
41
|
+
* component as its default export (i.e., a dynamic import).
|
|
42
|
+
* @param options Configuration options for the OpenMRS component decorator.
|
|
43
|
+
* @returns A function that returns a Promise resolving to a single-spa lifecycle object.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```ts
|
|
47
|
+
* import { getAsyncLifecycle } from '@openmrs/esm-framework';
|
|
48
|
+
* const options = { featureName: 'my-feature', moduleName: '@openmrs/esm-my-app' };
|
|
49
|
+
* export const root = getAsyncLifecycle(() => import('./root.component'), options);
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
18
52
|
export function getAsyncLifecycle<T>(
|
|
19
53
|
lazy: () => Promise<{ default: ComponentType<T> }>,
|
|
20
54
|
options: ComponentDecoratorOptions,
|
|
@@ -22,6 +56,24 @@ export function getAsyncLifecycle<T>(
|
|
|
22
56
|
return () => lazy().then(({ default: Component }) => getLifecycle(Component, options));
|
|
23
57
|
}
|
|
24
58
|
|
|
59
|
+
/**
|
|
60
|
+
* Creates a single-spa lifecycle for a React component that is already loaded.
|
|
61
|
+
* Unlike {@link getAsyncLifecycle}, this wraps a synchronously-available component
|
|
62
|
+
* in a Promise to match the expected lifecycle interface. Use this when the
|
|
63
|
+
* component doesn't need lazy loading.
|
|
64
|
+
*
|
|
65
|
+
* @param Component The React component to create a lifecycle for.
|
|
66
|
+
* @param options Configuration options for the OpenMRS component decorator.
|
|
67
|
+
* @returns A function that returns a Promise resolving to a single-spa lifecycle object.
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```ts
|
|
71
|
+
* import { getSyncLifecycle } from '@openmrs/esm-framework';
|
|
72
|
+
* import MyComponent from './MyComponent';
|
|
73
|
+
* const options = { featureName: 'my-feature', moduleName: '@openmrs/esm-my-app' };
|
|
74
|
+
* export const myExtension = getSyncLifecycle(MyComponent, options);
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
25
77
|
export function getSyncLifecycle<T>(Component: ComponentType<T>, options: ComponentDecoratorOptions) {
|
|
26
78
|
return () => Promise.resolve(getLifecycle(Component, options));
|
|
27
79
|
}
|
package/src/useAttachments.ts
CHANGED
|
@@ -4,6 +4,31 @@ import useSWR from 'swr';
|
|
|
4
4
|
import { openmrsFetch, type FetchResponse } from '@openmrs/esm-api';
|
|
5
5
|
import { attachmentUrl, type AttachmentResponse } from '@openmrs/esm-emr-api';
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* A React hook that fetches attachments for a patient using SWR for caching
|
|
9
|
+
* and automatic revalidation.
|
|
10
|
+
*
|
|
11
|
+
* @param patientUuid The UUID of the patient whose attachments should be fetched.
|
|
12
|
+
* @param includeEncounterless Whether to include attachments that are not
|
|
13
|
+
* associated with any encounter.
|
|
14
|
+
* @returns An object containing:
|
|
15
|
+
* - `data`: Array of attachment objects (empty array while loading)
|
|
16
|
+
* - `isLoading`: Whether the initial fetch is in progress
|
|
17
|
+
* - `isValidating`: Whether any request (initial or revalidation) is in progress
|
|
18
|
+
* - `error`: Any error that occurred during fetching
|
|
19
|
+
* - `mutate`: Function to trigger a revalidation of the data
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```tsx
|
|
23
|
+
* import { useAttachments } from '@openmrs/esm-framework';
|
|
24
|
+
* function PatientAttachments({ patientUuid }) {
|
|
25
|
+
* const { data, isLoading, error } = useAttachments(patientUuid, true);
|
|
26
|
+
* if (isLoading) return <span>Loading...</span>;
|
|
27
|
+
* if (error) return <span>Error loading attachments</span>;
|
|
28
|
+
* return <AttachmentList attachments={data} />;
|
|
29
|
+
* }
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
7
32
|
export function useAttachments(patientUuid: string, includeEncounterless: boolean) {
|
|
8
33
|
const { data, error, mutate, isLoading, isValidating } = useSWR<
|
|
9
34
|
FetchResponse<{ results: Array<AttachmentResponse> }>
|
package/src/useBodyScrollLock.ts
CHANGED
|
@@ -1,6 +1,24 @@
|
|
|
1
1
|
/** @module @category UI */
|
|
2
2
|
import { useEffect } from 'react';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* A React hook that prevents scrolling on the document body when active.
|
|
6
|
+
* Useful for modals, overlays, or any full-screen UI that should prevent
|
|
7
|
+
* background scrolling. The original overflow style is restored when the
|
|
8
|
+
* hook becomes inactive or the component unmounts.
|
|
9
|
+
*
|
|
10
|
+
* @param active Whether to lock the body scroll. When `true`, sets
|
|
11
|
+
* `document.body.style.overflow` to 'hidden'.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```tsx
|
|
15
|
+
* import { useBodyScrollLock } from '@openmrs/esm-framework';
|
|
16
|
+
* function Modal({ isOpen }) {
|
|
17
|
+
* useBodyScrollLock(isOpen);
|
|
18
|
+
* return isOpen ? <div className="modal">...</div> : null;
|
|
19
|
+
* }
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
4
22
|
export function useBodyScrollLock(active: boolean) {
|
|
5
23
|
useEffect(() => {
|
|
6
24
|
if (active) {
|
package/src/useConnectivity.ts
CHANGED
|
@@ -3,6 +3,22 @@ import { subscribeConnectivityChanged } from '@openmrs/esm-globals';
|
|
|
3
3
|
import { isOnline as isOnlineFn } from '@openmrs/esm-utils';
|
|
4
4
|
import { useEffect, useState } from 'react';
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* A React hook that returns the current online/offline status and automatically
|
|
8
|
+
* updates when connectivity changes. Useful for showing offline indicators or
|
|
9
|
+
* conditionally rendering UI based on network availability.
|
|
10
|
+
*
|
|
11
|
+
* @returns `true` if the browser is online, `false` if offline.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```tsx
|
|
15
|
+
* import { useConnectivity } from '@openmrs/esm-framework';
|
|
16
|
+
* function NetworkStatus() {
|
|
17
|
+
* const isOnline = useConnectivity();
|
|
18
|
+
* return <span>{isOnline ? 'Online' : 'Offline'}</span>;
|
|
19
|
+
* }
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
6
22
|
export function useConnectivity() {
|
|
7
23
|
let [isOnline, setIsOnline] = useState(isOnlineFn());
|
|
8
24
|
|
package/src/useLeftNav.ts
CHANGED
|
@@ -1,7 +1,28 @@
|
|
|
1
|
+
/** @module @category UI */
|
|
1
2
|
import { useContext, useEffect } from 'react';
|
|
2
3
|
import { type SetLeftNavParams, setLeftNav, unsetLeftNav } from '@openmrs/esm-extensions';
|
|
3
4
|
import { ComponentContext } from './ComponentContext';
|
|
4
5
|
|
|
6
|
+
/**
|
|
7
|
+
* A React hook that registers a left navigation menu for the current component.
|
|
8
|
+
* The navigation is automatically registered when the component mounts and
|
|
9
|
+
* unregistered when it unmounts.
|
|
10
|
+
*
|
|
11
|
+
* **Important:** This hook should only be used in "page" components, not in
|
|
12
|
+
* "extension" components. Extensions should not control the left navigation.
|
|
13
|
+
*
|
|
14
|
+
* @param params Configuration parameters for the left navigation, excluding the
|
|
15
|
+
* module name which is automatically determined from the component context.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```tsx
|
|
19
|
+
* import { useLeftNav } from '@openmrs/esm-framework';
|
|
20
|
+
* function MyPageComponent() {
|
|
21
|
+
* useLeftNav({ name: 'my-nav', slots: ['nav-slot-1', 'nav-slot-2'] });
|
|
22
|
+
* return <div>My Page</div>;
|
|
23
|
+
* }
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
5
26
|
export function useLeftNav(params: Omit<SetLeftNavParams, 'module'>) {
|
|
6
27
|
const componentContext = useContext(ComponentContext);
|
|
7
28
|
|
package/src/useLeftNavStore.ts
CHANGED
|
@@ -1,6 +1,22 @@
|
|
|
1
|
+
/** @module @category UI */
|
|
1
2
|
import { leftNavStore } from '@openmrs/esm-extensions';
|
|
2
3
|
import { useStore } from './useStore';
|
|
3
4
|
|
|
5
|
+
/**
|
|
6
|
+
* A React hook that provides access to the left navigation store state.
|
|
7
|
+
* The component will re-render whenever the left navigation state changes.
|
|
8
|
+
*
|
|
9
|
+
* @returns The current state of the left navigation store.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```tsx
|
|
13
|
+
* import { useLeftNavStore } from '@openmrs/esm-framework';
|
|
14
|
+
* function MyComponent() {
|
|
15
|
+
* const leftNavState = useLeftNavStore();
|
|
16
|
+
* return <div>Current nav: {leftNavState.activeNavName}</div>;
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
4
20
|
export function useLeftNavStore() {
|
|
5
21
|
return useStore(leftNavStore);
|
|
6
22
|
}
|
package/src/useLocations.tsx
CHANGED
|
@@ -2,6 +2,30 @@
|
|
|
2
2
|
import { useState, useEffect } from 'react';
|
|
3
3
|
import { getLocations, type Location } from '@openmrs/esm-emr-api';
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* A React hook that fetches and returns locations from the OpenMRS server.
|
|
7
|
+
* Locations can be filtered by a tag UUID/name and/or a search query string.
|
|
8
|
+
*
|
|
9
|
+
* @param tagUuidOrName Optional tag UUID or name to filter locations by.
|
|
10
|
+
* Pass `null` to not filter by tag.
|
|
11
|
+
* @param query Optional search query string to filter locations. Pass `null`
|
|
12
|
+
* to not filter by query.
|
|
13
|
+
* @returns An array of Location objects. Returns an empty array while loading
|
|
14
|
+
* or if an error occurs.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```tsx
|
|
18
|
+
* import { useLocations } from '@openmrs/esm-framework';
|
|
19
|
+
* function LocationList() {
|
|
20
|
+
* const locations = useLocations('Login Location');
|
|
21
|
+
* return (
|
|
22
|
+
* <ul>
|
|
23
|
+
* {locations.map((loc) => <li key={loc.uuid}>{loc.display}</li>)}
|
|
24
|
+
* </ul>
|
|
25
|
+
* );
|
|
26
|
+
* }
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
5
29
|
export function useLocations(tagUuidOrName: string | null = null, query: string | null = null): Array<Location> {
|
|
6
30
|
const [locations, setLocations] = useState<Array<Location>>([]);
|
|
7
31
|
|
package/src/useOnClickOutside.ts
CHANGED
|
@@ -1,6 +1,33 @@
|
|
|
1
1
|
/** @module @category UI */
|
|
2
2
|
import { useRef, useEffect } from 'react';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* A React hook that detects clicks outside of a referenced element. Useful for
|
|
6
|
+
* implementing dropdown menus, modals, or any component that should close when
|
|
7
|
+
* clicking outside of it.
|
|
8
|
+
*
|
|
9
|
+
* @typeParam T The type of HTML element the ref will be attached to.
|
|
10
|
+
* @param handler A callback function invoked when a click occurs outside the
|
|
11
|
+
* referenced element.
|
|
12
|
+
* @param active Whether the outside click detection is active. Defaults to `true`.
|
|
13
|
+
* Set to `false` to temporarily disable the detection.
|
|
14
|
+
* @returns A React ref object to attach to the element you want to detect
|
|
15
|
+
* outside clicks for.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```tsx
|
|
19
|
+
* import { useOnClickOutside } from '@openmrs/esm-framework';
|
|
20
|
+
* function Dropdown() {
|
|
21
|
+
* const [isOpen, setIsOpen] = useState(false);
|
|
22
|
+
* const ref = useOnClickOutside<HTMLDivElement>(() => setIsOpen(false), isOpen);
|
|
23
|
+
* return (
|
|
24
|
+
* <div ref={ref}>
|
|
25
|
+
* {isOpen && <ul>...</ul>}
|
|
26
|
+
* </div>
|
|
27
|
+
* );
|
|
28
|
+
* }
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
4
31
|
export function useOnClickOutside<T extends HTMLElement = HTMLElement>(
|
|
5
32
|
handler: (event: MouseEvent) => void,
|
|
6
33
|
active = true,
|
package/src/usePatient.ts
CHANGED
|
@@ -15,6 +15,11 @@ function getPatientUuidFromUrl() {
|
|
|
15
15
|
* as a parameter, then the patient for that UUID is returned. If the parameter
|
|
16
16
|
* is not provided, the patient UUID is obtained from the current route, and
|
|
17
17
|
* a route listener is set up to update the patient whenever the route changes.
|
|
18
|
+
*
|
|
19
|
+
* @param patientUuid Optional UUID of the patient to fetch. If not provided,
|
|
20
|
+
* the UUID is extracted from the current URL path.
|
|
21
|
+
* @returns An object containing the patient data, loading state, current patient UUID, and any error.
|
|
22
|
+
*
|
|
18
23
|
*/
|
|
19
24
|
export function usePatient(patientUuid?: string) {
|
|
20
25
|
const [currentPatientUuid, setCurrentPatientUuid] = useState(patientUuid ?? getPatientUuidFromUrl());
|
|
@@ -10,6 +10,14 @@ interface PrimaryIdentifierResponse {
|
|
|
10
10
|
results: Array<PrimaryIdentifier>;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
+
/**
|
|
14
|
+
* A React hook that retrieves the UUID of the primary patient identifier type
|
|
15
|
+
* from the metadata mapping configuration. This identifier type is commonly used
|
|
16
|
+
* to display the main identifier for a patient, such as their medical record number.
|
|
17
|
+
*
|
|
18
|
+
* @returns An object containing the primary identifier type UUID, loading state, and any error.
|
|
19
|
+
*
|
|
20
|
+
*/
|
|
13
21
|
export function usePrimaryIdentifierCode(): {
|
|
14
22
|
primaryIdentifierCode: string | undefined;
|
|
15
23
|
isLoading: boolean;
|
package/src/useVisitTypes.ts
CHANGED
|
@@ -2,6 +2,28 @@
|
|
|
2
2
|
import { getVisitTypes, type VisitType } from '@openmrs/esm-emr-api';
|
|
3
3
|
import { useEffect, useState } from 'react';
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* A React hook that fetches and returns all available visit types from the
|
|
7
|
+
* OpenMRS server. The data is fetched once when the component mounts.
|
|
8
|
+
*
|
|
9
|
+
* @returns An array of VisitType objects. Returns an empty array while loading
|
|
10
|
+
* or if an error occurs.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```tsx
|
|
14
|
+
* import { useVisitTypes } from '@openmrs/esm-framework';
|
|
15
|
+
* function VisitTypeSelector() {
|
|
16
|
+
* const visitTypes = useVisitTypes();
|
|
17
|
+
* return (
|
|
18
|
+
* <select>
|
|
19
|
+
* {visitTypes.map((vt) => (
|
|
20
|
+
* <option key={vt.uuid} value={vt.uuid}>{vt.display}</option>
|
|
21
|
+
* ))}
|
|
22
|
+
* </select>
|
|
23
|
+
* );
|
|
24
|
+
* }
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
5
27
|
export function useVisitTypes() {
|
|
6
28
|
const [visitTypes, setVisitTypes] = useState<Array<VisitType>>([]);
|
|
7
29
|
|