Skip to content

Commit

Permalink
Merge branch 'develop' into add/implement-content-helper-feature-perm…
Browse files Browse the repository at this point in the history
…issions
  • Loading branch information
acicovic committed Jul 4, 2024
2 parents 64dfc2a + 3d75412 commit 59301df
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 24 deletions.
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' => '2a49abdb7116eaea1017');
<?php return array('dependencies' => array('react', 'wp-api-fetch', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-url'), 'version' => '20fc48e438e82a58464f');
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' => 'a2af3963d0ec93c28029');
<?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' => '1f97f0ca87e022ed4921');
12 changes: 6 additions & 6 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' => 'b3a8c97419df2d1807a8');
<?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' => '4af404737b96aa89a9a6');
4 changes: 2 additions & 2 deletions build/content-helper/excerpt-generator.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/content-helper/common/content-helper-error.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export enum ContentHelperErrorCode {
PluginSettingsApiSecretNotSet = 'parsely_api_secret_not_set',
PluginSettingsSiteIdNotSet = 'parsely_site_id_not_set',
PostIsNotPublished = 'ch_post_not_published',
UnknownError = 'ch_unknown_error',

// Suggestions API.
ParselySuggestionsApiAuthUnavailable = 'AUTH_UNAVAILABLE', // HTTP Code 503.
Expand Down Expand Up @@ -79,6 +80,7 @@ export class ContentHelperError extends Error {
ContentHelperErrorCode.PluginSettingsApiSecretNotSet,
ContentHelperErrorCode.PluginSettingsSiteIdNotSet,
ContentHelperErrorCode.PostIsNotPublished,
ContentHelperErrorCode.UnknownError,

// Don't perform any fetch retries for the Suggestions API due to
// its time-consuming operations.
Expand Down
10 changes: 8 additions & 2 deletions src/content-helper/editor-sidebar/smart-linking/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { Icon, external } from '@wordpress/icons';
*/
import { GutenbergFunction, dispatchCoreEditor } from '../../../@types/gutenberg/types';
import { Telemetry } from '../../../js/telemetry/telemetry';
import { ContentHelperErrorCode } from '../../common/content-helper-error';
import { ContentHelperError, ContentHelperErrorCode } from '../../common/content-helper-error';
import { SidebarSettings, SmartLinkingSettings, useSettings } from '../../common/settings';
import { generateProtocolVariants } from '../../common/utils/functions';
import { ContentHelperPermissions } from '../../common/utils/permissions';
Expand Down Expand Up @@ -484,7 +484,11 @@ export const SmartLinkingPanel = ( {
await processSmartLinks( generatedLinks );
setIsReviewModalOpen( true );
} catch ( e: any ) { // eslint-disable-line @typescript-eslint/no-explicit-any
let snackBarMessage = __( 'There was a problem generating smart links.', 'wp-parsely' );
const contentHelperError = new ContentHelperError(
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 ) {
Expand Down Expand Up @@ -547,6 +551,7 @@ export const SmartLinkingPanel = ( {
err.numRetries = MAX_NUMBER_OF_RETRIES - retries;
throw err;
}

// If the error is a retryable fetch error, retry the fetch.
if ( retries > 0 && err.retryFetch ) {
// Print the error to the console to help with debugging.
Expand All @@ -555,6 +560,7 @@ export const SmartLinkingPanel = ( {
await incrementRetryAttempt();
return await generateSmartLinksWithRetry( retries - 1 );
}

// Throw the error to be handled elsewhere.
throw err;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ export const TitleSuggestionsPanel = (): React.JSX.Element => {

createNotice(
'error',
__( 'There was an error generating title suggestions.', 'wp-parsely' ),
error.message,
{
type: 'snackbar',
className: 'parsely-title-suggestion-error',
Expand Down
17 changes: 8 additions & 9 deletions wp-parsely.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,6 @@ function parsely_initialize_plugin(): void {
$GLOBALS['parsely'] = new Parsely();
$GLOBALS['parsely']->run();

/**
* The Editor Sidebar instance.
*
* @since 3.16.0
* @var Editor_Sidebar $GLOBALS['parsely_editor_sidebar']
*/
$GLOBALS['parsely_editor_sidebar'] = new Editor_Sidebar( $GLOBALS['parsely'] );

if ( class_exists( 'WPGraphQL' ) ) {
$graphql = new GraphQL_Metadata( $GLOBALS['parsely'] );
$graphql->run();
Expand Down Expand Up @@ -294,13 +286,20 @@ function init_content_helper_editor_sidebar(): void {

require_once __DIR__ . '/src/content-helper/excerpt-generator/class-excerpt-generator.php';

add_action( 'init', __NAMESPACE__ . '\\parsely_content_helper_editor_sidebar_features' );
add_action( 'admin_init', __NAMESPACE__ . '\\parsely_content_helper_editor_sidebar_features' );
/**
* Initializes the PCH Editor Sidebar features.
*
* @since 3.16.0
*/
function parsely_content_helper_editor_sidebar_features(): void {
/**
* The Editor Sidebar instance.
*
* @since 3.16.0
* @var Editor_Sidebar $GLOBALS['parsely_editor_sidebar']
*/
$GLOBALS['parsely_editor_sidebar'] = new Editor_Sidebar( $GLOBALS['parsely'] );
$GLOBALS['parsely_editor_sidebar']->init_features();
}

Expand Down

0 comments on commit 59301df

Please sign in to comment.