-
Notifications
You must be signed in to change notification settings - Fork 33
feat: datafiles action type json #1790
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
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @nitrosx - I've reviewed your changes - here's some feedback:
Overall Comments:
- Consider adding error handling to the
fetch
call intype_json
.
Here's what I looked at during the review
- 🟡 General issues: 1 issue found
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟢 Complexity: all looks good
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
@@ -159,21 +161,27 @@ export class DatafilesActionComponent implements OnInit, OnChanges { | |||
return true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (bug_risk): Consider handling the fetch promise to manage asynchronous errors.
The current implementation calls fetch without awaiting its result or handling potential errors. This might lead to unhandled rejections or race conditions if the response is used later. Consider refactoring this method as an async function and using async/await, or at least adding a .then/.catch to deal with the promise resolution.
Suggested implementation:
async handleAction() {
try {
const response = await fetch(this.actionConfig.url, {
method: this.actionConfig.method || "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(data),
});
if (!response.ok) {
throw new Error(`Network response was not ok: ${response.statusText}`);
}
return true;
} catch (error) {
console.error("Fetch error:", error);
return false;
}
Ensure that any callers of handleAction() are updated to handle the Promise returned by this async method.
Yes, I am looking forward, as this makes writing action consumers much easier. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ai comments are not related to this change, but should probably be considered fr a separate change.
…to swap-4596-datafiles-action-json
cbf4891
to
f1fa6ff
Compare
src/app/datasets/datafiles-actions/datafiles-action.component.ts
Outdated
Show resolved
Hide resolved
…SciCatProject/frontend into swap-4596-datafiles-action-json
src/app/datasets/datafiles-actions/datafiles-action.component.ts
Outdated
Show resolved
Hide resolved
…SciCatProject/frontend into swap-4596-datafiles-action-json
## Description This PR update the frontend configuration with the updated examples of datafile actions. Now there are two datafiles actions: `form` and `json-download`. The `form` option will submit the information as a submitted form, while the `json-download` will POST the information to the specified URL in json format and expect the results to be saved in a file. The file name is specified in the action configuration Matching FE PR: [1790](SciCatProject/frontend#1790) ## Motivation While integrating FE with sciwyrm (jupyter notebook generator), we realized that FE was sending the data as submitted form, while the generator needed a json format. Also the structure of the data was different. ## Changes: * refactor the datafiles action controller ## Tests included The feature has been manually tested - [ ] Included for each change/fix? - [ ] Passing? <!-- Merge will not be approved unless tests pass --> ## Documentation - [ ] swagger documentation updated (required for API changes) - Not needed - [ ] official documentation updated - In progress
Description
This PR add the option to create a datafile action in json format.
It will submit a request to the specified URL with the payload in json format in the body. The results from the request will be saved by the browser in a file with the named specified in the action configuration.
The structure of the payload can be specified in configuration
There is the matching backend PR to update the frontend config file: 1800
Motivation
sciwyrm (Jupiter notebook generator) accepts only requests formatted as json.
ESS is currently deploying it in their infrastructure.
Changes:
Please provide a list of the changes implemented by this PR
Tests included
Documentation
official documentation info
If you have updated the official documentation, please provide PR # and URL of the pages where the updates are included
Backend version
Summary by Sourcery
New Features: