From a009fd87e6108352943eacd0a82363bb6ebafd2f Mon Sep 17 00:00:00 2001 From: Andy Meerwaldt Date: Tue, 23 Mar 2021 15:37:27 +0100 Subject: [PATCH 1/3] Add links to the warning --- .../functions/gutenberg/watchers/warningWatcher.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/schema-blocks/src/functions/gutenberg/watchers/warningWatcher.ts b/packages/schema-blocks/src/functions/gutenberg/watchers/warningWatcher.ts index fa473c522e..12b6570f37 100644 --- a/packages/schema-blocks/src/functions/gutenberg/watchers/warningWatcher.ts +++ b/packages/schema-blocks/src/functions/gutenberg/watchers/warningWatcher.ts @@ -47,25 +47,29 @@ function getInnerBlocksInstruction( blockName: string ): InnerBlocks | null { function getDefaultWarningMessage( blockTitle: string, warningType: WarningType ): string { switch ( warningType ) { case WarningType.BLOCK_REQUIRED: { - /* translators: %s expands to the block name that is removed. */ + /* translators: %1$s: the block name that is removed, %2$s: the anchor to a page about required blocks, %3$s the closing anchor tag. */ return sprintf( __( - "You've just removed the ‘%s’ block, but this is a required block for Schema output. " + + "You've just removed the ‘%1$s’ block, but this is a %2$srequired block for Schema output%3$s. " + "Without this block no Schema will be generated. Are you sure you want to do this?", "yoast-schema-blocks", ), blockTitle, + '', + "", ); } case WarningType.BLOCK_RECOMMENDED: { - /* translators: %s expands to the block name that is removed. */ + /* translators: %1$s: the block name that is removed, %2$s: the anchor to a page about recommended blocks, %3$s the closing anchor tag. */ return sprintf( __( - "You've just removed the ‘%s’ block, but this is a recommended block for Schema output. " + + "You've just removed the ‘%1$s’ block, but this is a %2$srecommended block for Schema output%3$s. " + "Are you sure you want to do this?", "yoast-schema-blocks", ), blockTitle, + '', + "", ); } } From 0f2ba031900a7590d6dec12ef37ec9b2dce7a20c Mon Sep 17 00:00:00 2001 From: Andy Meerwaldt Date: Wed, 24 Mar 2021 11:09:01 +0100 Subject: [PATCH 2/3] Fixes the tests which are failing because changes in the warningWatcher.ts --- .../gutenberg/watchers/warningWatcher.ts | 4 ++-- .../gutenberg/watchers/warningWatcher.test.ts | 20 ++++++++++++++++--- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/packages/schema-blocks/src/functions/gutenberg/watchers/warningWatcher.ts b/packages/schema-blocks/src/functions/gutenberg/watchers/warningWatcher.ts index 12b6570f37..146d9f7435 100644 --- a/packages/schema-blocks/src/functions/gutenberg/watchers/warningWatcher.ts +++ b/packages/schema-blocks/src/functions/gutenberg/watchers/warningWatcher.ts @@ -55,7 +55,7 @@ function getDefaultWarningMessage( blockTitle: string, warningType: WarningType "yoast-schema-blocks", ), blockTitle, - '', + '', "", ); } @@ -68,7 +68,7 @@ function getDefaultWarningMessage( blockTitle: string, warningType: WarningType "yoast-schema-blocks", ), blockTitle, - '', + '', "", ); } diff --git a/packages/schema-blocks/tests/functions/gutenberg/watchers/warningWatcher.test.ts b/packages/schema-blocks/tests/functions/gutenberg/watchers/warningWatcher.test.ts index dc1b3a17f2..7b4ee903ba 100644 --- a/packages/schema-blocks/tests/functions/gutenberg/watchers/warningWatcher.test.ts +++ b/packages/schema-blocks/tests/functions/gutenberg/watchers/warningWatcher.test.ts @@ -10,7 +10,13 @@ import { RequiredBlock, RequiredBlockOption } from "../../../../src/core/validat jest.mock( "@wordpress/i18n", () => ( { __: jest.fn( text => text ), - sprintf: jest.fn( ( text, value ) => text.replace( "%s", value ) ), + sprintf: jest.fn( ( text, value, value2, value3 ) => { + text = text.replace( "%1$s", value ); + text = text.replace( "%2$s", value2 ); + text = text.replace( "%3$s", value3 ); + + return text; + } ), } ) ); jest.mock( "@wordpress/block-editor", () => ( { @@ -54,6 +60,11 @@ jest.mock( "@yoast/components", () => { }; } ); +( window as any ).yoastSchemaBlocks = { + requiredLink: "https://yoa.st/required-fields", + recommendedLink: "https://yoa.st/recommended-fields", +}; + describe( "The warning watcher", () => { it( "adds warnings when required blocks are removed", () => { const previousBlocks = [ @@ -106,7 +117,8 @@ describe( "The warning watcher", () => { innerBlocks: [], name: "yoast/ingredients", }, - warningText: "You've just removed the ‘Ingredients’ block, but this is a required block for Schema output. " + + warningText: "You've just removed the ‘Ingredients’ block, but this is a " + + "required block for Schema output. " + "Without this block no Schema will be generated. Are you sure you want to do this?", }, ); @@ -164,7 +176,9 @@ describe( "The warning watcher", () => { name: "yoast/ingredients", }, // eslint-disable-next-line max-len - warningText: "You've just removed the ‘Ingredients’ block, but this is a recommended block for Schema output. Are you sure you want to do this?", + warningText: "You've just removed the ‘Ingredients’ block, but this is a " + + "recommended block for Schema output. " + + "Are you sure you want to do this?", }, ); expect( dispatch ).toBeCalled(); From 66843c77bb84894239f1bba850e84e8e7017ec36 Mon Sep 17 00:00:00 2001 From: Hans-Christiaan Date: Thu, 25 Mar 2021 11:29:21 +0100 Subject: [PATCH 3/3] Made links in warning message blue. --- packages/schema-blocks/css/schema-blocks.css | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/schema-blocks/css/schema-blocks.css b/packages/schema-blocks/css/schema-blocks.css index 25d7690404..77364ec017 100644 --- a/packages/schema-blocks/css/schema-blocks.css +++ b/packages/schema-blocks/css/schema-blocks.css @@ -50,6 +50,11 @@ color: #0073aa; } +.wp-block .yoast-warning-block > .yoast-warning-block-message > a { + text-decoration: underline; + color: #0073aa; +} + .yoast-warning-block > div > button:not(:last-child) { margin-right: 24px; }