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

PCH Related Posts: Add advanced search #3117

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

acicovic
Copy link
Collaborator

@acicovic acicovic commented Jan 30, 2025

Description

With this PR, we're adding advanced search to PCH Related Posts.

To keep the fetching operation to a single API call, only AND search queries are supported. The search can query for author, section, and up to 5 tags simultaneously.

Additional changes:

  • Messaging like Top related posts in the x section in the last x days was removed, as it would become quite large and unwieldy for composite searches.
  • The tool doesn't remember that last selections/values anymore, since this would also not play well with composite searches while opening different posts.
  • We fixed a bug and added some tests for this case.
  • The code was greatly simplified in many places.

Motivation and context

Offer a way to get more specific results.

How has this been tested?

Some tests were added, others adjusted and a couple of them removed.

Screenshots

image

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced related posts filtering with support for multiple tags, authors, and sections
  • Changes

    • Simplified related posts settings and filter management
    • Updated API query parameters to support multiple tags
    • Removed deprecated filter types and settings
  • Improvements

    • Streamlined related posts component logic
    • Updated test coverage for new filtering approach
  • Refactoring

    • Removed unnecessary filter-related code and interfaces
    • Simplified URL parameter handling in API endpoints

This release focuses on improving the flexibility and usability of related posts filtering while removing legacy code and simplifying the overall implementation.

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

coderabbitai bot commented Jan 30, 2025

📝 Walkthrough

Walkthrough

This pull request introduces significant changes to the Related Posts functionality across multiple files. The primary modifications involve removing FilterBy and FilterValue properties from various interfaces and components, simplifying the filter mechanism for related posts. The changes streamline the approach to filtering posts by introducing a more flexible PostFilters structure with separate properties for authors, sections, and tags. The refactoring affects TypeScript types, React components, API endpoints, and test files.

Changes

File Change Summary
src/content-helper/common/settings/types/sidebar-settings.d.ts Removed FilterBy and FilterValue properties from RelatedPostsSettings interface
src/content-helper/common/utils/api.ts Updated tag property type from string to string[] in AnalyticsApiOptionalQueryParams
src/content-helper/common/utils/constants.ts Removed Unavailable from PostFilterType enum, replaced PostFilter with PostFilters interface
src/content-helper/editor-sidebar/... Multiple files updated to remove filter-related logic and simplify related posts handling
src/rest-api/settings/... Removed FilterBy and FilterValue keys from RelatedPosts configuration
tests/... Updated test cases to reflect new related posts filtering and message handling

Sequence Diagram

sequenceDiagram
    participant User
    participant EditorSidebar
    participant RelatedPostsProvider
    participant ContentAPI

    User->>EditorSidebar: Open sidebar
    EditorSidebar->>RelatedPostsProvider: Request related posts
    RelatedPostsProvider->>ContentAPI: Fetch posts with new filters
    ContentAPI-->>RelatedPostsProvider: Return filtered posts
    RelatedPostsProvider-->>EditorSidebar: Display related posts
Loading

Possibly related PRs

Suggested Labels

Type: Refactoring, Changelog: Changed

Suggested Reviewers

  • vaurdan
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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. (Beta)
  • @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.

foreach ( $params as $param ) {
$param = rawurlencode( $param );
if ( strpos( $url, $param_name . '=' ) === false ) {
$url = add_query_arg( $param_name, $param, $url );
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Changed because add_query_arg() would remove same key params that were previously added.

Comment on lines -185 to -208
test( 'should show no results message when there is no tag or category in the post', async () => {
const getRelatedPostsFn = getRelatedPostsMockFn( () => Promise.resolve( {
message: 'The Parse.ly API did not return any results for posts by "author".',
posts: [],
} ) );

setMockPostData( [ 'admin' ], [], [] );

await waitFor( async () => {
render( relatedPostsPanel );
expect( getLoadingMessage() ).toBeInTheDocument();
} );

expect( getRelatedPostsFn ).toHaveBeenCalled();
expect( getLoadingMessage() ).toBeNull();

const relatedPostDescr = getRelatedPostDescr();
expect( relatedPostDescr ).toBeInTheDocument();
expect( relatedPostDescr ).toBeVisible();

// When there is no tag or category in the post, it should fallback to the author.
expect( relatedPostDescr?.textContent ).toEqual( 'Top related posts by admin in the last 7 days.' );
expect( getRelatedPostsEmptyMessage() ).toBeInTheDocument();
} );
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not really applicable with the new setup.

Comment on lines -50 to -61
/**
* Verifies that the Related Posts panel will work correctly when a new
* taxonomy is added from within the WordPress Post Editor.
*
* @since 3.17.0 Migrated to Playwright.
*/
test( 'Should work correctly when a taxonomy is added from within the WordPress Post Editor', async ( { admin } ) => {
const categoryName = 'Analytics That Matter';

expect( await getRelatedPostsMessage(
admin, categoryName, '', 'section', '.related-posts-descr'
) ).toMatch( `Top related posts in the “${ categoryName }” section in the last 7 days.` );
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We were essentially testing Gutenberg functionality here. With the cleanup in the getRelatedPostsMessage() function, I chose to just remove it.

Comment on lines -63 to -91
// Select/add category in the Post Editor.
if ( category !== '' ) {
const categoryToggleButton = page.getByRole( 'button', { name: 'Categories' } );
await categoryToggleButton.click();
await page.getByRole( 'button', { name: 'Add New Category' } ).first().click();
await page.getByLabel( 'New Category Name' ).fill( category );
await page.getByRole( 'button', { name: 'Add New Category' } ).last().click();
await categoryToggleButton.click();
}

// Select/add tag in the Post Editor.
if ( tag !== '' ) {
const tagToggleButton = page.getByRole( 'button', { name: 'Tags' } );
await tagToggleButton.click();
await page.getByLabel( 'Add New Tag' ).fill( tag );
await page.keyboard.press( 'Enter' );
await tagToggleButton.click();
}

// Show the Content Helper Sidebar.
// Show the Content Helper Sidebar and expand the Related Posts panel.
await page.getByRole( 'button', { name: 'Parse.ly' } ).click();
await setSidebarPanelExpanded( page, 'Related Posts', true );

// Set the filter type.
if ( '' !== filterType ) {
await page.keyboard.press( 'Tab' );
await page.keyboard.type( filterType.charAt( 0 ) );
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The removed code wasn't been used in most tests, and our new advanced search approach made it obsolete. Rewriting it would provide very limited value and take some time, so I opted to remove it instead.

If we ever want to extensively test filter selection impact, it will be maybe better to have a dedicated function for that.

@acicovic acicovic marked this pull request as ready for review January 30, 2025 13:10
@acicovic acicovic requested a review from a team as a code owner January 30, 2025 13:10
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: 1

🧹 Nitpick comments (9)
src/content-helper/editor-sidebar/related-posts/provider.ts (3)

44-50: Add a @SInCE tag in the method’s JSDoc.
WordPress coding standards require a @since annotation for newly introduced methods.


53-65: End parameter descriptions with a period.
WordPress coding guidelines recommend ending each JSDoc parameter line with a period.


71-90: Sanitize filter input before API requests.
Ensure that author, section, and tags values are safely handled to prevent potential injection.

src/content-helper/editor-sidebar/related-posts/component.tsx (3)

126-130: Externalize default filter values.
Consider moving them to a constants file to simplify updates and maintenance.


Line range hint 185-209: Consider a fully async/await approach.
Refactor the promise chain for clearer readability and error handling.


212-217: Complete JSDoc with @SInCE and punctuation.
Add a @since annotation if newly introduced, and end each parameter line with a period.

src/content-helper/common/utils/api.ts (1)

15-15: Update JSDoc for the tag property to document the array support.

The change from string to string[] is correct and aligns with the multi-tag filtering requirement. Consider adding JSDoc to document this capability.

 export interface AnalyticsApiOptionalQueryParams extends ApiPeriodRange {
+	/** Array of tags to filter by. Supports up to 5 tags. @since 3.14.0 */
 	tag?: string[];
src/content-helper/editor-sidebar/related-posts/component-filter-settings.tsx (2)

22-24: Add JSDoc for FilterControlsProps properties.

The type definition needs documentation for its properties.

 type FilterControlsProps = {
+	/** Post filters containing author, section, and tags. @since 3.14.0 */
 	filters: PostFilters;
+	/** Optional label for the filter controls. @since 3.14.0 */
 	label?: string;
+	/** Callback function when filters change. @since 3.14.0 */
 	onFiltersChange: ( selection: string | null | undefined, type:PostFilterType ) => void;

40-43: Consider extracting the condition to a descriptive variable.

The condition checking for empty data could be more readable.

-	if ( 0 === postData.authors.length &&
-			0 === postData.categories.length &&
-			0 === postData.tags.length
-	) {
+	const hasNoFilterableData = 0 === postData.authors.length &&
+		0 === postData.categories.length &&
+		0 === postData.tags.length;
+	
+	if (hasNoFilterableData) {
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between cb94d35 and d0c97d0.

⛔ Files ignored due to path filters (8)
  • build/content-helper/dashboard-widget.asset.php is excluded by !build/**
  • build/content-helper/dashboard-widget.js 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/**
  • build/loader.asset.php is excluded by !build/**
  • build/loader.js is excluded by !build/**
📒 Files selected for processing (17)
  • src/content-helper/common/settings/types/sidebar-settings.d.ts (0 hunks)
  • src/content-helper/common/utils/api.ts (1 hunks)
  • src/content-helper/common/utils/constants.ts (1 hunks)
  • src/content-helper/editor-sidebar/editor-sidebar.tsx (1 hunks)
  • src/content-helper/editor-sidebar/related-posts/component-filter-settings.tsx (2 hunks)
  • src/content-helper/editor-sidebar/related-posts/component.tsx (8 hunks)
  • src/content-helper/editor-sidebar/related-posts/provider.ts (2 hunks)
  • src/content-helper/editor-sidebar/related-posts/related-posts.scss (0 hunks)
  • src/rest-api/settings/class-endpoint-editor-sidebar-settings.php (1 hunks)
  • src/services/content-api/endpoints/class-endpoint-analytics-posts.php (2 hunks)
  • tests/Integration/RestAPI/Settings/EndpointEditorSidebarSettingsTest.php (1 hunks)
  • tests/Integration/Services/ContentAPI/Endpoints/EndpointAnalyticsPostsTest.php (2 hunks)
  • tests/e2e/specs/content-helper/errors.spec.ts (2 hunks)
  • tests/e2e/specs/content-helper/related-posts-panel-filters.spec.ts (1 hunks)
  • tests/e2e/specs/content-helper/top-bar-icon.spec.ts (1 hunks)
  • tests/e2e/utils.ts (1 hunks)
  • tests/js/content-helper/structure.test.tsx (7 hunks)
💤 Files with no reviewable changes (2)
  • src/content-helper/common/settings/types/sidebar-settings.d.ts
  • src/content-helper/editor-sidebar/related-posts/related-posts.scss
🧰 Additional context used
📓 Path-based instructions (15)
tests/e2e/specs/content-helper/related-posts-panel-filters.spec.ts (1)

Pattern **/*.{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/utils/api.ts (1)

Pattern **/*.{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/rest-api/settings/class-endpoint-editor-sidebar-settings.php (1)

Pattern **/*.{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."
tests/Integration/RestAPI/Settings/EndpointEditorSidebarSettingsTest.php (1)

Pattern **/*.{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."
tests/e2e/utils.ts (1)

Pattern **/*.{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."
tests/e2e/specs/content-helper/top-bar-icon.spec.ts (1)

Pattern **/*.{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."
tests/e2e/specs/content-helper/errors.spec.ts (1)

Pattern **/*.{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/services/content-api/endpoints/class-endpoint-analytics-posts.php (1)

Pattern **/*.{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."
tests/Integration/Services/ContentAPI/Endpoints/EndpointAnalyticsPostsTest.php (1)

Pattern **/*.{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/content-helper/common/utils/constants.ts (1)

Pattern **/*.{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/editor-sidebar/related-posts/component-filter-settings.tsx (1)

Pattern **/*.{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/editor-sidebar/related-posts/provider.ts (1)

Pattern **/*.{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."
tests/js/content-helper/structure.test.tsx (1)

Pattern **/*.{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/editor-sidebar/related-posts/component.tsx (1)

Pattern **/*.{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/editor-sidebar/editor-sidebar.tsx (1)

Pattern **/*.{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."
🪛 Biome (1.9.4)
src/content-helper/editor-sidebar/related-posts/provider.ts

[error] 40-40: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)

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

121-123: LGTM! Method name change improves clarity.

The renamed method append_same_key_params_to_url better describes its purpose of appending multiple values with the same key.


157-170: LGTM! Well-documented method with improved parameter names.

The PHPDoc follows WordPress standards, and the parameter names are more descriptive and aligned with their purpose.


171-186: LGTM! Robust implementation with proper validation.

The implementation includes:

  • Empty key and value validation
  • Proper URL encoding for special characters
  • Correct URL parameter appending logic
tests/Integration/Services/ContentAPI/Endpoints/EndpointAnalyticsPostsTest.php (3)

50-71: LGTM! Well-structured test method with comprehensive documentation.

The test method follows PHPUnit best practices with proper annotations and parameter documentation.


72-81: LGTM! Test implementation follows best practices.

The test properly uses reflection to access the protected method and performs exact string comparison for validation.


83-158: LGTM! Comprehensive data provider with excellent test coverage.

The data provider includes well-organized test cases covering:

  • Basic URL parameter handling
  • Complex scenarios with existing parameters
  • Special character handling
  • Edge cases with empty values
src/content-helper/editor-sidebar/related-posts/provider.ts (1)

10-14: No concerns about the new imports.
They adhere to standard WordPress and TypeScript usage with no functional or security concerns.

src/content-helper/editor-sidebar/related-posts/component.tsx (5)

Line range hint 11-24: Imports and enumerations are consistent.
Usage of WordPress imports and enumerations appears fine and secure.


219-236: Validate or sanitize filter input.
Ensure that user-provided data is not used in a way that could introduce XSS or other vulnerabilities.


259-259: Localized string usage is correct.
Good job using the __() function for translations.


295-296: Filter component integration looks good.
Props usage is consistent with the new PostFilters interface.


314-314: Clear no-results message.
Provides a user-friendly fallback in case no posts are returned.

tests/e2e/specs/content-helper/related-posts-panel-filters.spec.ts (1)

46-47: Test coverage is appropriate.
Verifying for “Loading…” ensures the fetch request initiates successfully.

src/content-helper/editor-sidebar/related-posts/component-filter-settings.tsx (1)

82-92: LGTM! Well-implemented tag filtering.

The FormTokenField implementation correctly:

  • Limits tags to 5 using maxLength
  • Hides unnecessary help text
  • Uses placeholder text
  • Provides tag suggestions
tests/e2e/specs/content-helper/errors.spec.ts (1)

86-87: LGTM! Tests updated to match new UI text.

The test changes correctly reflect the updated UI message and selector.

src/rest-api/settings/class-endpoint-editor-sidebar-settings.php (1)

84-91: LGTM! Clean removal of deprecated filter settings.

The RelatedPosts configuration has been correctly simplified while maintaining essential settings.

tests/e2e/utils.ts (2)

44-45: LGTM! Function signature simplified to match new advanced search approach.

The removal of category, tag, and filterType parameters aligns with the PR's objective of supporting composite searches. The simplified signature improves maintainability.

Also applies to: 50-51


57-60: LGTM! Clear and focused implementation.

The code is well-commented and performs the necessary steps in a straightforward manner.

src/content-helper/common/utils/constants.ts (2)

Line range hint 32-38: LGTM! Filter types aligned with advanced search feature.

The PostFilterType enum now precisely reflects the available filter types for the advanced search feature.


50-55: LGTM! Well-designed interface for advanced search.

The PostFilters interface effectively supports:

  • AND search queries with author and section
  • Multiple tag selection through the tags array
tests/e2e/specs/content-helper/top-bar-icon.spec.ts (1)

78-79: LGTM! Tests updated to match new UI.

The selector and expected message have been appropriately updated to reflect the new advanced search interface.

src/content-helper/editor-sidebar/editor-sidebar.tsx (2)

14-14: LGTM! Import reorganized for better code organization.

The PluginSidebar import is now properly sourced from type definitions.


Line range hint 71-77: LGTM! Settings structure simplified.

The removal of FilterBy and FilterValue from RelatedPosts settings aligns with the new advanced search implementation, reducing complexity while maintaining type safety.

tests/js/content-helper/structure.test.tsx (5)

21-21: LGTM: Import statement aligns with type changes.

The addition of the PostData type import is consistent with the refactoring of related posts handling.


128-128: LGTM: Mock function signature simplified.

The function now directly returns PostData[], which aligns with the simplified related posts API interactions.


183-185: LGTM: Mock data structure simplified.

The mock data is now directly returned without wrapping it in a GetRelatedPostsResult object, consistent with the new API structure.


290-292: LGTM: Function signature updated correctly.

The type annotation change to PostData[] maintains consistency with the simplified data structure.


308-310: LGTM: Function signature updated correctly.

The type annotation change to PostData[] maintains consistency with the simplified data structure.

tests/Integration/RestAPI/Settings/EndpointEditorSidebarSettingsTest.php (1)

77-79: LGTM: RelatedPosts array simplified and properly ordered.

The removal of FilterBy and FilterValue keys aligns with the broader restructuring, and the remaining keys are correctly sorted alphabetically as per the comment guidelines.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant