From 6d58ed97c4b250536bb18fdf5f472aa5850230d5 Mon Sep 17 00:00:00 2001 From: Tiago Noronha Date: Fri, 15 Feb 2019 18:01:18 +0000 Subject: [PATCH] Add array of notice ids and/or classes and iterate to collapse --- .../activity-panel/wordpress-notices.js | 42 +++++++++++-------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/plugins/woocommerce-admin/client/header/activity-panel/wordpress-notices.js b/plugins/woocommerce-admin/client/header/activity-panel/wordpress-notices.js index 6e09ad5fe1c..8fa95a5fb4e 100644 --- a/plugins/woocommerce-admin/client/header/activity-panel/wordpress-notices.js +++ b/plugins/woocommerce-admin/client/header/activity-panel/wordpress-notices.js @@ -116,32 +116,38 @@ class WordPressNotices extends Component { // Some messages should not be displayed in the toggle, like Jetpack JITM messages or update/success messages shouldCollapseNotice( element ) { - if ( element.classList.contains( 'jetpack-jitm-message' ) ) { - return false; - } + const noticesToHide = [ + [ null, [ 'jetpack-jitm-message' ] ], // ID and/or array of classes + [ 'woocommerce_errors', null ], + [ null, [ 'hidden' ] ], + [ 'message', [ 'notice', 'updated' ] ], + [ 'dolly', null ], + ]; - if ( 'woocommerce_errors' === element.id ) { - return false; - } + let collapse = true; + for ( let i = 0; collapse && i < noticesToHide.length; i++ ) { + const [ id, classes ] = noticesToHide[ i ]; - if ( element.classList.contains( 'hidden' ) ) { - return false; - } - - if ( 'message' === element.id && element.classList.contains( 'notice' ) ) { - return false; - } - - if ( 'message' === element.id && 'updated' === element.className ) { - return false; + if ( Array.isArray( classes ) ) { + for ( let j = 0; j < classes.length; j++ ) { + if ( + element.classList.contains( classes[ j ] ) && + ( ! id || ( id && id === element.id ) ) + ) { + collapse = false; + break; + } + } + } else if ( id && id === element.id ) { + collapse = false; + } } if ( 'dolly' === element.id ) { element.style.display = 'none'; - return false; } - return true; + return collapse; } updateCount() {