-
Notifications
You must be signed in to change notification settings - Fork 143
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
Code example generation for search page #381
base: main
Are you sure you want to change the base?
Code example generation for search page #381
Conversation
Vue.use(CardPlugin); | ||
Vue.use(BadgePlugin) | ||
Vue.use(VueHighlightJS); |
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.
Can this be registered so that it doesn't import into the global bundle? Ideally this would only be loaded if needed.
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.
Maybe you could say a bit more - I'm new to Vue, so some of the concepts here require me to squint a bit more than others might
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.
This should only be imported in the CodeBox component and not use Vue.use. I'm not sure whether this library supports this though.
Similarly, the Bootstrap Badges should also be imported individually where the are used. I think there should be examples around in the code if you search for the BBadge component.
I'm a bit busy right now so can't elaborate further at this point.
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.
I think I follow you - just been using python and jvm lingo for long enough that 'global bundle' tripped me up. Also, I think the badge plugin is from prior work and I accidentally shifted its order to the diff's confusion
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.
Global Bundle is probably also not the right terminology. I think better is "app bundle" or "initially loaded files". I pretty much just want that it is lazily loaded when needed, not everytime the page loads. :-)
src/views/Search.vue
Outdated
@@ -237,13 +260,90 @@ export default { | |||
} | |||
return false; | |||
}, | |||
filterString() { |
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.
Ideally all the code related to the code generation etc. should be in a separate component, not in the Search component.
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.
Actually, even better would be to have model classes for code generation. One method per use case and one class per language. Similarly to what I did here for another project: https://github.com/Open-EO/openeo-web-editor/tree/master/src/export
All UI related stuff should still be in the Vue Component, of course. So really just the code generation in classes.
Thanks for the PR. I left some general comments about the code structure, haven't had a lot of time yet to do a deeper review. I think I'd like to not show the code by default next to the map. Maybe can we add a button somewhere (next to the Submit / Reset button?) that only shows the code on demand? As a second idea, it would be great if we could show the generated CQL2 Text & JSON code. |
RE placement next to the map: How about a tab above the map/item returns which allows users to look at code examples instead of results? |
Thematically that doesn't quite match for me. The left side is the search parameters, which is what the generated code shows. So it should be on the left side. The right side are results and the code isn't really that. Thinking about this longer-term (see #114), I'd also like to generate code for pretty much every page at some point. So I'm wondering whether it should move into the toolbar in the top right of the page (where API, Source, Share, ... are). We could add a general "Open In" or "Export to" button... |
Your views about the location sound right to me. I appreciate the push back, as I'm no designer and my notions here might not be fully baked |
I'm not a designer either, so if there is any UI/UX expert that wants to chime in.... ;-) |
package.json
Outdated
@@ -41,8 +41,10 @@ | |||
"bootstrap-vue": "^2.21.2", | |||
"bs58": "^4.0.1", | |||
"chart.js": "^4.3.0", | |||
"clipboard": "^2.0.11", |
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.
We already use v-clipboard, can you re-use that instead of a new/this dependency?
@m-mohr - I'm also not a design expert, but an option that we looked at was making this a modal and a button to open it next the the submit/reset buttons. I've updated the PR with this change |
A Modal should work, indeed. We've used popovers until now, but that doesn't works better for less information. I don't have the time right now to give a deep review, sorry. Why was R removed? Ideally, we'd include even more (e.g. C#, R, Java, Rust, ...) |
R was removed just because the API doesn't have a similar, simple translation from JSON to request. I have some example code that I stashed which uses rstac, but am a bit busy at the moment else I'd have finished it up and included it |
Just for the record, this is similar to the Python code snippet generator of Microsoft Planetary Computer: I think the choice of modal for exposing the code snippet is good, since viewing and copying the code is a UI function otherwise separate from the main user flow, so it is adequate that it appears and disappears without otherwise affecting the UI, IMO. |
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.
Thanks again, I think we need a bit more polishing here. A couple of small change requests.
Also, STAC Browser in the meantime got Collection Search support and I'm not sure whether the PR caters for that correctly?
}, | ||
data() { | ||
return { | ||
componentId: `${this.language}Content`, |
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.
Seems unsused
this.updateCode(); | ||
}, | ||
methods: { | ||
dedent(str) { |
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.
This dedents a bit too much, the JS code is not indented at all, which looks rather weird.
console.error("Error fetching STAC data:", error); | ||
});`); | ||
}, | ||
updateCode() { |
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.
It might be a bit better to only generate what's shown, not everything upfront, especially if we extend this.
componentId: `${this.language}Content`, | ||
pythonCode: null, | ||
javascriptCode: null, | ||
rCode: null |
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.
Seems unsused
components: { | ||
CopyButton: () => import("./CopyButton.vue") | ||
}, | ||
props: { |
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.
Both props should probably be required.
</b-card-footer> | ||
</b-card> | ||
<b-modal id="code" :title="$t('exampleCode')" size="lg"> |
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 model shows a Cancel and OK button, it seems one Close button is enough?
This PR aims to enable example code generation for searches.