Link to single files from the list table

This commit is contained in:
Corey McKrill 2023-10-09 23:28:03 -07:00
parent 06aaed23d9
commit e17654226a
No known key found for this signature in database
GPG Key ID: 84BBFE669C4D97B8
3 changed files with 49 additions and 4 deletions

View File

@ -61,6 +61,15 @@ class File {
}
}
/**
* Get the name of the file, with extension, but without full path.
*
* @return string
*/
public function get_basename() {
return basename( $this->path );
}
/**
* Get the file's source property.
*

View File

@ -2,6 +2,8 @@
namespace Automattic\WooCommerce\Internal\Admin\Logging\FileV2;
use Automattic\WooCommerce\Internal\Admin\Logging\PageController;
use WP_List_Table;
/**
@ -18,11 +20,17 @@ class ListTable extends WP_List_Table {
*/
private $file_controller;
/**
* @var PageController
*/
private $page_controller;
/**
* ListTable class.
*/
public function __construct( FileController $file_controller ) {
public function __construct( FileController $file_controller, PageController $page_controller ) {
$this->file_controller = $file_controller;
$this->page_controller = $page_controller;
parent::__construct(
array(
@ -170,7 +178,20 @@ class ListTable extends WP_List_Table {
* @return string
*/
public function column_source( $item ) {
return $item->get_source();
$log_file = sanitize_title( $item->get_basename() );
$single_file_url = add_query_arg(
array(
'view' => 'single_file',
'log_file' => $log_file,
),
$this->page_controller->get_logs_tab_url()
);
return sprintf(
'<a href="%1$s">%2$s</a>',
$single_file_url,
$item->get_source()
);
}
/**
@ -183,7 +204,7 @@ class ListTable extends WP_List_Table {
public function column_created( $item ) {
$timestamp = $item->get_created_timestamp();
return date( 'Y-m-d H:i:s', $timestamp );
return date( 'Y-m-d', $timestamp );
}
/**

View File

@ -48,6 +48,21 @@ class PageController {
self::add_action( 'load-woocommerce_page_wc-status', array( $this, 'setup_screen_options' ) );
}
/**
* Get the canonical URL for the Logs tab of the Status admin page.
*
* @return string
*/
public function get_logs_tab_url() {
return add_query_arg(
array(
'page' => 'wc-status',
'tab' => 'logs',
),
admin_url( 'admin.php' )
);
}
/**
* Determine the default log handler.
*
@ -144,7 +159,7 @@ class PageController {
return $this->list_table;
}
$this->list_table = new ListTable( $this->file_controller );
$this->list_table = new ListTable( $this->file_controller, $this );
return $this->list_table;
}