Skip to content

Conversation

@bullet03
Copy link
Contributor

@bullet03 bullet03 commented Jun 21, 2022

Resolves #22301

  • add playground section with no autofocus set in playground iframe on page loading
  • update playground shortcode
  • move fix-playground-nested-scroll.js to head.html/head_homepage.html from body-end.html, since soon playground will be used on many pages
  • wrap fix-playground-nested-scroll.js in jQuery.ready, so func works only when DOM is ready

Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:

  • Choose reviewer(s) and mention them in a comment (R: @username).
  • Mention the appropriate issue in your description (for example: addresses #123), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, comment fixes #<ISSUE NUMBER> instead.
  • Update CHANGES.md with noteworthy changes.
  • If this contribution is large, please file an Apache Individual Contributor License Agreement.

See the Contributor Guide for more tips on how to make review process smoother.

To check the build health, please visit https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md

GitHub Actions Tests Status (on master branch)

Build python source distribution and wheels
Python tests
Java tests

See CI.md for more information about GitHub Actions CI.

@asf-ci
Copy link

asf-ci commented Jun 21, 2022

Can one of the admins verify this patch?

4 similar comments
@asf-ci
Copy link

asf-ci commented Jun 21, 2022

Can one of the admins verify this patch?

@asf-ci
Copy link

asf-ci commented Jun 21, 2022

Can one of the admins verify this patch?

@asf-ci
Copy link

asf-ci commented Jun 21, 2022

Can one of the admins verify this patch?

@asf-ci
Copy link

asf-ci commented Jun 21, 2022

Can one of the admins verify this patch?

@bullet03 bullet03 force-pushed the website-add-playground-without-autofocus branch 3 times, most recently from d2940d0 to 9d1bc9f Compare June 27, 2022 09:34
@bullet03 bullet03 force-pushed the website-add-playground-without-autofocus branch 3 times, most recently from d3a8b6e to 3723b77 Compare July 8, 2022 11:51
</a>
<div id="playgroundIframeContainer">
<iframe
src="https://play.beam.apache.org/embedded?enabled=true&example=SDK_JAVA/PRECOMPILED_OBJECT_TYPE_EXAMPLE/MinimalWordCount&code="
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to pass code if it's empty.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

class="code-snippet playground"
allow="clipboard-write">
</iframe>
<div id="playgroundIframeContainer">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

id should not be used in shortcode because the shortcode can be used multiple times on a page. It actually will be used many times since we need to convert many doc highlighted examples to playground instances.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

<a class="playground__mobile" href="https://play.beam.apache.org/">
<img src="images/playground.png" alt="beam playground">
</a>
<div id="playgroundIframeContainer">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use a shortcode here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as far as I understood according to the answer, we are not able to use shortcodes: https://discourse.gohugo.io/t/shortcode-inside-define-block/39410

</iframe>
<div id="playgroundIframeContainer">
<iframe
src="https://frontend-beta-dot-apache-beam-testing.appspot.com/embedded?enabled={{ .Get 0 }}&example={{ .Get 1 }}&code={{ .Get 2 }}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better use named parameters in this shortcode since we already have 5. They will only be adding up.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opportunity to update embedded playground source to https://play.beam.apache.org/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

## Beam Playground WordCount Example

{{< playground "true" "SDK_JAVA/PRECOMPILED_OBJECT_TYPE_EXAMPLE/MinimalWordCount" "" "700px">}}
{{< playground "true" "SDK_JAVA/PRECOMPILED_OBJECT_TYPE_EXAMPLE/MinimalWordCount" "" "700px" "playgroundIframe">}}
Copy link
Contributor

@alexeyinkin alexeyinkin Jul 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have another vision for this. We often will need Playground with tabs for multiple languages. A shortcode should be like

{{< playground height="700px" >}}
  {{< playground_snippet sdk="java" example="SDK_JAVA/PRECOMPILEDOBJECT_TYPE_EXAMPLE/MinimalWordCount" ... >}}
  {{< playground_snippet sdk="python" ... >}}
{{< /playground >}}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea is that playground_snippet inserts a div with data-xxx attributes or something like this.
playground shortcode then inserts a JS that looks for these nested dives. If only one is given, it renders a single iframe. If multiple are given, it creates tabs.

If you need to push this fast, can you rename playground shortcode to playground_iframe or something like so we can reserve playground shortcode for the above solution?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

renamed playground shortcode to playground_iframe

src="https://frontend-beta-dot-apache-beam-testing.appspot.com/embedded?enabled={{ .Get 0 }}&example={{ .Get 1 }}&code={{ .Get 2 }}"
width="100%"
height="{{ .Get 3 }}"
id="{{ .Get 4 }}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the use for this ID? Is it used outside of the shortcode? If not, can it be generated here or omitted?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed id

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Playground now has subdomain https://play.beam.apache.org/ - would be nice to update

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@bullet03 bullet03 force-pushed the website-add-playground-without-autofocus branch 4 times, most recently from e6b7c47 to 51be88d Compare July 11, 2022 09:55
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's better to add and remove classes to the div instead if tweaking styles at runtime. I suggest to:

  1. Rename this class to playground-iframe-wrapper-no-scroll so it is self-descriptive. (Dashes are for this to go in line with my parallel work on embedding).
  2. On click, add another class playground-iframe-wrapper-scroll that sets pointer-events: auto on iframe so it takes over.
  3. On mouse leave, remove playground-iframe-wrapper-scroll class.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is hard to read without an example. I think I will add it myself when I'm done on my part.
Sorry for the overhead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed Embedding note from README

@alexeyinkin
Copy link
Contributor

I renamed enabled param to editable. enabled was vague, it gives an impression that disabled playground is unable to run the code. editable is more precise.

I did it in this branch because it is likely the fastest way to deploy it, and we want this change before URLs start to spread.

@bullet03 bullet03 force-pushed the website-add-playground-without-autofocus branch 3 times, most recently from 1e197af to 2692f9d Compare July 13, 2022 11:16
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be done on $(this), otherwise we affect all Playground instances on the page.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to include this on each page where this scrolling trick is used? If so, it is inconvenient.

I see the following options to avoid it:

  1. There seems to be a technique to check if a shortcode is used anywhere in the page to include scripts in that case:
    https://gohugo.io/templates/shortcode-templates/#checking-for-existence

  2. Inline JS in the shortcode. It may be non-trivial if we want to avoid IDs on iframes and divs.

  3. Include this JS unconditionally on all pages as the last resort, since Playground will likely be used on most of them.

Copy link
Contributor Author

@bullet03 bullet03 Jul 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, used approach #1.
Made a partial from this code, so it could be reusable in future, since playground will be used on many pages.

{{ if .HasShortcode "playground_iframe" }}
  {{ $fixPlaygroundNestedScroll := resources.Get "js/fix-playground-nested-scroll.js" | minify | fingerprint }}
  <script type="text/javascript" src="{{ $fixPlaygroundNestedScroll.RelPermalink }}" defer></script>
{{ end }}

@bullet03 bullet03 force-pushed the website-add-playground-without-autofocus branch 3 times, most recently from 10ae5c0 to 3dfa455 Compare July 14, 2022 08:53
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only adds this check to get-started, but not the home page. Maybe better add this to footer.html? That will cover all pages on the website.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added to head.html/head_homepage.html

@bullet03 bullet03 force-pushed the website-add-playground-without-autofocus branch 2 times, most recently from 5ad7835 to d9f3fdf Compare July 15, 2022 08:16
Copy link
Contributor

@alexeyinkin alexeyinkin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@bullet03 bullet03 force-pushed the website-add-playground-without-autofocus branch from d9f3fdf to 87bced5 Compare July 15, 2022 12:47
Copy link
Contributor

@alexeyinkin alexeyinkin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@bullet03 bullet03 marked this pull request as ready for review July 15, 2022 16:55
@bullet03 bullet03 force-pushed the website-add-playground-without-autofocus branch from 87bced5 to 62a0d0a Compare July 15, 2022 17:12
@alexeyinkin
Copy link
Contributor

alexeyinkin commented Jul 15, 2022

Known limitations:

  • Mid impact: To avoid text editor inside embedded Playground take over focus and scrolling while user intends to scroll web page and bring mouse over iframe, implemented an overlay container over embedded Playground leaving only top buttons bar (Run, theme, copy, Try Playground) buttons react to the first user click. If user wants to interact with the code example, Result, Graph – user will first need to click (on the overlay container) that will hide the overlay container, and user will be able to interact with Playground code editor (scroll, edit, etc.). When mouse pointer leaves iframe (user navigates away), the overlay container displayed again so user scrolls web page, as intended
  • Low impact: On Beam staging, copy button scrolls user to the top of web not reproduced on a local environment or in the current production environment. Do not expect most users to copy in the scenarios we have for home page and try Playground page. Needs more investigate to understand difference between local and staging behavior. http://apache-beam-website-pull-requests.storage.googleapis.com/21959/index.html
  • Low impact: Firefox browser only – selected text from Results does not loose selection when user clicks outside of Result edit box
  • Low impact: When selecting text in Output window and dragging mouse pointer below the field, the selection is lost because the pointer leaves the iframe. This is a side effect of the workaround to release the focus.

This PR will also expose the trade-off from #22154 (comment) that was chosen to fix #22153. It was not visible before because the embedded Playground was read-only since the last deployment and will become editable again in this PR.

@AKosolapov
Copy link
Contributor

@alexeyinkin Thank you for adding notes from our testing and triage with @alevtinaboiko and @bullet03

Copy link
Contributor

@damondouglas damondouglas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pabloem LGTM

@pabloem pabloem merged commit 29b26be into apache:master Jul 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Website]: Add embedded Playground to home page

6 participants