From 247e180f516262e81572c682c3c1babaf6aaa9ae Mon Sep 17 00:00:00 2001 From: Scott Kingsley Clark Date: Sun, 18 Aug 2024 10:31:58 -0500 Subject: [PATCH] Add Query Monitor CSS to allow filtering the debug log and move it into the Pods QM menu --- src/Pods/Integrations/Query_Monitor.php | 3 + .../Query_Monitor/Outputters/Constants.php | 2 +- .../Query_Monitor/Outputters/Debug.php | 65 +++++++++++++++++-- ui/styles/dist/pods-query-monitor.css | 1 + ui/styles/src/pods-query-monitor.scss | 5 ++ 5 files changed, 68 insertions(+), 8 deletions(-) create mode 100644 ui/styles/dist/pods-query-monitor.css create mode 100644 ui/styles/src/pods-query-monitor.scss diff --git a/src/Pods/Integrations/Query_Monitor.php b/src/Pods/Integrations/Query_Monitor.php index bb6f6bb20c..b813d0c05b 100644 --- a/src/Pods/Integrations/Query_Monitor.php +++ b/src/Pods/Integrations/Query_Monitor.php @@ -44,6 +44,9 @@ class Query_Monitor extends Integration { public function post_hook() { QM_Collectors::add( new Collectors\Constants() ); QM_Collectors::add( new Collectors\Debug() ); + + wp_register_style( 'pods-query-monitor', PODS_URL . 'ui/styles/dist/pods-query-monitor.css', [ 'query-monitor' ], PODS_VERSION ); + wp_enqueue_style( 'pods-query-monitor' ); } /** diff --git a/src/Pods/Integrations/Query_Monitor/Outputters/Constants.php b/src/Pods/Integrations/Query_Monitor/Outputters/Constants.php index 79b83e3962..f3fa37c0a2 100644 --- a/src/Pods/Integrations/Query_Monitor/Outputters/Constants.php +++ b/src/Pods/Integrations/Query_Monitor/Outputters/Constants.php @@ -30,7 +30,7 @@ public function __construct( QM_Collector $collector ) { * {@inheritDoc} */ public function name(): string { - return __( 'Pods Constants', 'pods' ); + return __( 'Pods', 'pods' ); } /** diff --git a/src/Pods/Integrations/Query_Monitor/Outputters/Debug.php b/src/Pods/Integrations/Query_Monitor/Outputters/Debug.php index 4c9319e29a..1fb1a790ac 100644 --- a/src/Pods/Integrations/Query_Monitor/Outputters/Debug.php +++ b/src/Pods/Integrations/Query_Monitor/Outputters/Debug.php @@ -3,6 +3,7 @@ namespace Pods\Integrations\Query_Monitor\Outputters; use QM_Collector; +use QM_Collectors; use QM_Output_Html; // Exit if accessed directly. @@ -24,6 +25,7 @@ public function __construct( QM_Collector $collector ) { parent::__construct( $collector ); add_filter( 'qm/output/menus', [ $this, 'admin_menu' ], 999 ); + add_filter( 'qm/output/panel_menus', [ $this, 'panel_menu' ], 20 ); } /** @@ -48,8 +50,10 @@ public function output(): void { sort( $contexts ); $debug_log_types = [ - 'yes' => __( 'Log is JSON', 'pods' ), - 'no' => __( 'Log is not JSON', 'pods' ), + 'is-json' => __( 'Log is JSON', 'pods' ), + 'not-json' => __( 'Log is not JSON', 'pods' ), + 'is-sql' => __( 'Log is SQL query', 'pods' ), + 'not-sql' => __( 'Log is not SQL query', 'pods' ), ]; ?> @@ -64,7 +68,7 @@ public function output(): void { build_filter( 'context', $contexts, __( 'Context', 'pods' ) ); ?> - build_filter( 'debug-log-is-json', $debug_log_types, __( 'Debug Log', 'pods' ) ); ?> + build_filter( 'debug-log-type', $debug_log_types, __( 'Debug Log', 'pods' ) ); ?> @@ -93,12 +97,33 @@ public function output(): void { } } + $context = $debug['context']; + + $sql_contexts = [ + 'sql-select', + 'sql-query', + ]; + $has_toggle = $has_json || $is_long; + $log_type = []; + + if ( $has_json ) { + $log_type[] = 'is-json'; + } else { + $log_type[] = 'not-json'; + } + + if ( in_array( $context, $sql_contexts, true ) ) { + $log_type[] = 'is-sql'; + } else { + $log_type[] = 'not-sql'; + } + $row_attr = [ - 'data-qm-function' => $debug['function'], - 'data-qm-context' => $debug['context'], - 'data-qm-debug-log-is-json' => $has_json ? 'yes' : 'no', + 'data-qm-function' => $debug['function'], + 'data-qm-context' => $debug['context'], + 'data-qm-debug-log-type' => implode( ' ', $log_type ), ]; $attr = ''; @@ -115,7 +140,7 @@ public function output(): void { - + after_tabular_output(); } + + /** + * Register the panel menu for this outputter. + * + * @since TBD + * + * @param array $menus The panel menus. + * + * @return array The updated panel menus. + */ + public function panel_menu( array $menus ) { + $id = $this->collector->id(); + + if ( isset( $menus[ $id ] ) ) { + /** @var \Pods\Integrations\Query_Monitor\Collectors\Constants|null $constants */ + $constants = QM_Collectors::get( 'pods-constants' ); + + if ( $constants ) { + $menus[ $constants->id() ]['children'][] = $menus[ $id ]; + } + + unset( $menus[ $id ] ); + } + + return $menus; + } } diff --git a/ui/styles/dist/pods-query-monitor.css b/ui/styles/dist/pods-query-monitor.css new file mode 100644 index 0000000000..45e08f9739 --- /dev/null +++ b/ui/styles/dist/pods-query-monitor.css @@ -0,0 +1 @@ +#qm-pods-debug-container .qm-hide-function,#qm-pods-debug-container .qm-hide-context,#qm-pods-debug-container .qm-hide-debug-log-type{display:none !important} diff --git a/ui/styles/src/pods-query-monitor.scss b/ui/styles/src/pods-query-monitor.scss new file mode 100644 index 0000000000..5fe9bf4512 --- /dev/null +++ b/ui/styles/src/pods-query-monitor.scss @@ -0,0 +1,5 @@ +#qm-pods-debug-container .qm-hide-function, +#qm-pods-debug-container .qm-hide-context, +#qm-pods-debug-container .qm-hide-debug-log-type { + display: none !important; +}