Skip to content

Commit

Permalink
feat(TestRuns): adjust overview styling and functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
domtra committed Sep 11, 2024
1 parent 0e0dba7 commit 9edf4f0
Show file tree
Hide file tree
Showing 12 changed files with 263 additions and 183 deletions.
8 changes: 8 additions & 0 deletions assets/admin.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
@import "@wordpress/base-styles/colors.native"; // stylelint-disable-line scss/at-import-partial-extension

.vrts-list-table-page {
th, td {
border-bottom: 1px solid #CCCCCC;
}

.vrts-testing-status {
display: flex;
Expand Down Expand Up @@ -29,6 +32,11 @@
// background-color: #FCFCFC;
// }
// }
&:not(.vrts-test-runs-list-queue-table) {
.test-run-row:not([data-has-alerts]) {
background-color: #F6F7F7;
}
}
}

.column-vrts_testing_status {
Expand Down
38 changes: 16 additions & 22 deletions components/test-runs-page/_style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -112,32 +112,29 @@
display: flex;
flex-wrap: wrap;
gap: 4px;
visibility: hidden;

.tests {
color: $gray-80;

@media screen and (max-width: 782px){
padding: 4px 8px !important;
}
}

.details {
visibility: hidden;

&::before {
content: " | ";
}
> *:not(:first-child)::before {
content: " | ";
}
}

tr {

&[data-has-alerts] {
font-weight: 600;
.row-title,
.vrts-test-run-trigger,
.vrts-testing-status-wrapper > *:first-child {
font-weight: 600;
}

.check-column {
border-left: 4px solid $blue-50;
padding-left: 6px;
// .check-column {
// border-left: 4px solid $blue-50;
// padding-left: 6px;
// }

.row-title::after {
content: "\25CF";
}
}

Expand All @@ -152,10 +149,7 @@
&:hover {

.row-actions {

.details {
visibility: visible;
}
visibility: visible;
}
}
}
Expand Down
28 changes: 14 additions & 14 deletions components/test-runs-page/script.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
document
.querySelectorAll( '.vrts-show-test-run-details' )
.forEach( ( element ) => {
element.addEventListener( 'click', ( e ) => {
e.preventDefault();
const $row = element.closest( 'tr' );
const isHidden =
$row.getAttribute( 'data-vrts-test-run-details' ) === 'hidden';
$row.setAttribute(
'data-vrts-test-run-details',
isHidden ? 'visible' : 'hidden'
);
} );
} );
// document
// .querySelectorAll( '.vrts-show-test-run-details' )
// .forEach( ( element ) => {
// element.addEventListener( 'click', ( e ) => {
// e.preventDefault();
// const $row = element.closest( 'tr' );
// const isHidden =
// $row.getAttribute( 'data-vrts-test-run-details' ) === 'hidden';
// $row.setAttribute(
// 'data-vrts-test-run-details',
// isHidden ? 'visible' : 'hidden'
// );
// } );
// } );

/**
* @param {HTMLTableElement} table
Expand Down
29 changes: 29 additions & 0 deletions includes/core/utilities/class-url-helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,33 @@ public static function get_alerts_page( $test_run = null ) {
}
return $admin_url . $page;
}

public static function get_test_run_page( $test_run_id ) {
if ( is_object($test_run_id) ) {
$test_run_id = $test_run_id->ID;
} else
$admin_url = get_admin_url();
return $admin_url . 'admin.php?page=vrts-runs&run_id=' . $test_run_id;
}

public static function get_test_runs_page() {
$admin_url = get_admin_url();
return $admin_url . 'admin.php?page=vrts-runs';
}

public static function get_mark_as_read_url( $test_run_id, $redirect_to_overview = false ) {
$url = static::get_test_run_page( $test_run_id );
return add_query_arg( [
'action' => 'mark_as_read',
'redirect' => $redirect_to_overview ? 'overview' : '',
], $url );
}

public static function get_mark_as_unread_url( $test_run_id, $redirect_to_overview = false ) {
$url = static::get_test_run_page( $test_run_id );
return add_query_arg( [
'action' => 'mark_as_unread',
'redirect' => $redirect_to_overview ? 'overview' : '',
], $url );
}
}
5 changes: 3 additions & 2 deletions includes/features/class-alerts-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ class Alerts_Page {
* Constructor.
*/
public function __construct() {
add_action( 'admin_menu', [ $this, 'add_submenu_page' ] );
add_filter( 'set-screen-option', [ $this, 'set_screen' ], 10, 3 );
// TODO: remove before release.
// add_action( 'admin_menu', [ $this, 'add_submenu_page' ] );
// add_filter( 'set-screen-option', [ $this, 'set_screen' ], 10, 3 );
}

/**
Expand Down
59 changes: 59 additions & 0 deletions includes/features/class-test-runs-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Vrts\Features;

use Vrts\Core\Utilities\Url_Helpers;
use Vrts\List_Tables\Test_Runs_List_Table;
use Vrts\List_Tables\Test_Runs_Queue_List_Table;
use Vrts\Models\Alert;
Expand All @@ -15,6 +16,8 @@ class Test_Runs_Page {
public function __construct() {
add_action( 'admin_menu', [ $this, 'add_submenu_page' ] );
add_action( 'admin_body_class', [ $this, 'add_body_class' ] );
add_action( 'admin_init', [ $this, 'submit_mark_as_read' ] );
add_action( 'admin_init', [ $this, 'submit_mark_as_unread' ] );
}

/**
Expand Down Expand Up @@ -123,4 +126,60 @@ public function init_notifications() {
public function render_notification_connection_failed() {
Admin_Notices::render_notification( 'connection_failed' );
}

public function submit_mark_as_read() {
if ( ! isset( $_GET['run_id'] ) || ! isset( $_GET['page'] ) || 'vrts-runs' !== $_GET['page'] ) {
return;
}

// phpcs:ignore WordPress.Security.NonceVerification.Missing -- It's ok.
if ( ! isset( $_GET['action'] ) || 'mark_as_read' !== $_GET['action'] ) {
return;
}

if ( ! isset( $_GET['_wpnonce'] ) || ! wp_verify_nonce( $_GET['_wpnonce'], 'mark_as_read' ) ) {
return;
}

// phpcs:ignore WordPress.Security.NonceVerification.Missing -- It's ok.
$run_id = intval( $_GET['run_id'] );
$run = Test_Run::get_item( $run_id );

if ( ! $run ) {
return;
}

Alert::mark_as_read_by_test_run( $run_id );
$redirect_url = ( isset( $_GET['redirect'] ) && 'overview' === $_GET['redirect'] ) ? Url_Helpers::get_test_runs_page() : Url_Helpers::get_test_run_page( $run_id );
wp_safe_redirect( $redirect_url );
exit;
}

public function submit_mark_as_unread() {
if ( ! isset( $_GET['run_id'] ) || ! isset( $_GET['page'] ) || 'vrts-runs' !== $_GET['page'] ) {
return;
}

// phpcs:ignore WordPress.Security.NonceVerification.Missing -- It's ok.
if ( ! isset( $_GET['action'] ) || 'mark_as_unread' !== $_GET['action'] ) {
return;
}

if ( ! isset( $_GET['_wpnonce'] ) || ! wp_verify_nonce( $_GET['_wpnonce'], 'mark_as_unread' ) ) {
return;
}

// phpcs:ignore WordPress.Security.NonceVerification.Missing -- It's ok.
$run_id = intval( $_GET['run_id'] );
$run = Test_Run::get_item( $run_id );

if ( ! $run ) {
return;
}

Alert::mark_as_unread_by_test_run( $run_id );
$redirect_url = ( isset( $_GET['redirect'] ) && 'overview' === $_GET['redirect'] ) ? Url_Helpers::get_test_runs_page() : Url_Helpers::get_test_run_page( $run_id );
wp_safe_redirect( $redirect_url );
exit;
}
}
Loading

0 comments on commit 9edf4f0

Please sign in to comment.