Skip to content

Commit 1751f1c

Browse files
committed
Added date and time picker for the list.
1 parent 2ac6584 commit 1751f1c

File tree

3 files changed

+54
-5
lines changed

3 files changed

+54
-5
lines changed

plugins/wpgraphql-logging/src/Admin/View/List/List_Table.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ public function column_query( DatabaseEntity $item ): ?string {
276276
*/
277277
public function get_query(DatabaseEntity $item): string {
278278
$query = $item->get_query();
279-
if (! is_string($query) || '' === $query) {
279+
if ( ! is_string( $query ) || '' === $query ) {
280280
return '';
281281
}
282282
return $this->format_code( $query );

plugins/wpgraphql-logging/src/Admin/View/Templates/wpgraphql-logger-filters.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@
3838
*/
3939
$wpgraphql_logging_log_levels = [ 'debug', 'info', 'notice', 'warning', 'error', 'critical', 'alert', 'emergency' ];
4040
?>
41-
<input type="text" name="start_date" placeholder="Start Date (YYYY-MM-DD)" value="<?php echo esc_attr( $wpgraphql_logging_current_start_date ); ?>" />
42-
<input type="text" name="end_date" placeholder="End Date (YYYY-MM-DD)" value="<?php echo esc_attr( $wpgraphql_logging_current_end_date ); ?>" />
41+
<input type="text" name="start_date" class="wpgraphql-logging-datepicker" placeholder="Start Date" value="<?php echo esc_attr( $wpgraphql_logging_current_start_date ); ?>" />
42+
<input type="text" name="end_date" class="wpgraphql-logging-datepicker" placeholder="End Date" value="<?php echo esc_attr( $wpgraphql_logging_current_end_date ); ?>" />
4343

4444
<select name="level_filter">
4545
<option value="">All Levels</option>

plugins/wpgraphql-logging/src/Admin/View_Logs_Page.php

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ class View_Logs_Page {
2323
*/
2424
public const ADMIN_PAGE_SLUG = 'wpgraphql-logging-view';
2525

26+
/**
27+
* The hook suffix for the admin page.
28+
*
29+
* @var string
30+
*/
31+
protected string $page_hook = '';
32+
2633
/**
2734
* The instance of the view logs page.
2835
*
@@ -61,7 +68,7 @@ public function setup(): void {
6168
public function register_settings_page(): void {
6269

6370
// Add submenu under GraphQL menu using the correct parent slug.
64-
$menu_page = add_menu_page(
71+
$this->page_hook = add_menu_page(
6572
esc_html__( 'GraphQL Logs', 'wpgraphql-logging' ),
6673
esc_html__( 'GraphQL Logs', 'wpgraphql-logging' ),
6774
'manage_options',
@@ -80,7 +87,49 @@ public function register_settings_page(): void {
8087
);
8188

8289
// Updates the list table when filters are applied.
83-
add_action( 'load-' . $menu_page, [ $this, 'process_page_actions_before_rendering' ], 10, 0 );
90+
add_action( 'load-' . $this->page_hook, [ $this, 'process_page_actions_before_rendering' ], 10, 0 );
91+
92+
// Enqueue scripts for the admin page.
93+
add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_admin_scripts' ] );
94+
}
95+
96+
/**
97+
* Enqueues scripts and styles for the admin page.
98+
*
99+
* @param string $hook_suffix The current admin page.
100+
*/
101+
public function enqueue_admin_scripts( string $hook_suffix ): void {
102+
if ( $hook_suffix !== $this->page_hook ) {
103+
return;
104+
}
105+
106+
// Enqueue WordPress's built-in datepicker and slider.
107+
wp_enqueue_script( 'jquery-ui-datepicker' );
108+
wp_enqueue_script( 'jquery-ui-slider' );
109+
110+
// Enqueue the timepicker addon script and styles from a CDN.
111+
wp_enqueue_script(
112+
'jquery-ui-timepicker-addon',
113+
'https://cdnjs.cloudflare.com/ajax/libs/jquery-ui-timepicker-addon/1.6.3/jquery-ui-timepicker-addon.min.js',
114+
[ 'jquery-ui-datepicker', 'jquery-ui-slider' ],
115+
'1.6.3',
116+
true
117+
);
118+
wp_enqueue_style(
119+
'jquery-ui-timepicker-addon-style',
120+
'https://cdnjs.cloudflare.com/ajax/libs/jquery-ui-timepicker-addon/1.6.3/jquery-ui-timepicker-addon.min.css',
121+
[],
122+
'1.6.3'
123+
);
124+
125+
// Enqueue the base jQuery UI styles.
126+
wp_enqueue_style( 'jquery-ui-style', 'https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css', [], '1.12.1' );
127+
128+
// Add inline script to initialize the datetimepicker.
129+
wp_add_inline_script(
130+
'jquery-ui-timepicker-addon',
131+
'jQuery(document).ready(function($){ $(".wpgraphql-logging-datepicker").datetimepicker({ dateFormat: "yy-mm-dd", timeFormat: "HH:mm:ss" }); });'
132+
);
84133
}
85134

86135
/**

0 commit comments

Comments
 (0)