From f9b44c5f197855aa06de077132f3a9b7122d68e8 Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Fri, 16 Nov 2018 13:05:58 -0500 Subject: [PATCH] Edit Post: Add missing AdminNotices classes --- .../src/components/admin-notices/index.js | 32 ++++++++----------- .../components/admin-notices/test/index.js | 2 +- 2 files changed, 14 insertions(+), 20 deletions(-) diff --git a/packages/edit-post/src/components/admin-notices/index.js b/packages/edit-post/src/components/admin-notices/index.js index 84ab424406460..1302995c16f7c 100644 --- a/packages/edit-post/src/components/admin-notices/index.js +++ b/packages/edit-post/src/components/admin-notices/index.js @@ -5,24 +5,19 @@ import { Component } from '@wordpress/element'; import { withDispatch } from '@wordpress/data'; /** - * Set of class name suffixes to associate as the status of an admin notice. + * Mapping of server-supported notice class names to an equivalent notices + * module status. * - * @type {Set} + * @type {Map} */ -const NOTICE_STATUSES = new Set( [ - 'success', - 'warning', - 'error', - 'info', -] ); - -/** - * Pattern matching a class list item matching the pattern of an admin notice - * status class. - * - * @type {RegExp} - */ -const REGEXP_NOTICE_STATUS = /^notice-(\w+)$/; +const NOTICE_CLASS_STATUSES = { + 'notice-success': 'success', + updated: 'success', + 'notice-warning': 'warning', + 'notice-error': 'error', + error: 'error', + 'notice-info': 'info', +}; /** * Returns an array of admin notice Elements. @@ -59,9 +54,8 @@ function getNoticeContentSourceFromElement( element ) { */ function getNoticeStatusFromClassList( element ) { for ( const className of element.classList ) { - const match = className.match( REGEXP_NOTICE_STATUS ); - if ( match && NOTICE_STATUSES.has( match[ 1 ] ) ) { - return match[ 1 ]; + if ( NOTICE_CLASS_STATUSES.hasOwnProperty( className ) ) { + return NOTICE_CLASS_STATUSES[ className ]; } } } diff --git a/packages/edit-post/src/components/admin-notices/test/index.js b/packages/edit-post/src/components/admin-notices/test/index.js index f5c4a4d983d0c..4283499fab667 100644 --- a/packages/edit-post/src/components/admin-notices/test/index.js +++ b/packages/edit-post/src/components/admin-notices/test/index.js @@ -14,10 +14,10 @@ describe( 'AdminNotices', () => { // outputs of (a) non-element first child of the element (whitespace // text node) and (b) untrimmed content. document.body.innerHTML = ` -

My notice text

+