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

Blueprints sidebar section for single-click Playground presets #1759

Merged
merged 4 commits into from
Oct 10, 2024

Conversation

adamziel
Copy link
Collaborator

@adamziel adamziel commented Sep 12, 2024

Motivation for the change, related issues

Adds the Blueprint Gallery to the Playground UI as a first-class feature.

CleanShot 2024-10-10 at 13 40 17@2x

Implementation

Sourcing the list of Blueprints

GitHub automation maintains a JSON index of all the Blueprints in the directory at https://raw.githubusercontent.com/WordPress/blueprints/trunk/index.json. This PR just sources that data and adds a DataView where it can be browsed.

It ships a new useFetch() React hook that makes the state management around fetch() easier. Maybe this simplistic hook will be enough, or maybe we'll quickly replace it with react-query or so. We'll see.

Fetch proxy for offline caching

This PR ships a "proxy" service worker route for offline caching of cross-origin requests.

Playground is now an offline-enabled PWA and anytime we rely on network resources, we must consider what happens when there's network connectivity.

For same-origin request, that's easy. We can just cache them in the fetch event handler in the service worker. However, that event handler won't handle cross-origin requests. Therefore, this PR ships a special same-origin /proxy/network-first-fetch/ route that can cache cross-origin requests in CacheStorage.

For example, the following request would fetch the list of all the Blueprints from the Blueprints directory:

https://playground.wordpress.net/proxy/network-first-fetch/https://raw.githubusercontent.com/WordPress/blueprints/trunk/index.json

The service worker would be notified, then it would strip the https://playground.wordpress.net/proxy/network-first-fetch/ prefix, and source the actual information from https://raw.githubusercontent.com/WordPress/blueprints/trunk/index.json. If the network is available, it will always request the fresh data. If the network is not available, it would source the data from CacheStorage if available.

Testing Instructions

Interact with the gallery, confirm it works in the offline mode, confirm the blueprints load without issues and that the rest of the UI works the same as before this PR.

Follow-up work

  • Revisit the design based on user feedback and @jarekmorawski's explorations in Figma
  • Integrate with the Blueprints builder when it's ready
  • Add GitHub connection to make contributing Blueprints easy
  • Integrate with the upcoming visual Blueprints builder

cc @brandonpayton @bgrgicak @mtias

@adamziel adamziel added [Type] UI / UX / User Experience [Type] Exploration An exploration that may or may not result in mergable code [Feature] Blueprints Builder labels Sep 12, 2024
@mtias
Copy link
Member

mtias commented Sep 12, 2024

Nice, this is cool

@bgrgicak
Copy link
Collaborator

This is great! Let's see with @jarekmorawski how to integrate it into the new UI.

Consider accepting Blueprint preview thumbnails in the directory

I don't think that we need this for v1. It's frequently hard to visualize a blueprint in an interesting way (examples add mu-plugin, install theme from git).

UX decision – should the "preview button" keep spinning new sites? Or should it kill the previous Blueprint preview?

I would keep it consistent with the rest of the UI. Clicking on preview should start that site on the right side of the sidebar. Ideally as a temporary site so that users can save it from the manage UI if they want to.

@adamziel
Copy link
Collaborator Author

adamziel commented Sep 14, 2024

I would keep it consistent with the rest of the UI. Clicking on preview should start that site on the right side of the sidebar. Ideally as a temporary site so that users can save it from the manage UI if they want to.

Right, but would clicking through 10 Blueprints leave me with 10 temporary sites? Or would it clean up those sites as I browse?

An idea: create a single temporary Playground called "Blueprint preview" and reset it with the last selected Blueprint every time.

@bgrgicak
Copy link
Collaborator

Right, but would clicking through 10 Blueprints leave me with 10 temporary sites? Or would it clean up those sites as I browse?

The temp site could be created when you expand the site, so if you are just clicking on items, they wouldn't be created.
But making it deliberate and offering the user a save button seems like a better choice.

This would also be useful for temporary sites in general.

@brandonpayton
Copy link
Member

This is such a great idea.

An idea: create a single temporary Playground called "Blueprint preview" and reset it with the last selected Blueprint every time.

Since #1731 is keeping multiple temporary sites in-memory, this sounds like a good compromise to me. Perhaps we could create a separate temporary site (and notify the user) whenever they start interacting with "Blueprint preview". At that point, they aren't merely clicking through options but have started "trying things on".

@bgrgicak
Copy link
Collaborator

I'm wondering if using the blueprint gallery will be the best thing in the long term.

This section is technically Playground Apps. You go there and add a WordPress-based app to your Playground.

The Blueprint gallery is more about showing the technical capabilities of Playground while this could be much more.

Imagine going to Playground.WordPress.net or your locally installed PWA and seeing all your apps there.
You have a note-taking app built from the post editor and a search plugin.
You have a development environment, a collection of code, and SQL editing plugins.
You have a RSS reader for everything that you follow...

To get more apps you just go to the apps section and install more.
Submitting a new app is just writing a blueprint which anyone can do with the help of GPT and our documentation.

@asirota
Copy link

asirota commented Sep 24, 2024

Can someone inspect the underlying json?

@bgrgicak
Copy link
Collaborator

Can someone inspect the underlying json?

@asirota I'm happy to help, please open new issue and share the file with us.

@asirota
Copy link

asirota commented Sep 25, 2024

@bgrgicak sorry I wasn't more clear. I meant could there be a feature in this to inspect the json of the blueprint being previewed? Useful for learners.

@adamziel
Copy link
Collaborator Author

I'm wondering if using the blueprint gallery will be the best thing in the long term.
This section is technically Playground Apps. You go there and add a WordPress-based app to your Playground.
The Blueprint gallery is more about showing the technical capabilities of Playground while this could be much more.

To me, showcasing technical capabilities is just a convenient starting point for the Blueprints gallery. It can be both a source of demos and a source of powerful apps. Both use-cases require a central location, contributing workflows, integrations, ways of forking and remixing the Blueprints. Why split that in two places? Once we have powerful app-like Blueprints, we can just add a "features": true meta flag to show or hide then in the webapp.

Note all WordPress directories already work this way. There are demo themes like stacks, and there are powerful themes like TwentyTwentyFour. There are demo blocks and app-like block suites. There are demo plugins like hello-dolly or classic-editor, and there are app-like plugins such as WooCommerce.

And in an even longer term, we can propose Blueprints for WordPress core and it will already have an extensive Blueprints directory on day 1.

@bgrgicak
Copy link
Collaborator

To me, showcasing technical capabilities is just a convenient starting point for the Blueprints gallery. It can be both a source of demos and a source of powerful apps.

I agree, it's more about the naming, but I'm probably jumping 5 steps ahead.
We definitely first need some apps before we can start calling it like that.

Base automatically changed from routing to trunk September 27, 2024 17:00
@adamziel adamziel force-pushed the trunk branch 2 times, most recently from 680cd19 to 2e376d2 Compare October 4, 2024 09:24
@adamziel adamziel closed this Oct 10, 2024
@adamziel adamziel reopened this Oct 10, 2024
@adamziel adamziel marked this pull request as ready for review October 10, 2024 11:40
@adamziel adamziel requested a review from a team as a code owner October 10, 2024 11:40
@adamziel adamziel merged commit aaa764a into trunk Oct 10, 2024
8 of 9 checks passed
@adamziel adamziel deleted the blueprints-apps branch October 10, 2024 13:07
@juanmaguitar
Copy link
Collaborator

juanmaguitar commented Oct 12, 2024

Closing this related issue: #1463

brandonpayton added a commit that referenced this pull request Nov 23, 2024
## Motivation for the change, related issues

We added a general CSS reset to the web app styles in
#1759, and some
modal dialog content depended on user agent styles for rendering
properly.

For example, before the CSS reset, the GitHub auth dialog used to be
styled like this:
<img
src="https://github.com/user-attachments/assets/b3a2c91b-6a30-4385-9a90-190b510bcd44"
width="600">

After the reset, its paragraphs lost default vertical margins, and
content in a `<b>` element lost its bold look. After the reset, the
dialog looked like this:
<img
src="https://github.com/user-attachments/assets/005b8d9f-3fe2-446b-ab7f-0f9fccb47854"
width="600">

## Implementation details

The PR attempts to restore the styles assumed by modals before this
change.

This PR adds some style rules for modals to restore vertical margins to
paragraph elements and boldness to `<b>` tags. A downside to this
approach is that we'll have to manually add CSS rules every time we miss
a user agent style that was reset, but an upside to the approach is that
we can have consistent, explicit rules for the styles we require.

## Testing Instructions (or ideally a Blueprint)

Run `npm run dev`, open all the different dialogs, and confirm they are
styled as expected.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Blueprints Builder [Type] Exploration An exploration that may or may not result in mergable code [Type] UI / UX / User Experience
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

6 participants