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

Plugin check UX improvement for results #326

Open
wants to merge 23 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions assets/js/plugin-check-admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,15 @@
for ( let i = 0; i < categoriesList.length; i++ ) {
categoriesList[ i ].disabled = false;
}

// Adding Open All/Collapse All button
if ( resultsContainer.innerHTML !== '' ) {
resultsContainer.innerHTML =
'<div><button style="margin-top:1.33em;" class="button button-primary collapse-all" data-state="open">' +
PLUGIN_CHECK.collapseAll +
'</button></div>' +
resultsContainer.innerHTML;
}
}

/**
Expand Down Expand Up @@ -467,4 +476,61 @@
const template = templates[ templateSlug ];
return template( data );
}

/**
* Manage collapse/open tables click event
*/
document.addEventListener( 'click', function ( e ) {
const button = e.target;
// Manage Collapse/Open All tables separately.
if ( button.classList.contains( 'collapse-btn' ) ) {
const dataIndex = button
.closest( '.plugin-check__results-heading' )
.getAttribute( 'data-index' );
const tableContainer = document.querySelector(
'#plugin-check__results-table-' + dataIndex
);

// Toggle the visibility of the table container.
if ( tableContainer.style.display === 'none' ) {
tableContainer.style.display = 'table';
button.innerHTML = PLUGIN_CHECK.collapse;
} else {
tableContainer.style.display = 'none';
button.innerHTML = PLUGIN_CHECK.open;
}
}

// Manage Collapse/Open All tables together.
if ( button.classList.contains( 'collapse-all' ) ) {
const tableContainers = document.querySelectorAll(
'.plugin-check__results-table'
);
const buttons = document.querySelectorAll( '.collapse-btn' );
const state = button.getAttribute( 'data-state' );
const isVisible = state && state === 'open';

// Collapase/Open All tables.
tableContainers.forEach( function ( tableContainer ) {
tableContainer.style.display = isVisible ? 'none' : 'table';
} );

// Change All buttons text.
buttons.forEach( function ( _button ) {
_button.innerHTML = isVisible ? 'Open' : 'Collapse';
_button.setAttribute(
'data-state',
isVisible ? 'closed' : 'open'
);
} );

// Change Collapse All/Open All Button text.
button.innerHTML = isVisible
? PLUGIN_CHECK.openAll
: PLUGIN_CHECK.collapseAll;

// Change Collapse All/Open All Button attribute.
button.setAttribute( 'data-state', isVisible ? 'closed' : 'open' );
}
} );
} )( PLUGIN_CHECK ); /* global PLUGIN_CHECK */
4 changes: 4 additions & 0 deletions includes/Admin/Admin_Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@
'actionCleanUpRuntimeEnvironment' => Admin_AJAX::ACTION_CLEAN_UP_ENVIRONMENT,
'successMessage' => __( 'No errors found.', 'plugin-check' ),
'errorMessage' => __( 'Errors were found.', 'plugin-check' ),
'collapseAll' => __( 'Collapse All', 'plugin-check' ),
'openAll' => __( 'Open All', 'plugin-check' ),
'collapse' => __( 'Collapse', 'plugin-check' ),
'open' => __( 'Open', 'plugin-check' ),

Check warning on line 124 in includes/Admin/Admin_Page.php

View check run for this annotation

Codecov / codecov/patch

includes/Admin/Admin_Page.php#L121-L124

Added lines #L121 - L124 were not covered by tests
)
),
'before'
Expand Down
5 changes: 4 additions & 1 deletion templates/results-table.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<h4><?php esc_html_e( 'FILE:', 'plugin-check' ); ?> {{ data.file }}</h4>
<h4 id="plugin-check__results-heading-{{data.index}}" class="plugin-check__results-heading" data-index="{{data.index}}">
<?php esc_html_e( 'FILE:', 'plugin-check' ); ?> {{ data.file }}
<button class="collapse-btn" data-state="collapse"><?php esc_html_e( 'Collapse', 'plugin-check' ); ?></button>
</h4>
<table id="plugin-check__results-table-{{data.index}}" class="widefat striped plugin-check__results-table">
<thead>
<tr>
Expand Down
Loading