Skip to content

Commit

Permalink
Block Editor: Mark last change as persistent on save (#36887)
Browse files Browse the repository at this point in the history
* Mark last change as persistent when saving changes
  • Loading branch information
zaguiini committed Dec 4, 2021
1 parent ee54f07 commit d4e57dc
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 9 deletions.
66 changes: 57 additions & 9 deletions packages/e2e-tests/specs/site-editor/multi-entity-saving.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,19 @@ describe( 'Multi-entity save flow', () => {
const disabledSaveSiteSelector = `${ saveSiteSelector }[aria-disabled=true]`;
const saveA11ySelector = '.edit-site-editor__toggle-save-panel-button';

const saveAllChanges = async () => {
// Clicking button should open panel with boxes checked.
await page.click( activeSaveSiteSelector );
await page.waitForSelector( savePanelSelector );
await assertAllBoxesChecked();

// Save a11y button should not be present with save panel open.
await assertExistance( saveA11ySelector, false );

// Saving should result in items being saved.
await page.click( entitiesSaveSelector );
};

it( 'Save flow should work as expected', async () => {
// Navigate to site editor.
await siteEditor.visit( {
Expand Down Expand Up @@ -267,20 +280,55 @@ describe( 'Multi-entity save flow', () => {
// Save a11y button should be present.
await assertExistance( saveA11ySelector, true );

// Clicking button should open panel with boxes checked.
await page.click( activeSaveSiteSelector );
await page.waitForSelector( savePanelSelector );
await assertAllBoxesChecked();

// Save a11y button should not be present with save panel open.
await assertExistance( saveA11ySelector, false );
// Save all changes.
await saveAllChanges();

// Saving should result in items being saved.
await page.click( entitiesSaveSelector );
const disabledButton = await page.waitForSelector(
disabledSaveSiteSelector
);
expect( disabledButton ).not.toBeNull();
} );

it( 'Save flow should allow re-saving after changing the same block attribute', async () => {
// Navigate to site editor.
await siteEditor.visit( {
postId: 'tt1-blocks//index',
postType: 'wp_template',
} );
await siteEditor.disableWelcomeGuide();

// Insert a paragraph at the bottom.
await insertBlock( 'Paragraph' );

// Open the block settings.
await page.click( 'button[aria-label="Settings"]' );

// Click on font size selector.
await page.click( 'button[aria-label="Font size"]' );

// Click on a different font size.
const extraSmallFontSize = await page.waitForXPath(
'//li[contains(text(), "Extra small")]'
);
await extraSmallFontSize.click();

// Save all changes.
await saveAllChanges();

// Click on font size selector again.
await page.click( 'button[aria-label="Font size"]' );

// Select another font size.
const normalFontSize = await page.waitForXPath(
'//li[contains(text(), "Normal")]'
);
await normalFontSize.click();

// Assert that the save button has been re-enabled.
const saveButton = await page.waitForSelector(
activeSaveSiteSelector
);
expect( saveButton ).not.toBeNull();
} );
} );
} );
7 changes: 7 additions & 0 deletions packages/editor/src/components/entities-saved-states/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { __ } from '@wordpress/i18n';
import { useSelect, useDispatch } from '@wordpress/data';
import { useState, useCallback, useRef } from '@wordpress/element';
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';

Expand Down Expand Up @@ -75,6 +76,10 @@ export default function EntitiesSavedStates( { close } ) {
__experimentalSaveSpecifiedEntityEdits: saveSpecifiedEntityEdits,
} = useDispatch( coreStore );

const { __unstableMarkLastChangeAsPersistent } = useDispatch(
blockEditorStore
);

// To group entities by type.
const partitionedSavables = groupBy( dirtyEntityRecords, 'name' );

Expand Down Expand Up @@ -159,6 +164,8 @@ export default function EntitiesSavedStates( { close } ) {
siteItemsToSave
);
}

__unstableMarkLastChangeAsPersistent();
};

// Explicitly define this with no argument passed. Using `close` on
Expand Down

0 comments on commit d4e57dc

Please sign in to comment.