diff --git a/docs/designers-developers/developers/data/data-core-notices.md b/docs/designers-developers/developers/data/data-core-notices.md index 5ae7f1fb000679..b7ea283f02687f 100644 --- a/docs/designers-developers/developers/data/data-core-notices.md +++ b/docs/designers-developers/developers/data/data-core-notices.md @@ -32,11 +32,6 @@ Yields action objects used in signalling that a notice is to be created. * options.isDismissible: Whether the notice can be dismissed by user. Defaults to `true`. - * options.speak: Whether the notice - content should be - announced to screen - readers. Defaults to - `true`. * options.actions: User actions to be presented with notice. diff --git a/lib/packages-dependencies.php b/lib/packages-dependencies.php index 34c70851ff727c..74f54a6e2c0afe 100644 --- a/lib/packages-dependencies.php +++ b/lib/packages-dependencies.php @@ -124,7 +124,6 @@ 'wp-embed', 'wp-i18n', 'wp-keycodes', - 'wp-notices', 'wp-nux', 'wp-plugins', 'wp-url', diff --git a/packages/components/src/notice/index.js b/packages/components/src/notice/index.js index 90b2d908deee92..616774ec99915c 100644 --- a/packages/components/src/notice/index.js +++ b/packages/components/src/notice/index.js @@ -8,7 +8,6 @@ import classnames from 'classnames'; * WordPress dependencies */ import { __ } from '@wordpress/i18n'; -import { RawHTML } from '@wordpress/element'; /** * Internal dependencies @@ -22,16 +21,11 @@ function Notice( { onRemove = noop, isDismissible = true, actions = [], - __unstableHTML, } ) { const classes = classnames( className, 'components-notice', 'is-' + status, { 'is-dismissible': isDismissible, } ); - if ( __unstableHTML ) { - children = { children }; - } - return (
diff --git a/packages/components/src/notice/list.js b/packages/components/src/notice/list.js index 4ff12e2a451181..a9e72c546deb6e 100644 --- a/packages/components/src/notice/list.js +++ b/packages/components/src/notice/list.js @@ -25,11 +25,7 @@ function NoticeList( { notices, onRemove = noop, className = 'components-notice-
{ children } { [ ...notices ].reverse().map( ( notice ) => ( - + { notice.content } ) ) } diff --git a/packages/edit-post/CHANGELOG.md b/packages/edit-post/CHANGELOG.md index 055d3a6b47b011..cd4918d368d778 100644 --- a/packages/edit-post/CHANGELOG.md +++ b/packages/edit-post/CHANGELOG.md @@ -1,3 +1,9 @@ +## 4.0.0 (Unreleased) + +### Breaking Change + +- Revert: The `AdminNotices` component added in 3.1.0 has been removed. + ## 3.1.2 (2018-11-22) ## 3.1.1 (2018-11-21) diff --git a/packages/edit-post/src/components/admin-notices/index.js b/packages/edit-post/src/components/admin-notices/index.js deleted file mode 100644 index af04efaa9953a3..00000000000000 --- a/packages/edit-post/src/components/admin-notices/index.js +++ /dev/null @@ -1,105 +0,0 @@ -/** - * WordPress dependencies - */ -import { Component } from '@wordpress/element'; -import { withDispatch } from '@wordpress/data'; - -/** - * Mapping of server-supported notice class names to an equivalent notices - * module status. - * - * @type {Map} - */ -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. - * - * @return {Element[]} Admin notice elements. - */ -function getAdminNotices() { - // The order is reversed to match expectations of rendered order, since a - // NoticesList is itself rendered in reverse order (newest to oldest). - return [ ...document.querySelectorAll( '#wpbody-content > .notice' ) ].reverse(); -} - -/** - * Given an admin notice Element, returns the relevant notice content HTML. - * - * @param {Element} element Admin notice element. - * - * @return {Element} Upgraded notice HTML. - */ -function getNoticeHTML( element ) { - const fragments = []; - - for ( const child of element.childNodes ) { - if ( child.nodeType !== window.Node.ELEMENT_NODE ) { - const value = child.nodeValue.trim(); - if ( value ) { - fragments.push( child.nodeValue ); - } - } else if ( ! child.classList.contains( 'notice-dismiss' ) ) { - fragments.push( child.outerHTML ); - } - } - - return fragments.join( '' ); -} - -/** - * Given an admin notice Element, returns the upgraded status type, or - * undefined if one cannot be determined (i.e. one is not assigned). - * - * @param {Element} element Admin notice element. - * - * @return {?string} Upgraded status type. - */ -function getNoticeStatus( element ) { - for ( const className of element.classList ) { - if ( NOTICE_CLASS_STATUSES.hasOwnProperty( className ) ) { - return NOTICE_CLASS_STATUSES[ className ]; - } - } -} - -export class AdminNotices extends Component { - componentDidMount() { - this.convertNotices(); - } - - convertNotices() { - const { createNotice } = this.props; - getAdminNotices().forEach( ( element ) => { - // Convert and create. - const status = getNoticeStatus( element ); - const content = getNoticeHTML( element ); - const isDismissible = element.classList.contains( 'is-dismissible' ); - createNotice( status, content, { - speak: false, - __unstableHTML: true, - isDismissible, - } ); - - // Remove (now-redundant) admin notice element. - element.parentNode.removeChild( element ); - } ); - } - - render() { - return null; - } -} - -export default withDispatch( ( dispatch ) => { - const { createNotice } = dispatch( 'core/notices' ); - - return { createNotice }; -} )( AdminNotices ); diff --git a/packages/edit-post/src/components/admin-notices/test/index.js b/packages/edit-post/src/components/admin-notices/test/index.js deleted file mode 100644 index 1dcda9a00a2755..00000000000000 --- a/packages/edit-post/src/components/admin-notices/test/index.js +++ /dev/null @@ -1,61 +0,0 @@ -/** - * External dependencies - */ -import renderer from 'react-test-renderer'; - -/** - * Internal dependencies - */ -import { AdminNotices } from '../'; - -describe( 'AdminNotices', () => { - beforeEach( () => { - // The superfluous whitespace is intentional in verifying expected - // outputs of (a) non-element first child of the element (whitespace - // text node) and (b) untrimmed content. - document.body.innerHTML = ` -
-
-

My notice text

-

My second line of text

- -
-
Warning
- -
- `; - } ); - - it( 'should upgrade notices', () => { - const createNotice = jest.fn(); - - renderer.create( ); - - expect( createNotice ).toHaveBeenCalledTimes( 2 ); - expect( createNotice.mock.calls[ 0 ] ).toEqual( [ - 'warning', - 'Warning', - { - speak: false, - __unstableHTML: true, - isDismissible: false, - }, - ] ); - expect( createNotice.mock.calls[ 1 ] ).toEqual( [ - 'success', - '

My notice text

My second line of text

', - { - speak: false, - __unstableHTML: true, - isDismissible: true, - }, - ] ); - - // Verify all but `