Skip to content

Commit

Permalink
Renamed the param opfs-browser from Query API, to browser (#651)
Browse files Browse the repository at this point in the history
## What is this PR doing?

Changed the param 'opfs-browser' to 'browser' as discussed at:
#636

Kept the old names working, for now.

## What problem does it solve?

Renamed the opfs-browser parameter to simply browser, to make it easier
for users to remember.
  • Loading branch information
marcarmengou authored Oct 5, 2023
1 parent 0e27fe5 commit 54e16b1
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion packages/docs/site/docs/08-query-api/01-index.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ You can go ahead and try it out. The Playground will automatically install the t
| `lazy` | | Defer loading the Playground assets until someone clicks on the "Run" button |
| `login` | `1` | Logs the user in as an admin |
| `gutenberg-pr` | | Loads the specified Gutenberg Pull Request |
| `storage` | | Selects the storage for Playground: `temporary` gets erased on page refresh, `opfs-browser` is stored in the browser, and `opfs-host` is stored in the selected directory on a local computer. The last two protect the user from accidentally losing their work upon page refresh. |
| `storage` | | Selects the storage for Playground: `temporary` gets erased on page refresh, `browser` is stored in the browser, and `opfs-host` is stored in the selected directory on a device. The last two protect the user from accidentally losing their work upon page refresh. |

For example, the following code embeds a Playground with a preinstalled Gutenberg plugin, and opens the post editor:

Expand Down
6 changes: 3 additions & 3 deletions packages/playground/remote/src/lib/worker-thread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ let virtualOpfsDir: FileSystemDirectoryHandle | undefined;
let lastOpfsDir: FileSystemDirectoryHandle | undefined;
let wordPressAvailableInOPFS = false;
if (
startupOptions.storage === 'opfs-browser' &&
// @ts-ignore
typeof navigator?.storage?.getDirectory !== 'undefined'
(startupOptions.storage === 'opfs-browser' || startupOptions.storage === 'browser') &&
// @ts-ignore
typeof navigator?.storage?.getDirectory !== 'undefined'
) {
virtualOpfsRoot = await navigator.storage.getDirectory();
virtualOpfsDir = await virtualOpfsRoot.getDirectoryHandle('wordpress', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,14 @@ export function PlaygroundConfigurationForm({
<input
type="radio"
name="storage"
value="opfs-browser"
id="storage-opfs-browser"
value="browser"
id="storage-browser"
className={forms.radioInput}
onChange={handleStorageChange}
checked={storage === 'opfs-browser'}
checked={storage === 'browser'}
/>
<label
htmlFor="storage-opfs-browser"
htmlFor="storage-browser"
className={forms.radioLabel}
>
Persistent: stored in this browser
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export default function PlaygroundConfigurationGroup({
});
await playground.goTo('/');

// Read current querystring and replace storage=opfs-browser with storage=opfs-host.
// Read current querystring and replace storage=browser with storage=opfs-host.
const url = new URL(window.location.href);
url.searchParams.set('storage', 'opfs-host');
window.history.pushState({}, '', url.toString());
Expand All @@ -157,7 +157,7 @@ export default function PlaygroundConfigurationGroup({

async function handleSubmit(config: PlaygroundConfiguration) {
const playground = await playgroundRef.current!.promise;
if (config.resetSite && config.storage === 'opfs-browser') {
if (config.resetSite && (config.storage === 'opfs-browser' || config.storage === 'browser')) {
if (
!window.confirm(
'This will wipe out all stored data and start a new site. Do you want to proceed?'
Expand All @@ -176,14 +176,14 @@ export default function PlaygroundConfigurationGroup({
WP {runningWp || currentConfiguration.wp} {' - '}
{currentConfiguration.storage === 'opfs-host'
? `Local (${dirName})`
: currentConfiguration.storage === 'opfs-browser'
: currentConfiguration.storage === 'opfs-browser' || currentConfiguration.storage === 'browser'
? 'Persistent'
: '⚠️ Temporary'}
</Button>
{currentConfiguration.storage === 'opfs-host' ? (
<SyncLocalFilesButton />
) : null}
{currentConfiguration.storage === 'opfs-browser' ? (
{currentConfiguration.storage === 'opfs-browser' || currentConfiguration.storage === 'browser' ? (
<StartOverButton />
) : null}
{isResumeLastDirOpen ? (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ export async function reloadWithNewConfiguration(
playground: PlaygroundClient,
config: PlaygroundConfiguration
) {
if (config.resetSite && config.storage === 'opfs-browser') {
await playground?.resetVirtualOpfs();
if (config.resetSite && (config.storage === 'opfs-browser' || config.storage === 'browser')) {
await playground?.resetVirtualOpfs();
}

const url = new URL(window.location.toString());
Expand Down
2 changes: 1 addition & 1 deletion packages/playground/website/src/lib/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { buildVersion } from './config';

interface UsePlaygroundOptions {
blueprint?: Blueprint;
storage?: 'opfs-host' | 'opfs-browser' | 'temporary';
storage?: 'opfs-host' | 'opfs-browser' | 'browser' | 'temporary';
}
export function usePlayground({ blueprint, storage }: UsePlaygroundOptions) {
const iframeRef = useRef<HTMLIFrameElement>(null);
Expand Down
2 changes: 1 addition & 1 deletion packages/playground/website/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export const StorageTypes = ['opfs-browser', 'temporary', 'opfs-host'] as const;
export const StorageTypes = ['browser', 'temporary', 'opfs-host', 'opfs-browser'] as const;
export type StorageType = (typeof StorageTypes)[number];

0 comments on commit 54e16b1

Please sign in to comment.