Apply Operation History from JSON file
Related to #4498, I would like to see a button to Apply Operation History by opening a JSON file instead of having to open the file separately. This would remove any need to copy-paste the contents of these files, and make it easier for users.
What about this as an approach?
- "Import" button added to the Apply Operation History dialogue
- On clicking import, user prompted to upload file
- Once file is uploaded the content (assuming can be read correctly) is populated into the operation history window
- User can then click "Perform operations" as usual
Yeah, I like this approach.
Hello, can I be assigned this issue?
How do I best approach this issue?
@IjayAbby I'd first familiarise myself with the existing process for applying an operation history from the users perspective - see the user docs at https://openrefine.org/docs/manual/running#history-undoredo
Once you've understood this you can identify how this works in the code base - the proposed approach I made above will (as far as I know) only require changes in the front end - so somewhere under /webapp/modules/core/ in the code structure I think - but basically find out what generates the "Apply Operation History" pop-up and the various elements of that screen.
At this point you should be in a position to think about how you'd add an "Import" button to this screen and be able to start thinking through the process of doing this - where it would display on the screen, what it would need to do etc.
If you reach this point successfully I'd suggest you come back with a proposal at that point and say what you intend to do to get some final feedback before you go ahead - although you could also do that through a PR if the changes seem v straightforward.
Of course if you get stuck at any point or have questions feel free to raise them here
And if you haven't already please read through the contributing guidelines etc https://openrefine.org/docs/technical-reference/contributing - this includes information on how to run the software locally and making your first PR
Thank you so much for clarity and resources you have shared.I will reach out.
On Thu, Mar 16, 2023 at 6:11 PM, Owen Stephens @.***> wrote:
And if you haven't already please read through the contributing guidelines etc https://openrefine.org/docs/technical-reference/contributing
— Reply to this email directly, view it on GitHub https://github.com/OpenRefine/OpenRefine/issues/5022#issuecomment-1472169469, or unsubscribe https://github.com/notifications/unsubscribe-auth/AKOQBCAWL7MPIQUH4FHCNWLW4MUTJANCNFSM52V3W4WA . You are receiving this because you were assigned.Message ID: @.***>
@ostephens I think I can add my changes on this function. Let me know if its correct
That looks right to me. You might find this example of adding the "Export" button to the Extract History dialogue useful to look at as it also shows how this was done in the same file plus the tests added
https://github.com/OpenRefine/OpenRefine/commit/879da1f2f0b30b4c507758e52807245568f96b7e
So this is my thought process:
-
Open OpenRefine and create a new project. -
Click on the "Undo/Redo" button in the top right corner of the screen. -
In the "Undo/Redo" panel, click on the "Apply" button. -
In the "Apply Operations" dialog box, click on the "Import..." button. -
In the "Import Operations" dialog box, select the JSON file that contains the operation history you want to apply. -
Open the file and click on the "Apply" button. -
The operations in the JSON file will be applied to your current OpenRefine project. You can see the changes in the preview pane on the right side of the screen. -
Once you're satisfied with the changes, you can click on the "Perform operations" button to make the changes permanent.
This is the code I want to implement but am not too sure how to incorporate it, I need help:
$.ajax({ url: "path/to/your/file.json", dataType: "json", success: function(data) { var operations = data["operations"]; var applyOperations = function() { var applyUrl = "http://localhost:3333/command/core/apply-operations"; var params = { "operations": JSON.stringify(operations) }; $.ajax({ url: applyUrl, data: params, type: "POST", success: function() { console.log("Operations applied successfully"); }, error: function() { console.log("Error applying operations"); } }); }; applyOperations(); }, error: function() { console.log("Error loading JSON file"); } });
Thanks @ljayAbby
I think you've got an extra step in there that would be a separate enhancement:
- The operations in the JSON file will be applied to your current OpenRefine project. You can see the changes in the preview pane on the right side of the screen.
This isn't something that currently happens when applying an operation history and while I think adding it is a great idea I think that should be a separate enhancement (as it should work whether you do via a file upload or cut and paste of JSON). So I think you should aim for:
- Click on the "Undo/Redo" button in the top right corner of the screen.
- In the "Undo/Redo" panel, click on the "Apply" button.
- In the "Apply Operations" dialog box, click on the "Import..." button.
- In the "Import Operations" dialog box, select the JSON file that contains the operation history you want to apply.
- Open the file and the file content will be populated into the window
- Click on the "Perform operations" button to apply the operations to your current OpenRefine Project
This is the code I want to implement but am not too sure how to incorporate it, I need help:
That doesn't look quite right to me. Did you look at the example I linked to above? https://github.com/OpenRefine/OpenRefine/commit/879da1f2f0b30b4c507758e52807245568f96b7e
Yes I have, do you happen to be free we do a quick call maybe I will understand it better.
I'm afraid I can't do a call today. I'm also not an expert, but I think I'd expect to see you proposing changes to at least history-apply-dialog.html and history-panel.js
I'd expect to see something in the HistoryPanel.prototype._showApplyOperationsDialog in history-panel.js that defines the new 'Import operations" button and the function that will be triggered when that button is clicked.
Then I'd expect something in history-apply-dialog.html to display the button and bind it appropriately
Okay let me try this and I will reach out.
@ostephens, I managed to create the button but my function is not working well due to the URL on line 355 on history-panel.js. Advice me on how to best approach this. Link to pull request Thanks.
Link to pull request. @ostephens In the pull request, I was able to create the button the file cannot be uploaded correctly since the URL I am using is incorrect. How do I fix this?