Skip to content
This repository was archived by the owner on Oct 4, 2022. It is now read-only.

Commit f0edfb4

Browse files
authored
Merge pull request #1117 from Yoast/P2-690-show-link-in-warning
2 parents 7c7d0fd + 66843c7 commit f0edfb4

File tree

3 files changed

+30
-7
lines changed

3 files changed

+30
-7
lines changed

packages/schema-blocks/css/schema-blocks.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@
5050
color: #0073aa;
5151
}
5252

53+
.wp-block .yoast-warning-block > .yoast-warning-block-message > a {
54+
text-decoration: underline;
55+
color: #0073aa;
56+
}
57+
5358
.yoast-warning-block > div > button:not(:last-child) {
5459
margin-right: 24px;
5560
}

packages/schema-blocks/src/functions/gutenberg/watchers/warningWatcher.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,25 +47,29 @@ function getInnerBlocksInstruction( blockName: string ): InnerBlocks | null {
4747
function getDefaultWarningMessage( blockTitle: string, warningType: WarningType ): string {
4848
switch ( warningType ) {
4949
case WarningType.BLOCK_REQUIRED: {
50-
/* translators: %s expands to the block name that is removed. */
50+
/* 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. */
5151
return sprintf(
5252
__(
53-
"You've just removed the ‘%s’ block, but this is a required block for Schema output. " +
53+
"You've just removed the ‘%1$s’ block, but this is a %2$srequired block for Schema output%3$s. " +
5454
"Without this block no Schema will be generated. Are you sure you want to do this?",
5555
"yoast-schema-blocks",
5656
),
5757
blockTitle,
58+
'<a href="' + ( window as any ).yoastSchemaBlocks.requiredLink + '" target="_blank">',
59+
"</a>",
5860
);
5961
}
6062
case WarningType.BLOCK_RECOMMENDED: {
61-
/* translators: %s expands to the block name that is removed. */
63+
/* 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. */
6264
return sprintf(
6365
__(
64-
"You've just removed the ‘%s’ block, but this is a recommended block for Schema output. " +
66+
"You've just removed the ‘%1$s’ block, but this is a %2$srecommended block for Schema output%3$s. " +
6567
"Are you sure you want to do this?",
6668
"yoast-schema-blocks",
6769
),
6870
blockTitle,
71+
'<a href="' + ( window as any ).yoastSchemaBlocks.recommendedLink + '" target="_blank">',
72+
"</a>",
6973
);
7074
}
7175
}

packages/schema-blocks/tests/functions/gutenberg/watchers/warningWatcher.test.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,13 @@ import { RequiredBlock, RequiredBlockOption } from "../../../../src/core/validat
1010

1111
jest.mock( "@wordpress/i18n", () => ( {
1212
__: jest.fn( text => text ),
13-
sprintf: jest.fn( ( text, value ) => text.replace( "%s", value ) ),
13+
sprintf: jest.fn( ( text, value, value2, value3 ) => {
14+
text = text.replace( "%1$s", value );
15+
text = text.replace( "%2$s", value2 );
16+
text = text.replace( "%3$s", value3 );
17+
18+
return text;
19+
} ),
1420
} ) );
1521

1622
jest.mock( "@wordpress/block-editor", () => ( {
@@ -54,6 +60,11 @@ jest.mock( "@yoast/components", () => {
5460
};
5561
} );
5662

63+
( window as any ).yoastSchemaBlocks = {
64+
requiredLink: "https://yoa.st/required-fields",
65+
recommendedLink: "https://yoa.st/recommended-fields",
66+
};
67+
5768
describe( "The warning watcher", () => {
5869
it( "adds warnings when required blocks are removed", () => {
5970
const previousBlocks = [
@@ -106,7 +117,8 @@ describe( "The warning watcher", () => {
106117
innerBlocks: [],
107118
name: "yoast/ingredients",
108119
},
109-
warningText: "You've just removed the ‘Ingredients’ block, but this is a required block for Schema output. " +
120+
warningText: "You've just removed the ‘Ingredients’ block, but this is a " +
121+
"<a href=\"https://yoa.st/required-fields\" target=\"_blank\">required block for Schema output</a>. " +
110122
"Without this block no Schema will be generated. Are you sure you want to do this?",
111123
},
112124
);
@@ -164,7 +176,9 @@ describe( "The warning watcher", () => {
164176
name: "yoast/ingredients",
165177
},
166178
// eslint-disable-next-line max-len
167-
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?",
179+
warningText: "You've just removed the ‘Ingredients’ block, but this is a " +
180+
"<a href=\"https://yoa.st/recommended-fields\" target=\"_blank\">recommended block for Schema output</a>. " +
181+
"Are you sure you want to do this?",
168182
},
169183
);
170184
expect( dispatch ).toBeCalled();

0 commit comments

Comments
 (0)