-
Notifications
You must be signed in to change notification settings - Fork 33
dhis2: Add paging examples and default async:false in tracker.import
#1681
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
Open
hunterachieng
wants to merge
14
commits into
main
Choose a base branch
from
feature/1546-dhis2-fix
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 12 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
03e0898
feat: allow async value change
hunterachieng 4cb8649
feat: update tests
hunterachieng 58dd4e1
feat: add changeset
hunterachieng 291ed1d
add integration tests for tracker.export
mtuchi bd90f85
add pagination example
mtuchi f81d8ad
update example
mtuchi f9a8733
update integration test
mtuchi bc358ef
improve format
mtuchi 85445c9
remove async and add pagination docs
mtuchi bf0f34c
update tracker unit tests
mtuchi fd37b92
update changeset
mtuchi 0f34f29
fix typo
mtuchi 04428e8
fix: update chngeset and tracker pagination examples
hunterachieng a38e154
fix: update docs
hunterachieng File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| '@openfn/language-dhis2': patch | ||
| --- | ||
|
|
||
| Default `async:false` in `tracker.import` and add paging examples to | ||
| `tracker.export()` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,6 +47,7 @@ import * as util from './util.js'; | |
| * @param {string} strategy - The effect the import should have. Can either be CREATE, UPDATE, CREATE_AND_UPDATE and DELETE. | ||
| * @param {object} payload - The data to be imported. | ||
| * @param {TrackerOptions} [options] - An optional object containing parseAs, and apiVersion, and queries for the request | ||
| * @param {boolean} [options.async=false] - Whether to perform the import asynchronously. Defaults to false. | ||
|
hunterachieng marked this conversation as resolved.
Outdated
|
||
| * @state {DHIS2State} | ||
| * @returns {Operation} | ||
| */ | ||
|
|
@@ -57,7 +58,7 @@ function _import(strategy, payload, options = {}) { | |
| const [resolvedStrategy, resolvedPayload, resolvedOptions] = | ||
| expandReferences(state, strategy, payload, options); | ||
|
|
||
| const { apiVersion, parseAs, ...query } = resolvedOptions; | ||
| const { apiVersion, parseAs, async = false, ...query } = resolvedOptions; | ||
|
|
||
| const response = await util.request(state.configuration, { | ||
| method: 'POST', | ||
|
|
@@ -67,14 +68,14 @@ function _import(strategy, payload, options = {}) { | |
| ...resolvedOptions, | ||
| resolvedStrategy, | ||
| }, | ||
| 'tracker' | ||
| 'tracker', | ||
| ), | ||
| options: { | ||
| apiVersion, | ||
| parseAs, | ||
| query: { | ||
| ...query, | ||
| async: false, | ||
| async, | ||
| }, | ||
| }, | ||
| data: resolvedPayload, | ||
|
|
@@ -95,37 +96,62 @@ export { _import as import }; | |
| * @example <caption>Export all enrollment resources</caption> | ||
| * tracker.export('enrollments', {orgUnit: 'TSyzvBiovKh'}); | ||
| * @example <caption>Export all events</caption> | ||
| * tracker.export('events') | ||
| * tracker.export('events', { paging: false}) | ||
| * @example <caption>Export all events with pagination</caption> | ||
|
hunterachieng marked this conversation as resolved.
Outdated
|
||
| * tracker.export('events', { totalPages: true, pageSize: 1e4 }); | ||
| * fn(state => { | ||
| * state.results = state.data.instances; | ||
| * const { page, pageSize, pageCount, total } = state.data.pager; | ||
| * const remainingPages = pageCount - page; | ||
| * | ||
| * state.pages = Array.from({ length: remainingPages }, (_, i) => page + i + 1); | ||
| * state.pageSize = pageSize; | ||
| * return state; | ||
| * }); | ||
| * | ||
| * each( | ||
| * $.pages, | ||
| * tracker | ||
| * .export('events', { pageSize: $.pageSize, page: $.data }) | ||
| * .then(state => { | ||
| * state.results = state.results.concat(state.data.instances); | ||
| * return state; | ||
| * }), | ||
| * ); | ||
| * @function | ||
| * @param {string} path - Path to the resource, relative to the /tracker endpoint | ||
| * @param {object} query - An object of query parameters to be encoded into the URL | ||
| * @param {object} query - An object of query parameters to be encoded into the URL. Can include pagination parameters, filters, etc. | ||
| * @param {number} [query.page=1] - Page number to return | ||
| * @param {number} [query.pageSize=50] - Number of results per page | ||
|
hunterachieng marked this conversation as resolved.
Outdated
|
||
| * @param {boolean} [query.totalPages=false] - Whether to return total number of elements and pages | ||
| * @param {boolean} [query.paging=true] - Set to false to return all rows without paging | ||
| * @param {string} [query.order] - Comma-separated field:sortDirection pairs, e.g. `createdAt:desc` | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the only query property we're actually documenting now. Why is this one so important?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I must have missed it. i removed it |
||
| * @param {TrackerOptions} [options] - An optional object containing parseAs, and apiVersion for the request | ||
| * @state {DHIS2State} | ||
| * @returns {Operation} | ||
| */ | ||
| function _export(path, query, options = {}) { | ||
| function _export(path, query = {}, options = {}) { | ||
| return async state => { | ||
| console.log('Preparing tracker export operation...'); | ||
|
|
||
| const [resolvedPath, resolvedQuery, resolvedOptions] = expandReferences( | ||
| state, | ||
| path, | ||
| query, | ||
| options | ||
| options, | ||
| ); | ||
|
|
||
| const response = await util.request(state.configuration, { | ||
| method: 'GET', | ||
| path: util.prefixVersionToPath( | ||
| state.configuration, | ||
| resolvedOptions, | ||
| `tracker/${resolvedPath}` | ||
| `tracker/${resolvedPath}`, | ||
| ), | ||
| options: { | ||
| ...resolvedOptions, | ||
| query: { | ||
| ...resolvedQuery, | ||
| async: false, | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.