Skip to content

Commit

Permalink
Editor: Extract snackbars into a separate component (#33355)
Browse files Browse the repository at this point in the history
* Add notices container to InterfaceSkeleton.
* Move the `EditorSnackbars` component to the notices container.
  • Loading branch information
Mamaduka authored and youknowriad committed Jul 15, 2021
1 parent d95ef3c commit 1c20923
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 9 deletions.
2 changes: 2 additions & 0 deletions packages/edit-post/src/components/layout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
UnsavedChangesWarning,
EditorNotices,
EditorKeyboardShortcutsRegister,
EditorSnackbars,
store as editorStore,
} from '@wordpress/editor';
import { AsyncModeProvider, useSelect, useDispatch } from '@wordpress/data';
Expand Down Expand Up @@ -220,6 +221,7 @@ function Layout( { styles } ) {
</>
)
}
notices={ <EditorSnackbars /> }
content={
<>
<EditorNotices />
Expand Down
2 changes: 2 additions & 0 deletions packages/edit-site/src/components/editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
} from '@wordpress/interface';
import {
EditorNotices,
EditorSnackbars,
EntitiesSavedStates,
UnsavedChangesWarning,
store as editorStore,
Expand Down Expand Up @@ -213,6 +214,7 @@ function Editor( { initialSettings } ) {
}
/>
}
notices={ <EditorSnackbars /> }
content={
<>
<EditorNotices />
Expand Down
10 changes: 1 addition & 9 deletions packages/editor/src/components/editor-notices/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { filter } from 'lodash';
/**
* WordPress dependencies
*/
import { NoticeList, SnackbarList } from '@wordpress/components';
import { NoticeList } from '@wordpress/components';
import { withSelect, withDispatch } from '@wordpress/data';
import { compose } from '@wordpress/compose';
import { store as noticesStore } from '@wordpress/notices';
Expand All @@ -25,9 +25,6 @@ export function EditorNotices( { notices, onRemove } ) {
isDismissible: false,
type: 'default',
} );
const snackbarNotices = filter( notices, {
type: 'snackbar',
} );

return (
<>
Expand All @@ -42,11 +39,6 @@ export function EditorNotices( { notices, onRemove } ) {
>
<TemplateValidationNotice />
</NoticeList>
<SnackbarList
notices={ snackbarNotices }
className="components-editor-notices__snackbar"
onRemove={ onRemove }
/>
</>
);
}
Expand Down
30 changes: 30 additions & 0 deletions packages/editor/src/components/editor-snackbars/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* External dependencies
*/
import { filter } from 'lodash';

/**
* WordPress dependencies
*/
import { SnackbarList } from '@wordpress/components';
import { useSelect, useDispatch } from '@wordpress/data';
import { store as noticesStore } from '@wordpress/notices';

export default function EditorSnackbars() {
const notices = useSelect(
( select ) => select( noticesStore ).getNotices(),
[]
);
const { removeNotice } = useDispatch( noticesStore );
const snackbarNotices = filter( notices, {
type: 'snackbar',
} );

return (
<SnackbarList
notices={ snackbarNotices }
className="components-editor-notices__snackbar"
onRemove={ removeNotice }
/>
);
}
1 change: 1 addition & 0 deletions packages/editor/src/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export { default as EditorKeyboardShortcutsRegister } from './global-keyboard-sh
export { default as EditorHistoryRedo } from './editor-history/redo';
export { default as EditorHistoryUndo } from './editor-history/undo';
export { default as EditorNotices } from './editor-notices';
export { default as EditorSnackbars } from './editor-snackbars';
export { default as EntitiesSavedStates } from './entities-saved-states';
export { default as ErrorBoundary } from './error-boundary';
export { default as LocalAutosaveMonitor } from './local-autosave-monitor';
Expand Down
9 changes: 9 additions & 0 deletions packages/interface/src/components/interface-skeleton/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
*/
import classnames from 'classnames';

/**
* WordPress dependencies
*/
/**
* WordPress dependencies
*/
Expand Down Expand Up @@ -31,6 +34,7 @@ function InterfaceSkeleton(
header,
sidebar,
secondarySidebar,
notices,
content,
drawer,
actions,
Expand Down Expand Up @@ -105,6 +109,11 @@ function InterfaceSkeleton(
{ secondarySidebar }
</div>
) }
{ !! notices && (
<div className="interface-interface-skeleton__notices">
{ notices }
</div>
) }
<div
className="interface-interface-skeleton__content"
role="region"
Expand Down

0 comments on commit 1c20923

Please sign in to comment.