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 6 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
62 changes: 62 additions & 0 deletions assets/js/plugin-check-admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,13 @@
for ( let i = 0; i < categoriesList.length; i++ ) {
categoriesList[ i ].disabled = false;
}

//Adding Open All/Collapse All button
jakaria-istauk marked this conversation as resolved.
Show resolved Hide resolved
if ( resultsContainer.innerHTML !== '' ) {
resultsContainer.innerHTML =
'<div><button style="margin-top:1.33em;" class="button button-primary clollaps-all" data-state="open">Clollaps All</button></div>' +
jakaria-istauk marked this conversation as resolved.
Show resolved Hide resolved
resultsContainer.innerHTML;
}
}

/**
Expand Down Expand Up @@ -469,4 +476,59 @@
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 = 'Collapse';
} else {
tableContainer.style.display = 'none';
button.innerHTML = 'Open';
}
}

//Manage Collapse/Open All tables together
if ( button.classList.contains( 'clollaps-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 ? 'Open All' : 'Collapse All';

//Change Collapse All/Open All Button attribute
button.setAttribute( 'data-state', isVisible ? 'closed' : 'open' );
}
} );
} )( PLUGIN_CHECK ); /* global PLUGIN_CHECK */
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' ); ?></button>
jakaria-istauk marked this conversation as resolved.
Show resolved Hide resolved
</h4>
<table id="plugin-check__results-table-{{data.index}}" class="widefat striped plugin-check__results-table">
<thead>
<tr>
Expand Down