@openmrs/esm-react-utils 6.3.1-pre.3136 → 6.3.1-pre.3140

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.
@@ -1,3 +1,3 @@
1
- [0] Successfully compiled: 52 files with swc (125.02ms)
1
+ [0] Successfully compiled: 52 files with swc (118.84ms)
2
2
  [0] swc --strip-leading-paths src -d dist exited with code 0
3
3
  [1] tsc --project tsconfig.build.json exited with code 0
package/dist/useVisit.js CHANGED
@@ -42,8 +42,8 @@ dayjs.extend(isToday);
42
42
  ]);
43
43
  const previousCurrentVisit = useRef(null);
44
44
  useEffect(()=>{
45
- // if an active visit is created and either there is no visit in context or we've switched to a different patient, set the context to the active visit
46
- if (!activeIsValidating && activeVisit && (visitStorePatientUuid != patientUuid || manuallySetVisitUuid == null)) {
45
+ // if an active visit is created for the visit store patient and they have no visit in context, set the context to the active visit
46
+ if (!activeIsValidating && activeVisit && visitStorePatientUuid === patientUuid && manuallySetVisitUuid === null) {
47
47
  setVisitContext(activeVisit);
48
48
  }
49
49
  if (!retroIsValidating) {
@@ -1,12 +1,16 @@
1
1
  import { useEffect, useId } from "react";
2
2
  import { getVisitStore } from "@openmrs/esm-emr-api";
3
3
  import { useStoreWithActions } from "./useStore.js";
4
- // TODO: add better typing with `satisfies` keyword when we upgrade typescript
5
4
  const visitContextStoreActions = {
6
5
  setVisitContext (_, newSelectedVisit) {
6
+ if (newSelectedVisit == null) {
7
+ return {
8
+ manuallySetVisitUuid: null
9
+ };
10
+ }
7
11
  return {
8
- manuallySetVisitUuid: newSelectedVisit?.uuid ?? null,
9
- patientUuid: newSelectedVisit?.patient?.uuid ?? null
12
+ manuallySetVisitUuid: newSelectedVisit.uuid,
13
+ patientUuid: newSelectedVisit.patient?.uuid
10
14
  };
11
15
  },
12
16
  mutateVisit (currState) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openmrs/esm-react-utils",
3
- "version": "6.3.1-pre.3136",
3
+ "version": "6.3.1-pre.3140",
4
4
  "license": "MPL-2.0",
5
5
  "description": "React utilities for OpenMRS.",
6
6
  "type": "module",
@@ -78,17 +78,17 @@
78
78
  "swr": "2.x"
79
79
  },
80
80
  "devDependencies": {
81
- "@openmrs/esm-api": "6.3.1-pre.3136",
82
- "@openmrs/esm-config": "6.3.1-pre.3136",
83
- "@openmrs/esm-context": "6.3.1-pre.3136",
84
- "@openmrs/esm-emr-api": "6.3.1-pre.3136",
85
- "@openmrs/esm-error-handling": "6.3.1-pre.3136",
86
- "@openmrs/esm-extensions": "6.3.1-pre.3136",
87
- "@openmrs/esm-feature-flags": "6.3.1-pre.3136",
88
- "@openmrs/esm-globals": "6.3.1-pre.3136",
89
- "@openmrs/esm-navigation": "6.3.1-pre.3136",
90
- "@openmrs/esm-state": "6.3.1-pre.3136",
91
- "@openmrs/esm-utils": "6.3.1-pre.3136",
81
+ "@openmrs/esm-api": "6.3.1-pre.3140",
82
+ "@openmrs/esm-config": "6.3.1-pre.3140",
83
+ "@openmrs/esm-context": "6.3.1-pre.3140",
84
+ "@openmrs/esm-emr-api": "6.3.1-pre.3140",
85
+ "@openmrs/esm-error-handling": "6.3.1-pre.3140",
86
+ "@openmrs/esm-extensions": "6.3.1-pre.3140",
87
+ "@openmrs/esm-feature-flags": "6.3.1-pre.3140",
88
+ "@openmrs/esm-globals": "6.3.1-pre.3140",
89
+ "@openmrs/esm-navigation": "6.3.1-pre.3140",
90
+ "@openmrs/esm-state": "6.3.1-pre.3140",
91
+ "@openmrs/esm-utils": "6.3.1-pre.3140",
92
92
  "@swc/cli": "^0.7.7",
93
93
  "@swc/core": "^1.11.29",
94
94
  "concurrently": "^9.1.2",
package/src/useVisit.ts CHANGED
@@ -76,8 +76,8 @@ export function useVisit(patientUuid: string, representation = defaultVisitCusto
76
76
  const previousCurrentVisit = useRef<Visit | null>(null);
77
77
 
78
78
  useEffect(() => {
79
- // if an active visit is created and either there is no visit in context or we've switched to a different patient, set the context to the active visit
80
- if (!activeIsValidating && activeVisit && (visitStorePatientUuid != patientUuid || manuallySetVisitUuid == null)) {
79
+ // if an active visit is created for the visit store patient and they have no visit in context, set the context to the active visit
80
+ if (!activeIsValidating && activeVisit && visitStorePatientUuid === patientUuid && manuallySetVisitUuid === null) {
81
81
  setVisitContext(activeVisit);
82
82
  }
83
83
  if (!retroIsValidating) {
@@ -1,13 +1,15 @@
1
1
  import { useEffect, useId } from 'react';
2
2
  import { getVisitStore, type Visit, type VisitStoreState } from '@openmrs/esm-emr-api';
3
- import { useStoreWithActions } from './useStore';
3
+ import { type Actions, useStoreWithActions } from './useStore';
4
4
 
5
- // TODO: add better typing with `satisfies` keyword when we upgrade typescript
6
5
  const visitContextStoreActions = {
7
6
  setVisitContext(_: VisitStoreState, newSelectedVisit: Visit | null) {
7
+ if (newSelectedVisit == null) {
8
+ return { manuallySetVisitUuid: null };
9
+ }
8
10
  return {
9
- manuallySetVisitUuid: newSelectedVisit?.uuid ?? null,
10
- patientUuid: newSelectedVisit?.patient?.uuid ?? null,
11
+ manuallySetVisitUuid: newSelectedVisit.uuid,
12
+ patientUuid: newSelectedVisit.patient?.uuid,
11
13
  };
12
14
  },
13
15
  mutateVisit(currState: VisitStoreState) {
@@ -16,7 +18,7 @@ const visitContextStoreActions = {
16
18
  }
17
19
  return {};
18
20
  },
19
- };
21
+ } satisfies Actions<VisitStoreState>;
20
22
 
21
23
  /**
22
24
  * A hook to return the visit context store and corresponding actions.