Skip to content

Commit

Permalink
Editor: Use hooks instead of HoCs for EditorNotices (#57772)
Browse files Browse the repository at this point in the history
* Editor: Use hooks instead of HoCs for EditorNotices

* Minor optimizations as per feedback
  • Loading branch information
tyxla committed Jan 12, 2024
1 parent 7ca256c commit 3c57278
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions packages/editor/src/components/editor-notices/index.js
Expand Up @@ -2,16 +2,22 @@
* WordPress dependencies
*/
import { NoticeList } from '@wordpress/components';
import { withSelect, withDispatch } from '@wordpress/data';
import { compose } from '@wordpress/compose';
import { useDispatch, useSelect } from '@wordpress/data';
import { store as noticesStore } from '@wordpress/notices';

/**
* Internal dependencies
*/
import TemplateValidationNotice from '../template-validation-notice';

export function EditorNotices( { notices, onRemove } ) {
export function EditorNotices() {
const { notices } = useSelect(
( select ) => ( {
notices: select( noticesStore ).getNotices(),
} ),
[]
);
const { removeNotice } = useDispatch( noticesStore );
const dismissibleNotices = notices.filter(
( { isDismissible, type } ) => isDismissible && type === 'default'
);
Expand All @@ -28,19 +34,12 @@ export function EditorNotices( { notices, onRemove } ) {
<NoticeList
notices={ dismissibleNotices }
className="components-editor-notices__dismissible"
onRemove={ onRemove }
onRemove={ removeNotice }
>
<TemplateValidationNotice />
</NoticeList>
</>
);
}

export default compose( [
withSelect( ( select ) => ( {
notices: select( noticesStore ).getNotices(),
} ) ),
withDispatch( ( dispatch ) => ( {
onRemove: dispatch( noticesStore ).removeNotice,
} ) ),
] )( EditorNotices );
export default EditorNotices;

1 comment on commit 3c57278

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in 3c57278.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/7501832833
📝 Reported issues:

Please sign in to comment.