Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Widgets screen] Don't add undo levels when editing records on save #32572

Merged
merged 3 commits into from
Jun 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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