From 8bd9d58f1eeb5f9bb3ee606b4d3d058216dec7fd Mon Sep 17 00:00:00 2001 From: tellthemachines Date: Fri, 26 Nov 2021 16:17:03 +1100 Subject: [PATCH 1/5] Show notice on save in site editor --- .../components/entities-saved-states/index.js | 32 +++++++++++++++---- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/packages/editor/src/components/entities-saved-states/index.js b/packages/editor/src/components/entities-saved-states/index.js index ea5e4e5fa25ec..86eff388ab75d 100644 --- a/packages/editor/src/components/entities-saved-states/index.js +++ b/packages/editor/src/components/entities-saved-states/index.js @@ -14,6 +14,7 @@ import { store as coreStore } from '@wordpress/core-data'; import { store as blockEditorStore } from '@wordpress/block-editor'; import { __experimentalUseDialog as useDialog } from '@wordpress/compose'; import { close as closeIcon } from '@wordpress/icons'; +import { store as noticesStore } from '@wordpress/notices'; /** * Internal dependencies @@ -79,6 +80,10 @@ export default function EntitiesSavedStates( { close } ) { const { __unstableMarkLastChangeAsPersistent } = useDispatch( blockEditorStore ); + + const { createSuccessNotice, createErrorNotice } = useDispatch( + noticesStore + ); // To group entities by type. const partitionedSavables = groupBy( dirtyEntityRecords, 'name' ); @@ -139,6 +144,7 @@ export default function EntitiesSavedStates( { close } ) { close( entitiesToSave ); const siteItemsToSave = []; + const pendingSavedRecords = []; entitiesToSave.forEach( ( { kind, name, key, property } ) => { if ( 'root' === kind && 'site' === name ) { siteItemsToSave.push( property ); @@ -153,19 +159,33 @@ export default function EntitiesSavedStates( { close } ) { editEntityRecord( kind, name, key, { status: 'publish' } ); } - saveEditedEntityRecord( kind, name, key ); + pendingSavedRecords.push( + saveEditedEntityRecord( kind, name, key ) + ); } } ); if ( siteItemsToSave.length ) { - saveSpecifiedEntityEdits( - 'root', - 'site', - undefined, - siteItemsToSave + pendingSavedRecords.push( + saveSpecifiedEntityEdits( + 'root', + 'site', + undefined, + siteItemsToSave + ) ); } __unstableMarkLastChangeAsPersistent(); + + Promise.all( pendingSavedRecords ).then( ( values ) => { + if ( values.some( ( value ) => typeof value === 'undefined' ) ) { + createErrorNotice( __( 'Saving failed.' ) ); + } else { + createSuccessNotice( __( 'Site updated.' ), { + type: 'snackbar', + } ); + } + } ); }; // Explicitly define this with no argument passed. Using `close` on From 0cff4a97fa1a5683fa630384213b889d1b64ff00 Mon Sep 17 00:00:00 2001 From: tellthemachines Date: Mon, 29 Nov 2021 17:53:24 +1100 Subject: [PATCH 2/5] Try stabilising e2e test --- .../e2e-tests/specs/site-editor/multi-entity-saving.test.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/e2e-tests/specs/site-editor/multi-entity-saving.test.js b/packages/e2e-tests/specs/site-editor/multi-entity-saving.test.js index 26ba4976a506b..de77892879db9 100644 --- a/packages/e2e-tests/specs/site-editor/multi-entity-saving.test.js +++ b/packages/e2e-tests/specs/site-editor/multi-entity-saving.test.js @@ -173,7 +173,9 @@ describe( 'Multi-entity save flow', () => { await page.keyboard.type( '...more title!' ); // Verify update button is enabled. - const enabledSaveButton = await page.$( enabledSavePostSelector ); + const enabledSaveButton = await page.waitForSelector( + enabledSavePostSelector + ); expect( enabledSaveButton ).not.toBeNull(); // Verify multi-entity saving not enabled. await assertMultiSaveDisabled(); From e1cae89aa2d094787f3a42f14bed365599da1b29 Mon Sep 17 00:00:00 2001 From: Kai Hao Date: Tue, 30 Nov 2021 15:06:38 +0800 Subject: [PATCH 3/5] Wait for the close panel button to not be disabled --- .../specs/site-editor/multi-entity-saving.test.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/e2e-tests/specs/site-editor/multi-entity-saving.test.js b/packages/e2e-tests/specs/site-editor/multi-entity-saving.test.js index de77892879db9..e1391a6fee99b 100644 --- a/packages/e2e-tests/specs/site-editor/multi-entity-saving.test.js +++ b/packages/e2e-tests/specs/site-editor/multi-entity-saving.test.js @@ -27,7 +27,7 @@ describe( 'Multi-entity save flow', () => { const activatedTemplatePartSelector = `${ templatePartSelector }.block-editor-block-list__layout`; const savePanelSelector = '.entities-saved-states__panel'; const closePanelButtonSelector = - '.editor-post-publish-panel__header-cancel-button button'; + '.editor-post-publish-panel__header-cancel-button button:not(:disabled)'; const createNewButtonSelector = '//button[contains(text(), "New template part")]'; @@ -158,7 +158,10 @@ describe( 'Multi-entity save flow', () => { await assertExistance( savePanelSelector, false ); // Close publish panel. - await page.click( closePanelButtonSelector ); + const closePanelButton = await page.waitForSelector( + closePanelButtonSelector + ); + await closePanelButton.click(); // Verify saving is disabled. const draftSaved = await page.waitForSelector( draftSavedSelector ); From 5bbcc4122804622115ceee30f7aab36bb3717314 Mon Sep 17 00:00:00 2001 From: Kai Hao Date: Tue, 30 Nov 2021 15:53:59 +0800 Subject: [PATCH 4/5] Wait for the notice specifically for the published post --- .../specs/site-editor/multi-entity-saving.test.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/e2e-tests/specs/site-editor/multi-entity-saving.test.js b/packages/e2e-tests/specs/site-editor/multi-entity-saving.test.js index e1391a6fee99b..0f965a15dbff4 100644 --- a/packages/e2e-tests/specs/site-editor/multi-entity-saving.test.js +++ b/packages/e2e-tests/specs/site-editor/multi-entity-saving.test.js @@ -170,6 +170,13 @@ describe( 'Multi-entity save flow', () => { await assertExistance( saveA11ySelector, false ); await publishPost(); + // Wait for the success notice specifically for the published post. + // `publishPost()` has a similar check but it only checks for the + // existence of any snackbars. In this case, there's another "Site updated" + // notice which will be sufficient for that and thus creating a false-positive. + await page.waitForXPath( + '//*[@id="a11y-speak-polite"][contains(text(), "Post published")]' + ); // Update the post. await page.click( '.editor-post-title' ); From cd451ec5239e6bcc6137bdc636bc0b30a9f40fd1 Mon Sep 17 00:00:00 2001 From: tellthemachines Date: Tue, 14 Dec 2021 16:05:43 +1100 Subject: [PATCH 5/5] Add catch --- .../components/entities-saved-states/index.js | 28 +++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/packages/editor/src/components/entities-saved-states/index.js b/packages/editor/src/components/entities-saved-states/index.js index 86eff388ab75d..becb092165dda 100644 --- a/packages/editor/src/components/entities-saved-states/index.js +++ b/packages/editor/src/components/entities-saved-states/index.js @@ -80,7 +80,7 @@ export default function EntitiesSavedStates( { close } ) { const { __unstableMarkLastChangeAsPersistent } = useDispatch( blockEditorStore ); - + const { createSuccessNotice, createErrorNotice } = useDispatch( noticesStore ); @@ -176,16 +176,22 @@ export default function EntitiesSavedStates( { close } ) { } __unstableMarkLastChangeAsPersistent(); - - Promise.all( pendingSavedRecords ).then( ( values ) => { - if ( values.some( ( value ) => typeof value === 'undefined' ) ) { - createErrorNotice( __( 'Saving failed.' ) ); - } else { - createSuccessNotice( __( 'Site updated.' ), { - type: 'snackbar', - } ); - } - } ); + + Promise.all( pendingSavedRecords ) + .then( ( values ) => { + if ( + values.some( ( value ) => typeof value === 'undefined' ) + ) { + createErrorNotice( __( 'Saving failed.' ) ); + } else { + createSuccessNotice( __( 'Site updated.' ), { + type: 'snackbar', + } ); + } + } ) + .catch( ( error ) => + createErrorNotice( `${ __( 'Saving failed.' ) } ${ error }` ) + ); }; // Explicitly define this with no argument passed. Using `close` on