-
Notifications
You must be signed in to change notification settings - Fork 79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/daniele/enrich debug page #748
base: develop
Are you sure you want to change the base?
Conversation
templates/debug.php
Outdated
<h2><?php fs_esc_html_echo_inline( 'Actions', 'actions' ) ?></h2> | ||
<h2> | ||
<?php fs_esc_html_echo_inline( 'Actions', 'actions' ) ?> | ||
</h2> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DanieleAlessandra I suggest reverting this as the text remains the same.
templates/debug.php
Outdated
<h2><?php fs_esc_html_echo_inline( 'Debug Log', 'debug-log' ) ?></h2> | ||
<h2> | ||
<?php fs_esc_html_echo_inline( 'Debug Log', 'debug-log' ) ?> | ||
</h2> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
templates/debug/scheduled-crons.php
Outdated
<h1><?php fs_esc_html_echo_inline( 'Scheduled Crons' ) ?></h1> | ||
<?php echo $title_tag_open; ?> | ||
<?php | ||
if ($display_toggle_button) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DanieleAlessandra There are missing spaces here.
templates/debug/scheduled-crons.php
Outdated
<h1><?php fs_esc_html_echo_inline( 'Scheduled Crons' ) ?></h1> | ||
<?php echo $title_tag_open; ?> | ||
<?php | ||
if ($display_toggle_button) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DanieleAlessandra How about this instead?
<?php if ( $display_toggle_button ) : ?>
<button class="toggle-table" aria-expanded="<?php echo $is_open ?>">
<span class="caret-icon">▼</span>
</button>
<?php endif ?>
Also, in our convention, we don't add a semicolon for single-line PHP code.
templates/debug/scheduled-crons.php
Outdated
@@ -13,6 +13,17 @@ | |||
$fs_options = FS_Options::instance( WP_FS__ACCOUNTS_OPTION_NAME, true ); | |||
$scheduled_crons = array(); | |||
|
|||
$title_tag = isset($VARS['title_tag']) ? $VARS['title_tag'] : 'h1'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DanieleAlessandra Missing spaces. I recommend reviewing this and adding the relevant spacing accordingly:
https://developer.wordpress.org/coding-standards/wordpress-coding-standards/php/#whitespace
templates/debug/scheduled-crons.php
Outdated
if (isset($VARS['is_open'])) { | ||
$is_open = $VARS['is_open'] ? 'true' : 'false'; | ||
} | ||
else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DanieleAlessandra I recommend reviewing this for control structures and brace styles:
https://developer.wordpress.org/coding-standards/wordpress-coding-standards/php/#brace-style
templates/debug.php
Outdated
@@ -888,3 +934,32 @@ class="dashicons dashicons-download"></i> <?php fs_esc_html_echo_inline( 'Downlo | |||
}); | |||
</script> | |||
<?php endif ?> | |||
<script type="text/javascript"> | |||
// JavaScript to toggle the visibility of the table body and change the caret icon | |||
document.addEventListener('DOMContentLoaded', function () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DanieleAlessandra Similar to PHP, please review this and improve the spacing accordingly:
https://developer.wordpress.org/coding-standards/wordpress-coding-standards/javascript/#examples-of-good-spacing
templates/debug.php
Outdated
<script type="text/javascript"> | ||
// JavaScript to toggle the visibility of the table body and change the caret icon | ||
document.addEventListener('DOMContentLoaded', function () { | ||
document.querySelectorAll('.toggle-table').forEach(function (button) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DanieleAlessandra The JS code just above this block uses jQuery. Is there any reason why we can't do the same here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While the codebase still contains some jQuery usage, I believe it is beneficial for us to reduce dependency on it over time, as it’s likely to be phased out in the future.
For this specific block, I opted not to use jQuery because it is entirely new and independent from the other scripts on the page. Additionally, the functionality is simple enough to implement without relying on the library.
includes/class-fs-logger.php
Outdated
* @return bool | ||
*/ | ||
private static function write_csv_to_filesystem( $file_path, $query_results ) { | ||
require_once( ABSPATH . 'wp-admin/includes/file.php' ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DanieleAlessandra I think it should be like this (please double-check):
private static function write_csv_to_filesystem( $file_path, $query_results ) {
if ( empty( $query_results ) ) {
return false;
}
WP_Filesystem();
global $wp_filesystem;
if ( ! $wp_filesystem->is_writable( dirname( $file_path ) ) ) {
return false;
}
$headers = array_keys( (array) $query_results[0] );
This way, we won't trigger the other lines if we will return false
anyway.
Also, the require_once
line doesn't appear to be needed, as we are in a WordPress admin context where that is already included.
includes/class-fs-logger.php
Outdated
@@ -691,5 +695,38 @@ public static function get_logs_download_url( $filename = '' ) { | |||
return rtrim( $upload_dir['url'], '/' ) . $filename; | |||
} | |||
|
|||
/** | |||
* @param $file_path | |||
* @param $query_results |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DanieleAlessandra Parameter types are missing.
includes/class-fs-logger.php
Outdated
return false; | ||
} | ||
|
||
$content = implode( "\t", $headers ) . "\n"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DanieleAlessandra The headers are duplicated by the foreach()
loop below.
templates/debug.php
Outdated
} ); | ||
} ); | ||
</script> | ||
<style> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DanieleAlessandra It seems that the styles here should be in the assets/sass/admin/debug.scss
file.
templates/debug.php
Outdated
@@ -284,7 +288,12 @@ function stopCountdownManually() { | |||
<?php endforeach ?> | |||
</tbody> | |||
</table> | |||
<h2><?php fs_esc_html_echo_x_inline( 'SDK Versions', 'as software development kit versions', 'sdk-versions' ) ?></h2> | |||
<h2> | |||
<button class="toggle-table" aria-expanded="true"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DanieleAlessandra I see that this is duplicated in multiple places, so I suggest storing it in a variable and then doing something like <?php echo $toggle_button ?>
.
Also, the class should have the fs-
prefix. It could be something like fs-debug-table-toggle-button
and fs-debug-table-toggle-icon
.
templates/debug.php
Outdated
button.find( '.caret-icon' ).text( isExpanded ? '▼' : '▲' ); | ||
table.css( { | ||
display : isExpanded ? 'table' : 'block', | ||
maxHeight: isExpanded ? 'auto' : '0' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DanieleAlessandra Maybe also add borderBottomWidth: isExpanded ? '1px' : '0',
.
templates/debug.php
Outdated
@@ -714,6 +748,15 @@ function stopCountdownManually() { | |||
</table> | |||
<?php endif ?> | |||
<?php endforeach ?> | |||
<?php | |||
$page_params = array( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DanieleAlessandra, I see that the previous line uses spaces, not tabs.
templates/debug.php
Outdated
'is_open' => false, | ||
); | ||
|
||
fs_require_template( 'debug/scheduled-crons.php', $page_params ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DanieleAlessandra Regarding the duplicated <button class="toggle-table" aria-expanded="true">
, if it's stored in a variable, then it can also be included in $page_params
.
90aadc3
to
5a8a3de
Compare
Add: Scheduled Crons; Add: Collapsible tables Fix: Export logs in CSV PHP compatibility Formatting [debug page] Fixed code style, Fixed duplicated header in exported file Changed toggle script from vanilla JS to jQuery Toggle button in a variable, class names Added toggle button factory function Added border width Moved css snippet to debug.scss
0857469
to
65fc86c
Compare
Enriched Debug Page: