@openmrs/esm-react-utils 3.2.1-pre.1073 → 3.2.1-pre.1084

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openmrs/esm-react-utils",
3
- "version": "3.2.1-pre.1073",
3
+ "version": "3.2.1-pre.1084",
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": "^3.2.1-pre.1073",
59
- "@openmrs/esm-config": "^3.2.1-pre.1073",
60
- "@openmrs/esm-error-handling": "^3.2.1-pre.1073",
61
- "@openmrs/esm-extensions": "^3.2.1-pre.1073",
62
- "@openmrs/esm-globals": "^3.2.1-pre.1073",
58
+ "@openmrs/esm-api": "^3.2.1-pre.1084",
59
+ "@openmrs/esm-config": "^3.2.1-pre.1084",
60
+ "@openmrs/esm-error-handling": "^3.2.1-pre.1084",
61
+ "@openmrs/esm-extensions": "^3.2.1-pre.1084",
62
+ "@openmrs/esm-globals": "^3.2.1-pre.1084",
63
63
  "dayjs": "^1.10.8",
64
64
  "i18next": "^19.6.0",
65
65
  "react": "^16.13.1",
@@ -68,5 +68,5 @@
68
68
  "rxjs": "^6.5.3",
69
69
  "unistore": "^3.5.2"
70
70
  },
71
- "gitHead": "375669d9327f82ab0cc86bc51f1ce626d9ee3430"
71
+ "gitHead": "c2a5b8ed52049b3e302df8043f42ac57ec3321b1"
72
72
  }
@@ -1,3 +1,4 @@
1
+ /** @module @category Navigation */
1
2
  import React, { MouseEvent, AnchorHTMLAttributes } from "react";
2
3
  import { navigate, interpolateUrl } from "@openmrs/esm-config";
3
4
 
@@ -27,7 +28,6 @@ export interface ConfigurableLinkProps
27
28
  * @param to The target path or URL. Supports interpolation. See [[navigate]]
28
29
  * @param children Inline elements within the link
29
30
  * @param otherProps Any other valid props for an <a> tag except `href` and `onClick`
30
- * @category Navigation
31
31
  */
32
32
  export const ConfigurableLink: React.FC<ConfigurableLinkProps> = ({
33
33
  to,
@@ -1,3 +1,4 @@
1
+ /** @module @category API */
1
2
  import React, { useEffect, useState } from "react";
2
3
  import { getCurrentUser, userHasAccess, LoggedInUser } from "@openmrs/esm-api";
3
4
 
@@ -1,3 +1,4 @@
1
+ /** @module @category Store */
1
2
  import { useEffect, useMemo, useState } from "react";
2
3
  import { Store, BoundAction } from "unistore";
3
4
 
@@ -1,3 +1,4 @@
1
+ /** @module @category Framework */
1
2
  import React from "react";
2
3
  import ReactDOM from "react-dom";
3
4
  import singleSpaReact from "single-spa-react";
package/src/public.ts ADDED
@@ -0,0 +1,26 @@
1
+ export { ExtensionData } from "./ComponentContext";
2
+ export * from "./ConfigurableLink";
3
+ export * from "./createUseStore";
4
+ export * from "./Extension";
5
+ export * from "./ExtensionSlot";
6
+ export * from "./getLifecycle";
7
+ export * from "./useAssignedExtensions";
8
+ export * from "./useAssignedExtensionIds";
9
+ export * from "./useBodyScrollLock";
10
+ export * from "./useConfig";
11
+ export * from "./useConnectedExtensions";
12
+ export * from "./useConnectivity";
13
+ export * from "./usePatient";
14
+ export * from "./useCurrentPatient";
15
+ export * from "./useExtensionSlot";
16
+ export * from "./useExtensionSlotMeta";
17
+ export * from "./useExtensionStore";
18
+ export * from "./useLayoutType";
19
+ export * from "./useLocations";
20
+ export * from "./useOnClickOutside";
21
+ export * from "./UserHasAccess";
22
+ export * from "./useSessionUser";
23
+ export * from "./useStore";
24
+ export * from "./useVisit";
25
+ export * from "./useVisitTypes";
26
+ export * from "./usePagination";
@@ -1,3 +1,4 @@
1
+ /** @module @category Extension */
1
2
  import { useEffect, useState } from "react";
2
3
  import { getExtensionStore } from "@openmrs/esm-extensions";
3
4
  import { isEqual } from "lodash";
@@ -1,3 +1,4 @@
1
+ /** @module @category Extension */
1
2
  import { useEffect, useState } from "react";
2
3
  import {
3
4
  AssignedExtension,
@@ -1,3 +1,4 @@
1
+ /** @module @category UI */
1
2
  import { useEffect } from "react";
2
3
 
3
4
  export function useBodyScrollLock(active: boolean) {
package/src/useConfig.ts CHANGED
@@ -1,3 +1,4 @@
1
+ /** @module @category Config */
1
2
  import { useContext, useEffect, useMemo, useState } from "react";
2
3
  import {
3
4
  getConfigStore,
@@ -1,3 +1,4 @@
1
+ /** @module @category Extension */
1
2
  import { useMemo } from "react";
2
3
  import {
3
4
  ConnectedExtension,
@@ -1,3 +1,4 @@
1
+ /** @module @category Offline */
1
2
  import { subscribeConnectivityChanged } from "@openmrs/esm-globals";
2
3
  import { useEffect, useState } from "react";
3
4
 
@@ -1,3 +1,4 @@
1
+ /** @module @category API */
1
2
  import { useEffect, useReducer } from "react";
2
3
  import { fetchCurrentPatient, PatientUuid } from "@openmrs/esm-api";
3
4
 
@@ -1,3 +1,4 @@
1
+ /** @module @category Extension */
1
2
  import { ExtensionMeta } from "@openmrs/esm-extensions";
2
3
  import { useMemo } from "react";
3
4
  import { useConnectedExtensions } from "./useConnectedExtensions";
@@ -1,3 +1,4 @@
1
+ /** @module @category Extension */
1
2
  import { ExtensionStore, getExtensionStore } from "@openmrs/esm-extensions";
2
3
  import { createUseStore } from "./createUseStore";
3
4
 
@@ -1,3 +1,4 @@
1
+ /** @module @category UI */
1
2
  import { useEffect, useState } from "react";
2
3
 
3
4
  export type LayoutType = "tablet" | "phone" | "desktop";
@@ -1,3 +1,4 @@
1
+ /** @module @category API */
1
2
  import { getLocations, Location } from "@openmrs/esm-api";
2
3
  import { useState, useEffect } from "react";
3
4
 
@@ -0,0 +1,59 @@
1
+ import React from "react";
2
+ import { render, fireEvent } from "@testing-library/react";
3
+ import { useOnClickOutside } from "./useOnClickOutside";
4
+
5
+ describe("useOnClickOutside", () => {
6
+ const handler: (e: Event) => void = jest.fn();
7
+ afterEach(() => (handler as jest.Mock).mockClear());
8
+
9
+ it("should call the handler when clicking outside", () => {
10
+ // setup
11
+ const Component: React.FC = ({ children }) => {
12
+ const ref = useOnClickOutside<HTMLDivElement>(handler);
13
+ return <div ref={ref}>{children}</div>;
14
+ };
15
+ const ref = render(<Component />);
16
+
17
+ // act
18
+ fireEvent.click(ref.container);
19
+
20
+ // verify
21
+ expect(handler).toHaveBeenCalledTimes(1);
22
+ });
23
+
24
+ it("should not call the handler when clicking on the element", () => {
25
+ // setup
26
+ const Component: React.FC = ({ children }) => {
27
+ const ref = useOnClickOutside<HTMLDivElement>(handler);
28
+ return <div ref={ref}>{children}</div>;
29
+ };
30
+ const mutableRef: { current: HTMLDivElement } = { current: undefined };
31
+ render(
32
+ <Component>
33
+ <div ref={mutableRef}></div>
34
+ </Component>
35
+ );
36
+
37
+ // act
38
+ fireEvent.click(mutableRef.current);
39
+
40
+ // verify
41
+ expect(handler).not.toHaveBeenCalled();
42
+ });
43
+
44
+ it("should unregister the event listener when unmounted", () => {
45
+ // setup
46
+ const Component: React.FC = ({ children }) => {
47
+ const ref = useOnClickOutside<HTMLDivElement>(handler);
48
+ return <div ref={ref}>{children}</div>;
49
+ };
50
+ const ref = render(<Component />);
51
+ const spy = jest.spyOn(window, "removeEventListener");
52
+
53
+ // act
54
+ ref.unmount();
55
+
56
+ // verify
57
+ expect(spy).toHaveBeenCalledWith("click", expect.any(Function));
58
+ });
59
+ });
@@ -1,3 +1,4 @@
1
+ /** @module @category UI */
1
2
  import { useRef, useEffect } from "react";
2
3
 
3
4
  export function useOnClickOutside<T extends HTMLElement = HTMLElement>(
@@ -10,7 +11,7 @@ export function useOnClickOutside<T extends HTMLElement = HTMLElement>(
10
11
  if (active) {
11
12
  const listener = (event: Event) => {
12
13
  if (ref?.current?.contains(event.target as Node)) {
13
- return;
14
+ return;
14
15
  }
15
16
 
16
17
  handler(event);
@@ -1,3 +1,4 @@
1
+ /** @module @category UI */
1
2
  import { useMemo, useState } from "react";
2
3
 
3
4
  const defaultResultsPerPage = 10;
package/src/usePatient.ts CHANGED
@@ -1,7 +1,8 @@
1
+ /** @module @category API */
1
2
  import { useEffect, useReducer } from "react";
2
3
  import { fetchCurrentPatient, PatientUuid } from "@openmrs/esm-api";
3
4
 
4
- type NullablePatient = fhir.Patient | null;
5
+ export type NullablePatient = fhir.Patient | null;
5
6
 
6
7
  interface CurrentPatientState {
7
8
  patientUuid: string | null;
@@ -1,3 +1,4 @@
1
+ /** @module @category API */
1
2
  import { openmrsObservableFetch, SessionUser } from "@openmrs/esm-api";
2
3
  import { useState, useEffect } from "react";
3
4
 
package/src/useStore.ts CHANGED
@@ -1,3 +1,4 @@
1
+ /** @module @category Store */
1
2
  import { subscribeTo } from "@openmrs/esm-state";
2
3
  import { useEffect, useMemo, useState } from "react";
3
4
  import { Store } from "unistore";
package/src/useVisit.ts CHANGED
@@ -1,3 +1,4 @@
1
+ /** @module @category API */
1
2
  import {
2
3
  defaultVisitCustomRepresentation,
3
4
  openmrsFetch,
@@ -1,3 +1,4 @@
1
+ /** @module @category API */
1
2
  import { getVisitTypes, VisitType } from "@openmrs/esm-api";
2
3
  import { useEffect, useState } from "react";
3
4