Skip to content

Commit

Permalink
Confirm dialog: use more descriptive text for the confirm button (#60364
Browse files Browse the repository at this point in the history
)

* Improve confirm dialog confirm button text.

* Adjust tests.

* Adjust more tests.

* Improve apply revision confirm dialog copy.

* Improve edit template confirm dialog copy.

* Update string.

* Adjust test.

Co-authored-by: afercia <afercia@git.wordpress.org>
Co-authored-by: noisysocks <noisysocks@git.wordpress.org>
  • Loading branch information
3 people authored Apr 15, 2024
1 parent 3a830e2 commit 158d3b9
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ function ScreenRevisions() {
}
>
{ __(
'Any unsaved changes will be lost when you apply this revision.'
'Are you sure you want to apply this revision? Any unsaved changes will be lost.'
) }
</ConfirmDialog>
) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export default function EditTemplateBlocksNotification( { contentRef } ) {
onCancel={ () => setIsDialogOpen( false ) }
>
{ __(
'You’ve tried to select a block that is part of a template, which may be used on other posts and pages.'
'You’ve tried to select a block that is part of a template, which may be used on other posts and pages. Would you like to edit the template?.'
) }
</ConfirmDialog>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,13 @@ export default function PostSwitchToDraftButton() {
const isDisabled = isSaving || ( ! isPublished && ! isScheduled );

let alertMessage;
let confirmButtonText;
if ( isPublished ) {
alertMessage = __( 'Are you sure you want to unpublish this post?' );
confirmButtonText = __( 'Unpublish' );
} else if ( isScheduled ) {
alertMessage = __( 'Are you sure you want to unschedule this post?' );
confirmButtonText = __( 'Unschedule' );
}

const handleConfirm = () => {
Expand Down Expand Up @@ -63,6 +66,7 @@ export default function PostSwitchToDraftButton() {
isOpen={ showConfirmDialog }
onConfirm={ handleConfirm }
onCancel={ () => setShowConfirmDialog( false ) }
confirmButtonText={ confirmButtonText }
>
{ alertMessage }
</ConfirmDialog>
Expand Down
1 change: 1 addition & 0 deletions packages/editor/src/components/post-trash/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export default function PostTrash() {
isOpen={ showConfirmDialog }
onConfirm={ handleConfirm }
onCancel={ () => setShowConfirmDialog( false ) }
confirmButtonText={ __( 'Move to trash' ) }
>
{ __(
'Are you sure you want to move this post to the trash?'
Expand Down
1 change: 1 addition & 0 deletions packages/editor/src/components/post-visibility/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ export default function PostVisibility( { onClose } ) {
isOpen={ showPrivateConfirmDialog }
onConfirm={ confirmPrivate }
onCancel={ handleDialogCancel }
confirmButtonText={ __( 'Publish' ) }
>
{ __( 'Would you like to privately publish this post now?' ) }
</ConfirmDialog>
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/specs/editor/various/change-detection.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ test.describe( 'Change detection', () => {
.click();
await page
.getByRole( 'dialog' )
.getByRole( 'button', { name: 'OK' } )
.getByRole( 'button', { name: 'Move to trash' } )
.click();

await expect(
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/specs/editor/various/post-visibility.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ test.describe( 'Post visibility', () => {

await page.click( 'role=radio[name="Private"i]' );

await page.click( 'role=button[name="OK"i]' );
await page.click( 'role=button[name="Publish"i]' );

const currentStatus = await page.evaluate( () => {
return window.wp.data
Expand Down Expand Up @@ -99,7 +99,7 @@ test.describe( 'Post visibility', () => {

await page.click( 'role=radio[name="Private"i]' );

await page.click( 'role=button[name="OK"i]' );
await page.click( 'role=button[name="Publish"i]' );

const currentStatus = await page.evaluate( () => {
return window.wp.data
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/specs/editor/various/preview.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ test.describe( 'Preview', () => {
.getByRole( 'button', { name: 'Switch to draft' } )
.click();
// FIXME: The confirmation dialog is not named yet.
await page.click( 'role=dialog >> role=button[name="OK"i]' );
await page.click( 'role=dialog >> role=button[name="Unpublish"i]' );

// Wait for the status change.
// @see https://github.com/WordPress/gutenberg/pull/43933
Expand Down
5 changes: 4 additions & 1 deletion test/e2e/specs/editor/various/switch-to-draft.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,12 @@ test.describe( 'Clicking "Switch to draft" on a published/scheduled post/page',

await switchToDraftUtils.switchToDraftButton.click();

const confirmButtonText =
postStatus === 'publish' ? 'Unpublish' : 'Unschedule';

await page
.getByRole( 'dialog' )
.getByRole( 'button', { name: 'OK' } )
.getByRole( 'button', { name: confirmButtonText } )
.click();

await expect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ test.describe( 'Style Revisions', () => {
const confirm = page.getByRole( 'dialog' );
await expect( confirm ).toBeVisible();
await expect( confirm ).toHaveText(
/^Any unsaved changes will be lost when you apply this revision./
/^Are you sure you want to apply this revision\? Any unsaved changes will be lost./
);

// This is to make sure there are no lingering unsaved changes.
Expand Down

0 comments on commit 158d3b9

Please sign in to comment.