Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(feat) O3-4143: useLocations should support searching by tag or query… #1191

Merged
merged 3 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 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,16 @@ export function toLocationObject(openmrsRestForm: any): Location {
};
}

export function getLocations(tagUuidOrName: string | null = null): Observable<Array<Location>> {
const url = `${restBaseUrl}/location` + (tagUuidOrName ? '?tag=' + tagUuidOrName : '');
export function getLocations(
tagUuidOrName: string | null = null,
query: string | null = null,
): Observable<Array<Location>> {
const url =
`${restBaseUrl}/location` +
(tagUuidOrName || query ? '?' : '') +
(tagUuidOrName ? 'tag=' + tagUuidOrName : '') +
(tagUuidOrName && query ? '&' : '') +
(query ? 'q=' + query : '');
return openmrsObservableFetch<any>(url)
mogoodrich marked this conversation as resolved.
Show resolved Hide resolved
.pipe(
map((results) => {
Expand Down
6 changes: 3 additions & 3 deletions packages/framework/esm-react-utils/src/useLocations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import type { Location } from '@openmrs/esm-api';
import { getLocations } from '@openmrs/esm-api';
import { useState, useEffect } from 'react';

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

useEffect(() => {
const locationSub = getLocations(tagUuidOrName).subscribe(
const locationSub = getLocations(tagUuidOrName, query).subscribe(
(locations) => {
setLocations(locations);
},
Expand All @@ -16,7 +16,7 @@ export function useLocations(tagUuidOrName: string | null = null) {
},
);
return () => locationSub.unsubscribe();
}, []);
}, [tagUuidOrName, query]);

return locations;
}
Loading