'vrts-run', 'plural' => 'vrts-runs', 'ajax' => false, ]); } /** * Get table classes. */ public function get_table_classes() { return [ 'vrts-test-runs-list-table', 'widefat', 'fixed', $this->_args['plural'] ]; } /** * Message to show if no designation found. * * @return void */ public function no_items() { esc_html_e( 'No Runs finished.', 'visual-regression-tests' ); } /** * Get the column names. * * @return array */ public function get_columns() { $columns = [ 'cb' => '', 'title' => esc_html__( 'Test Run', 'visual-regression-tests' ), 'trigger' => esc_html__( 'Trigger', 'visual-regression-tests' ), 'status' => esc_html__( 'Status', 'visual-regression-tests' ), ]; return $columns; } /** * Get sortable columns * * @return array */ public function get_sortable_columns() { $sortable_columns = [ 'title' => [ 'finished_at', true ], 'trigger' => [ 'trigger', true ], ]; return $sortable_columns; } /** * Gets the list of views available on this table. * * @return array */ public function get_views() { $base_link = Url_Helpers::get_page_url( 'runs' ); $links = [ 'all' => [ 'title' => esc_html__( 'All', 'visual-regression-tests' ), 'link' => $base_link, 'count' => Test_Run::get_total_items(), ], 'changes-detected' => [ 'title' => esc_html__( 'Changes detected', 'visual-regression-tests' ), 'link' => "{$base_link}&status=changes-detected", 'count' => Test_Run::get_total_items( 'changes-detected' ), ], ]; $status_links = []; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- It's status request. $filter_status_query = ( isset( $_REQUEST['status'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['status'] ) ) : 'all' ); foreach ( $links as $key => $link ) { $current_class = ( $filter_status_query === $key ? 'class="current" ' : '' ); $link = sprintf( '%s (%s)', $current_class, $link['link'], $link['title'], $link['count'] ); $status_links[ $key ] = $link; } return $status_links; } /** * Prepare the class items * * @return void */ public function prepare_items() { $columns = $this->get_columns(); $hidden = []; $sortable = $this->get_sortable_columns(); $this->_column_headers = [ $columns, $hidden, $sortable ]; $per_page = $this->get_items_per_page( 'vrts_test_runs_per_page', 20 ); $current_page = $this->get_pagenum(); $offset = ( $current_page - 1 ) * $per_page; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- It's the list order parameter. $order = isset( $_REQUEST['order'] ) && 'asc' === $_REQUEST['order'] ? 'ASC' : 'DESC'; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- It's the list order by parameter. $order_by = isset( $_REQUEST['orderby'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['orderby'] ) ) : 'finished_at'; // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing -- It's the list search query parameter. $filter_status_query = isset( $_REQUEST['status'] ) && '' !== $_REQUEST['status'] ? sanitize_text_field( wp_unslash( $_REQUEST['status'] ) ) : null; $args = [ 'offset' => $offset, 'number' => $per_page, 'order' => $order, 'orderby' => $order_by, 'filter_status' => $filter_status_query, ]; $this->items = Test_Run::get_items( $args ); $total_items = 0; if ( null !== $args['filter_status'] ) { $total_items = Test_Run::get_total_items( $filter_status_query ); } else { $total_items = Test_Run::get_total_items(); } $this->set_pagination_args([ 'total_items' => $total_items, 'per_page' => $per_page, ]); } /** * Generates content for a single row of the table. * * @param object|array $item The current item. */ public function single_row( $item ) { $classes = 'iedit test-run-row'; $current_time = time(); $finished_at = strtotime( $item->finished_at ); $is_new_run = $current_time - $finished_at < 20 * MINUTE_IN_SECONDS; ?>
%1$s
', $trigger_note ) ); } /** * Render the status column. * * @param object $item column item. * * @return string */ public function column_status( $item ) { $tests_count = count( maybe_unserialize( $item->tests ) ?? [] ); if ( $item->alerts_count > 0 ) { $status_class = 'paused'; $status_text = esc_html__( 'Changes detected ', 'visual-regression-tests' ) . sprintf( '(%s)', $item->alerts_count ); } else { $status_class = 'running'; $status_text = esc_html__( 'No changes', 'visual-regression-tests' ); } $status_instructions = sprintf( // translators: %s: number of alerts, %s: number of tests. esc_html( _n( '%s Test', '%s Tests', $tests_count, 'visual-regression-tests' ) ), $tests_count ); return sprintf( '%s
%s