-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding snackbar notices support to the new widgets page #16020
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { filter } from 'lodash'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { SnackbarList } from '@wordpress/components'; | ||
import { useSelect, useDispatch } from '@wordpress/data'; | ||
|
||
function Notices() { | ||
const { notices } = useSelect( ( select ) => { | ||
return { | ||
notices: select( 'core/notices' ).getNotices(), | ||
}; | ||
} ); | ||
const snackbarNotices = filter( notices, { | ||
type: 'snackbar', | ||
} ); | ||
const { removeNotice } = useDispatch( 'core/notices' ); | ||
|
||
return ( | ||
<SnackbarList | ||
notices={ snackbarNotices } | ||
className="edit-widgets-notices__snackbar" | ||
onRemove={ removeNotice } | ||
/> | ||
); | ||
} | ||
|
||
export default Notices; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
.edit-widgets-notices__snackbar { | ||
position: fixed; | ||
right: 0; | ||
bottom: 20px; | ||
padding-left: 16px; | ||
padding-right: 16px; | ||
} | ||
@include editor-left(".edit-widgets-notices__snackbar"); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -178,6 +178,24 @@ describe( 'actions', () => { | |
}, | ||
} ); | ||
|
||
expect( | ||
saveWidgetAreasGen.next() | ||
).toEqual( { | ||
done: false, | ||
value: { | ||
type: 'DISPATCH', | ||
storeKey: 'core/notices', | ||
actionName: 'createSuccessNotice', | ||
args: [ | ||
'Block areas saved succesfully.', | ||
{ | ||
id: 'WIDGET_AREAS_SAVE_NOTICE_ID', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit pick: Maybe the test can import WIDGET_AREAS_SAVE_NOTICE_ID as a constant from the actions file. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not exported at the moment. I mean I could export it but for a test, maybe it's not that important. |
||
type: 'snackbar', | ||
}, | ||
], | ||
}, | ||
} ); | ||
|
||
expect( | ||
saveWidgetAreasGen.next() | ||
).toEqual( { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This made me wonder if we want to move the
EditorNotices
component from theeditor
package to thenotices
package as we'd have to rewrite such component for each consumer.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I guess it would be good to avoid this code repetition and just expose the component as part of the notices package.