Added a button to download SSR to a file. (#38110)

This commit is contained in:
Peter Fabian 2023-05-04 15:58:33 +02:00 committed by GitHub
parent 865fcd053c
commit 81b899b55e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 2 deletions

View File

@ -0,0 +1,4 @@
Significance: minor
Type: enhancement
Added a button to download SSR to a file.

View File

@ -14,7 +14,8 @@ jQuery( function ( $ ) {
.on( 'click', 'a.debug-report', this.generateReport )
.on( 'click', '#copy-for-support', this.copyReport )
.on( 'aftercopy', '#copy-for-support', this.copySuccess )
.on( 'aftercopyfailure', '#copy-for-support', this.copyFail );
.on( 'aftercopyfailure', '#copy-for-support', this.copyFail )
.on( 'click', '#download-for-support', this.downloadReport );
},
/**
@ -112,6 +113,21 @@ jQuery( function ( $ ) {
copyFail: function() {
$( '.copy-error' ).removeClass( 'hidden' );
$( '#debug-report' ).find( 'textarea' ).trigger( 'focus' ).trigger( 'select' );
},
downloadReport: function() {
var ssr_text = new Blob( [ $( '#debug-report' ).find( 'textarea' ).val() ], { type: 'text/plain' } );
var domain = window.location.hostname;
var datetime = new Date().toISOString().slice( 0, 19 ).replace( /:/g, '-' );
var a = document.createElement( 'a' );
a.download = 'SystemStatusReport_' + domain + '_' + datetime + '.txt';
a.href = window.URL.createObjectURL( ssr_text );
a.textContent = 'Download ready';
a.style='display:none';
a.click();
a.remove();
}
};

View File

@ -38,7 +38,10 @@ $untested_plugins = $plugin_updates->get_untested_plugins( WC()->version, Cons
<div id="debug-report">
<textarea readonly="readonly"></textarea>
<p class="submit">
<button id="copy-for-support" class="button-primary" href="#" data-tip="<?php esc_attr_e( 'Copied!', 'woocommerce' ); ?>">
<button id="download-for-support" class="button-primary" href="#">
<?php esc_html_e( 'Download for support', 'woocommerce' ); ?>
</button>
<button id="copy-for-support" class="button" href="#" data-tip="<?php esc_attr_e( 'Copied!', 'woocommerce' ); ?>">
<?php esc_html_e( 'Copy for support', 'woocommerce' ); ?>
</button>
</p>