Skip to content

Commit

Permalink
Merge pull request #21861 from Yoast/533-include-query-completion-tim…
Browse files Browse the repository at this point in the history
…e-and-whether-cache-was-used-in-the-api-endpoint-responses

Include metadata in the API endpoints
  • Loading branch information
thijsoo authored Nov 26, 2024
2 parents 851d976 + a94b9db commit 589303a
Show file tree
Hide file tree
Showing 49 changed files with 1,121 additions and 983 deletions.
1 change: 1 addition & 0 deletions packages/js/src/dashboard/scores/components/scores.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ export const Scores = ( { analysisType, contentTypes, endpoint, headers } ) => {
},
},
fetchDelay: 0,
prepareData: ( data ) => data?.scores,
} );

useEffect( () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php
// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong
// phpcs:disable Yoast.NamingConventions.NamespaceName.MaxExceeded
namespace Yoast\WP\SEO\Dashboard\Application\Score_Results;

use Yoast\WP\SEO\Dashboard\Domain\Content_Types\Content_Type;
use Yoast\WP\SEO\Dashboard\Domain\Score_Groups\Score_Groups_Interface;
use Yoast\WP\SEO\Dashboard\Domain\Score_Results\Score_Result;
use Yoast\WP\SEO\Dashboard\Domain\Taxonomies\Taxonomy;
use Yoast\WP\SEO\Dashboard\Infrastructure\Score_Results\Score_Results_Collector_Interface;

/**
* The abstract score results repository.
*/
abstract class Abstract_Score_Results_Repository {

/**
* The score results collector.
*
* @var Score_Results_Collector_Interface
*/
protected $score_results_collector;

/**
* The current scores repository.
*
* @var Current_Scores_Repository
*/
protected $current_scores_repository;

/**
* All score groups.
*
* @var Score_Groups_Interface[]
*/
protected $score_groups;

/**
* Sets the repositories.
*
* @required
*
* @param Current_Scores_Repository $current_scores_repository The current scores repository.
*
* @return void
*/
public function set_repositories(
Current_Scores_Repository $current_scores_repository
) {
$this->current_scores_repository = $current_scores_repository;
}

/**
* Returns the score results for a content type.
*
* @param Content_Type $content_type The content type.
* @param Taxonomy|null $taxonomy The taxonomy of the term we're filtering for.
* @param int|null $term_id The ID of the term we're filtering for.
*
* @return array<array<string, string|int|array<string, string>>> The scores.
*/
public function get_score_results( Content_Type $content_type, ?Taxonomy $taxonomy, ?int $term_id ): array {
$score_results = $this->score_results_collector->get_score_results( $this->score_groups, $content_type, $term_id );

$current_scores_list = $this->current_scores_repository->get_current_scores( $this->score_groups, $score_results, $content_type, $taxonomy, $term_id );
$score_result_object = new Score_Result( $current_scores_list, $score_results['query_time'], $score_results['cache_used'] );

return $score_result_object->to_array();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php
// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong
// phpcs:disable Yoast.NamingConventions.NamespaceName.MaxExceeded
namespace Yoast\WP\SEO\Dashboard\Application\Score_Results;

use Yoast\WP\SEO\Dashboard\Domain\Content_Types\Content_Type;
use Yoast\WP\SEO\Dashboard\Domain\Score_Groups\Score_Groups_Interface;
use Yoast\WP\SEO\Dashboard\Domain\Score_Results\Current_Score;
use Yoast\WP\SEO\Dashboard\Domain\Score_Results\Current_Scores_List;
use Yoast\WP\SEO\Dashboard\Domain\Taxonomies\Taxonomy;
use Yoast\WP\SEO\Dashboard\Infrastructure\Score_Groups\Score_Group_Link_Collector;

/**
* The current scores repository.
*/
class Current_Scores_Repository {

/**
* The score group link collector.
*
* @var Score_Group_Link_Collector
*/
protected $score_group_link_collector;

/**
* The constructor.
*
* @param Score_Group_Link_Collector $score_group_link_collector The score group link collector.
*/
public function __construct(
Score_Group_Link_Collector $score_group_link_collector
) {
$this->score_group_link_collector = $score_group_link_collector;
}

/**
* Returns the current results.
*
* @param Score_Groups_Interface[] $score_groups The score groups.
* @param array<string, string> $score_results The score results.
* @param Content_Type $content_type The content type.
* @param Taxonomy|null $taxonomy The taxonomy of the term we're filtering for.
* @param int|null $term_id The ID of the term we're filtering for.
*
* @return array<array<string, string|int|array<string, string>>> The current results.
*/
public function get_current_scores( array $score_groups, array $score_results, Content_Type $content_type, ?Taxonomy $taxonomy, ?int $term_id ): Current_Scores_List {
$current_scores_list = new Current_Scores_List();

foreach ( $score_groups as $score_group ) {
$score_name = $score_group->get_name();
$current_score_links = $this->get_current_score_links( $score_group, $content_type, $taxonomy, $term_id );

$current_score = new Current_Score( $score_name, (int) $score_results['scores']->$score_name, $current_score_links );
$current_scores_list->add( $current_score, $score_group->get_position() );
}

return $current_scores_list;
}

/**
* Returns the links for the current scores of a score group.
*
* @param Score_Groups_Interface $score_group The scoure group.
* @param Content_Type $content_type The content type.
* @param Taxonomy|null $taxonomy The taxonomy of the term we're filtering for.
* @param int|null $term_id The ID of the term we're filtering for.
*
* @return array<string,string> The current score links.
*/
protected function get_current_score_links( Score_Groups_Interface $score_group, Content_Type $content_type, ?Taxonomy $taxonomy, ?int $term_id ): array {
return [
'view' => $this->score_group_link_collector->get_view_link( $score_group, $content_type, $taxonomy, $term_id ),
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong
// phpcs:disable Yoast.NamingConventions.NamespaceName.MaxExceeded
namespace Yoast\WP\SEO\Dashboard\Application\Score_Results\Readability_Score_Results;

use Yoast\WP\SEO\Dashboard\Application\Score_Results\Abstract_Score_Results_Repository;
use Yoast\WP\SEO\Dashboard\Domain\Score_Groups\Readability_Score_Groups\Readability_Score_Groups_Interface;
use Yoast\WP\SEO\Dashboard\Infrastructure\Score_Results\Readability_Score_Results\Readability_Score_Results_Collector;

/**
* The repository to get readability score results.
*/
class Readability_Score_Results_Repository extends Abstract_Score_Results_Repository {

/**
* The constructor.
*
* @param Readability_Score_Results_Collector $readability_score_results_collector The readability score results collector.
* @param Readability_Score_Groups_Interface ...$readability_score_groups All readability score groups.
*/
public function __construct(
Readability_Score_Results_Collector $readability_score_results_collector,
Readability_Score_Groups_Interface ...$readability_score_groups
) {
$this->score_results_collector = $readability_score_results_collector;
$this->score_groups = $readability_score_groups;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong
// phpcs:disable Yoast.NamingConventions.NamespaceName.MaxExceeded
namespace Yoast\WP\SEO\Dashboard\Application\Score_Results\SEO_Score_Results;

use Yoast\WP\SEO\Dashboard\Application\Score_Results\Abstract_Score_Results_Repository;
use Yoast\WP\SEO\Dashboard\Domain\Score_Groups\SEO_Score_Groups\SEO_Score_Groups_Interface;
use Yoast\WP\SEO\Dashboard\Infrastructure\Score_Results\SEO_Score_Results\SEO_Score_Results_Collector;

/**
* The repository to get SEO score results.
*/
class SEO_Score_Results_Repository extends Abstract_Score_Results_Repository {

/**
* The constructor.
*
* @param SEO_Score_Results_Collector $seo_score_results_collector The SEO score results collector.
* @param SEO_Score_Groups_Interface ...$seo_score_groups All SEO score groups.
*/
public function __construct(
SEO_Score_Results_Collector $seo_score_results_collector,
SEO_Score_Groups_Interface ...$seo_score_groups
) {
$this->score_results_collector = $seo_score_results_collector;
$this->score_groups = $seo_score_groups;
}
}
77 changes: 0 additions & 77 deletions src/dashboard/application/scores/abstract-scores-repository.php

This file was deleted.

This file was deleted.

24 changes: 0 additions & 24 deletions src/dashboard/application/scores/scores-repository-interface.php

This file was deleted.

This file was deleted.

Loading

0 comments on commit 589303a

Please sign in to comment.