Skip to content
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

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

DanieleAlessandra
Copy link
Collaborator

Enriched Debug Page:

  • Added: unfiltered_site_url;
  • Added: Scheduled Crons
  • Added: Collapsile Tables
  • Fixed: CSV Logs Download

<h2><?php fs_esc_html_echo_inline( 'Actions', 'actions' ) ?></h2>
<h2>
<?php fs_esc_html_echo_inline( 'Actions', 'actions' ) ?>
</h2>
Copy link
Contributor

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.

<h2><?php fs_esc_html_echo_inline( 'Debug Log', 'debug-log' ) ?></h2>
<h2>
<?php fs_esc_html_echo_inline( 'Debug Log', 'debug-log' ) ?>
</h2>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<h1><?php fs_esc_html_echo_inline( 'Scheduled Crons' ) ?></h1>
<?php echo $title_tag_open; ?>
<?php
if ($display_toggle_button) {
Copy link
Contributor

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.

<h1><?php fs_esc_html_echo_inline( 'Scheduled Crons' ) ?></h1>
<?php echo $title_tag_open; ?>
<?php
if ($display_toggle_button) {
Copy link
Contributor

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.

@@ -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';
Copy link
Contributor

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

if (isset($VARS['is_open'])) {
$is_open = $VARS['is_open'] ? 'true' : 'false';
}
else {
Copy link
Contributor

@fajardoleo fajardoleo Nov 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -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 () {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<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) {
Copy link
Contributor

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?

Copy link
Collaborator Author

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.

* @return bool
*/
private static function write_csv_to_filesystem( $file_path, $query_results ) {
require_once( ABSPATH . 'wp-admin/includes/file.php' );
Copy link
Contributor

@fajardoleo fajardoleo Nov 28, 2024

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.

@@ -691,5 +695,38 @@ public static function get_logs_download_url( $filename = '' ) {
return rtrim( $upload_dir['url'], '/' ) . $filename;
}

/**
* @param $file_path
* @param $query_results
Copy link
Contributor

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.

return false;
}

$content = implode( "\t", $headers ) . "\n";
Copy link
Contributor

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.

} );
} );
</script>
<style>
Copy link
Contributor

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.

@@ -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">
Copy link
Contributor

@fajardoleo fajardoleo Dec 4, 2024

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.

button.find( '.caret-icon' ).text( isExpanded ? '▼' : '▲' );
table.css( {
display : isExpanded ? 'table' : 'block',
maxHeight: isExpanded ? 'auto' : '0'
Copy link
Contributor

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',.

@@ -714,6 +748,15 @@ function stopCountdownManually() {
</table>
<?php endif ?>
<?php endforeach ?>
<?php
$page_params = array(
Copy link
Contributor

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.

'is_open' => false,
);

fs_require_template( 'debug/scheduled-crons.php', $page_params );
Copy link
Contributor

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.

@DanieleAlessandra DanieleAlessandra force-pushed the feature/daniele/enrich-debug-page branch 2 times, most recently from 90aadc3 to 5a8a3de Compare December 4, 2024 20:02
DanieleAlessandra and others added 2 commits December 11, 2024 14:50
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
@DanieleAlessandra DanieleAlessandra force-pushed the feature/daniele/enrich-debug-page branch from 0857469 to 65fc86c Compare December 11, 2024 13:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants