fix(DHIS2-16988): download uncompressed json rather than open inline #2015
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.
In new tracker API, the backend no longer sends a
content-disposition
header which means that, when exporting events or tracked entity instances, the JSON file doesn't get downloaded but they open inline instead.To get around this, we're able to control the behaviour from the frontend by making use of the
download
property of an anchor element: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#download. Since the download in our case is triggered with JavaScript, rather than an anchor element in the HTML, we need to create an element on the fly with JavaScript and trigger a click programatically.While working on this, I also changed the name of the downloaded file to include extra information so the file looks something like
trackedEntities_2024-04-24_ouMode_CAPTURE__program_lxAQ7Zs9VYR.json
orevents_2024-04-24_orgUnit_ImspTQPwCqd__program_lxAQ7Zs9VYR__ouMode_SELECTED.json
rather than justtrackedEntities.json
andevents.json
as before - the extra info in the file name are a timestamp of the download, and some extra info related to the exported entities (program, orgUnits, ouMode, trackedEntityType).