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

Fix CL by-author on frontend #5624

Merged
merged 1 commit into from
Jun 20, 2024
Merged

Fix CL by-author on frontend #5624

merged 1 commit into from
Jun 20, 2024

Conversation

elzadj
Copy link
Collaborator

@elzadj elzadj commented Jun 19, 2024

Description

Fixes CL / DC by author on frontend for pagination (or when we have fewer posts that we need for one page).

Fixes #5623

How Has This Been Tested?

Basically, test CL by author.

Test checklist

_ Front/Back Testing _

  • Test the component in normal state in sidebar
  • Test the component in hover state in sidebar (if hover exists)
  • Check that the settings work on frontend
  • Check that backend works and saves the settings after the editor reload
  • Same 1-4 points for the toolbar
  • Same 1-4 points on responsive
  • Test the block inside the grid (Container + Row + Column)
  • Test the block as a standalone block
  • Duplicate the block, test that the settings of the first do not affect the second
  • Test with 2 blocks of the same type

_ Pre-Code Testing _

  • Test the component in normal state in sidebar
  • Test the component in hover state in sidebar (if hover exists)
  • Check that the settings work on frontend
  • Check that backend works and saves the settings after the editor reload
  • Same 1-4 points for the toolbar
  • Same 1-4 points on responsive
  • Test the block inside the grid (Container + Row + Column)
  • Test the block as a standalone block
  • Duplicate the block, test that the settings of the first do not affect the second
  • Test with 2 blocks of the same type
  • Check no commented code and no unnecessary imports
  • Standards of the project have been followed
  • No errors/warnings on console

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings/errors
  • I have added/updated tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Summary by CodeRabbit

  • New Features
    • Enhanced posts retrieval logic to support dynamic content relationships, providing more relevant and related posts.

@elzadj elzadj requested a review from Olekrut June 19, 2024 15:56
@elzadj elzadj self-assigned this Jun 19, 2024
@dosubot dosubot bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Jun 19, 2024
Copy link
Contributor

coderabbitai bot commented Jun 19, 2024

Walkthrough

In core/class-maxi-dynamic-content.php, the changes involve adding a condition related to $dc_relation for retrieving posts, and modifying query arguments based on different relationships, addressing issues with retrieving posts by author correctly on both frontend and backend.

Changes

File Change Summary
core/class-maxi-dynamic-content.php Added condition involving $dc_relation and modified query arguments for posts retrieval based on different relations.

Assessment against linked issues

Objective Addressed Explanation
DC/CL Get by author does not work correctly (frontend) (#5623)
DC/CL Get by author does not work correctly (backend) (#5623)

Poem

In code, the queries twist and turn,
Dynamics shift, relations churn,
By author, fetching posts once lost,
Now returns, no matter the cost.
Backend, frontend, both now align,
In sync, these changes shine!


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.
    • @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 as 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @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/schema.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.

@dosubot dosubot bot added the bug 🐛 Something isn't working label Jun 19, 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 details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between d58632e and abb221f.

Files selected for processing (1)
  • core/class-maxi-dynamic-content.php (3 hunks)
Additional comments not posted (1)
core/class-maxi-dynamic-content.php (1)

257-257: Ensure the WP_Query instance is properly utilized.

The instantiation of WP_Query here is standard and follows WordPress best practices for custom queries.

@@ -1120,7 +1121,7 @@ public function get_post($attributes)

$query = new WP_Query($args);

if (empty($query->posts) && !$is_current_archive) {
if (empty($query->posts) && !$is_current_archive && $dc_relation !== 'by-author') {
Copy link
Contributor

Choose a reason for hiding this comment

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

Check for potential infinite recursion.

- return $this->get_post(array_replace($attributes, $validated_attributes));
+ // Ensure there is a condition to break the recursion
+ if ($someCondition) {
+     return $this->get_post(array_replace($attributes, $validated_attributes));
+ } else {
+     return null;
+ }

This recursive call to get_post could potentially lead to infinite recursion if the conditions are always met. Consider adding a termination condition or a maximum recursion depth.

Committable suggestion was skipped due to low confidence.


Optimize the validation logic for orderby attributes.

- $validated_attributes = self::get_validated_orderby_attributes($dc_relation, $dc_id);
- if (in_array($dc_relation, self::$order_by_relations) && $validated_attributes) {
+ $validated_attributes = $this->get_validated_orderby_attributes($dc_relation, $dc_id);
+ if ($validated_attributes) {

Refactor the method to use instance method access ($this->) instead of static method access (self::) since get_validated_orderby_attributes is not a static method. Also, simplify the condition to check only if validated attributes exist.

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (empty($query->posts) && !$is_current_archive && $dc_relation !== 'by-author') {
if (empty($query->posts) && !$is_current_archive && $dc_relation !== 'by-author') {
$validated_attributes = $this->get_validated_orderby_attributes($dc_relation, $dc_id);
if ($validated_attributes) {

@@ -2119,6 +2120,7 @@
}
} elseif($relation === 'by-author') {
$args['author'] = $id;

Copy link
Contributor

Choose a reason for hiding this comment

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

Tip

Codebase Verification

The extraction of the switch statements shows that some types returned by get_current_archive_type_and_id (such as custom taxonomy and not_an_archive) are not handled in the switch statements. This indicates that the handling of dynamic archive types is incomplete.

  • switch ($archive_type) is missing cases for custom taxonomy and not_an_archive.

Please ensure that all possible types returned by get_current_archive_type_and_id are properly handled in the switch statements.

  • Add handling for custom taxonomy.
  • Add handling for not_an_archive.
Analysis chain

Validate dynamic archive type handling.

Ensure that all possible archive types returned by get_current_archive_type_and_id are properly handled in the switch statement. This script checks for the presence of all necessary cases.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Check if all possible archive types are properly handled in the switch statement.

# Test: Search for all usages of `get_current_archive_type_and_id` and ensure all types are handled.
rg --type php $'get_current_archive_type_and_id' | rg --type php $'switch'

Length of output: 70



Script:

#!/bin/bash
# Search for the definition of the function `get_current_archive_type_and_id` in the codebase.
ast-grep --lang php --pattern 'function get_current_archive_type_and_id() { $$$ }'

Length of output: 191



Script:

#!/bin/bash
# Search for the definition of the function `get_current_archive_type_and_id` in the codebase.
rg --type php 'function get_current_archive_type_and_id'

Length of output: 148



Script:

#!/bin/bash
# Extract the implementation of the function `get_current_archive_type_and_id` from the file.
rg --type php -A 50 'function get_current_archive_type_and_id' core/class-maxi-dynamic-content.php

Length of output: 2179



Script:

#!/bin/bash
# Search for switch statements handling the return value of `get_current_archive_type_and_id`.
rg --type php -A 10 'switch.*get_current_archive_type_and_id' core/class-maxi-dynamic-content.php

Length of output: 99



Script:

#!/bin/bash
# Search for all switch statements in the file `core/class-maxi-dynamic-content.php`.
rg --type php 'switch' core/class-maxi-dynamic-content.php

Length of output: 299



Script:

#!/bin/bash
# Extract the code for the switch statements handling $archive_info['type'] and $archive_type.
rg --type php -A 20 'switch \(\$archive_info\[\'type\'\]\)' core/class-maxi-dynamic-content.php
rg --type php -A 20 'switch \(\$archive_type\)' core/class-maxi-dynamic-content.php

Length of output: 93



Script:

#!/bin/bash
# Extract the code for the switch statements handling $archive_info['type'] and $archive_type.
rg --type php -A 20 'switch \(\$archive_info\['type'\]\)' core/class-maxi-dynamic-content.php
rg --type php -A 20 'switch \(\$archive_type\)' core/class-maxi-dynamic-content.php

Length of output: 1073

Copy link
Collaborator

@Olekrut Olekrut left a comment

Choose a reason for hiding this comment

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

yes, local is ok now

@dosubot dosubot bot added the lgtm This PR has been approved by maintainer label Jun 19, 2024
@elzadj
Copy link
Collaborator Author

elzadj commented Jun 20, 2024

yes, local is ok now

Great, tx, going to try to fix backend in another PR.

@elzadj elzadj merged commit 393dd8d into master Jun 20, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something isn't working Final code review lgtm This PR has been approved by maintainer size:XS This PR changes 0-9 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DC/CL Get by author does not work correct
2 participants