Skip to content
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

Editor: Extract snackbars into a separate component #33355

Merged
merged 5 commits into from
Jul 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -225,6 +226,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() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you think it should be EditorSnackbarNotices (I'm not great with naming, just asking :) )

Copy link
Member Author

@Mamaduka Mamaduka Jul 12, 2021

Choose a reason for hiding this comment

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

I'm not great with naming, just asking :)

Same here 😄

Since "Snackbars" or "Toasts" are notice types themself, I don't think there's a need for the Notices suffix IMO.

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