From d4fb9ae9059e67636f80bd54001503a8b1b66b77 Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Thu, 29 Nov 2018 12:25:45 -0500 Subject: [PATCH] Revert "Compat: Upgrade admin notices to use Notices module at runtime (#11604)" This reverts commit 5dbc6414f1f365b4b76e69fa35134365e1291e40. --- docs/contributors/coding-guidelines.md | 10 +- .../developers/data/data-core-notices.md | 5 - lib/packages-dependencies.php | 1 - packages/components/src/notice/index.js | 6 - packages/components/src/notice/list.js | 6 +- .../src/components/admin-notices/index.js | 105 ------------------ .../components/admin-notices/test/index.js | 61 ---------- .../edit-post/src/components/layout/index.js | 2 - packages/edit-post/src/index.js | 1 - packages/notices/src/store/actions.js | 21 +--- packages/notices/src/store/constants.js | 7 -- packages/notices/src/store/selectors.js | 9 +- packages/notices/src/store/test/actions.js | 57 +--------- 13 files changed, 14 insertions(+), 277 deletions(-) delete mode 100644 packages/edit-post/src/components/admin-notices/index.js delete mode 100644 packages/edit-post/src/components/admin-notices/test/index.js diff --git a/docs/contributors/coding-guidelines.md b/docs/contributors/coding-guidelines.md index 8264e76523104..dcc943b3288ae 100644 --- a/docs/contributors/coding-guidelines.md +++ b/docs/contributors/coding-guidelines.md @@ -93,13 +93,9 @@ Exposed APIs that are still being tested, discussed and are subject to change sh Example: ```js -export { __experimentalDoAction } from './api'; -``` - -If an API must be exposed but is clearly not intended to be supported into the future, you may also use `__unstable` as a prefix to differentiate it from an experimental API. Unstable APIs should serve an immediate and temporary purpose. They should _never_ be used by plugin developers as they can be removed at any point without notice, and thus should be omitted from public-facing documentation. The inline code documentation should clearly caution their use. - -```js -export { __unstableDoAction } from './api'; +export { + internalApi as __experimentalExposedApi +} from './internalApi.js'; ``` ### Variable Naming diff --git a/docs/designers-developers/developers/data/data-core-notices.md b/docs/designers-developers/developers/data/data-core-notices.md index 5ae7f1fb00067..b7ea283f02687 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 34c70851ff727..74f54a6e2c0af 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 90b2d908deee9..616774ec99915 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 4ff12e2a45118..a9e72c546deb6 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/src/components/admin-notices/index.js b/packages/edit-post/src/components/admin-notices/index.js deleted file mode 100644 index af04efaa9953a..0000000000000 --- 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 1dcda9a00a275..0000000000000 --- 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 `