Skip to content

Commit

Permalink
[Widgets screen] Don't add undo levels when editing records on save (#…
Browse files Browse the repository at this point in the history
…32572)

* Don't add undo levels when saving widgets.

* Add e2e test for undoing widget deletion.

* Update failing snapshot
  • Loading branch information
tellthemachines authored and youknowriad committed Jun 14, 2021
1 parent 0521fb3 commit 0f1bec8
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 2 deletions.
57 changes: 57 additions & 0 deletions packages/e2e-tests/specs/widgets/editing-widgets.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
showBlockToolbar,
visitAdminPage,
deleteAllWidgets,
pressKeyWithModifier,
} from '@wordpress/e2e-test-utils';

/**
Expand Down Expand Up @@ -694,6 +695,62 @@ describe( 'Widgets screen', () => {
}
` );
} );

it( 'Allows widget deletion to be undone', async () => {
const [ firstWidgetArea ] = await findAll( {
role: 'group',
name: 'Block: Widget Area',
} );

let addParagraphBlock = await getBlockInGlobalInserter( 'Paragraph' );
await addParagraphBlock.click();

let addedParagraphBlockInFirstWidgetArea = await find(
{
name: /^Empty block/,
selector: '[data-block][data-type="core/paragraph"]',
},
{
root: firstWidgetArea,
}
);
await addedParagraphBlockInFirstWidgetArea.focus();
await page.keyboard.type( 'First Paragraph' );

addParagraphBlock = await getBlockInGlobalInserter( 'Paragraph' );
await addParagraphBlock.click();

addedParagraphBlockInFirstWidgetArea = await firstWidgetArea.$(
'[data-block][data-type="core/paragraph"][aria-label^="Empty block"]'
);
await addedParagraphBlockInFirstWidgetArea.focus();
await page.keyboard.type( 'Second Paragraph' );

await saveWidgets();

// Delete the last block and save again.
await pressKeyWithModifier( 'access', 'z' );
await saveWidgets();

// Undo block deletion and save again
await pressKeyWithModifier( 'primary', 'z' );
await saveWidgets();

// Reload the page to make sure changes were actually saved.
await page.reload();

const serializedWidgetAreas = await getSerializedWidgetAreas();
expect( serializedWidgetAreas ).toMatchInlineSnapshot( `
Object {
"sidebar-1": "<div class=\\"widget widget_block widget_text\\"><div class=\\"widget-content\\">
<p>First Paragraph</p>
</div></div>
<div class=\\"widget widget_block widget_text\\"><div class=\\"widget-content\\">
<p>Second Paragraph</p>
</div></div>",
}
` );
} );
} );

/**
Expand Down
6 changes: 4 additions & 2 deletions packages/edit-widgets/src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ export function* saveWidgetArea( widgetAreaId ) {
{
...widget,
sidebar: widgetAreaId,
}
},
{ undoIgnore: true }
);

const hasEdits = yield select(
Expand Down Expand Up @@ -242,7 +243,8 @@ export function* saveWidgetArea( widgetAreaId ) {
widgetAreaId,
{
widgets: sidebarWidgetsIds,
}
},
{ undoIgnore: true }
);

yield* trySaveWidgetArea( widgetAreaId );
Expand Down

0 comments on commit 0f1bec8

Please sign in to comment.