Skip to content

Commit

Permalink
Don't show Snackbar Notices for error messages with links
Browse files Browse the repository at this point in the history
  • Loading branch information
acicovic committed Jul 1, 2024
1 parent f40cd5f commit 505615b
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 26 deletions.
4 changes: 3 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
"no-shadow": "off",
"@typescript-eslint/no-shadow": ["error"],
// Allow usage of Gutenberg experimental components.
"@wordpress/no-unsafe-wp-apis": "off"
"@wordpress/no-unsafe-wp-apis": "off",
// Allow link tag in JSDocs.
"jsdoc/check-tag-names": ["error", { "definedTags": ["link"] }]
}
}
2 changes: 1 addition & 1 deletion build/content-helper/dashboard-widget.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('react', 'wp-api-fetch', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-url'), 'version' => '819f710d52220b763db9');
<?php return array('dependencies' => array('react', 'wp-api-fetch', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-url'), 'version' => '41355598f65d773e3ae8');
2 changes: 1 addition & 1 deletion build/content-helper/dashboard-widget.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/content-helper/editor-sidebar.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('react', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-core-data', 'wp-data', 'wp-dom-ready', 'wp-edit-post', 'wp-editor', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-plugins', 'wp-primitives', 'wp-url'), 'version' => '6c2b3ad92ee55ee35e24');
<?php return array('dependencies' => array('react', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-core-data', 'wp-data', 'wp-dom-ready', 'wp-edit-post', 'wp-editor', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-plugins', 'wp-primitives', 'wp-url'), 'version' => 'ec507e87150f513b4332');
8 changes: 4 additions & 4 deletions build/content-helper/editor-sidebar.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/content-helper/excerpt-generator.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('react', 'wp-api-fetch', 'wp-components', 'wp-data', 'wp-edit-post', 'wp-editor', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-plugins', 'wp-primitives', 'wp-url', 'wp-wordcount'), 'version' => '4c13093f6531e0a67792');
<?php return array('dependencies' => array('react', 'wp-api-fetch', 'wp-components', 'wp-data', 'wp-edit-post', 'wp-editor', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-plugins', 'wp-primitives', 'wp-url', 'wp-wordcount'), 'version' => '57db27c7670068ac721e');
4 changes: 2 additions & 2 deletions build/content-helper/excerpt-generator.js

Large diffs are not rendered by default.

23 changes: 23 additions & 0 deletions src/content-helper/common/content-helper-error.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { __ } from '@wordpress/i18n';
/**
* Internal dependencies
*/
import { dispatch } from '@wordpress/data';
import {
ContentHelperErrorMessage,
ContentHelperErrorMessageProps,
Expand Down Expand Up @@ -182,4 +183,26 @@ export class ContentHelperError extends Error {
protected Hint( hint: string ): string {
return `<p className="content-helper-error-message-hint" data-testid="content-helper-error-message-hint"><strong>${ __( 'Hint:', 'wp-parsely' ) }</strong> ${ hint }</p>`;
}

/**
* Creates an error Snackbar Notice, unless the error message contains links.
*
* @since 3.16.0
*
* @link https://github.com/Parsely/wp-parsely/issues/2424#issuecomment-2196196232
*/
public createErrorSnackbar(): void {
if ( /<a.*?>/.test( this.message ) ) {
return;
}

// @ts-ignore
dispatch( 'core/notices' ).createNotice(
'error',
this.message,
{
type: 'snackbar',
}
);
}
}
10 changes: 3 additions & 7 deletions src/content-helper/editor-sidebar/smart-linking/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -474,23 +474,19 @@ export const SmartLinkingPanel = ( {
e.message ?? 'An unknown error has occurred.',
e.code ?? ContentHelperErrorCode.UnknownError
);
let snackBarMessage = contentHelperError.message;

// Handle the case where the operation was aborted by the user.
if ( e.code && e.code === ContentHelperErrorCode.ParselyAborted ) {
snackBarMessage = sprintf(
contentHelperError.message = sprintf(
/* translators: %d: number of retry attempts, %s: attempt plural */
__( 'The Smart Linking process was cancelled after %1$d %2$s.', 'wp-parsely' ),
e.numRetries,
_n( 'attempt', 'attempts', e.numRetries, 'wp-parsely' )
);
e.message = snackBarMessage;
}

await setError( e );
createNotice( 'error', snackBarMessage, {
type: 'snackbar',
} );
await setError( contentHelperError );
contentHelperError.createErrorSnackbar();
} finally {
await setLoading( false );
await setApplyTo( previousApplyTo );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,14 +196,7 @@ export const TitleSuggestionsPanel = (): React.JSX.Element => {
return;
}

createNotice(
'error',
error.message,
{
type: 'snackbar',
className: 'parsely-title-suggestion-error',
}
);
error.createErrorSnackbar();
}, [ error ] ); // eslint-disable-line react-hooks/exhaustive-deps

return (
Expand Down

0 comments on commit 505615b

Please sign in to comment.