Skip to content
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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

moradology
Copy link

This PR aims to enable example code generation for searches.
image

Vue.use(CardPlugin);
Vue.use(BadgePlugin)
Vue.use(VueHighlightJS);
Copy link
Collaborator

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.

Copy link
Author

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

Copy link
Collaborator

@m-mohr m-mohr Oct 18, 2023

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.

Copy link
Author

@moradology moradology Oct 18, 2023

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

Copy link
Collaborator

@m-mohr m-mohr Oct 18, 2023

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. :-)

@@ -237,13 +260,90 @@ export default {
}
return false;
},
filterString() {
Copy link
Collaborator

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.

Copy link
Collaborator

@m-mohr m-mohr Oct 18, 2023

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.

@m-mohr
Copy link
Collaborator

m-mohr commented Oct 18, 2023

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.

@moradology moradology changed the title Working syntax highlighting Code example generation for search page Oct 18, 2023
@moradology
Copy link
Author

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?

@m-mohr
Copy link
Collaborator

m-mohr commented Oct 18, 2023

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...

@moradology
Copy link
Author

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

@m-mohr
Copy link
Collaborator

m-mohr commented Oct 18, 2023

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",
Copy link
Collaborator

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?

@stephenkilbourn
Copy link

stephenkilbourn commented Oct 20, 2023

I'm not a designer either, so if there is any UI/UX expert that wants to chime in.... ;-)

@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

Screenshot 2023-10-20 at 2 19 11 PM

@moradology moradology marked this pull request as ready for review October 30, 2023 15:27
@m-mohr
Copy link
Collaborator

m-mohr commented Oct 30, 2023

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, ...)

@moradology
Copy link
Author

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

@j08lue
Copy link

j08lue commented Jan 10, 2024

Just for the record, this is similar to the Python code snippet generator of Microsoft Planetary Computer:

image

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.

Copy link
Collaborator

@m-mohr m-mohr left a 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`,
Copy link
Collaborator

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) {
Copy link
Collaborator

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() {
Copy link
Collaborator

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
Copy link
Collaborator

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: {
Copy link
Collaborator

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">
Copy link
Collaborator

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?

@m-mohr m-mohr added this to the 3.5.0 milestone Sep 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants