Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Smart Linking: Add post details to the "Review" modal #3176

Merged
merged 7 commits into from
Mar 10, 2025

Conversation

acicovic
Copy link
Collaborator

@acicovic acicovic commented Mar 7, 2025

Description

Following user feedback, we're introducing additional post details in the Smart Linking "Review" modal. The following data points have been added:

  • Post's published date and author
  • Post's views, visitors and average time metrics

In addition, it's now possible to open a preview of the suggested post, using the icon located next to the post title.

Motivation and context

How has this been tested?

Manual testing, existing tests pass.

Screenshots

Suggestion with thumbnail

image

Suggestion with long post type name (shrinks author and post type)

image

Shrinkable Elements (post title, author, post type) show a tooltip when hovered

image

Summary by CodeRabbit

  • New Features

    • Introduced a Thumbnail component for displaying post images or fallback icons.
    • Enhanced smart linking by enriching outbound links with additional metadata and performance statistics.
    • Expanded API capabilities to support batch retrieval of post metadata and analytics.
  • Style

    • Refined visual layouts for link suggestions and thumbnails with updated styles and new color variables for improved consistency.
  • Refactor

    • Streamlined backend logic for post data retrieval by consolidating functionality into centralized, reusable methods.

@acicovic acicovic added this to the 3.18.0 milestone Mar 7, 2025
@acicovic acicovic self-assigned this Mar 7, 2025
Copy link
Contributor

coderabbitai bot commented Mar 7, 2025

📝 Walkthrough

Walkthrough

This pull request refactors the logic for retrieving post IDs by removing the private method from Smart_Link and shifting that responsibility to a new static method in the Utils class. It also updates access modifiers in the BaseProvider to allow subclass access, introduces a new BaseWordPressProvider for standardized API interactions with enriched type definitions and methods, and adds a new Thumbnail component with related styling and exports. Smart linking functionality in the editor sidebar is enhanced with new outbound link types and metadata handling, and several REST API endpoints are adjusted to support batch processing and URL arrays.

Changes

File(s) Change Summary
src/Models/class-smart-link.php
src/Utils/class-utils.php
Removed the private get_post_id_by_url method from Smart_Link and replaced its usage with a new static method Utils::get_post_id_by_url that handles caching and uses fallback logic.
src/content-helper/common/base-provider.tsx Changed access levels for abortControllers and getOrCreateController from private to protected, allowing subclass access.
src/content-helper/common/base-wordpress-provider.tsx Introduced a new base class BaseWordPressProvider with related type definitions and methods (apiFetch, fetch, hydratePosts, getPosts, getPost, fetchFromRestApi) for handling WordPress REST API interactions.
src/content-helper/common/components/thumbnail/component.tsx
src/content-helper/common/components/thumbnail/index.ts
src/content-helper/common/components/thumbnail/style.scss
src/content-helper/common/css/common.scss
Added a new Thumbnail component with its export and SCSS styles, and imported the thumbnail styles into the common styles file.
src/content-helper/common/css/variables.scss Added a new CSS variable --gray-350 with the value #e1e3e5 to expand the gray color scale.
src/content-helper/editor-sidebar/smart-linking/provider.ts
src/content-helper/editor-sidebar/smart-linking/review-modal/component-modal.tsx
src/content-helper/editor-sidebar/smart-linking/review-modal/component-suggestion.tsx
src/content-helper/editor-sidebar/smart-linking/smart-linking.scss
Updated smart linking functionality by introducing the OutboundSmartLink type, enriching metadata and performance data handling, renaming and updating methods, and overhauling component layouts and styles for link suggestions.
src/rest-api/content-helper/class-endpoint-smart-linking.php
src/rest-api/stats/class-endpoint-posts.php
src/services/content-api/endpoints/class-endpoint-analytics-posts.php
Modified API endpoints to remove single URL post type conversion in favor of batch retrieval of post metadata, added URL sanitization, and enabled handling of URL arrays in analytics endpoints.

Sequence Diagram(s)

sequenceDiagram
    participant UI as Editor Sidebar
    participant SP as SmartLinkingProvider
    participant REST as REST API Endpoint
    participant Utils as Utils Class

    UI->>SP: generateSmartLinks(content, maxLinks, exclusionList)
    SP->>SP: Parse content for smart links
    SP->>REST: Concurrently fetch post metadata & performance data for URLs
    REST-->>SP: Return respective metadata and stats
    SP->>Utils: Invoke Utils::get_post_id_by_url(url) for post ID resolution
    SP->>UI: Return enriched OutboundSmartLinks array
Loading

Possibly related PRs

Suggested labels

Feature: Dashboard

Suggested reviewers

  • vaurdan
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@acicovic
Copy link
Collaborator Author

acicovic commented Mar 7, 2025

Hey @vaurdan!

I noticed you recently introduced a thumbnail component, so I'll attempt to port that commit into this PR. That should allow you to keep the credit, and also prevent us from duplicating things.

This should probably do it, but I wanted to bring your attention to this in case there's anything else I need to do.

@acicovic
Copy link
Collaborator Author

acicovic commented Mar 7, 2025

@LauraKalnicky, we're currently hardcoding the stats to be for the last 30 days. Let me know if you think we should change the period to something else. We can eventually offer a setting for this at some point.

@acicovic
Copy link
Collaborator Author

acicovic commented Mar 7, 2025

@dabowman: Regarding visuals, the final piece is adding the thumbnail, as well as making any possible CSS micro-adjustments needed. Let me know if you see anything that obviously needs fixing in the screenshot.

If you want to take a look at the files, these would be the relevant ones:

  • CSS
  • Component (towards the bottom of the file, within the return)

@acicovic
Copy link
Collaborator Author

acicovic commented Mar 7, 2025

@dabowman, related to my comment to Laura, should we be actually showing the number of days somewhere?

@LauraKalnicky
Copy link

@LauraKalnicky, we're currently hardcoding the stats to be for the last 30 days. Let me know if you think we should change the period to something else. We can eventually offer a setting for this at some point.

@acicovic 30 days is in alignment with our longest option for Top Posts in PCH performance data on the WP admin dash. If we are only starting with one option I think having the most data works, although I envision that some of the posts will not have collected 30 days of data yet. In that case, would we just show all the data we have for them?

I'll also answer your question to @dabowmon - we should definitely indicate the number of days so it's clear to the user.

@acicovic
Copy link
Collaborator Author

acicovic commented Mar 7, 2025

@LauraKalnicky, if there's no data for the last 30 days (or whichever timeframe we choose), the metrics in question will show as N/A. There's not really a way to show "all data", since we need to specify a timeframe. If we want to enlarge it, I can look into how long this timeframe can be.

@dabowman, let's see where we can put the number of days.

@LauraKalnicky
Copy link

@acicovic I was thinking that if a post was too new to have 30 days of data would we then show whatever amount of data we've collected during that time?

@dabowman
Copy link

dabowman commented Mar 7, 2025

@acicovic @LauraKalnicky i would probably put the time period in a tooltip for each stat. So "visitors over last 30 days" or something like that. I'm not sure how folks are going to be using these metrics here but I don't think the period is super super relevant. Good to know, but probably not as important as the stats themselves. I imagine folks would be looking at these numbers to confirm trends and high-level performance not compare performance across posts or do any kind of analysis. I think less is more in those situations, that's why I opted for icons instead of writing stat names. But we should definitely make the period clear if we don't let them configure it. I think a tooltip should do it, maybe a little info icon, I'll try a couple things. In any case I think it's just enhancing what you've already built with a little extra progressive disclosure.

@acicovic
Copy link
Collaborator Author

@dabowman, another scenario I can think of is adding the period next to the metrics. This should work as we limit number length (eg 100k instead of 100000).

Copy link
Collaborator Author

@acicovic acicovic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The following files/code are cherry-picked from @vaurdan's work in commits 1e50213 and d04ecb9:

src/content-helper/common/base-provider.tsx
src/content-helper/common/base-wordpress-provider.tsx
src/content-helper/common/components/thumbnail/component.tsx
src/content-helper/common/components/thumbnail/index.ts
src/content-helper/common/components/thumbnail/style.scss
src/content-helper/common/css/common.scss
src/content-helper/common/css/variables.scss

As such, credit for that code is kept to him, and the files don't need review since they are already merged work. 🎉

@acicovic acicovic marked this pull request as ready for review March 10, 2025 15:03
@acicovic acicovic requested a review from a team as a code owner March 10, 2025 15:03
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (7)
src/Utils/class-utils.php (1)

410-435: Clean implementation of the URL to post ID utility method.

This method effectively retrieves a post ID from a URL with proper caching implementation. The function follows good practices by:

  1. Using cache to avoid redundant processing
  2. Checking for VIP environment functions
  3. Including appropriate documentation with @since tags

For optimal handling, consider adding caching for the VIP implementation as well.

 if ( function_exists( 'wpcom_vip_url_to_postid' ) ) {
 	$post_id = wpcom_vip_url_to_postid( $url );
+	wp_cache_set( $url, $post_id, 'wp_parsely_smart_link_url_to_postid' );
 } else {
 	// phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.url_to_postid_url_to_postid
 	$post_id = url_to_postid( $url );
 	wp_cache_set( $url, $post_id, 'wp_parsely_smart_link_url_to_postid' );
 }
src/content-helper/common/components/thumbnail/component.tsx (2)

1-24: Ensure JSDoc comments end with periods.

The component interface and imports look good, but JSDoc comments should end with periods as per WordPress coding standards.

/**
 * Defines the props structure for Thumbnail.
 *
- * @since 3.18.0
+ * @since 3.18.0
 */

25-58: Well-structured component with clear rendering logic.

The Thumbnail component is well-implemented with proper handling of optional props and conditional rendering. For clarity, consider adding units to size values in the style object and ensuring all JSDoc comments end with periods.

/**
 * Thumbnail component that displays either a post's thumbnail, a custom image, or a fallback icon.
 *
- * @since 3.18.0
+ * @since 3.18.0.
 *
- * @param {ThumbnailProps} props Component props.
+ * @param {ThumbnailProps} props Component props.
 */
export const Thumbnail = ( {
	post,
	imageUrl,
	icon = page,
	size = 100,
	className = '',
}: Readonly<ThumbnailProps> ): React.JSX.Element => {
	const thumbnailUrl = post?.thumbnail ?? imageUrl;
	const altText = post?.title.rendered ?? '';

	return (
-		<div className={ `parsely-thumbnail ${ className }` } style={ { width: size, height: size } }>
+		<div className={ `parsely-thumbnail ${ className }` } style={ { width: `${size}px`, height: `${size}px` } }>
			{ thumbnailUrl ? (
				<img
					src={ thumbnailUrl }
					alt={ altText }
					width={ size }
					height={ size }
				/>
			) : (
				<div className="parsely-thumbnail-icon-container">
					<Icon icon={ icon } size={ size } />
				</div>
			) }
		</div>
	);
};
src/content-helper/editor-sidebar/smart-linking/review-modal/component-suggestion.tsx (1)

110-121: Update JSDoc to match the new function signature and finalize doc style.

You've changed the component to accept OutboundSmartLink but the doc is still marked with @since 3.16.0. Additionally, the @param line doesn’t end with a period. Suggested fix:

- * @since 3.16.0
- * @param {{link: OutboundSmartLink}} props The component props
+ * @since 3.18.0
+ * @param {{link: OutboundSmartLink}} props The component props.
src/content-helper/editor-sidebar/smart-linking/provider.ts (1)

167-239: generateSmartLinks updates are solid, but consider chunking large batches.

Using Promise.all for parallel fetching of stats and post meta is good. For large sets of links, you might consider queueing or pagination to avoid performance bottlenecks. Otherwise, the concurrency approach looks fine.

src/content-helper/common/base-wordpress-provider.tsx (2)

167-182: Consider unifying the @since version tags.

Lines 101-108 consistently use @since 3.18.0, whereas lines 167-182 reference @since 3.15.0. If this code was truly introduced in 3.15.0, that’s fine. Otherwise, updating these references to match a single version would improve clarity.


215-217: Use optional chaining to simplify the conditional checks.

Instead of verifying post._embedded && post._embedded[...], consider using optional chaining for better readability.

Apply this diff to adopt optional chaining:

-if ( post._embedded && post._embedded['wp:term'] ) {
+if ( post._embedded?.['wp:term'] ) {
  [ categories, tags ] = post._embedded['wp:term'];
}

-if ( post._embedded && post._embedded['wp:featuredmedia'] ) {
+if ( post._embedded?.['wp:featuredmedia'] ) {
  const featuredMedia = post._embedded['wp:featuredmedia'][ 0 ];
  thumbnail = featuredMedia.media_details.sizes.thumbnail.source_url;
}

Also applies to: 220-223

🧰 Tools
🪛 Biome (1.9.4)

[error] 215-215: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 95f636c and 83ccc4f.

⛔ Files ignored due to path filters (10)
  • build/admin-settings-rtl.css is excluded by !build/**
  • build/admin-settings.asset.php is excluded by !build/**
  • build/admin-settings.css is excluded by !build/**
  • build/content-helper/dashboard-widget-rtl.css is excluded by !build/**
  • build/content-helper/dashboard-widget.asset.php is excluded by !build/**
  • build/content-helper/dashboard-widget.css is excluded by !build/**
  • build/content-helper/editor-sidebar-rtl.css is excluded by !build/**
  • build/content-helper/editor-sidebar.asset.php is excluded by !build/**
  • build/content-helper/editor-sidebar.css is excluded by !build/**
  • build/content-helper/editor-sidebar.js is excluded by !build/**
📒 Files selected for processing (16)
  • src/Models/class-smart-link.php (3 hunks)
  • src/Utils/class-utils.php (1 hunks)
  • src/content-helper/common/base-provider.tsx (2 hunks)
  • src/content-helper/common/base-wordpress-provider.tsx (1 hunks)
  • src/content-helper/common/components/thumbnail/component.tsx (1 hunks)
  • src/content-helper/common/components/thumbnail/index.ts (1 hunks)
  • src/content-helper/common/components/thumbnail/style.scss (1 hunks)
  • src/content-helper/common/css/common.scss (1 hunks)
  • src/content-helper/common/css/variables.scss (1 hunks)
  • src/content-helper/editor-sidebar/smart-linking/provider.ts (5 hunks)
  • src/content-helper/editor-sidebar/smart-linking/review-modal/component-modal.tsx (2 hunks)
  • src/content-helper/editor-sidebar/smart-linking/review-modal/component-suggestion.tsx (3 hunks)
  • src/content-helper/editor-sidebar/smart-linking/smart-linking.scss (2 hunks)
  • src/rest-api/content-helper/class-endpoint-smart-linking.php (3 hunks)
  • src/rest-api/stats/class-endpoint-posts.php (3 hunks)
  • src/services/content-api/endpoints/class-endpoint-analytics-posts.php (2 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
`**/*.{js,ts,tsx,jsx}`: "Perform a detailed review of the pr...

**/*.{js,ts,tsx,jsx}: "Perform a detailed review of the provided code with following key aspects in mind:

  • Review the code to ensure it is well-structured and adheres to best practices.
  • Verify compliance with WordPress coding standards.
  • Ensure the code is well-documented.
  • Check for security vulnerabilities and confirm the code is secure.
  • Optimize the code for performance, removing any unnecessary elements.
  • Validate JSDoc comments for accuracy, currency, and adherence to WordPress coding standards.
  • Ensure each line comment concludes with a period.
  • Confirm every JSDoc comment includes a @SInCE tag indicating the next version of the plugin to include the code.
  • Guarantee compatibility with the latest version of WordPress, avoiding deprecated functions or features."
  • src/content-helper/common/components/thumbnail/index.ts
  • src/content-helper/common/base-provider.tsx
  • src/content-helper/editor-sidebar/smart-linking/review-modal/component-modal.tsx
  • src/content-helper/editor-sidebar/smart-linking/review-modal/component-suggestion.tsx
  • src/content-helper/editor-sidebar/smart-linking/provider.ts
  • src/content-helper/common/components/thumbnail/component.tsx
  • src/content-helper/common/base-wordpress-provider.tsx
`**/*.{css,scss}`: "Perform a detailed review of the provide...

**/*.{css,scss}: "Perform a detailed review of the provided code with following key aspects in mind:

  • Review the SCSS code to ensure it is well-structured and adheres to best practices.
  • Convert dimensions greater than or equal to 3px to rem units using the to_rem function.
  • Utilize variables for sizes and colors defined in src/content-helper/common/css/variables.scss instead of hardcoding values."
  • src/content-helper/common/css/variables.scss
  • src/content-helper/common/components/thumbnail/style.scss
  • src/content-helper/common/css/common.scss
  • src/content-helper/editor-sidebar/smart-linking/smart-linking.scss
`**/*.{html,php}`: "Perform a detailed review of the provide...

**/*.{html,php}: "Perform a detailed review of the provided code with following key aspects in mind:

  • Review the HTML and PHP code to ensure it is well-structured and adheres to best practices.
  • Ensure the code follows WordPress coding standards and is well-documented.
  • Confirm the code is secure and free from vulnerabilities.
  • Optimize the code for performance, removing any unnecessary elements.
  • Validate comments for accuracy, currency, and adherence to WordPress coding standards.
  • Ensure each line comment concludes with a period.
  • Verify code compatibility with the latest version of WordPress, avoiding deprecated functions or features."
  • src/rest-api/stats/class-endpoint-posts.php
  • src/Utils/class-utils.php
  • src/Models/class-smart-link.php
  • src/services/content-api/endpoints/class-endpoint-analytics-posts.php
  • src/rest-api/content-helper/class-endpoint-smart-linking.php
🪛 Biome (1.9.4)
src/content-helper/common/base-wordpress-provider.tsx

[error] 215-215: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 220-220: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

🔇 Additional comments (30)
src/content-helper/common/css/variables.scss (1)

45-45: LGTM! Clean addition of the new gray color variable.

The new variable follows the existing naming convention and is placed in the appropriate location within the grayscale sequence.

src/content-helper/common/css/common.scss (1)

10-10: LGTM! Properly added import for the thumbnail component style.

The import statement is correctly positioned with other component style imports, maintaining consistent organization.

src/services/content-api/endpoints/class-endpoint-analytics-posts.php (3)

112-114: LGTM! Well-documented variable definition.

The $urls variable is properly documented with a PHPDoc comment and type annotation, following the established pattern in the file.


119-119: LGTM! Clean removal of processed parameter.

The code properly unsets the urls parameter after storing it in a variable, consistent with how other parameters are handled.


128-128: LGTM! Properly implemented URL parameter handling.

The code correctly appends URL parameters to the endpoint using the existing helper method, ensuring consistent parameter handling and proper URL encoding.

src/rest-api/stats/class-endpoint-posts.php (3)

177-182: Well-structured parameter definition.

The new urls parameter is properly defined with appropriate description, type, sanitization callback, and required flag.


205-215: Secure implementation of URL sanitization.

The sanitize_urls method provides a clean implementation for sanitizing an array of URLs, properly leveraging WordPress's built-in sanitize_url function. The documentation is clear and includes the appropriate @since tag.


272-272: Parameter properly passed to API.

The urls parameter is correctly passed to the Content API service, maintaining consistency with other parameters.

src/Models/class-smart-link.php (3)

15-15: Added necessary import for Utils class.

The addition of this import statement is required to support the refactoring of the get_post_id_by_url method to the Utils class.


246-246: Replaced private method with centralized utility method.

The code now uses Utils::get_post_id_by_url instead of a private method implementation, which is good for code maintainability and reuse.


438-438: Consistent use of utility method.

Using the same Utils::get_post_id_by_url method here ensures consistency throughout the codebase.

src/content-helper/editor-sidebar/smart-linking/review-modal/component-modal.tsx (2)

16-16: Updated import to include OutboundSmartLink type.

This change supports the enhancement of the Smart Linking "Review" modal with additional post details as mentioned in the PR objectives.


86-86: Updated selectedLink state type to use OutboundSmartLink.

The state now uses OutboundSmartLink instead of the generic SmartLink, which properly reflects the enhanced data structure needed for displaying additional post details in the modal.

src/content-helper/common/base-provider.tsx (2)

48-48: Changed access modifier from private to protected.

This change allows subclasses to access the abortControllers map directly, which is necessary for the new BaseWordPressProvider class to manage API request cancellations.


111-111: Changed access modifier from private to protected.

Making getOrCreateController protected allows subclasses to utilize this method for managing abort controllers, enhancing the reusability of this functionality.

src/content-helper/editor-sidebar/smart-linking/smart-linking.scss (2)

325-325: Cleaned up selector formatting.

This is a minor formatting change that improves code readability.


430-493: Enhanced styling for link suggestion details.

The complete overhaul of the .wp-parsely-link-suggestion-link-details class adds support for the new post details (thumbnail, title, metadata) mentioned in the PR objectives. The updated styling uses a clean, flexible layout with proper spacing and overflow handling.

I particularly like:

  • The use of flexbox for responsive layout
  • Proper handling of text overflow with ellipsis
  • The well-organized nested structure for different components
  • Consistent use of WordPress design variables

This implementation effectively supports the UI enhancements requested in the PR.

src/content-helper/editor-sidebar/smart-linking/review-modal/component-suggestion.tsx (7)

8-13: New imports for the suggestion component look good.

These newly introduced imports (Dashicon, KeyboardShortcuts, Tooltip, selectFn) are aligned with WordPress standards.


15-28: Icons import is consistent with WordPress best practices.

Importing the icon set from @wordpress/icons is appropriate. No concerns identified.


34-37: Imports from common utilities and new type references look fine.

The new imports (Thumbnail, getSmartShortDate, formatToImpreciseNumber, and OutboundSmartLink) integrate well with existing code.


124-145: Thumbnail and URL button block appear correct.

Utilizing <Tooltip> and adding rel="noopener" for external links meets security standards.


146-169: Data presentation layout looks good.

Displaying date, author, post type, views, and visitors is coherent.


181-181: Type change to OutboundSmartLink is valid.

Switching link to OutboundSmartLink aligns with the new approach. Ensure any dependent usage is also updated.


343-343: Param type updated to OutboundSmartLink for ReviewSuggestion.

Making sure the link prop references the richer OutboundSmartLink type is consistent with the rest of the changes.

src/rest-api/content-helper/class-endpoint-smart-linking.php (3)

18-18: New import from Parsely\Utils\Utils is fine.

Including Utils is consistent with the newly introduced functionality.


187-201: New REST route for retrieving post meta looks good.

The registration of POST /smart-linking/get-post-meta-for-urls is well documented. Make sure to confirm all relevant permissions and validations if you anticipate invalid input.


486-519: New method get_post_meta_for_urls appears logically correct.

Fetching a post by URL and returning associated metadata follows the intended design. Consider verifying URLs via filter_var or a validation callback if stricter handling of invalid URLs is required.

Would you like a script to search for existing references to confirm error handling for invalid URLs?

src/content-helper/editor-sidebar/smart-linking/provider.ts (2)

12-14: Additional imports for API period parameters, Metric, Period, and PerformanceData are appropriate.

These added imports align with existing usage patterns for stats retrieval.


343-360: New getPostMetaForURLs function is well-structured.

This method aligns with the new get-post-meta-for-urls endpoint. The doc block references @since 3.18.0 correctly, and the return type is well-defined.

src/content-helper/common/base-wordpress-provider.tsx (1)

1-316: Well-structured implementation and thorough documentation.

All functions and types are documented with @since tags, adhere to WordPress coding standards, and handle localization with @wordpress/i18n. The usage of BaseProvider for request cancellation is a sensible architectural decision that promotes maintainability. Great work!

🧰 Tools
🪛 Biome (1.9.4)

[error] 215-215: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 220-220: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

Copy link
Contributor

@vaurdan vaurdan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for working on this. It looks good to me, approved! 🙂

@acicovic acicovic merged commit d995f57 into develop Mar 10, 2025
40 checks passed
@acicovic acicovic deleted the add/post-details-to-pch-smart-linking-review-modal branch March 10, 2025 16:45
github-actions bot added a commit that referenced this pull request Mar 10, 2025
…smart-linking-review-modal Smart Linking: Add post details to the "Review" modal" (d995f57)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants