Skip to content

Commit

Permalink
Edit Post: Add missing AdminNotices classes
Browse files Browse the repository at this point in the history
  • Loading branch information
aduth committed Nov 16, 2018
1 parent 137b3bd commit f9b44c5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 20 deletions.
32 changes: 13 additions & 19 deletions packages/edit-post/src/components/admin-notices/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 ];
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = `
<div class="notice notice-success is-dismissible">
<p>
My <strong>notice</strong> text
</p>
<div class="notice updated is-dismissible">
<button type="button" class="notice-dismiss">
<span class="screen-reader-text">Dismiss this notice.</span>
</button>
Expand Down

0 comments on commit f9b44c5

Please sign in to comment.