-
Notifications
You must be signed in to change notification settings - Fork 29
Feature request: UI for passing bindings object #9
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
Comments
Something like this: https://sarathkcm.github.io/jsonata-exerciser/ - I can't get the syntax highlighting to work though |
This is really nice, I like it. I think as it stands in your demo, it might confuse users who are not familiar with the ability to pass in external bindings - I wonder if it could be hidden by default, with an option to reveal it for advanced users (my UI skills are not that great). Also this feature would be really useful if there was a way to import external libraries and bind those to JSONata variables. Since it all runs in the client browser, this might mean automatically inserting script tags to jsdelivr or something. Happy to receive a PR if you can figure this out! 😄 |
Mine neither, but can you please have a look now? https://sarathkcm.github.io/jsonata-exerciser/ - just a simple non-animated toggle.
I too think it'll be useful, I use moment js in the expressions and aren't testable in the exerciser. Adding script tags is probably not the way as global variables won't go away even if the tags are removed. It works for loading JSONata module because its always needed. I will try and give it a go this weekend. |
I'm really sorry for not keeping up with this promise for months. I have added the ability to load external libraries from a CDN url and have fixed the syntax highlighting. @andrew-coleman Could you please give it a try here https://sarathkcm.github.io/jsonata-exerciser/. If you are happy with the UI and functionality I will raise a PR after a little cleanup of the code (mostly just moving inline styles to css file). |
@andrew-coleman I also would like to confirm a behaviour with Jsonata. The imported modules are made available in the bindings pane and also passed to the Jsonata expression as bindings. However in Jsonata expression, only the top level module is accessible and works as expected, but if I try to access a nested function it returns undefined. For example in this screenshot the moment library is available as $moment and works. but $moment.utc is undefined. If I console log the bindings, assign moment to global temp variable in console and use temp1.utc it is available (just to make sure library is correctly parsed and passed to the bindings). Is this something related to the way Jsonata handles bindings? |
I raised a PR #12 with the necessary changes. |
Hey @sarathkcm this is awesome. The PR looks good to me. I'm going to ask @mattbaileyuk to review it as well (thanks Matt). |
@sarathkcm As mentioned in the PR review, this is excellent, thank you 👍 I have merged the change into the @andrew-coleman Does this now require you to do a redeployment so it goes live on try.jsonata.org? |
@mattbaileyuk It does, but I'm going to test locally first |
Hi @sarathkcm Thanks again, this is a great enhancement. Just noticed a couple of issues while playing with this:
Do you think you could take a look at these please? |
@andrew-coleman Some comments and queries regarding these issues. Apologies if a bit long.
Please let me know your thoughts on these, I will give it a go during the weekend. |
Either way I don't mind, we can add to this later. On the question of global libraries, I think it's fine to keep them global as you've done. I notice that when adding an external library that doesn't exist, it silently fails (apart from logging the 404 error to the browser console). It might be useful to pop up an error box for that. Also, when reloading a saved expression that has an external library that has since gone away will also cause an error. We'll need to think about how to handle that. Let's not worry now though. |
Hm. I followed what's done already when fetching of saved expressions fail. It's logging only to the developer's console, which I think is fine - after all this is a tool targetted to developers. I will anyways add a very simple self disappearing error message when loading of libraries entered manually fail. Will leave the errors when re-loading saved expressions as it is now - only on the console. |
Raised PR #14 for the fixes/changes. @andrew-coleman If you could modify the backend API to support new fields, it would help in testing and identifying any issues in save/load. |
I've fixed up the save/load backend. It all seems to work fine. |
@andrew-coleman Should this be raised as an issue in jsonata repo? I had observed the same behaviour when I do
|
It's probably because moment identifies itself as a function, so jsonata only allows operations that can be done on functions (i.e. invoke, partial apply, chain).
Then the expression If it's an object that contains functions, then that works ok. E.g. for the bindings:
Then the expression |
|
Ok, so this is the reason. It's wrong to expect Javascript behaviour in JSONATA. That clears it up. |
I'm loving this library ever since I discovered it. Kudos to the developers.
Often, I spin up a JSONata exerciser tab to debug issues in my expressions, and most of the times I find the need to pass bindings object with multiple properties, and I end up declaring the variables individually in the JSONata expression itself. It would be nice and cool to have a UI to input the bindings as well.
The text was updated successfully, but these errors were encountered: