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: Update Settings API structure #2351

Merged
merged 17 commits into from
Apr 2, 2024
Merged

Conversation

vaurdan
Copy link
Contributor

@vaurdan vaurdan commented Apr 1, 2024

Description

This PR aims to update the Settings API structure, by fixing a known issue with nested settings and by improving the consistency of the code base by moving all the individual feature settings to its own nested setting.

Motivation and context

Improve the reliability of the Parse.ly plugin, while improving the code base for better maintainability.

How has this been tested?

Tested locally. I have tested all the individual settings, and also reset my user preferences to look for any issues when starting with a blank state.

Summary by CodeRabbit

  • New Features

    • Introduced a more granular settings structure for related posts, including period, metric, filter by, and filter value adjustments directly within the editor sidebar.
    • Added a new hook for fetching post data such as authors, categories, and tags to enhance content relevance and connectivity.
  • Refactor

    • Refactored the settings interface to accommodate new categorizations for performance stats, related posts, smart linking, and title suggestions, ensuring a more organized and accessible settings management experience.
  • Tests

    • Expanded test coverage to include mocking of new settings and post data fetching functionalities, alongside adding new helper functions and cleanup procedures to maintain test environment integrity.

@vaurdan vaurdan added this to the 3.14.3 milestone Apr 1, 2024
@vaurdan vaurdan self-assigned this Apr 1, 2024
@vaurdan vaurdan requested a review from a team as a code owner April 1, 2024 11:24
Copy link
Contributor

coderabbitai bot commented Apr 1, 2024

Walkthrough

Walkthrough

The updates revolve around enhancing related posts settings and data management in a content management system. Key improvements include the introduction of a hook to fetch post data such as authors, categories, and tags. The restructuring of related posts settings aims to improve organization and accessibility, while test enhancements increase reliability. These changes collectively aim to streamline the management and presentation of related posts, enhancing usability and customization.

Changes

File Path Change Summary
.../editor-sidebar/related-posts/component.tsx Updated to access and modify RelatedPosts settings with nested properties.
.../editor-sidebar/related-posts/hooks.ts Introduced usePostData hook for retrieving current post data.
tests/js/content-helper/structure.test.tsx Enhanced tests with mocking, new helper functions, and usePostData hook.
.../common/settings/types/index.ts Exported RelatedPostsSettings and SmartLinkingSettings types.
.../common/settings/types/sidebar-settings.d.ts Refactored SidebarSettings to use separate interfaces for subsettings like RelatedPosts.

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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

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.

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: 0

Review Status

Configuration used: .coderabbit.yaml

Commits Files that changed from the base of the PR and between de97cc5 and cf11d5c.
Files ignored due to path filters (2)
  • build/content-helper/editor-sidebar.asset.php is excluded by !build/**
  • build/content-helper/editor-sidebar.js is excluded by !build/**
Files selected for processing (16)
  • src/Endpoints/user-meta/class-base-endpoint-user-meta.php (2 hunks)
  • src/Endpoints/user-meta/class-editor-sidebar-settings-endpoint.php (2 hunks)
  • src/content-helper/common/settings/types/index.ts (1 hunks)
  • src/content-helper/common/settings/types/sidebar-settings.d.ts (2 hunks)
  • src/content-helper/editor-sidebar/editor-sidebar.tsx (3 hunks)
  • src/content-helper/editor-sidebar/performance-details/component-panel-overview.tsx (4 hunks)
  • src/content-helper/editor-sidebar/performance-details/component.tsx (5 hunks)
  • src/content-helper/editor-sidebar/related-posts/component.tsx (5 hunks)
  • src/content-helper/editor-sidebar/smart-linking/component-settings.tsx (4 hunks)
  • src/content-helper/editor-sidebar/smart-linking/component.tsx (5 hunks)
  • src/content-helper/editor-sidebar/smart-linking/smart-linking.tsx (1 hunks)
  • src/content-helper/editor-sidebar/tabs/sidebar-tools-tab.tsx (3 hunks)
  • src/content-helper/editor-sidebar/title-suggestions/component-settings.tsx (1 hunks)
  • src/content-helper/editor-sidebar/title-suggestions/component.tsx (3 hunks)
  • tests/Integration/BaseUserMetaEndpointTest.php (1 hunks)
  • tests/Integration/Endpoints/EditorSidebarSettingsEndpointTest.php (9 hunks)
Additional Context Used
Path-based Instructions (16)
src/content-helper/common/settings/types/index.ts (1)

**/*.{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/settings/types/sidebar-settings.d.ts (1)

**/*.{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/title-suggestions/component-settings.tsx (1)

**/*.{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/tabs/sidebar-tools-tab.tsx (1)

**/*.{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/Endpoints/user-meta/class-editor-sidebar-settings-endpoint.php (1)

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

**/*.{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/Integration/BaseUserMetaEndpointTest.php (1)

**/*.{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/editor-sidebar/performance-details/component-panel-overview.tsx (1)

**/*.{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/smart-linking/component-settings.tsx (1)

**/*.{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/performance-details/component.tsx (1)

**/*.{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)

**/*.{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/title-suggestions/component.tsx (1)

**/*.{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/Endpoints/user-meta/class-base-endpoint-user-meta.php (1)

**/*.{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/Endpoints/EditorSidebarSettingsEndpointTest.php (1)

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

**/*.{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/smart-linking/component.tsx (1)

**/*.{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.
Additional comments not posted (38)
src/content-helper/common/settings/types/index.ts (2)

5-8: Ensure that the newly added settings types (RelatedPostsSettings and SmartLinkingSettings) are being used elsewhere in the codebase as intended. This addition aligns with the PR objectives of enhancing the handling of nested settings.

Verification successful

The verification process has confirmed that RelatedPostsSettings and SmartLinkingSettings are being used across the codebase as intended, particularly within the src/content-helper/editor-sidebar/smart-linking/ directory and related settings types. This aligns with the PR objectives of enhancing the handling of nested settings, thus confirming the original review comment.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that RelatedPostsSettings and SmartLinkingSettings are used in other parts of the codebase.
rg --type ts "RelatedPostsSettings|SmartLinkingSettings"

Length of output: 3760


17-20: The export statements for RelatedPostsSettings and SmartLinkingSettings are correctly added and align with the PR's objectives. However, ensure that all newly exported types are properly documented, especially if they introduce significant changes or new concepts.

Consider adding JSDoc comments for the newly exported types to improve code documentation and maintainability.

src/content-helper/common/settings/types/sidebar-settings.d.ts (3)

11-14: The refactoring of SidebarSettings to include PerformanceStats, RelatedPosts, SmartLinking, and TitleSuggestions as separate interfaces is a positive change for modularity and clarity. This aligns well with the PR's objectives to improve the handling of nested settings.


39-50: The RelatedPostsSettings interface is well-defined and aligns with the PR's objectives. Ensure that the types for FilterBy, FilterValue, Metric, and Period are consistent with their usage elsewhere in the codebase.

Verification successful

The types for FilterBy, FilterValue, Metric, and Period in the RelatedPostsSettings interface are used consistently across the codebase, aligning with their usage elsewhere as indicated by the script output. This confirms the initial review comment regarding the alignment of these types with the PR's objectives.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify consistency of types for RelatedPostsSettings across the codebase.
rg --type ts "FilterBy|FilterValue|Metric|Period"

Length of output: 19265


52-61: The SmartLinkingSettings interface is correctly defined. It's important to ensure that the MaxLinks and MaxLinkWords properties are used appropriately in the codebase, especially in functions that might affect the plugin's performance.

Verification successful

The verification process has confirmed that the MaxLinks and MaxLinkWords properties are used appropriately within the SmartLinking functionality. These properties are integral to configuring the feature, including setting default values, validating property types, and directly influencing the SmartLinking logic. This usage pattern suggests a level of control over the feature's behavior, which is crucial for managing performance. Therefore, the initial review comment is consistent with the codebase.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify usage of MaxLinks and MaxLinkWords in SmartLinking functionality.
rg --type ts "MaxLinks|MaxLinkWords"

Length of output: 3568

src/content-helper/editor-sidebar/title-suggestions/component-settings.tsx (1)

19-19: The update to the onSettingChange function signature, changing the key reference from 'TitleSuggestionsSettings' to 'TitleSuggestions', is consistent with the PR's objectives to improve settings structure. Ensure that this change is reflected and correctly handled in all places where onSettingChange is called.

Verification successful

The verification process confirms that the updated onSettingChange function signature is correctly handled within the title-suggestions feature. The usage in other features, such as smart-linking, has a different context and does not affect this verification.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that the updated onSettingChange function signature is correctly handled everywhere it's called.
rg --type ts "onSettingChange"

Length of output: 1343

src/content-helper/editor-sidebar/tabs/sidebar-tools-tab.tsx (3)

42-46: The update to use settings.TitleSuggestions.Open for the initialOpen property of the PanelBody for Title Suggestions is a good practice, aligning with the PR's objectives to improve settings structure. Ensure that similar updates are consistently applied across all relevant components.


60-66: The changes for Smart Linking settings, specifically updating the initialOpen property to use settings.SmartLinking.Open, are correctly implemented. This enhances the maintainability and clarity of the settings structure.


80-86: The adjustments for Related Posts settings, using settings.RelatedPosts.Open for the initialOpen property, are in line with the PR's objectives. This structured approach to settings improves code readability and maintainability.

src/content-helper/editor-sidebar/smart-linking/component-settings.tsx (3)

17-17: The import statement has been updated to reflect the new structure of Smart Linking settings. This change aligns with the PR's objective to improve the consistency of the code base by organizing settings into distinct, nested entities.


29-29: The signature of the onSettingChange function has been updated to accept a keyof Settings type for the setting parameter and a number type for the value parameter. This change ensures type safety and clarity in the function's usage, aligning with best practices for TypeScript development.


226-226: The keys passed to the onSettingChange function have been updated from 'SmartLinkingMaxLinks' to 'MaxLinks' and 'SmartLinkingMaxLinkWords' to 'MaxLinkWords'. This change is part of the restructuring effort to improve the clarity and maintainability of the code by using more concise and meaningful identifiers.

Also applies to: 239-239

src/content-helper/editor-sidebar/performance-details/component.tsx (3)

83-83: The function isPanelVisible has been updated to access the PerformanceStats settings using the new structure. This change ensures that the visibility of panels in the Performance Stats menu is correctly determined based on the updated settings structure.


114-130: The togglePanel function has been updated to work with the new settings structure for managing visible panels in the Performance Stats menu. This change ensures that the visibility state of panels can be toggled and saved correctly according to the updated settings structure.

Also applies to: 128-130


156-157: The resetAll and PerformanceStats component have been updated to reflect the new settings structure for managing performance settings. These changes ensure that the default visibility of panels can be reset and that the period setting is correctly accessed and updated.

Also applies to: 251-251

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

73-90: The initialization of default settings for Performance Stats, Related Posts, Smart Linking, and Title Suggestions has been updated to reflect the new settings structure. This change ensures that the default settings align with the restructured settings objects, improving code consistency and maintainability.


117-163: The getSettingsFromJson function has been updated to validate and merge settings according to the new structure. This includes checks and default assignments for various settings related to Performance Stats, Related Posts, Smart Linking, and Title Suggestions. Ensuring that settings are correctly validated and merged is crucial for maintaining the reliability of the plugin's functionality.


249-249: The SidebarPerformanceTab component's period prop has been updated to access the PerformanceStats.Period setting according to the new settings structure. This change ensures that the correct period setting is passed to the component, aligning with the updated settings organization.

src/content-helper/editor-sidebar/title-suggestions/component.tsx (3)

38-39: The state initialization for tone and persona has been updated to access the TitleSuggestions settings using the new structure. This change ensures that the component's state is correctly initialized based on the updated settings structure, aligning with the PR's objectives to improve code consistency.


77-80: The onSettingChange function has been updated to work with the new TitleSuggestions settings structure. This change ensures that updates to the title suggestions settings are correctly applied and saved, aligning with the updated settings organization.


288-289: The props persona and tone for the TitleSuggestionsSettings component have been updated to access the TitleSuggestions settings using the new structure. This ensures that the correct settings are passed to the component, aligning with the updated settings organization.

src/Endpoints/user-meta/class-base-endpoint-user-meta.php (4)

199-203: The addition of the $parent_key parameter to the sanitize_value method enables support for nested settings structures. This enhancement is crucial for handling complex settings arrangements, aligning with the PR's objectives to improve the handling of nested settings.


206-239: The logic within the sanitize_value method has been updated to recursively handle nested arrays and specifications based on the parent key. This change ensures that nested settings are correctly sanitized and validated, improving the reliability and maintainability of the plugin's settings handling.


256-281: The sanitize_subvalue method has been enhanced to work with composite keys, allowing for the validation and sanitization of nested settings. This change supports the improved handling of nested settings structures, ensuring that settings values are correctly sanitized based on their hierarchical position.


293-314: New methods have been added to check the validity of composite keys, retrieve valid values and defaults based on key paths, and get specifications for nested settings. These enhancements facilitate the improved handling of nested settings, ensuring that settings are correctly validated and managed according to their hierarchical structure.

Also applies to: 322-337, 345-360, 369-382

tests/Integration/Endpoints/EditorSidebarSettingsEndpointTest.php (3)

32-38: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [35-48]

The changes to the $default_value array, specifically the renaming of key names within the PerformanceStats and TitleSuggestions arrays, align with the PR's objectives to update the Settings API structure. Ensure that these new key names are consistently used across the entire codebase to avoid any discrepancies.


179-188: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [168-185]

The annotations for the test_endpoint_correctly_handles_put_requests method have been updated to reflect the correct functionality being tested. This is a good practice as it ensures clarity and accuracy in test documentation. However, ensure that the test implementation aligns with these updated annotations and accurately tests the endpoint's behavior with the new settings structure.


212-219: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [198-216]

The method test_valid_nested_performance_stats_settings_period has been updated to reflect the new nested settings structure. It's crucial to ensure that this test, along with others, thoroughly covers the changes made to the settings API, particularly the handling of nested settings. Consider adding more test cases if necessary to cover all possible scenarios and edge cases introduced by the restructuring.

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

49-50: The changes to access settings using nested properties under RelatedPosts for Period and Metric are in line with the PR's objectives to improve the handling of nested settings. This approach enhances code readability and maintainability. Ensure that these properties are consistently accessed using the new structure throughout the codebase.


103-104: The update to use nested properties for FilterBy and FilterValue within the RelatedPosts settings is a positive change that aligns with the PR's goals. This modification improves the clarity of how settings are structured and accessed. Double-check that the new structure is correctly implemented in all relevant parts of the codebase.


127-131: The restructuring of settings to use nested properties under RelatedPosts when updating filter settings is a good practice that enhances the code's maintainability and readability. It's important to ensure that the rest of the codebase is updated to reflect these changes, particularly in areas where these settings are being read or modified.


145-148: The changes to organize settings related to the metric under the RelatedPosts nested structure are consistent with the PR's objectives. This organization makes the settings structure more intuitive and easier to manage. Confirm that this new structure is properly utilized wherever these settings are accessed or updated.


164-167: The update to nest the Period setting under RelatedPosts is a logical step towards improving the settings API structure. This change not only makes the code more organized but also aligns with the PR's goals. Ensure that this new nested structure is correctly implemented across the entire codebase.

src/content-helper/editor-sidebar/smart-linking/component.tsx (5)

18-20: The renaming of the SmartLinkingSettings component to SmartLinkingSettingsComponent and its updated usage within the SmartLinkingPanel is a clear and understandable change. This renaming helps differentiate between the settings data structure and the component itself, improving code readability. Ensure that this new naming convention is consistently applied throughout the codebase.


147-148: The changes to handle setting changes for MaxLinks and MaxLinkWords with updated state management are crucial for the functionality of the SmartLinkingPanel. It's important to ensure that these settings are correctly updated both in the component's state and in the broader application context. Consider adding tests to verify that these settings changes are handled as expected.


158-177: The implementation of the onSettingChange function to update settings in the Smart Linking store and the Settings Context is a good practice. This ensures that settings changes are propagated correctly throughout the application. Double-check that this function is robustly implemented and handles all possible edge cases, especially considering the dynamic nature of the settings it manages.


194-195: The loading of Smart Linking settings from the WordPress database and storing them in the Smart Linking store is a critical operation. Ensure that this operation is performed securely and efficiently, with proper error handling in case the settings cannot be loaded. Additionally, verify that these settings are used consistently across the application.


618-618: The usage of the SmartLinkingSettingsComponent with the onSettingChange handler is correctly implemented. This ensures that changes to the Smart Linking settings are handled appropriately. Ensure that the component's props are fully utilized and that the component behaves as expected in all scenarios.

coderabbitai[bot]
coderabbitai bot previously requested changes Apr 1, 2024
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: 3

Review Status

Configuration used: .coderabbit.yaml

Commits Files that changed from the base of the PR and between cf11d5c and 00edf87.
Files selected for processing (4)
  • bin/install-wp-tests.sh (1 hunks)
  • src/Endpoints/user-meta/class-base-endpoint-user-meta.php (2 hunks)
  • src/Endpoints/user-meta/class-editor-sidebar-settings-endpoint.php (1 hunks)
  • tests/Integration/Endpoints/EditorSidebarSettingsEndpointTest.php (9 hunks)
Files skipped from review as they are similar to previous changes (2)
  • src/Endpoints/user-meta/class-editor-sidebar-settings-endpoint.php
  • tests/Integration/Endpoints/EditorSidebarSettingsEndpointTest.php
Additional Context Used
Path-based Instructions (1)
src/Endpoints/user-meta/class-base-endpoint-user-meta.php (1)

**/*.{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.
Additional comments not posted (2)
src/Endpoints/user-meta/class-base-endpoint-user-meta.php (2)

199-203: The addition of the $parent_key parameter to the sanitize_value method enhances the handling of nested arrays. Ensure that all calls to this method have been updated to include the new parameter where necessary.


288-289: Ensure to add @since DocBlocks for new functions introduced in this file to maintain consistency and provide versioning information for future reference.

bin/install-wp-tests.sh Show resolved Hide resolved
bin/install-wp-tests.sh Show resolved Hide resolved
src/Endpoints/user-meta/class-base-endpoint-user-meta.php Outdated Show resolved Hide resolved
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: 0

Review Status

Configuration used: .coderabbit.yaml

Commits Files that changed from the base of the PR and between 00edf87 and 3a1dd9a.
Files selected for processing (2)
  • src/Endpoints/user-meta/class-base-endpoint-user-meta.php (2 hunks)
  • tests/Integration/Endpoints/EditorSidebarSettingsEndpointTest.php (8 hunks)
Files skipped from review as they are similar to previous changes (1)
  • tests/Integration/Endpoints/EditorSidebarSettingsEndpointTest.php
Additional Context Used
Path-based Instructions (1)
src/Endpoints/user-meta/class-base-endpoint-user-meta.php (1)

**/*.{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.
Additional comments not posted (7)
src/Endpoints/user-meta/class-base-endpoint-user-meta.php (7)

202-203: The addition of the $parent_key parameter to the sanitize_value method is a significant change. It enables handling nested settings more effectively by allowing recursion based on the parent key. This is a positive change for the codebase, enhancing its ability to manage complex settings structures.


206-240: The implementation of nested array handling in the sanitize_value method is well thought out. It uses recursion for nested arrays and leverages the sanitize_subvalue method for non-array values or non-nested specs. This approach maintains code readability and ensures that each setting, regardless of its depth, is sanitized appropriately.


249-281: The sanitize_subvalue method has been updated to handle composite keys, which is crucial for supporting nested settings. The method now correctly identifies valid values for each setting based on its path, ensuring that only allowed values are saved. This is a critical security and integrity measure for the settings API.


287-316: The addition of the is_valid_key method is a valuable enhancement. It provides a mechanism to verify the validity of a composite key, which is essential for ensuring that only valid settings paths are accessed or modified. This method enhances the security and robustness of the settings API by preventing unauthorized access to settings.


318-341: The get_valid_values method is a well-implemented utility that retrieves valid values for a given setting path. This method is crucial for the sanitize_subvalue method to determine if a value is allowed for a specific setting. It's a good practice to centralize the logic for retrieving valid values, as it improves maintainability and reduces code duplication.


343-366: The get_default method provides a mechanism to retrieve default values for settings based on their path. This method is essential for ensuring that missing or invalid settings are replaced with sensible defaults, thereby maintaining the integrity of the plugin's configuration. The implementation is straightforward and effective.


368-390: The get_nested_specs method is a new addition that retrieves specifications for nested settings based on a composite key. This method is crucial for supporting the new nested settings structure, allowing the sanitize_value method to correctly process nested arrays. The implementation is clear and aligns with the objectives of enhancing nested settings handling.

@acicovic
Copy link
Collaborator

acicovic commented Apr 1, 2024

@vaurdan, I've addressed my own feedback in 3a1dd9a and cb76479. Please review the changes just to make sure!

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: 0

Review Status

Configuration used: .coderabbit.yaml

Commits Files that changed from the base of the PR and between 3a1dd9a and cb76479.
Files ignored due to path filters (2)
  • build/content-helper/editor-sidebar.asset.php is excluded by !build/**
  • build/content-helper/editor-sidebar.js is excluded by !build/**
Files selected for processing (1)
  • src/content-helper/editor-sidebar/editor-sidebar.tsx (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • src/content-helper/editor-sidebar/editor-sidebar.tsx
Additional Context Used

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: 0

Review Status

Configuration used: .coderabbit.yaml

Commits Files that changed from the base of the PR and between cb76479 and 352c41b.
Files selected for processing (1)
  • src/Endpoints/user-meta/class-base-endpoint-user-meta.php (2 hunks)
Additional Context Used
Path-based Instructions (1)
src/Endpoints/user-meta/class-base-endpoint-user-meta.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."
Additional comments not posted (4)
src/Endpoints/user-meta/class-base-endpoint-user-meta.php (4)

202-202: The addition of the $parent_key parameter to the sanitize_value method is a significant change. It enables handling nested settings more effectively. Ensure that all calls to this method have been updated to include this new parameter where necessary.

Verification successful

The search results indicate that the sanitize_value method has been correctly updated to include the new $parent_key parameter, and all calls to this method within the provided context have been appropriately adjusted. There are no outdated calls missing the new parameter.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Search for calls to sanitize_value without the new parameter.
ast-grep --lang php --pattern $'sanitize_value($_, $_)'

Length of output: 163



Script:

#!/bin/bash
# Search for calls to sanitize_value with exactly two parameters.
rg 'sanitize_value\([^,]+,[^,]+\)' -g '*.php'

Length of output: 333


205-238: The logic introduced for handling nested arrays and specifications based on the parent key is well-implemented. It enhances the flexibility and maintainability of the settings API by allowing for more complex settings structures. However, ensure that extensive testing covers various nesting levels and scenarios to guarantee robustness.


248-279: The sanitize_subvalue method's update to work with composite keys is crucial for the nested settings feature. It's important to verify that the method correctly handles all expected data types and that the validation against valid_values is strict and secure.


285-388: The addition of new methods (is_valid_key, get_valid_values, get_default, get_nested_specs) to check validity, retrieve valid values, and defaults based on key paths significantly improves the class's functionality. It's essential to ensure these methods are used consistently throughout the class and that their implementations are efficient and secure.

@acicovic
Copy link
Collaborator

acicovic commented Apr 2, 2024

I've given this a manual test run and it works well for me.

… update/settings-api-nested

# Conflicts:
#	build/content-helper/editor-sidebar.asset.php
#	build/content-helper/editor-sidebar.js
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: 0

Review Status

Configuration used: .coderabbit.yaml

Commits Files that changed from the base of the PR and between 352c41b and cac5f6b.
Files ignored due to path filters (2)
  • build/content-helper/editor-sidebar.asset.php is excluded by !build/**
  • build/content-helper/editor-sidebar.js is excluded by !build/**
Files selected for processing (4)
  • jest.config.js (1 hunks)
  • src/content-helper/editor-sidebar/related-posts/component.tsx (10 hunks)
  • src/content-helper/editor-sidebar/related-posts/hooks.ts (1 hunks)
  • tests/js/content-helper/structure.test.tsx (7 hunks)
Files skipped from review as they are similar to previous changes (1)
  • src/content-helper/editor-sidebar/related-posts/component.tsx
Additional Context Used
Path-based Instructions (3)
jest.config.js (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/hooks.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."
Additional comments not posted (9)
jest.config.js (1)

1-1: Consider adding a comment explaining why the eslint-disable-next-line @typescript-eslint/no-var-requires directive is necessary here, for example, due to dynamic imports not being supported in Node.js configurations. This will improve code readability and maintainability.

src/content-helper/editor-sidebar/related-posts/hooks.ts (2)

14-18: The PostDataStore interface is well-defined and adheres to TypeScript best practices.


27-49: The usePostData hook is implemented correctly and follows best practices for fetching and returning post data. Consider adding more detailed JSDoc comments for the PostDataStore return type to enhance documentation quality.

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

30-45: The mocking setup for SettingsProvider and useSettings is correctly implemented and simplifies the testing environment.


52-73: The MockPostData type and mockPostData constant are well-defined and provide a sensible default state for tests.


84-86: The afterEach cleanup function is correctly implemented to ensure test isolation and prevent side effects between tests.


213-250: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [88-262]

The updated test cases are well-structured and cover various scenarios, including error handling and displaying messages. The use of async/await and waitFor for asynchronous operations is correct.


233-246: The setMockPostData function provides a convenient way to update the mock post data for different test scenarios and is correctly implemented.


257-266: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [247-262]

The new helper functions improve code readability and maintainability by abstracting common querying operations.

@vaurdan
Copy link
Contributor Author

vaurdan commented Apr 2, 2024

@coderabbitai resolve

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: 0

Review Status

Configuration used: .coderabbit.yaml

Commits Files that changed from the base of the PR and between cac5f6b and 4e2064a.
Files ignored due to path filters (2)
  • build/content-helper/editor-sidebar.asset.php is excluded by !build/**
  • build/content-helper/editor-sidebar.js is excluded by !build/**
Files selected for processing (2)
  • src/content-helper/editor-sidebar/related-posts/component.tsx (10 hunks)
  • src/content-helper/editor-sidebar/related-posts/hooks.ts (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • src/content-helper/editor-sidebar/related-posts/component.tsx
  • src/content-helper/editor-sidebar/related-posts/hooks.ts

Co-authored-by: Alex Cicovic <23142906+acicovic@users.noreply.github.com>
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: 0

Review Status

Configuration used: .coderabbit.yaml

Commits Files that changed from the base of the PR and between 4e2064a and 42b99a5.
Files selected for processing (2)
  • src/content-helper/editor-sidebar/related-posts/hooks.ts (1 hunks)
  • tests/js/content-helper/structure.test.tsx (7 hunks)
Files skipped from review as they are similar to previous changes (2)
  • src/content-helper/editor-sidebar/related-posts/hooks.ts
  • tests/js/content-helper/structure.test.tsx

Copy link
Collaborator

@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.

Thank you! I'm glad we're done with this!

@vaurdan vaurdan merged commit ae19952 into develop Apr 2, 2024
36 checks passed
@vaurdan vaurdan deleted the update/settings-api-nested branch April 2, 2024 13:58
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.

2 participants