Skip to content

Commit

Permalink
(feat) allow useLocations react hook to take in tag parameter (#849)
Browse files Browse the repository at this point in the history
  • Loading branch information
chibongho authored Dec 14, 2023
1 parent 9db3402 commit 0067e39
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 6 deletions.
5 changes: 3 additions & 2 deletions packages/framework/esm-api/src/shared-api-objects/location.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ export function toLocationObject(openmrsRestForm: any): Location {
};
}

export function getLocations(): Observable<Array<Location>> {
return openmrsObservableFetch<any>(`/ws/rest/v1/location`)
export function getLocations(tagUuidOrName: string | null = null): Observable<Array<Location>> {
const url = `/ws/rest/v1/location` + (tagUuidOrName ? '?tag=' + tagUuidOrName : '');
return openmrsObservableFetch<any>(url)
.pipe(
map((results) => {
const locations: Array<Location> = results.data.results.map(toLocationObject);
Expand Down
16 changes: 14 additions & 2 deletions packages/framework/esm-framework/docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -1038,7 +1038,13 @@ ___

### getLocations

**getLocations**(): `Observable`<[`Location`](interfaces/Location.md)[]\>
**getLocations**(`tagUuidOrName?`): `Observable`<[`Location`](interfaces/Location.md)[]\>

#### Parameters

| Name | Type | Default value |
| :------ | :------ | :------ |
| `tagUuidOrName` | ``null`` \| `string` | `null` |

#### Returns

Expand Down Expand Up @@ -1484,7 +1490,13 @@ ___

### useLocations

**useLocations**(): [`Location`](interfaces/Location.md)[]
**useLocations**(`tagUuidOrName?`): [`Location`](interfaces/Location.md)[]

#### Parameters

| Name | Type | Default value |
| :------ | :------ | :------ |
| `tagUuidOrName` | ``null`` \| `string` | `null` |

#### Returns

Expand Down
4 changes: 2 additions & 2 deletions packages/framework/esm-react-utils/src/useLocations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
import { getLocations, Location } from '@openmrs/esm-api';
import { useState, useEffect } from 'react';

export function useLocations() {
export function useLocations(tagUuidOrName: string | null = null) {
const [locations, setLocations] = useState<Array<Location>>([]);

useEffect(() => {
const locationSub = getLocations().subscribe(
const locationSub = getLocations(tagUuidOrName).subscribe(
(locations) => {
setLocations(locations);
},
Expand Down

0 comments on commit 0067e39

Please sign in to comment.