diff --git a/docs/guide/creating-a-site.md b/docs/guide/creating-a-site.md index 3c1609d5..216b789c 100644 --- a/docs/guide/creating-a-site.md +++ b/docs/guide/creating-a-site.md @@ -4,13 +4,13 @@ A site is your own copy of the project you contribute to, cloned into a folder y You do not need one, though, for every work item. A site holds as many Core tickets or Gutenberg issues as you like, each on its own branch, and moving between them costs seconds rather than another clone and another build — see [Working on several work items](./ticket-branches). Create a second site when you want a genuinely separate environment: a different snapshot of trunk, or somewhere to test somebody else's work without disturbing the site you are working in. -When the app starts with no sites, the main area shows a short prompt to create your first one. +When the app starts with no sites, it opens the dialog that creates one for you. If you close the dialog, the main area shows a short prompt to create your first site. ![The app before any site exists: No sites, Create your first site to begin contributing, and a Create site button in the middle of the window](/screenshots/empty-state.png) ## Start the creation flow -Click **Create site** in the middle of the window when there are no sites yet, or **Create new site** at the top of the sites list once there are. A dialog opens with three fields. +When the app starts with no sites, the dialog is already open. Otherwise, click **Create site** in the middle of the window when there are no sites yet, or **Create new site** at the top of the sites list once there are. The dialog has three fields. ![The Create site dialog, with a Site name text field, a Project choice between WordPress Core and Gutenberg, with lines under it that describe the one selected and say it cannot be changed later, and a Location folder picker](/screenshots/create-site-modal.png) diff --git a/docs/public/screenshots/create-site-modal.png b/docs/public/screenshots/create-site-modal.png index e7d8ccda..13dc8fa3 100644 Binary files a/docs/public/screenshots/create-site-modal.png and b/docs/public/screenshots/create-site-modal.png differ diff --git a/scripts/screenshots/shots.cjs b/scripts/screenshots/shots.cjs index 1fc5b4ab..17f45170 100644 --- a/scripts/screenshots/shots.cjs +++ b/scripts/screenshots/shots.cjs @@ -199,7 +199,12 @@ const shots = [ slug: 'empty-state', tier: 'fixture', variant: 'empty', + // What is behind the dialog an empty launch opens by itself (#730), + // once it is closed. prepare: async (page) => { + await ui.createSiteDialog(page).waitFor(); + await page.keyboard.press('Escape'); + await ui.createSiteDialog(page).waitFor({ state: 'detached' }); await ui.noSitesTitle(page).waitFor(); } }, @@ -207,8 +212,8 @@ const shots = [ slug: 'create-site-modal', tier: 'fixture', variant: 'empty', + // An empty launch opens it by itself (#730). prepare: async (page) => { - await ui.createFirstSiteButton(page).click(); await ui.createSiteDialog(page).getByText('Site name').waitFor(); } }, diff --git a/src/renderer/hooks/use-sites.jsx b/src/renderer/hooks/use-sites.jsx index 152cdccc..3930f5e6 100644 --- a/src/renderer/hooks/use-sites.jsx +++ b/src/renderer/hooks/use-sites.jsx @@ -7,8 +7,12 @@ import { useCallback, useEffect, useState } from 'react'; // `setSiteMeta` keeps its old signature so every other caller is untouched; // `applySetup` is for the changes that need the pair, which is every change the // create flow makes. +// `loaded` is whether the first read has answered: until it has, the empty +// list is not an answer, and a window cannot tell "no sites" from "not read +// yet". It is state of its own because `applySetup` replaces the pair whole. export function useSites() { const [state, setState] = useState({ sites: [], siteMeta: {} }); + const [loaded, setLoaded] = useState(false); const setSiteMeta = useCallback((update) => setState((prev) => ({ ...prev, siteMeta: typeof update === 'function' ? update(prev.siteMeta) : update @@ -17,7 +21,8 @@ export function useSites() { const refresh = useCallback(async () => { const { sites: list, siteMeta: meta } = await window.api.getSitesWithMeta(); setState({ sites: list, siteMeta: meta || {} }); + setLoaded(true); }, []); useEffect(() => { refresh(); }, [refresh]); - return { sites: state.sites, siteMeta: state.siteMeta, refresh, setSiteMeta, applySetup }; + return { sites: state.sites, siteMeta: state.siteMeta, loaded, refresh, setSiteMeta, applySetup }; } diff --git a/src/renderer/index.jsx b/src/renderer/index.jsx index 8b4327f3..957c66d4 100644 --- a/src/renderer/index.jsx +++ b/src/renderer/index.jsx @@ -90,6 +90,7 @@ import { useContributorProvenance } from './hooks/use-contributor-provenance.jsx import { useSettings } from './hooks/use-settings.jsx'; import { phpVersionChoice, resumeFor } from './settings-view.cjs'; import { autoStartPlan } from './auto-start.cjs'; +import { launchCreateOffer } from './launch-create-offer.cjs'; import { useNextActionCue } from './hooks/use-next-action-cue.jsx'; import { useSites } from './hooks/use-sites.jsx'; import { usePullRequest } from './hooks/use-pull-request.jsx'; @@ -114,7 +115,7 @@ const SILENT = ''; const FEEDBACK_FORM_URL = 'https://docs.google.com/forms/d/e/1FAIpQLScnMxicyDxZO2OoaS5ela8FArYWjCyLfC3hxRBBRSF7XLPzKg/viewform'; function App({ settingsState }) { - const { sites, siteMeta, refresh, setSiteMeta, applySetup } = useSites(); + const { sites, siteMeta, loaded: sitesLoaded, refresh, setSiteMeta, applySetup } = useSites(); // The confirmation queue for the whole window. It lives here, above every // SiteRow, because only one row is visible at a time and a per-row toast would // be hidden along with its inactive row. See ConfirmationContext in hooks/use-confirmation.jsx. @@ -378,6 +379,15 @@ function App({ settingsState }) { setCreateModalOpen(true); }, [createSubmitting]); + // A window that opens with no site in it opens the dialog that makes one + // (#730). When, and that it happens once, is launch-create-offer.cjs's. + const offeredCreateRef = useRef(false); + useEffect(() => { + const offer = launchCreateOffer({ offered: offeredCreateRef.current, sitesLoaded, settings, siteCount: sites.length }); + if (offer.consume) offeredCreateRef.current = true; + if (offer.open) setCreateModalOpen(true); + }, [sitesLoaded, settings, sites]); + // What the create-site dialog hands over once it has every answer: the name, // trimmed, the parent folder and the project. The dialog closes here, and the // setup it started goes on without it. diff --git a/src/renderer/launch-create-offer.cjs b/src/renderer/launch-create-offer.cjs new file mode 100644 index 00000000..c23e3ed8 --- /dev/null +++ b/src/renderer/launch-create-offer.cjs @@ -0,0 +1,27 @@ +'use strict'; + +/** + * Whether a window that has just opened offers the create-site dialog (#730). + * + * An empty window with a "Create site" button nobody knew the meaning of was + * where newcomers stopped, so a window that opens with no site in it opens + * the dialog. The offer is an edge, consumed once per window: closing the + * dialog, or deleting the last site later, leaves the empty state. It is + * decided only once both reads have answered: the site list, which is empty + * for everyone until then, and the settings, since the dialog takes its + * folder from them as it opens (#559). Kept as a pure module so `node --test` + * covers the decision; the window keeps the flag and the call. + * + * @param {Object} root0 + * @param {boolean} root0.offered The offer has been consumed in this window. + * @param {boolean} root0.sitesLoaded The first read of the site list has answered. + * @param {?Object} root0.settings The settings, or null until read. + * @param {number} root0.siteCount How many sites the list has. + * @return {{consume: boolean, open: boolean}} Whether to consume the offer, and whether to open the dialog. + */ +function launchCreateOffer({ offered, sitesLoaded, settings, siteCount }) { + if (offered || !sitesLoaded || !settings) return { consume: false, open: false }; + return { consume: true, open: siteCount === 0 }; +} + +module.exports = { launchCreateOffer }; diff --git a/tests/e2e/journeys/delete-site.spec.js b/tests/e2e/journeys/delete-site.spec.js index 7684131f..4788ff4d 100644 --- a/tests/e2e/journeys/delete-site.spec.js +++ b/tests/e2e/journeys/delete-site.spec.js @@ -75,6 +75,11 @@ test( 'a site is deleted only after a question that names it, and nothing but a await ui.confirmYesButton( page, 'Delete site' ).click(); await expect( question ).toHaveCount( 0 ); await expect( ui.noSitesTitle( page ) ).toBeVisible( { timeout: 30_000 } ); + // INVARIANT — the dialog an empty launch opens is for the launch, not for + // a window that has just been emptied (#730). Read after a question the + // page has answered, so a dialog the empty list had opened would be there. + await page.evaluate( () => window.api.getSitesWithMeta() ); + await expect( ui.createSiteDialog( page ) ).toHaveCount( 0 ); expect( fs.existsSync( site.dir ) ).toBe( false ); expect( session.readSettings().sites ).toEqual( [] ); } ); diff --git a/tests/e2e/journeys/i18n.spec.js b/tests/e2e/journeys/i18n.spec.js index 88a9dbe4..413ae6f2 100644 --- a/tests/e2e/journeys/i18n.spec.js +++ b/tests/e2e/journeys/i18n.spec.js @@ -73,8 +73,22 @@ async function unwrapped( locator ) { return found.filter( ( text ) => text && ! /^\[[\s\S]*\]$/.test( text ) && ! UNTRANSLATED.has( text ) && ! CONSTANT_NAMES.test( text ) ); } +/** + * Closes the create-site dialog a launch with no site opens by itself (#730), + * for a journey that is about what is behind it. + * + * @param {Object} page + */ +async function closeLaunchDialog( page ) { + const dialog = page.getByRole( 'dialog', { name: pseudoLocalize( 'Create site' ), exact: true } ); + await expect( dialog ).toBeVisible( { timeout: 30_000 } ); + await page.keyboard.press( 'Escape' ); + await expect( dialog ).toHaveCount( 0 ); +} + test( 'the first-run screen and the create-site dialog are fully translatable', async ( { session } ) => { const { page } = await session.start( undefined, { lang: 'en-XA' } ); + await closeLaunchDialog( page ); const createButton = page.getByRole( 'button', { name: pseudoLocalize( 'Create site' ), exact: true } ); await expect( createButton ).toBeVisible( { timeout: 30_000 } ); @@ -115,6 +129,7 @@ test( 'the first-run screen and the create-site dialog are fully translatable', test( 'the settings dialog is fully translatable, on both of its tabs', async ( { session } ) => { const { page } = await session.start( undefined, { lang: 'en-XA' } ); + await closeLaunchDialog( page ); await page.getByRole( 'button', { name: pseudoLocalize( 'Settings' ), exact: true } ).click(); const dialog = page.getByRole( 'dialog', { name: pseudoLocalize( 'Settings' ), exact: true } ); await expect( dialog ).toBeVisible(); @@ -1279,6 +1294,7 @@ test( 'the ticket card\'s questions and notices are fully translatable: a refuse test( 'what a ticket from a link says is fully translatable, with no site to put it in', async ( { session } ) => { const { app, page } = await session.start( undefined, { lang: 'en-XA' } ); + await closeLaunchDialog( page ); await expect( page.getByRole( 'button', { name: pseudoLocalize( 'Create site' ), exact: true } ) ).toBeVisible( { timeout: 30_000 } ); await app.evaluate( ( { app: electronApp }, url ) => { electronApp.emit( 'open-url', { preventDefault() {} }, url ); @@ -1509,6 +1525,7 @@ test( 'the Playground web server is fully translatable, stopped, starting, runni }, [ channel, payload ] ); const notices = page.locator( '.page-body-notices' ); const SERVER_OUTPUT = 'listening for requests'; + await closeLaunchDialog( page ); await page.getByRole( 'button', { name: pseudoLocalize( 'Start Playground web server' ), exact: true } ).click( { timeout: 30_000 } ); await expect( page.getByText( pseudoLocalize( 'Playground web server' ), { exact: true } ) ).toBeVisible(); diff --git a/tests/e2e/journeys/shell.spec.js b/tests/e2e/journeys/shell.spec.js index 0de39fee..c20a78f2 100644 --- a/tests/e2e/journeys/shell.spec.js +++ b/tests/e2e/journeys/shell.spec.js @@ -72,6 +72,8 @@ test( 'the sites list opens a site without closing the others, and the open site // one the app opens on. await expect( ui.siteHeading( page, 'newer-site' ) ).toBeVisible( { timeout: 30_000 } ); await expect( page.getByRole( 'grid' ).getByRole( 'row' ) ).toHaveText( [ /newer-site/, /older-site/ ] ); + // INVARIANT — a launch with sites does not open the create dialog (#730). + await expect( ui.createSiteDialog( page ) ).toHaveCount( 0 ); // INVARIANT — the list says which site is open, and the page's header says // its name and its project. await expect( newer ).toHaveAttribute( 'aria-pressed', 'true' ); @@ -221,7 +223,7 @@ test( 'the sites list can be put away and brought back, and while it is away it await expect( ui.createSiteButton( page ) ).toBeFocused(); } ); -test( 'a window with no site in it has no list, says what to do, and keeps the footer', async ( { session } ) => { +test( 'a window with no site in it opens the create dialog, says what to do once it is closed, and keeps the footer', async ( { session } ) => { const { app, page } = await session.start(); const opened = async () => app.evaluate( () => global.__e2eOpened ); await app.evaluate( ( { ipcMain } ) => { @@ -233,16 +235,25 @@ test( 'a window with no site in it has no list, says what to do, and keeps the f } ); } ); - // INVARIANT — there is nothing to list, so there is no list and no button - // to hide one: the window says there are no sites and offers the one thing - // to do about it. - await expect( ui.noSitesTitle( page ) ).toBeVisible( { timeout: 30_000 } ); + // INVARIANT — a launch with nothing in it opens the one thing to do + // (#730), on the name. + const dialog = ui.createSiteDialog( page ); + await expect( dialog ).toBeVisible( { timeout: 30_000 } ); + await expect( dialog.getByLabel( 'Site name', { exact: true } ) ).toBeFocused(); + await page.keyboard.press( 'Escape' ); + await expect( dialog ).toHaveCount( 0 ); + + // INVARIANT — closed, it stays closed. There is nothing to list, so there + // is no list and no button to hide one: the window says there are no sites + // and offers the one thing to do about it. + await expect( ui.noSitesTitle( page ) ).toBeVisible(); + await expect( dialog ).toHaveCount( 0 ); await expect( page.getByRole( 'region', { name: 'My sites' } ) ).toHaveCount( 0 ); await expect( hideSitesListButton( page ) ).toHaveCount( 0 ); await ui.createFirstSiteButton( page ).click(); - await expect( ui.createSiteDialog( page ) ).toBeVisible(); + await expect( dialog ).toBeVisible(); await page.keyboard.press( 'Escape' ); - await expect( ui.createSiteDialog( page ) ).toHaveCount( 0 ); + await expect( dialog ).toHaveCount( 0 ); // INVARIANT — giving feedback is about the app, so it is there with no // site. It says where the form is and who reads it before anything is @@ -260,6 +271,19 @@ test( 'a window with no site in it has no list, says what to do, and keeps the f await expect( openForm ).toHaveCount( 0 ); } ); +test( 'the dialog an empty launch opens starts in the folder the settings say new sites go in', async ( { session } ) => { + const parent = session.track( fs.mkdtempSync( path.join( os.tmpdir(), 'wpct-e2e-parent-' ) ) ); + const { page } = await session.start( { sites: [], siteMeta: {}, preferences: { newSiteLocation: parent } } ); + + // INVARIANT — the dialog a launch opens by itself starts where the + // settings say new sites go, as the one the button opens does (#559, #730). + // That it waits for the settings to be read is launch-create-offer.cjs's, + // and its unit tests': here they are read before the window is drawn. + const dialog = ui.createSiteDialog( page ); + await expect( dialog ).toBeVisible( { timeout: 30_000 } ); + await expect( dialog.getByText( parent, { exact: true } ) ).toBeVisible(); +} ); + test( 'the window opens at the size the shell is designed for, or the screen\'s if that is smaller, and cannot be made smaller than its page', async ( { session } ) => { const { app } = await session.start(); const measured = await app.evaluate( ( { BrowserWindow, screen } ) => { diff --git a/tests/e2e/real-setup/create-site.spec.js b/tests/e2e/real-setup/create-site.spec.js index 93bafc79..4393c2a0 100644 --- a/tests/e2e/real-setup/create-site.spec.js +++ b/tests/e2e/real-setup/create-site.spec.js @@ -53,8 +53,9 @@ for ( const target of TARGETS ) { try { await test.step( 'Create a site in an isolated temporary directory', async () => { await session.answerFileDialog( [ parent ] ); - await ui.createFirstSiteButton( page ).click(); + // An empty launch opens the dialog itself (#730). const modal = ui.createSiteDialog( page ); + await expect( modal ).toBeVisible( { timeout: 30_000 } ); const choice = modal.getByRole( 'radio', { name: target.choice, exact: true } ); await choice.click(); await expect( choice ).toBeChecked(); diff --git a/tests/unit/launch-create-offer.test.cjs b/tests/unit/launch-create-offer.test.cjs new file mode 100644 index 00000000..f6b34f9c --- /dev/null +++ b/tests/unit/launch-create-offer.test.cjs @@ -0,0 +1,29 @@ +'use strict'; + +const test = require('node:test'); +const assert = require('node:assert/strict'); + +const { launchCreateOffer } = require('../../src/renderer/launch-create-offer.cjs'); + +const SETTINGS = { newSiteLocation: null }; +const wait = { consume: false, open: false }; + +test('a window whose reads have both answered with no site consumes the offer and opens the dialog', () => { + assert.deepEqual(launchCreateOffer({ offered: false, sitesLoaded: true, settings: SETTINGS, siteCount: 0 }), { consume: true, open: true }); +}); + +test('a window whose reads have both answered with a site consumes the offer without opening the dialog', () => { + assert.deepEqual(launchCreateOffer({ offered: false, sitesLoaded: true, settings: SETTINGS, siteCount: 2 }), { consume: true, open: false }); +}); + +test('an empty list that has not been read yet is not an answer, so nothing is decided', () => { + assert.deepEqual(launchCreateOffer({ offered: false, sitesLoaded: false, settings: SETTINGS, siteCount: 0 }), wait); +}); + +test('settings that have not been read yet wait, since the dialog takes its folder from them as it opens', () => { + assert.deepEqual(launchCreateOffer({ offered: false, sitesLoaded: true, settings: null, siteCount: 0 }), wait); +}); + +test('an offer already consumed is never made again, so emptying the list later does not reopen the dialog', () => { + assert.deepEqual(launchCreateOffer({ offered: true, sitesLoaded: true, settings: SETTINGS, siteCount: 0 }), wait); +});