-
Notifications
You must be signed in to change notification settings - Fork 273
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
WIP: Use selected site settings #1707
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
import { Blueprint } from '@wp-playground/blueprints'; | ||
import { makeBlueprint } from './make-blueprint'; | ||
import { type SiteInfo } from './site-storage'; | ||
|
||
const defaultPhpVersion = '8.0'; | ||
|
||
/** | ||
* Get a URL with query params representing the specified site settings. | ||
* | ||
* @param baseUrl The current Playground URL | ||
* @param siteInfo The site info to convert to Playground query params | ||
* @returns URL with query params representing the site info | ||
*/ | ||
export function siteInfoToUrl(baseUrl: URL, siteInfo: SiteInfo): URL { | ||
const newUrl = new URL(baseUrl); | ||
newUrl.search = ''; | ||
|
||
const query = newUrl.searchParams; | ||
query.set('php', siteInfo.phpVersion || defaultPhpVersion); | ||
query.set('wp', siteInfo.wpVersion || 'latest'); | ||
query.set('site-slug', siteInfo.slug); | ||
|
||
const preservedQueryParams = ['language', 'networking', 'storage']; | ||
for (const key of preservedQueryParams) { | ||
if (baseUrl.searchParams.has(key)) { | ||
query.set(key, baseUrl.searchParams.get(key)!); | ||
} | ||
} | ||
|
||
// TODO as playgroundFeatures | ||
// if (blueprint.features?.networking) { | ||
// query.set('networking', 'yes'); | ||
// } | ||
|
||
// TODO | ||
// if (blueprint.language) { | ||
// query.set('language', blueprint.language); | ||
// } | ||
|
||
// TODO | ||
// if (blueprint.theme) { | ||
// query.set('theme', blueprint.theme); | ||
// } | ||
|
||
// TODO | ||
// query.set('login', blueprint.login ? 'yes' : 'no'); | ||
// query.set('multisite', blueprint.multisite ? 'yes' : 'no'); | ||
|
||
// TODO | ||
// if (blueprint.plugins && blueprint.plugins.length > 0) { | ||
// blueprint.plugins.forEach(plugin => query.append('plugin', plugin)); | ||
//} | ||
|
||
// TODO | ||
// if (blueprint.landingPage) { | ||
// query.set('url', blueprint.landingPage); | ||
// } | ||
|
||
// TODO as playgroundFeatures | ||
// if (blueprint.phpExtensionBundles && blueprint.phpExtensionBundles.length > 0) { | ||
// blueprint.phpExtensionBundles.forEach(bundle => query.append('php-extension-bundle', bundle)); | ||
// } | ||
|
||
// TODO: Maybe | ||
// if (blueprint.importSite) { | ||
// query.set('import-site', blueprint.importSite); | ||
// } | ||
|
||
// TODO: Maybe | ||
// if (blueprint.importWxr) { | ||
// query.set('import-wxr', blueprint.importWxr); | ||
// } | ||
|
||
return newUrl; | ||
} | ||
|
||
/** | ||
* Create a Blueprint based on Playground query params. | ||
* | ||
* @param query Query params to convert to a Blueprint | ||
* @returns A Blueprint reflecting the settings specified by query params | ||
*/ | ||
export function queryParamsToBlueprint(query: URLSearchParams): Blueprint { | ||
const features: Blueprint['features'] = {}; | ||
|
||
/** | ||
* Networking is disabled by default, so we only need to enable it | ||
* if the query param is explicitly set to "yes". | ||
*/ | ||
if (query.get('networking') === 'yes') { | ||
features['networking'] = true; | ||
} | ||
const blueprint = makeBlueprint({ | ||
php: query.get('php') || defaultPhpVersion, | ||
wp: query.get('wp') || 'latest', | ||
theme: query.get('theme') || undefined, | ||
login: !query.has('login') || query.get('login') === 'yes', | ||
multisite: query.get('multisite') === 'yes', | ||
features, | ||
plugins: query.getAll('plugin'), | ||
landingPage: query.get('url') || undefined, | ||
phpExtensionBundles: query.getAll('php-extension-bundle') || [], | ||
importSite: query.get('import-site') || undefined, | ||
importWxr: | ||
query.get('import-wxr') || query.get('import-content') || undefined, | ||
language: query.get('language') || undefined, | ||
}); | ||
|
||
return blueprint; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Aha! We've hit the runtime configuration vs site configuration problem (see "Runtime setup options"). This is an important one. Let's not rush a solution but take it slow and methodically. We're effectively building a v1 of the runtime configuration interface here.
Let's treat things like languages, themes, plugins, multisite etc. as build-time features that are only relevant when the site is first created. If we tried re-applying them to an existing site, we'd end up with, say, two copies of the same theme – that's not what the user expects.
That leaves us with settings that don't trigger any filesystem– or database–level updates in
/wordpress
. For sure that's networking, PHP version, and landing page. Probably alsologin
, even though it causes some database writes. What else?We don't yet have the plumbing to hotswap the WordPress version so let's remove the "WP Version" from the "edit site" form for now. Same for the language and the storage option. That's tangential but relevant.
Here's another question: When user changes the runtime configuration of an existing site, how will we save that information? We can either alter the original Blueprint, or store runtime configuration in another file. What would you do here?
Tangentially related: Down the road we will provide a way of applying a Blueprint to an existing site. At that time, we will want to combine the new Blueprint with the original one used to boot that site. There's nothing immediately actionable today. Regardless of the direction this PR takes, I'm just noticing the problem of rewriting/merging Blueprints will come back on more than one occasion.
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 wonder what would be the ripple effect of decoupling the runtime options across JS API, Blueprints API, Query API, if any.
For example, imagine a version of the Query API that distinguishes between "site build options" and "runtime options":
https://playground.wordpress.net/?build[plugin]=gutenberg&runtime[networking]=yes
These long names would be difficult to type and to remember so our current short parameters (
?plugin=gutenberg&networking=yes
) seem to be a more useful choice.However, Blueprints and JS API are quite verbose already so maybe there may be an opportunity for an API refresh in there. If not, perhaps the documentation could distinguish between the two types of configuration options 🤔
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.
Also, notice this translates Blueprint->Query args only for Playground to do Query args->Blueprint. What if we passed the Blueprint directly? Or even just the site slug, since we know the config for each slug?
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 would be highly useful to have stable site URLs. Say I go to playground.wordpress.net/my–base–theme and it always brings up the same site. Also, the site itself wouldn't use a random numeric scope, but the slug
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.
Then we could pair that with github autocommit and offer public site urls, e.g. public.playground.wordpress.net/adamziel/blog
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.
And that could later form v1 of collaboration and site sync. Cc @akirk @griffbrad @dawidurbanski @dmsnell