Skip to content

(fix) Load every page of locations in the location data source - #866

Open
mherman22 wants to merge 6 commits into
openmrs:mainfrom
mherman22:fix/location-data-source-paging
Open

mherman22 wants to merge 6 commits into
openmrs:mainfrom
mherman22:fix/location-data-source-paging

Conversation

@mherman22

@mherman22 mherman22 commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

Requirements

  • This PR has a title that briefly describes the work done including the ticket number. If there is a ticket, make sure your PR title includes a conventional commit label. See existing PR titles for inspiration.
  • My work is based on designs, which are linked or shown either in the Jira ticket or the description below. (See also: Styleguide)
  • My work includes tests or is validated by existing tests.

Summary

LocationDataSource.fetchData made one request and returned data.results, so a location list only ever held the first page of results. A form with more tagged locations than the REST page size (webservices.rest.maxResultsDefault, 50 by default) silently drops the rest from the dropdown, for example a location_datasource question filtered to Visit Location.

The list and search branch now calls the framework's openmrsFetchAll (added in O3-6343) and returns response.data.results. openmrsFetchAll follows the response's next links until there are none, and requests each later page on the first request's origin with only the link's path and query, so a link naming the backend's host, port or scheme still goes through the frontend proxy. It rejects if any page fails, or if the server repeats a next link.

The uuid branch of fetchData keeps its single request.

Screenshots

No UI change; the dropdown just lists every location.

Related Issue

None yet. Happy to create an O3 ticket if you'd like one for this.

Other

Tests:

  • location-data-source.test.ts serves a two-page response and expects all 57 locations, the second request on the page's origin (main returns only the first 50).
  • location-data-source.origin.test.ts runs on a port-less https://clinic.example page with a next link from http://backend:8080, and expects the second request at https://clinic.example/openmrs/ws/rest/v1/location?..., not https://clinic.example:8080/....
  • A single page with no next link takes one request.

The framework's test mock wraps the real openmrsFetchAll around the mocked openmrsFetch, so these tests still check every request the data source makes. Replacing openmrsFetchAll with openmrsFetch fails the first two. src/datasources passes 12 of 12, and tsc is clean.

Also checked against a running OpenMRS through its gateway on http://localhost:8402, with the real openmrsFetchAll and webservices.rest.maxResultsDefault lowered to 2. The server's next links named http://localhost (port 80, unreachable), so the origin handling was exercised too:

Call Locations (single-page baseline) Requests at page size 2 At the default page size
fetchData(null) 13 of 13 7 1
fetchData(null, { tag: 'Visit Location' }) 4 of 4 2 1
fetchData('Dashboard') 3 of 3 2 1

Every request after the first went to http://localhost:8402/openmrs/ws/rest/v1/location?...&startIndex=N, the next link's path and query on the page's origin.

openmrsFetchAll is in the framework's 11.0.1 pre-releases, which this repo already resolves; the 11.x peer range is unchanged.

Not changed here: the other data sources (provider, encounter role, the base class) also read only the first page, so on an instance with more records than the page size their dropdowns still list only the first page, as on main.

@mherman22
mherman22 marked this pull request as ready for review November 18, 2026 20:26
@greptile-apps

greptile-apps Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 4/5

[Medium impact] The change reaches forms that use the built-in location data source.

Fix the port rewrite before merging so paged location lists work through standard HTTPS addresses.

Fix All in Claude CodeFindings

  1. P1 Next links keep backend ports ▶
Fix with agent prompt
### Issue 1
src/datasources/location-data-source.ts:48-49
**Next links keep backend ports.** Assigning `url.host` does not clear the old port when `window.location.host` has no port. For a page at `https://clinic.example`, the next link used in the test becomes `https://clinic.example:8443/...`, not the browser's origin. The second request bypasses the intended proxy and can fail, leaving the dropdown empty. Explicitly copy `window.location.port`, including its empty value, after changing the protocol.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

Loads every page of location choices while keeping single-location lookups unchanged.

  • Location dropdowns now include results from every page.

Reviews (1) · Last reviewed commit: "Pin the protocol swap in the location pa..." · Reviewed by Greptile

Comment thread src/datasources/location-data-source.ts Outdated
Comment on lines +48 to +49
url.host = window.location.host;
url.protocol = window.location.protocol;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Next links keep backend ports. Assigning url.host does not clear the old port when window.location.host has no port. For a page at https://clinic.example, the next link used in the test becomes https://clinic.example:8443/..., not the browser's origin. The second request bypasses the intended proxy and can fail, leaving the dropdown empty. Explicitly copy window.location.port, including its empty value, after changing the protocol.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/datasources/location-data-source.ts
Line: 48-49

Comment:
**Next links keep backend ports.** Assigning `url.host` does not clear the old port when `window.location.host` has no port. For a page at `https://clinic.example`, the next link used in the test becomes `https://clinic.example:8443/...`, not the browser's origin. The second request bypasses the intended proxy and can fail, leaving the dropdown empty. Explicitly copy `window.location.port`, including its empty value, after changing the protocol.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Fix in Claude Code

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, thanks. Fixed in 63c2189: the next link's path and query are now resolved against window.location.origin, so the backend's host, port and scheme are all dropped, and a new test on a port-less https://clinic.example page covers it.

@denniskigen

Copy link
Copy Markdown
Member

@mherman22 openmrs/openmrs-esm-core#2019 just merged. It adds openmrsFetchAll, which fills the gap you noted about needing a helper outside React. Can we use it for the list/search branch of LocationDataSource.fetchData, return response.data.results, and drop fetchAllPages and getNextUrl? It keeps the first request's origin and port for later pages, so the port case you added is covered there too. Let's keep those tests when we switch. This needs the framework dependency update first.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants