Skip to content

Commit

Permalink
fix(TestRuns): display first alert if requested alert is not found
Browse files Browse the repository at this point in the history
  • Loading branch information
domtra committed Oct 1, 2024
1 parent e8f1b95 commit 5ff2347
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions includes/features/class-test-runs-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use Vrts\Models\Test;
use Vrts\Models\Test_Run;
use Vrts\Services\Test_Run_Service;
use Vrts\Services\Test_Service;

class Test_Runs_Page {

Expand Down Expand Up @@ -81,7 +80,7 @@ public function render_page() {
if ( $run ) {
// $alerts_ids = maybe_unserialize( $run->alerts );
$alerts = Alert::get_items_by_test_run( $run_id );
$alert_id = isset( $_GET['alert_id'] ) ? intval( $_GET['alert_id'] ) : ( isset( $alerts[0] ) ? $alerts[0]->id : 0 );
[ $alert_id, $alert ] = $this->get_alert( $alerts );
$base_link = add_query_arg( [
'run_id' => $run_id,
], admin_url( 'admin.php?page=vrts-runs' ) );
Expand All @@ -90,7 +89,6 @@ public function render_page() {
$service = new Test_Run_Service();
$service->update_latest_alert_for_all_tests( $run );

$alert = Alert::get_item( $alert_id );
$test = $alert ? Test::get_item_by_post_id( $alert->post_id ) : null;

vrts()->component('test-run-page', [
Expand Down Expand Up @@ -124,6 +122,16 @@ public function render_page() {
}//end if
}

private function get_alert( $alerts ) {
$alert_id = isset( $_GET['alert_id'] ) ? intval( $_GET['alert_id'] ) : ( isset( $alerts[0] ) ? $alerts[0]->id : 0 );
$alert = Alert::get_item( $alert_id );
if ( ! $alert ) {
$alert_id = isset( $alerts[0] ) ? $alerts[0]->id : 0;
$alert = Alert::get_item( $alert_id );
}
return [ $alert_id, $alert ];
}

/**
* Init notifications.
*/
Expand Down

0 comments on commit 5ff2347

Please sign in to comment.