From 670285483d51cabb542f48b52ce543e58d698dbd Mon Sep 17 00:00:00 2001 From: Mikael Korpela Date: Thu, 10 Sep 2026 17:26:42 +0300 Subject: [PATCH 01/12] Notices: switch to core Snackbar notices everywhere --- pnpm-lock.yaml | 6 +- ...update-move-jetpack-notices-to-bottom-left | 4 ++ .../global-notices/global-notices.tsx | 31 ---------- .../components/global-notices/index.ts | 3 - .../global-notices/stories/index.stories.tsx | 55 ----------------- .../global-notices/styles.module.scss | 24 -------- .../global-notices/use-global-notices.ts | 37 ------------ projects/js-packages/components/index.ts | 1 - projects/js-packages/components/package.json | 6 -- .../_inc/components/module-toggle/index.tsx | 10 ++-- .../module-toggle/test/index.test.tsx | 13 ++-- .../products/pending-notice.ts | 7 ++- .../products/test/pending-notice.test.tsx | 8 ++- .../data/products/use-activate-plugins.ts | 8 ++- .../data/products/use-deactivate-plugins.ts | 8 ++- ...update-move-jetpack-notices-to-bottom-left | 4 ++ projects/packages/my-jetpack/package.json | 1 + ...update-move-jetpack-notices-to-bottom-left | 4 ++ .../newsletter/src/settings/index.tsx | 7 ++- .../src/settings/newsletter-settings.tsx | 9 ++- .../newsletter/src/settings/style.scss | 7 +++ .../newsletter/tests/settings.test.jsx | 6 +- .../connection-management/reconnect.tsx | 7 ++- .../confirmation-form/index.tsx | 9 ++- .../components/services/use-request-access.ts | 8 ++- .../social-store/actions/connection-data.ts | 12 ++-- ...update-move-jetpack-notices-to-bottom-left | 4 ++ ...update-move-jetpack-notices-to-bottom-left | 4 ++ projects/packages/scan/routes/index/stage.tsx | 2 - .../packages/scan/src/js/notices-list.tsx | 34 ----------- .../packages/seo/_inc/admin-page-layout.scss | 60 ------------------- ...update-move-jetpack-notices-to-bottom-left | 4 ++ ...update-move-jetpack-notices-to-bottom-left | 4 ++ .../videopress/routes/library/package.json | 2 + .../routes/library/promote-local.ts | 13 ++-- .../videopress/routes/library/stage.tsx | 34 ++++++----- .../routes/library/test/promote-local.test.ts | 10 +++- .../routes/library/test/stage.test.tsx | 19 +++++- .../videopress/routes/settings/package.json | 2 + .../videopress/routes/settings/stage.tsx | 8 ++- .../routes/settings/test/stage.test.tsx | 24 +++++++- .../routes/video-editor/package.json | 2 + .../videopress/routes/video-editor/stage.tsx | 17 ++++-- .../routes/video-editor/test/stage.test.tsx | 31 ++++++++-- .../videopress/routes/video/package.json | 2 + .../videopress/routes/video/stage.tsx | 15 +++-- .../routes/video/test/stage.test.tsx | 32 ++++++++-- .../components/upload-dropzone/index.tsx | 7 ++- .../upload-dropzone/test/index.test.tsx | 17 +++++- .../test/thumbnail-card.test.tsx | 14 ++++- .../test/video-info-card.test.tsx | 14 ++++- .../video-details/video-info-card.tsx | 12 ++-- .../hooks/test/use-update-chapters.test.ts | 18 +++++- .../hooks/test/use-upload-intake.test.ts | 19 +++++- .../dashboard/hooks/use-update-chapters.ts | 11 ++-- .../hooks/use-update-video-poster.ts | 13 ++-- .../src/dashboard/hooks/use-upload-intake.ts | 14 +++-- .../plugins/jetpack/_inc/client/ai/main.jsx | 15 +++-- .../_inc/client/ai/scheduled-tasks/index.jsx | 6 +- .../plugins/jetpack/_inc/client/ai/style.scss | 7 +++ .../jetpack/_inc/client/ai/test/main.jsx | 4 +- .../jetpack/_inc/client/settings/index.jsx | 5 +- .../jetpack/_inc/client/settings/style.scss | 7 +++ ...update-move-jetpack-notices-to-bottom-left | 4 ++ ...update-move-jetpack-notices-to-bottom-left | 4 ++ ...update-move-jetpack-notices-to-bottom-left | 4 ++ 66 files changed, 412 insertions(+), 401 deletions(-) create mode 100644 projects/js-packages/components/changelog/update-move-jetpack-notices-to-bottom-left delete mode 100644 projects/js-packages/components/components/global-notices/global-notices.tsx delete mode 100644 projects/js-packages/components/components/global-notices/index.ts delete mode 100644 projects/js-packages/components/components/global-notices/stories/index.stories.tsx delete mode 100644 projects/js-packages/components/components/global-notices/styles.module.scss delete mode 100644 projects/js-packages/components/components/global-notices/use-global-notices.ts create mode 100644 projects/packages/my-jetpack/changelog/update-move-jetpack-notices-to-bottom-left create mode 100644 projects/packages/newsletter/changelog/update-move-jetpack-notices-to-bottom-left create mode 100644 projects/packages/publicize/changelog/update-move-jetpack-notices-to-bottom-left create mode 100644 projects/packages/scan/changelog/update-move-jetpack-notices-to-bottom-left delete mode 100644 projects/packages/scan/src/js/notices-list.tsx create mode 100644 projects/packages/seo/changelog/update-move-jetpack-notices-to-bottom-left create mode 100644 projects/packages/videopress/changelog/update-move-jetpack-notices-to-bottom-left create mode 100644 projects/plugins/jetpack/changelog/update-move-jetpack-notices-to-bottom-left create mode 100644 projects/plugins/social/changelog/update-move-jetpack-notices-to-bottom-left create mode 100644 projects/plugins/videopress/changelog/update-move-jetpack-notices-to-bottom-left diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a4429bee7781..fc13d9317e64 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -568,9 +568,6 @@ importers: '@wordpress/icons': specifier: 16.0.0 version: 16.0.0(@types/react-dom@18.3.7(@types/react@18.3.31))(@types/react@18.3.31)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) - '@wordpress/notices': - specifier: 5.55.0 - version: 5.55.0(@types/react-dom@18.3.7(@types/react@18.3.31))(@types/react@18.3.31)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) '@wordpress/theme': specifier: 2.1.0 version: 2.1.0(@types/react-dom@18.3.7(@types/react@18.3.31))(@types/react@18.3.31)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) @@ -3443,6 +3440,9 @@ importers: '@wordpress/icons': specifier: 16.0.0 version: 16.0.0(@types/react@18.3.31)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) + '@wordpress/notices': + specifier: 5.55.0 + version: 5.55.0(@types/react@18.3.31)(postcss@8.5.23)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) '@wordpress/route': specifier: 0.21.0 version: 0.21.0(react-dom@18.3.1(react@18.3.1))(react@18.3.1) diff --git a/projects/js-packages/components/changelog/update-move-jetpack-notices-to-bottom-left b/projects/js-packages/components/changelog/update-move-jetpack-notices-to-bottom-left new file mode 100644 index 000000000000..9d90ac5b25e4 --- /dev/null +++ b/projects/js-packages/components/changelog/update-move-jetpack-notices-to-bottom-left @@ -0,0 +1,4 @@ +Significance: patch +Type: removed + +Remove GlobalNotices and useGlobalNotices in favor of core SnackbarNotices. diff --git a/projects/js-packages/components/components/global-notices/global-notices.tsx b/projects/js-packages/components/components/global-notices/global-notices.tsx deleted file mode 100644 index b439f99fbae2..000000000000 --- a/projects/js-packages/components/components/global-notices/global-notices.tsx +++ /dev/null @@ -1,31 +0,0 @@ -import { SnackbarList } from '@wordpress/components'; -import styles from './styles.module.scss'; -import { useGlobalNotices } from './use-global-notices.ts'; - -export type GlobalNoticesProps = { - maxVisibleNotices?: number; -}; - -/** - * Renders the global notices. - * - * @param {GlobalNoticesProps} props - Component props. - * - * @return {import('react').ReactNode} The rendered notices list. - */ -export function GlobalNotices( { maxVisibleNotices = 3 }: GlobalNoticesProps ) { - const { getNotices, removeNotice } = useGlobalNotices(); - - const snackbarNotices = getNotices() - .filter( ( { type } ) => type === 'snackbar' ) - // Slices from the tail end of the list. - .slice( -maxVisibleNotices ); - - return ( - - ); -} diff --git a/projects/js-packages/components/components/global-notices/index.ts b/projects/js-packages/components/components/global-notices/index.ts deleted file mode 100644 index 889eca40706d..000000000000 --- a/projects/js-packages/components/components/global-notices/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -export * from './global-notices.tsx'; -export * from './use-global-notices.ts'; -export { store as globalNoticesStore } from '@wordpress/notices'; diff --git a/projects/js-packages/components/components/global-notices/stories/index.stories.tsx b/projects/js-packages/components/components/global-notices/stories/index.stories.tsx deleted file mode 100644 index 811fcf694f14..000000000000 --- a/projects/js-packages/components/components/global-notices/stories/index.stories.tsx +++ /dev/null @@ -1,55 +0,0 @@ -import { useCallback } from 'react'; -import Button from '../../button/index.tsx'; -import { GlobalNotices, useGlobalNotices } from '../index.ts'; -import type { Meta } from '@storybook/react'; - -const meta: Meta< typeof GlobalNotices > = { - title: 'JS Packages/Components/GlobalNotices', - component: GlobalNotices, - decorators: [ story =>
{ story() }
], -}; - -export default meta; - -const Template = args => { - const { createErrorNotice, createSuccessNotice, createInfoNotice, createWarningNotice } = - useGlobalNotices(); - - return ( -
- -
- - - - -
-
- ); -}; - -export const _Default = Template.bind( {} ); diff --git a/projects/js-packages/components/components/global-notices/styles.module.scss b/projects/js-packages/components/components/global-notices/styles.module.scss deleted file mode 100644 index d16357fe9b3f..000000000000 --- a/projects/js-packages/components/components/global-notices/styles.module.scss +++ /dev/null @@ -1,24 +0,0 @@ -@use "@automattic/jetpack-base-styles/gutenberg-base-styles" as gb; - -.global-notices { - - &:global(.components-snackbar-list) { - position: fixed; - inset-block-start: auto; // top - inset-block-end: 0; // bottom - inset-inline: 0; // left and right - // Modals have 100000, so this needs to be above them - z-index: 100001; - - @include gb.break-small { - width: auto; - inset-inline: unset; // left and right - inset-block-start: 4rem; - inset-inline-end: 1rem; - } - - @include gb.break-medium { - inset-block-start: 3rem; - } - } -} diff --git a/projects/js-packages/components/components/global-notices/use-global-notices.ts b/projects/js-packages/components/components/global-notices/use-global-notices.ts deleted file mode 100644 index 4f924117bec0..000000000000 --- a/projects/js-packages/components/components/global-notices/use-global-notices.ts +++ /dev/null @@ -1,37 +0,0 @@ -import { useDispatch, useSelect } from '@wordpress/data'; -import { store as noticesStore } from '@wordpress/notices'; - -type NoticesStore = ReturnType< ( typeof noticesStore )[ 'instantiate' ] >; - -export type TGlobalNotices = ReturnType< NoticesStore[ 'getActions' ] > & - ReturnType< NoticesStore[ 'getSelectors' ] >; - -/** - * The global notices hook. - * - * @return {TGlobalNotices} The global notices selectors and actions. - */ -export function useGlobalNotices(): TGlobalNotices { - const actionCreators = useDispatch( noticesStore ); - const notices = useSelect( select => select( noticesStore ).getNotices(), [] ); - - return { - ...actionCreators, - createNotice( status, content, options ) { - return actionCreators.createNotice( status, content, { type: 'snackbar', ...options } ); - }, - createErrorNotice( content, options ) { - return actionCreators.createErrorNotice( content, { type: 'snackbar', ...options } ); - }, - createInfoNotice( content, options ) { - return actionCreators.createInfoNotice( content, { type: 'snackbar', ...options } ); - }, - createSuccessNotice( content, options ) { - return actionCreators.createSuccessNotice( content, { type: 'snackbar', ...options } ); - }, - createWarningNotice( content, options ) { - return actionCreators.createWarningNotice( content, { type: 'snackbar', ...options } ); - }, - getNotices: () => notices, - }; -} diff --git a/projects/js-packages/components/index.ts b/projects/js-packages/components/index.ts index 69633d5ded0f..e9bd3ef06c2d 100644 --- a/projects/js-packages/components/index.ts +++ b/projects/js-packages/components/index.ts @@ -69,5 +69,4 @@ export { default as StatCard } from './components/stat-card/index.tsx'; export { default as DiffViewer } from './components/diff-viewer/index.tsx'; export { default as MarkedLines } from './components/marked-lines/index.tsx'; export { default as DetailsViewer } from './components/details-viewer/index.tsx'; -export * from './components/global-notices/index.ts'; export * from './components/navigator-modal/index.tsx'; diff --git a/projects/js-packages/components/package.json b/projects/js-packages/components/package.json index bab1d637d94e..dfb7eecc786d 100644 --- a/projects/js-packages/components/package.json +++ b/projects/js-packages/components/package.json @@ -33,11 +33,6 @@ "types": "./build/components/button/index.d.ts", "default": "./build/components/button/index.js" }, - "./global-notices": { - "jetpack:src": "./components/global-notices/index.ts", - "types": "./build/components/global-notices/index.d.ts", - "default": "./build/components/global-notices/index.js" - }, "./gravatar": { "jetpack:src": "./components/gravatar/index.tsx", "types": "./build/components/gravatar/index.d.ts", @@ -104,7 +99,6 @@ "@wordpress/element": "8.7.0", "@wordpress/i18n": "6.28.0", "@wordpress/icons": "16.0.0", - "@wordpress/notices": "5.55.0", "@wordpress/theme": "2.1.0", "@wordpress/ui": "0.22.0", "clsx": "2.1.1", diff --git a/projects/packages/my-jetpack/_inc/components/module-toggle/index.tsx b/projects/packages/my-jetpack/_inc/components/module-toggle/index.tsx index d28ca131aa63..edc7db0f633f 100644 --- a/projects/packages/my-jetpack/_inc/components/module-toggle/index.tsx +++ b/projects/packages/my-jetpack/_inc/components/module-toggle/index.tsx @@ -1,8 +1,8 @@ -import { useGlobalNotices } from '@automattic/jetpack-components'; import { store as modulesStore } from '@automattic/jetpack-shared-stores'; import { FormToggle } from '@wordpress/components'; import { useDispatch, useSelect } from '@wordpress/data'; import { __, sprintf } from '@wordpress/i18n'; +import { store as noticesStore } from '@wordpress/notices'; import { useCallback } from 'react'; import { requestModuleSwitch } from '../../data/module-switch'; import { moduleSwitchKey, useRequestedSwitch } from '../../data/requested-switch-state'; @@ -46,7 +46,7 @@ export function useModuleActivation( { reload = true }: { reload?: boolean } = {} ) { const { updateJetpackModuleStatus: toggleModule } = useDispatch( modulesStore ); - const { createSuccessNotice, createErrorNotice } = useGlobalNotices(); + const { createSuccessNotice, createErrorNotice } = useDispatch( noticesStore ); const { trackProductAction } = useProductFiltersContext() || {}; const storeIsUpdating = useSelect( @@ -80,8 +80,8 @@ export function useModuleActivation( /* translators: %s is the module name */ __( '%s has been deactivated.', 'jetpack-my-jetpack' ), $module.name - ); - createSuccessNotice( message ); + ); + createSuccessNotice( message, { type: 'snackbar' } ); } else { const message = action === 'activation' @@ -96,7 +96,7 @@ export function useModuleActivation( $module.name ); - createErrorNotice( message ); + createErrorNotice( message, { type: 'snackbar' } ); } }, [ $module.module, $module.name, createErrorNotice, createSuccessNotice ] diff --git a/projects/packages/my-jetpack/_inc/components/module-toggle/test/index.test.tsx b/projects/packages/my-jetpack/_inc/components/module-toggle/test/index.test.tsx index 1735f99348c7..85eb6f578f04 100644 --- a/projects/packages/my-jetpack/_inc/components/module-toggle/test/index.test.tsx +++ b/projects/packages/my-jetpack/_inc/components/module-toggle/test/index.test.tsx @@ -14,7 +14,11 @@ const mockCreateErrorNotice = jest.fn(); jest.mock( '@automattic/jetpack-shared-stores', () => ( { store: {} } ) ); jest.mock( '@wordpress/data', () => ( { - useDispatch: () => ( { updateJetpackModuleStatus: mockToggleModule } ), + useDispatch: () => ( { + updateJetpackModuleStatus: mockToggleModule, + createSuccessNotice: mockCreateSuccessNotice, + createErrorNotice: mockCreateErrorNotice, + } ), useSelect: callback => callback( () => ( { isModuleUpdating: () => false } ) ), } ) ); @@ -57,13 +61,6 @@ jest.mock( '@wordpress/ui', () => { }; } ); -jest.mock( '@automattic/jetpack-components', () => ( { - useGlobalNotices: () => ( { - createSuccessNotice: mockCreateSuccessNotice, - createErrorNotice: mockCreateErrorNotice, - } ), -} ) ); - jest.mock( '../../my-jetpack-tab-panel/products/products-tracking-context', () => ( { useProductFiltersContext: () => ( { trackProductAction: mockTrackProductAction } ), } ) ); diff --git a/projects/packages/my-jetpack/_inc/components/my-jetpack-tab-panel/products/pending-notice.ts b/projects/packages/my-jetpack/_inc/components/my-jetpack-tab-panel/products/pending-notice.ts index 853d43522f0f..077270f41c25 100644 --- a/projects/packages/my-jetpack/_inc/components/my-jetpack-tab-panel/products/pending-notice.ts +++ b/projects/packages/my-jetpack/_inc/components/my-jetpack-tab-panel/products/pending-notice.ts @@ -1,4 +1,5 @@ -import { useGlobalNotices } from '@automattic/jetpack-components'; +import { useDispatch } from '@wordpress/data'; +import { store as noticesStore } from '@wordpress/notices'; import { useEffect } from 'react'; /** @@ -46,7 +47,7 @@ export function consumePendingSuccessNotice(): string | null { * On mount, replays any success notice persisted before a page reload. */ export function useReplayPendingNotice(): void { - const { createSuccessNotice } = useGlobalNotices(); + const { createSuccessNotice } = useDispatch( noticesStore ); // Consume the stored notice exactly once on mount. It must not re-run on later // re-renders (e.g. a product refetch), or it would consume the notice on the page @@ -54,7 +55,7 @@ export function useReplayPendingNotice(): void { useEffect( () => { const message = consumePendingSuccessNotice(); if ( message ) { - createSuccessNotice( message ); + createSuccessNotice( message, { type: 'snackbar' } ); } // eslint-disable-next-line react-hooks/exhaustive-deps -- run once on mount. }, [] ); diff --git a/projects/packages/my-jetpack/_inc/components/my-jetpack-tab-panel/products/test/pending-notice.test.tsx b/projects/packages/my-jetpack/_inc/components/my-jetpack-tab-panel/products/test/pending-notice.test.tsx index 42ec3566c032..12ec2abebb9d 100644 --- a/projects/packages/my-jetpack/_inc/components/my-jetpack-tab-panel/products/test/pending-notice.test.tsx +++ b/projects/packages/my-jetpack/_inc/components/my-jetpack-tab-panel/products/test/pending-notice.test.tsx @@ -6,8 +6,8 @@ import { } from '../pending-notice'; const mockCreateSuccessNotice = jest.fn(); -jest.mock( '@automattic/jetpack-components', () => ( { - useGlobalNotices: () => ( { createSuccessNotice: mockCreateSuccessNotice } ), +jest.mock( '@wordpress/data', () => ( { + useDispatch: () => ( { createSuccessNotice: mockCreateSuccessNotice } ), } ) ); describe( 'pending-notice', () => { @@ -33,7 +33,9 @@ describe( 'pending-notice', () => { renderHook( () => useReplayPendingNotice() ); - expect( mockCreateSuccessNotice ).toHaveBeenCalledWith( 'Forms activated successfully!' ); + expect( mockCreateSuccessNotice ).toHaveBeenCalledWith( 'Forms activated successfully!', { + type: 'snackbar', + } ); } ); it( 'shows no notice when none is pending', () => { diff --git a/projects/packages/my-jetpack/_inc/data/products/use-activate-plugins.ts b/projects/packages/my-jetpack/_inc/data/products/use-activate-plugins.ts index 4b46f39cbcd4..ea733cdc8ca0 100644 --- a/projects/packages/my-jetpack/_inc/data/products/use-activate-plugins.ts +++ b/projects/packages/my-jetpack/_inc/data/products/use-activate-plugins.ts @@ -1,5 +1,6 @@ -import { useGlobalNotices } from '@automattic/jetpack-components'; +import { useDispatch } from '@wordpress/data'; import { __, sprintf } from '@wordpress/i18n'; +import { store as noticesStore } from '@wordpress/notices'; import useAnalytics from '../../hooks/use-analytics'; import { REST_API_SITE_PRODUCTS_ENDPOINT, QUERY_ACTIVATE_PRODUCT_KEY } from '../constants'; import useSimpleMutation from '../use-simple-mutation'; @@ -37,7 +38,7 @@ const useActivatePlugins = ( productSlugs: string | string[] ) => { const { products, refetch } = useProducts( productIds ); const { recordEvent } = useAnalytics(); - const { createSuccessNotice } = useGlobalNotices(); + const { createSuccessNotice } = useDispatch( noticesStore ); const { mutate: activate, @@ -70,7 +71,8 @@ const useActivatePlugins = ( productSlugs: string | string[] ) => { /* translators: %s is either the product name, i.e.- "Jetpack Backup" or the word "Plugins". */ __( '%s activated successfully!', 'jetpack-my-jetpack' ), products?.length === 1 ? products[ 0 ].title : __( 'Plugins', 'jetpack-my-jetpack' ) - ) + ), + { type: 'snackbar' } ); } ); }, diff --git a/projects/packages/my-jetpack/_inc/data/products/use-deactivate-plugins.ts b/projects/packages/my-jetpack/_inc/data/products/use-deactivate-plugins.ts index 6ace4d61c788..dc987d3a80a5 100644 --- a/projects/packages/my-jetpack/_inc/data/products/use-deactivate-plugins.ts +++ b/projects/packages/my-jetpack/_inc/data/products/use-deactivate-plugins.ts @@ -1,5 +1,6 @@ -import { useGlobalNotices } from '@automattic/jetpack-components'; +import { useDispatch } from '@wordpress/data'; import { __, sprintf } from '@wordpress/i18n'; +import { store as noticesStore } from '@wordpress/notices'; import useAnalytics from '../../hooks/use-analytics'; import { QUERY_ACTIVATE_PRODUCT_KEY, REST_API_SITE_PRODUCTS_ENDPOINT } from '../constants'; import useSimpleMutation from '../use-simple-mutation'; @@ -35,7 +36,7 @@ export const useDeactivatePlugins = ( productSlugs: string | string[] ) => { const { products, refetch } = useProducts( productIds ); const { recordEvent } = useAnalytics(); - const { createSuccessNotice } = useGlobalNotices(); + const { createSuccessNotice } = useDispatch( noticesStore ); const { mutate: deactivate, @@ -68,7 +69,8 @@ export const useDeactivatePlugins = ( productSlugs: string | string[] ) => { /* translators: %s is either the product name, i.e.- "Jetpack Backup" or the word "Plugins". */ __( '%s deactivated successfully!', 'jetpack-my-jetpack' ), products?.length === 1 ? products[ 0 ].title : __( 'Plugins', 'jetpack-my-jetpack' ) - ) + ), + { type: 'snackbar' } ); } ); }, diff --git a/projects/packages/my-jetpack/changelog/update-move-jetpack-notices-to-bottom-left b/projects/packages/my-jetpack/changelog/update-move-jetpack-notices-to-bottom-left new file mode 100644 index 000000000000..ad0f901073c0 --- /dev/null +++ b/projects/packages/my-jetpack/changelog/update-move-jetpack-notices-to-bottom-left @@ -0,0 +1,4 @@ +Significance: patch +Type: changed + +Use core SnackbarNotices instead of Jetpack GlobalNotices. diff --git a/projects/packages/my-jetpack/package.json b/projects/packages/my-jetpack/package.json index 6d4e13695023..ef22b9374aeb 100644 --- a/projects/packages/my-jetpack/package.json +++ b/projects/packages/my-jetpack/package.json @@ -73,6 +73,7 @@ "@wordpress/element": "8.7.0", "@wordpress/i18n": "6.28.0", "@wordpress/icons": "16.0.0", + "@wordpress/notices": "5.55.0", "@wordpress/route": "0.21.0", "@wordpress/theme": "2.1.0", "@wordpress/ui": "0.22.0", diff --git a/projects/packages/newsletter/changelog/update-move-jetpack-notices-to-bottom-left b/projects/packages/newsletter/changelog/update-move-jetpack-notices-to-bottom-left new file mode 100644 index 000000000000..ad0f901073c0 --- /dev/null +++ b/projects/packages/newsletter/changelog/update-move-jetpack-notices-to-bottom-left @@ -0,0 +1,4 @@ +Significance: patch +Type: changed + +Use core SnackbarNotices instead of Jetpack GlobalNotices. diff --git a/projects/packages/newsletter/src/settings/index.tsx b/projects/packages/newsletter/src/settings/index.tsx index de0a674cceb8..3c29496f5dcf 100644 --- a/projects/packages/newsletter/src/settings/index.tsx +++ b/projects/packages/newsletter/src/settings/index.tsx @@ -1,11 +1,12 @@ /** * External dependencies */ -import { AdminPage, Col, Container, GlobalNotices } from '@automattic/jetpack-components'; +import { AdminPage, Col, Container } from '@automattic/jetpack-components'; import { useConnection, getUserConnectionUrl } from '@automattic/jetpack-connection'; import { getSiteData, isSimpleSite } from '@automattic/jetpack-script-data'; import { createRoot, useMemo } from '@wordpress/element'; import { __ } from '@wordpress/i18n'; +import { SnackbarNotices } from '@wordpress/notices'; /** * Internal dependencies */ @@ -15,7 +16,7 @@ import './style.scss'; /** * Newsletter Settings App — legacy `wp-admin/admin.php?page=jetpack-newsletter` * surface. The shared body lives in `./newsletter-settings`; this file owns - * the standalone chrome (Jetpack-styled `AdminPage`, container grid, global + * the standalone chrome (Jetpack-styled `AdminPage`, container grid, core * snackbar surface) and the WP.com connection check. * * The modernized dashboard mounts `NewsletterSettingsBody` directly inside @@ -52,7 +53,7 @@ export function NewsletterSettingsApp(): JSX.Element { apiRoot={ siteData?.rest_root } apiNonce={ siteData?.rest_nonce } > - +
diff --git a/projects/packages/newsletter/src/settings/newsletter-settings.tsx b/projects/packages/newsletter/src/settings/newsletter-settings.tsx index 919b7d33a28f..34ba560b19ae 100644 --- a/projects/packages/newsletter/src/settings/newsletter-settings.tsx +++ b/projects/packages/newsletter/src/settings/newsletter-settings.tsx @@ -128,8 +128,8 @@ export type NewsletterSettingsBodyProps = { * byte-for-byte identical. * * Snackbar dispatch goes straight to `@wordpress/notices`'s - * `noticesStore` — the wp-build polyfills already render a `SnackbarList` - * for us, and the legacy app wraps the body with its own `` + * `noticesStore` — the wp-build polyfills already render `SnackbarNotices` + * for us, and the legacy app mounts its own `` * surface, so both paths see the same snackbars without a shared rendering * primitive. * @@ -188,9 +188,8 @@ export function NewsletterSettingsBody( { // Get newsletter script data. const newsletterScriptData = useMemo( () => getNewsletterScriptData(), [] ); - // Snackbar notices via core data — `type: 'snackbar'` matches what the - // legacy `useGlobalNotices` defaulted to, so both legacy and modernized - // surfaces render the same snackbars. + // Snackbar notices via core data — `type: 'snackbar'` is required so + // both legacy and modernized surfaces render them in SnackbarNotices. const { createNotice } = useDispatch( noticesStore ); const createSuccessNotice = useCallback( ( content: string ) => createNotice( 'success', content, { type: 'snackbar' } ), diff --git a/projects/packages/newsletter/src/settings/style.scss b/projects/packages/newsletter/src/settings/style.scss index 4c86b0869e46..f905e753e141 100644 --- a/projects/packages/newsletter/src/settings/style.scss +++ b/projects/packages/newsletter/src/settings/style.scss @@ -1,4 +1,5 @@ @use "@automattic/jetpack-base-styles/admin-page-layout" as *; +@use "@automattic/jetpack-base-styles/gutenberg-base-styles" as gb; @use "sass:meta"; // This stylesheet feeds two bundles: the wp-build dashboard @@ -115,3 +116,9 @@ body.jetpack_page_jetpack-newsletter { } } } + +// Core snackbar placement (matches `@wordpress/boot`'s snackbar-container). +.jetpack-newsletter-snackbar-notices { + + @include gb.snackbar-container(); +} diff --git a/projects/packages/newsletter/tests/settings.test.jsx b/projects/packages/newsletter/tests/settings.test.jsx index 2f7e5941059f..de6991fafcd7 100644 --- a/projects/packages/newsletter/tests/settings.test.jsx +++ b/projects/packages/newsletter/tests/settings.test.jsx @@ -41,17 +41,13 @@ jest.mock( '@wordpress/components', () => ( { jest.mock( '@wordpress/notices', () => ( { store: {}, + SnackbarNotices: () => null, } ) ); jest.mock( '@automattic/jetpack-components', () => ( { AdminPage: ( { children } ) =>
{ children }
, Col: ( { children } ) =>
{ children }
, Container: ( { children } ) =>
{ children }
, - GlobalNotices: () => null, - useGlobalNotices: () => ( { - createSuccessNotice: jest.fn(), - createErrorNotice: jest.fn(), - } ), } ) ); // Capture the parent's wired props for `SubscribeModalSection` so the diff --git a/projects/packages/publicize/_inc/components/connection-management/reconnect.tsx b/projects/packages/publicize/_inc/components/connection-management/reconnect.tsx index 73fb2cb9cfff..5146b9026f89 100644 --- a/projects/packages/publicize/_inc/components/connection-management/reconnect.tsx +++ b/projects/packages/publicize/_inc/components/connection-management/reconnect.tsx @@ -1,7 +1,7 @@ -import { useGlobalNotices } from '@automattic/jetpack-components'; import { useDispatch, useSelect } from '@wordpress/data'; import { useCallback, useEffect, useState } from '@wordpress/element'; import { __, _x } from '@wordpress/i18n'; +import { store as noticesStore } from '@wordpress/notices'; import { Link } from '@wordpress/ui'; import { store as socialStore } from '../../social-store'; import { Connection } from '../../social-store/types'; @@ -29,7 +29,7 @@ export function Reconnect( { connection, service }: ReconnectProps ) { completeReconnect, } = useDispatch( socialStore ); - const { createErrorNotice } = useGlobalNotices(); + const { createErrorNotice } = useDispatch( noticesStore ); const { canManageConnection, isReconnectingThis } = useSelect( select => { @@ -71,7 +71,8 @@ export function Reconnect( { connection, service }: ReconnectProps ) { __( 'The reconnection could not be completed. Please try again.', 'jetpack-publicize-pkg' - ) + ), + { type: 'snackbar' } ); return; } diff --git a/projects/packages/publicize/_inc/components/manage-connections-modal/confirmation-form/index.tsx b/projects/packages/publicize/_inc/components/manage-connections-modal/confirmation-form/index.tsx index af0beb19d589..f351d50203af 100644 --- a/projects/packages/publicize/_inc/components/manage-connections-modal/confirmation-form/index.tsx +++ b/projects/packages/publicize/_inc/components/manage-connections-modal/confirmation-form/index.tsx @@ -1,8 +1,9 @@ -import { getRedirectUrl, useGlobalNotices } from '@automattic/jetpack-components'; +import { getRedirectUrl } from '@automattic/jetpack-components'; import { CheckboxControl, Notice, Button } from '@wordpress/components'; import { useDispatch, useSelect } from '@wordpress/data'; import { useCallback, useMemo } from '@wordpress/element'; import { __, _x } from '@wordpress/i18n'; +import { store as noticesStore } from '@wordpress/notices'; import { Link } from '@wordpress/ui'; import { store as socialStore } from '../../../social-store'; import { KeyringResult } from '../../../social-store/types'; @@ -107,7 +108,7 @@ export function ConfirmationForm( { }; }, [] ); - const { createErrorNotice } = useGlobalNotices(); + const { createErrorNotice } = useDispatch( noticesStore ); const service = supportedServices.find( supportedService => supportedService.id === keyringResult.service @@ -178,7 +179,9 @@ export function ConfirmationForm( { const external_user_ID = formData.get( 'external_user_ID' ); if ( ! external_user_ID ) { - createErrorNotice( __( 'Please select an account to connect.', 'jetpack-publicize-pkg' ) ); + createErrorNotice( __( 'Please select an account to connect.', 'jetpack-publicize-pkg' ), { + type: 'snackbar', + } ); return; } diff --git a/projects/packages/publicize/_inc/components/services/use-request-access.ts b/projects/packages/publicize/_inc/components/services/use-request-access.ts index b6721f968562..a9252429f081 100644 --- a/projects/packages/publicize/_inc/components/services/use-request-access.ts +++ b/projects/packages/publicize/_inc/components/services/use-request-access.ts @@ -1,8 +1,8 @@ -import { useGlobalNotices } from '@automattic/jetpack-components'; import { getAdminUrl } from '@automattic/jetpack-script-data'; import { useDispatch, useSelect } from '@wordpress/data'; import { useCallback } from '@wordpress/element'; import { __ } from '@wordpress/i18n'; +import { store as noticesStore } from '@wordpress/notices'; import { store } from '../../social-store'; import { requestExternalAccess } from '../../utils'; import { SupportedService } from './types'; @@ -40,7 +40,7 @@ export type RequestAccessArgs = { * @return - Function to request access */ export function useRequestAccess( { service, onConfirm }: RequestAccessOptions ) { - const { createErrorNotice } = useGlobalNotices(); + const { createErrorNotice } = useDispatch( noticesStore ); const validateInputs = useConnectInputValidation(); @@ -51,7 +51,9 @@ export function useRequestAccess( { service, onConfirm }: RequestAccessOptions ) return useCallback( // Resolves to true when the connect popup opened, false on any early failure. async ( formData: FormData, options: RequestAccessArgs = {} ): Promise< boolean > => { - const reportError = options.onError ?? createErrorNotice; + const reportError = + options.onError ?? + ( ( message: string ) => createErrorNotice( message, { type: 'snackbar' } ) ); let connectUrl = service.url; diff --git a/projects/packages/publicize/_inc/social-store/actions/connection-data.ts b/projects/packages/publicize/_inc/social-store/actions/connection-data.ts index ba3d27cdc9f5..96db2f175184 100644 --- a/projects/packages/publicize/_inc/social-store/actions/connection-data.ts +++ b/projects/packages/publicize/_inc/social-store/actions/connection-data.ts @@ -1,8 +1,8 @@ -import { globalNoticesStore } from '@automattic/jetpack-components'; import apiFetch from '@wordpress/api-fetch'; import { dispatch as coreDispatch } from '@wordpress/data'; import { store as editorStore } from '@wordpress/editor'; import { __, sprintf } from '@wordpress/i18n'; +import { store as noticesStore } from '@wordpress/notices'; import { addQueryArgs } from '@wordpress/url'; import { CUSTOMIZE_PER_NETWORK_KEY } from '../constants'; import { Connection, EditorConnection, KeyringResponse, KeyringResult } from '../types'; @@ -103,7 +103,7 @@ export function fetchKeyringResult( requestId: string ) { message = `${ message } ${ error.message }`; } - const { createErrorNotice } = coreDispatch( globalNoticesStore ); + const { createErrorNotice } = coreDispatch( noticesStore ); createErrorNotice( message, { type: 'snackbar', isDismissible: true } ); } finally { @@ -380,7 +380,7 @@ export function deleteConnectionById( { showSuccessNotice?: boolean; } ) { return async function ( { registry, dispatch } ) { - const { createErrorNotice, createSuccessNotice } = coreDispatch( globalNoticesStore ); + const { createErrorNotice, createSuccessNotice } = coreDispatch( noticesStore ); try { const path = `/wpcom/v2/publicize/connections/${ connectionId }`; @@ -438,7 +438,7 @@ export function createConnection( optimisticData: Partial< Connection > = {} ) { return async function ( { registry, dispatch } ) { - const { createErrorNotice, createSuccessNotice } = coreDispatch( globalNoticesStore ); + const { createErrorNotice, createSuccessNotice } = coreDispatch( noticesStore ); const tempId = `new-${ ++uniqueId }`; @@ -585,7 +585,7 @@ export function completeReconnect( keyringResult?: KeyringResult ) { // the connection list reflects the reconnection. dispatch( setReconnectingAccount( undefined ) ); - const { createSuccessNotice, createErrorNotice } = coreDispatch( globalNoticesStore ); + const { createSuccessNotice, createErrorNotice } = coreDispatch( noticesStore ); if ( recovered ) { createSuccessNotice( __( 'Account reconnected successfully.', 'jetpack-publicize-pkg' ), { @@ -618,7 +618,7 @@ export function updateConnectionById( options: UpdateConnectionOptions = {} ) { return async function ( { dispatch, select } ) { - const { createErrorNotice, createSuccessNotice } = coreDispatch( globalNoticesStore ); + const { createErrorNotice, createSuccessNotice } = coreDispatch( noticesStore ); const { silent = false } = options; const prevConnection = select.getConnectionById( connectionId ); diff --git a/projects/packages/publicize/changelog/update-move-jetpack-notices-to-bottom-left b/projects/packages/publicize/changelog/update-move-jetpack-notices-to-bottom-left new file mode 100644 index 000000000000..ad0f901073c0 --- /dev/null +++ b/projects/packages/publicize/changelog/update-move-jetpack-notices-to-bottom-left @@ -0,0 +1,4 @@ +Significance: patch +Type: changed + +Use core SnackbarNotices instead of Jetpack GlobalNotices. diff --git a/projects/packages/scan/changelog/update-move-jetpack-notices-to-bottom-left b/projects/packages/scan/changelog/update-move-jetpack-notices-to-bottom-left new file mode 100644 index 000000000000..cf3d0ab29fd4 --- /dev/null +++ b/projects/packages/scan/changelog/update-move-jetpack-notices-to-bottom-left @@ -0,0 +1,4 @@ +Significance: patch +Type: changed + +Rely on core SnackbarNotices from the wp-build boot layer. diff --git a/projects/packages/scan/routes/index/stage.tsx b/projects/packages/scan/routes/index/stage.tsx index 3b2be20ae392..9449eb9f7318 100644 --- a/projects/packages/scan/routes/index/stage.tsx +++ b/projects/packages/scan/routes/index/stage.tsx @@ -5,7 +5,6 @@ import ScanPage, { type ScanTab } from '../../_inc/components/scan-page'; import Gates from '../../src/js/gates'; import { HeaderActionsProvider } from '../../src/js/header-actions-context'; import MockBanner from '../../src/js/mock-banner'; -import NoticesList from '../../src/js/notices-list'; import ActiveThreats from '../../src/js/screens/overview/active-threats'; import ScanHistory from '../../src/js/screens/overview/scan-history'; import './route.scss'; @@ -54,7 +53,6 @@ function Stage(): JSX.Element { { activeTab === 'history' ? : null } - diff --git a/projects/packages/scan/src/js/notices-list.tsx b/projects/packages/scan/src/js/notices-list.tsx deleted file mode 100644 index 79cfbc8af643..000000000000 --- a/projects/packages/scan/src/js/notices-list.tsx +++ /dev/null @@ -1,34 +0,0 @@ -import { SnackbarList } from '@wordpress/components'; -import { useDispatch, useSelect } from '@wordpress/data'; -import { store as noticesStore } from '@wordpress/notices'; -import type { FC } from 'react'; - -const MAX_VISIBLE_NOTICES = 3; - -/** - * Floating snackbar layer for the Scan overview. Mirrors Forms' - * `DashboardNotices`: subscribes to the core `notices` store and renders - * the trailing 3 snackbars via ``. Anywhere in the page - * can fire a snackbar via `useDispatch( noticesStore ).createSuccessNotice(…)` - * and it'll surface here. - * - * @return The snackbar list, or `null` when there are no snackbars. - */ -const NoticesList: FC = () => { - const notices = useSelect( select => select( noticesStore ).getNotices(), [] ); - const { removeNotice } = useDispatch( noticesStore ); - - const snackbarNotices = notices - .filter( ( { type } ) => type === 'snackbar' ) - .slice( -MAX_VISIBLE_NOTICES ); - - return ( - - ); -}; - -export default NoticesList; diff --git a/projects/packages/seo/_inc/admin-page-layout.scss b/projects/packages/seo/_inc/admin-page-layout.scss index b841fdd46a19..cd987c697e82 100644 --- a/projects/packages/seo/_inc/admin-page-layout.scss +++ b/projects/packages/seo/_inc/admin-page-layout.scss @@ -116,63 +116,3 @@ body.toplevel_page_jetpack-seo { .jetpack-seo-page-content--flush { padding: 0; } - -// Toasts: move the boot layer's snackbars to the top-right, matching the -// rest of Jetpack. - -// Two systems place Jetpack toasts and they disagree. `@wordpress/boot` renders -// one `` per wp-build page -// and pins it bottom-center; `` in -// @automattic/jetpack-components pins top-right, which is what Newsletter, -// My Jetpack and VideoPress show. -// This page is wp-build, so it inherited the odd one out. - -// We restyle boot's list rather than rendering our own. Rendering a second -// `SnackbarList` is what #49470 removed: the store is shared, so both lists -// subscribe and every toast appears twice. - -// The values below intentionally mirror `global-notices/styles.module.scss` so -// the two stay identical — small screens keep the full-width bottom strip -// (nothing is pinned over the content on a narrow viewport), and the top offset -// steps down at 782px where the wp-admin bar shrinks. - -// Scoped to the SEO page's body class, like the layout rules at the top of -// this file. Every other rule here is namespaced by a `jetpack-seo-*` class, -// but this one targets a class we don't own — so without the scope it would -// move the snackbars on any other wp-build screen this stylesheet loaded on. - -// It also settles specificity. Boot injects its rule at runtime as a -// layout-scoped descendant (0,2,0); the body class puts this at (0,3,1), so it -// wins outright rather than depending on load order. Boot's classes come in two -// shapes; see the guard in `@automattic/jetpack-base-styles/admin-page-layout` -// for why. Both selectors below are (0,2,0), so the specificity holds either -// way. -body.jetpack_page_jetpack-seo, -body.toplevel_page_jetpack-seo { - - .boot-layout .boot-notices__snackbar, - [class*="__layout"] [class*="__notices-snackbar"] { - inset-block-start: auto; - inset-block-end: 0; - inset-inline: 0; - - @media (min-width: 600px) { - inset-block-start: 4rem; - inset-block-end: auto; - inset-inline-start: auto; - inset-inline-end: 1rem; - inline-size: auto; - - // Boot centers each snackbar in a full-width container - // (`margin-inline: auto`). The container is no longer full width, so - // that would now center them against the right edge, not align to it. - .components-snackbar { - margin-inline: 0; - } - } - - @media (min-width: 782px) { - inset-block-start: 3rem; - } - } -} diff --git a/projects/packages/seo/changelog/update-move-jetpack-notices-to-bottom-left b/projects/packages/seo/changelog/update-move-jetpack-notices-to-bottom-left new file mode 100644 index 000000000000..dae0f0edf473 --- /dev/null +++ b/projects/packages/seo/changelog/update-move-jetpack-notices-to-bottom-left @@ -0,0 +1,4 @@ +Significance: patch +Type: changed + +Use core snackbar notice placement instead of overriding boot styles. diff --git a/projects/packages/videopress/changelog/update-move-jetpack-notices-to-bottom-left b/projects/packages/videopress/changelog/update-move-jetpack-notices-to-bottom-left new file mode 100644 index 000000000000..ad0f901073c0 --- /dev/null +++ b/projects/packages/videopress/changelog/update-move-jetpack-notices-to-bottom-left @@ -0,0 +1,4 @@ +Significance: patch +Type: changed + +Use core SnackbarNotices instead of Jetpack GlobalNotices. diff --git a/projects/packages/videopress/routes/library/package.json b/projects/packages/videopress/routes/library/package.json index d3d8639737a8..0171d091e5aa 100644 --- a/projects/packages/videopress/routes/library/package.json +++ b/projects/packages/videopress/routes/library/package.json @@ -8,9 +8,11 @@ "@types/react": "18.3.31", "@wordpress/api-fetch": "7.55.0", "@wordpress/components": "40.1.0", + "@wordpress/data": "10.55.0", "@wordpress/dataviews": "19.0.0", "@wordpress/element": "8.7.0", "@wordpress/i18n": "6.28.0", + "@wordpress/notices": "5.55.0", "@wordpress/route": "0.21.0", "@wordpress/ui": "0.22.0" }, diff --git a/projects/packages/videopress/routes/library/promote-local.ts b/projects/packages/videopress/routes/library/promote-local.ts index eabbdaac43de..644d95ad2fb5 100644 --- a/projects/packages/videopress/routes/library/promote-local.ts +++ b/projects/packages/videopress/routes/library/promote-local.ts @@ -12,8 +12,8 @@ export type PromoteLocalDeps = { id: string; onProgress?: ( percent: number ) => void; } ) => Promise< unknown >; - createSuccessNotice: ( content: string ) => void; - createErrorNotice: ( content: string ) => void; + createSuccessNotice: ( content: string, options?: { type?: string } ) => void; + createErrorNotice: ( content: string, options?: { type?: string } ) => void; /** * Receives a fresh snapshot of the in-flight id → upload-percent map * whenever it changes (a promote starting, a chunk progress report, or @@ -65,7 +65,9 @@ export function createPromoteLocal( deps: PromoteLocalDeps ): ( id: string ) => }, } ) .then( () => { - deps.createSuccessNotice( __( 'Video uploaded to VideoPress.', 'jetpack-videopress-pkg' ) ); + deps.createSuccessNotice( __( 'Video uploaded to VideoPress.', 'jetpack-videopress-pkg' ), { + type: 'snackbar', + } ); } ) .catch( ( error: Error ) => { const reason = error?.message?.trim(); @@ -75,8 +77,9 @@ export function createPromoteLocal( deps: PromoteLocalDeps ): ( id: string ) => /* translators: %s: reason returned by the upload endpoint, e.g. "403: Invalid Mime". */ __( 'Failed to upload video to VideoPress: %s', 'jetpack-videopress-pkg' ), reason - ) - : __( 'Failed to upload video to VideoPress.', 'jetpack-videopress-pkg' ) + ) + : __( 'Failed to upload video to VideoPress.', 'jetpack-videopress-pkg' ), + { type: 'snackbar' } ); } ) .finally( () => { diff --git a/projects/packages/videopress/routes/library/stage.tsx b/projects/packages/videopress/routes/library/stage.tsx index d47602de4942..ef279c15cd34 100644 --- a/projects/packages/videopress/routes/library/stage.tsx +++ b/projects/packages/videopress/routes/library/stage.tsx @@ -1,9 +1,10 @@ -import { useGlobalNotices } from '@automattic/jetpack-components/global-notices'; import useConnectionErrorNotice from '@automattic/jetpack-connection/use-connection-error-notice'; import { DropZone, Tooltip } from '@wordpress/components'; +import { useDispatch } from '@wordpress/data'; import { DataViews } from '@wordpress/dataviews'; import { useCallback, useMemo, useRef, useState } from '@wordpress/element'; import { __, _n, sprintf } from '@wordpress/i18n'; +import { store as noticesStore } from '@wordpress/notices'; import { useNavigate } from '@wordpress/route'; import { Button, Card } from '@wordpress/ui'; import CaptionManagerModal from '../../src/client/components/caption-manager-modal/lazy'; @@ -159,7 +160,7 @@ const StageInner = () => { [ navigate ] ); - const { createSuccessNotice, createErrorNotice, createInfoNotice } = useGlobalNotices(); + const { createSuccessNotice, createErrorNotice, createInfoNotice } = useDispatch( noticesStore ); // Shared multi-file entry point for the DropZone, the header "Upload // video" file picker, and (via the same hook) the welcome modal's CTA. @@ -181,12 +182,10 @@ const StageInner = () => { // The factory owns the in-flight progress map (re-entry guard + overlay // snapshots, chunk progress folded in) and reacts via the mutateAsync // promise; see promote-local.ts for why. - // Deliberately created ONCE per stage instance: useGlobalNotices() returns - // fresh wrapper closures every render, so a dep-keyed useMemo would rebuild - // the factory (emptying its in-flight state) on each render — including the - // renders its own publishes trigger. All captured deps are stable: the - // notice wrappers forward to registry-bound dispatchers, mutateAsync is - // referentially stable in TanStack v5, and state setters never change. + // Deliberately created ONCE per stage instance: the in-flight map lives + // in this closure, so a fresh factory would forget mid-promote rows. + // Captured deps are stable (useDispatch notice creators, mutateAsync, + // state setters). const [ promoteLocal ] = useState( () => createPromoteLocal( { promote: uploadFromLibrary, @@ -224,7 +223,7 @@ const StageInner = () => { ), ids.length ), - { id: noticeId, explicitDismiss: true } + { id: noticeId, explicitDismiss: true, type: 'snackbar' } ); // React via the mutateAsync promise, not mutate-level callbacks: // those are dropped if another delete starts while this one is in @@ -247,7 +246,7 @@ const StageInner = () => { ), ids.length ), - { id: noticeId } + { id: noticeId, type: 'snackbar' } ); } catch ( error ) { // Unknown error shape → assume nothing was deleted. @@ -266,7 +265,7 @@ const StageInner = () => { ), failedIds.size ), - { id: noticeId } + { id: noticeId, type: 'snackbar' } ); } setDeletingIds( prev => { @@ -298,7 +297,8 @@ const StageInner = () => { ), succeeded.length, PRIVACY_LABELS[ privacy ] - ) + ), + { type: 'snackbar' } ); return; } @@ -310,7 +310,8 @@ const StageInner = () => { 'Failed to update privacy for the selected videos.', failed.length, 'jetpack-videopress-pkg' - ) + ), + { type: 'snackbar' } ); return; } @@ -324,11 +325,14 @@ const StageInner = () => { ), succeeded.length, failed.length - ) + ), + { type: 'snackbar' } ); } ) .catch( () => { - createErrorNotice( __( 'Failed to update privacy.', 'jetpack-videopress-pkg' ) ); + createErrorNotice( __( 'Failed to update privacy.', 'jetpack-videopress-pkg' ), { + type: 'snackbar', + } ); } ); }, } ), diff --git a/projects/packages/videopress/routes/library/test/promote-local.test.ts b/projects/packages/videopress/routes/library/test/promote-local.test.ts index 4af5f4639e25..e582ea610ca8 100644 --- a/projects/packages/videopress/routes/library/test/promote-local.test.ts +++ b/projects/packages/videopress/routes/library/test/promote-local.test.ts @@ -53,7 +53,9 @@ describe( 'createPromoteLocal', () => { expect( deps.promote ).toHaveBeenCalledWith( expect.objectContaining( { id: '9', onProgress: expect.any( Function ) } ) ); - expect( deps.createSuccessNotice ).toHaveBeenCalledWith( 'Video uploaded to VideoPress.' ); + expect( deps.createSuccessNotice ).toHaveBeenCalledWith( 'Video uploaded to VideoPress.', { + type: 'snackbar', + } ); expect( deps.createErrorNotice ).not.toHaveBeenCalled(); expect( snapshots ).toEqual( [ [ [ '9', 0 ] ], [] ] ); } ); @@ -80,7 +82,8 @@ describe( 'createPromoteLocal', () => { await flush(); expect( deps.createErrorNotice ).toHaveBeenCalledWith( - 'Failed to upload video to VideoPress: 403: Invalid Mime' + 'Failed to upload video to VideoPress: 403: Invalid Mime', + { type: 'snackbar' } ); } ); @@ -90,7 +93,8 @@ describe( 'createPromoteLocal', () => { await flush(); expect( deps.createErrorNotice ).toHaveBeenCalledWith( - 'Failed to upload video to VideoPress.' + 'Failed to upload video to VideoPress.', + { type: 'snackbar' } ); // The overlay still tears down on failure. expect( snapshots ).toEqual( [ [ [ '9', 0 ] ], [] ] ); diff --git a/projects/packages/videopress/routes/library/test/stage.test.tsx b/projects/packages/videopress/routes/library/test/stage.test.tsx index ad86b8b24f4c..46a361b9b456 100644 --- a/projects/packages/videopress/routes/library/test/stage.test.tsx +++ b/projects/packages/videopress/routes/library/test/stage.test.tsx @@ -115,8 +115,23 @@ jest.mock( '../../../src/dashboard/hooks/use-videopress-upgrade', () => ( { jest.mock( '../../../src/dashboard/hooks/use-persisted-view', () => ( { usePersistedView: ( fallback: unknown ) => [ fallback, jest.fn() ], } ) ); -jest.mock( '@automattic/jetpack-components/global-notices', () => ( { - useGlobalNotices: () => ( { +jest.mock( '@automattic/jetpack-connection/use-connection-error-notice', () => ( { + __esModule: true, + default: () => ( { hasConnectionError: false } ), + ConnectionError: () => null, +} ) ); + +jest.mock( '@wordpress/notices', () => ( { store: 'core/notices' } ) ); +jest.mock( '@wordpress/data', () => ( { + combineReducers: jest.fn( reducers => reducers ), + createReduxStore: jest.fn( () => ( { name: 'mock-store' } ) ), + createSelector: jest.fn( selector => selector ), + register: jest.fn(), + select: jest.fn( () => ( {} ) ), + dispatch: jest.fn( () => ( {} ) ), + useSelect: jest.fn( () => ( {} ) ), + useRegistry: jest.fn( () => ( { select: jest.fn(), dispatch: jest.fn() } ) ), + useDispatch: () => ( { createSuccessNotice: jest.fn(), createErrorNotice: jest.fn(), createInfoNotice: jest.fn(), diff --git a/projects/packages/videopress/routes/settings/package.json b/projects/packages/videopress/routes/settings/package.json index d89273c22b1c..639aa57852bc 100644 --- a/projects/packages/videopress/routes/settings/package.json +++ b/projects/packages/videopress/routes/settings/package.json @@ -7,8 +7,10 @@ "@types/react": "18.3.31", "@wordpress/api-fetch": "7.55.0", "@wordpress/components": "40.1.0", + "@wordpress/data": "10.55.0", "@wordpress/element": "8.7.0", "@wordpress/i18n": "6.28.0", + "@wordpress/notices": "5.55.0", "@wordpress/route": "0.21.0", "@wordpress/ui": "0.22.0" }, diff --git a/projects/packages/videopress/routes/settings/stage.tsx b/projects/packages/videopress/routes/settings/stage.tsx index 25b764c78667..c07ccbf4d163 100644 --- a/projects/packages/videopress/routes/settings/stage.tsx +++ b/projects/packages/videopress/routes/settings/stage.tsx @@ -1,7 +1,8 @@ -import { useGlobalNotices } from '@automattic/jetpack-components/global-notices'; import { ToggleControl } from '@wordpress/components'; +import { useDispatch } from '@wordpress/data'; import { useCallback } from '@wordpress/element'; import { __ } from '@wordpress/i18n'; +import { store as noticesStore } from '@wordpress/notices'; import { Card, Stack } from '@wordpress/ui'; import DashboardLayout from '../../src/dashboard/components/dashboard-layout'; import FreeTierNotice, { @@ -20,7 +21,7 @@ import type { SettingsPatch } from '../../src/dashboard/hooks/use-settings'; const SettingsForm = () => { const settings = useSettings(); const update = useUpdateSettings(); - const { createErrorNotice } = useGlobalNotices(); + const { createErrorNotice } = useDispatch( noticesStore ); const privateForSite = settings.data?.videoPressVideosPrivateForSite ?? false; const autoSubtitlesDisabled = settings.data?.videoPressAutoSubtitlesDisabled ?? false; const playerPreloadDisabled = settings.data?.videoPressPlayerPreloadDisabled ?? false; @@ -37,7 +38,8 @@ const SettingsForm = () => { mutate( patch, { onError: () => createErrorNotice( - __( 'Your setting couldn’t be saved. Please try again.', 'jetpack-videopress-pkg' ) + __( 'Your setting couldn’t be saved. Please try again.', 'jetpack-videopress-pkg' ), + { type: 'snackbar' } ), } ), [ mutate, createErrorNotice ] diff --git a/projects/packages/videopress/routes/settings/test/stage.test.tsx b/projects/packages/videopress/routes/settings/test/stage.test.tsx index 0fb7b25bf9d1..66e2b3836f73 100644 --- a/projects/packages/videopress/routes/settings/test/stage.test.tsx +++ b/projects/packages/videopress/routes/settings/test/stage.test.tsx @@ -35,9 +35,29 @@ jest.mock( '@automattic/jetpack-components/admin-page', () => ( { ), } ) ); +jest.mock( '../../../src/dashboard/components/dashboard-layout', () => ( { + __esModule: true, + default: ( { actions, children }: { actions?: ReactNode; children?: ReactNode } ) => ( +
+
{ actions }
+ { children } +
+ ), +} ) ); + const mockErrorNotice = jest.fn(); -jest.mock( '@automattic/jetpack-components/global-notices', () => ( { - useGlobalNotices: () => ( { +jest.mock( '@wordpress/notices', () => ( { store: 'core/notices' } ) ); +jest.mock( '@wordpress/data', () => ( { + combineReducers: jest.fn( reducers => reducers ), + createReduxStore: jest.fn( () => ( { name: 'mock-store' } ) ), + createSelector: jest.fn( selector => selector ), + keyedReducer: jest.fn( ( _key, reducer ) => reducer ), + register: jest.fn(), + select: jest.fn( () => ( {} ) ), + dispatch: jest.fn( () => ( {} ) ), + useSelect: jest.fn( () => ( {} ) ), + useRegistry: jest.fn( () => ( { select: jest.fn(), dispatch: jest.fn() } ) ), + useDispatch: () => ( { createErrorNotice: mockErrorNotice, } ), } ) ); diff --git a/projects/packages/videopress/routes/video-editor/package.json b/projects/packages/videopress/routes/video-editor/package.json index 3380ee9af3f3..1353863c2c39 100644 --- a/projects/packages/videopress/routes/video-editor/package.json +++ b/projects/packages/videopress/routes/video-editor/package.json @@ -8,9 +8,11 @@ "@wordpress/admin-ui": "2.10.0", "@wordpress/api-fetch": "7.55.0", "@wordpress/components": "40.1.0", + "@wordpress/data": "10.55.0", "@wordpress/element": "8.7.0", "@wordpress/i18n": "6.28.0", "@wordpress/icons": "16.0.0", + "@wordpress/notices": "5.55.0", "@wordpress/route": "0.21.0", "@wordpress/ui": "0.22.0", "@wordpress/url": "4.55.0" diff --git a/projects/packages/videopress/routes/video-editor/stage.tsx b/projects/packages/videopress/routes/video-editor/stage.tsx index eaa6b0026de2..28378f48729b 100644 --- a/projects/packages/videopress/routes/video-editor/stage.tsx +++ b/projects/packages/videopress/routes/video-editor/stage.tsx @@ -1,7 +1,8 @@ -import { useGlobalNotices } from '@automattic/jetpack-components/global-notices'; import { Button as IconButton } from '@wordpress/components'; +import { useDispatch } from '@wordpress/data'; import { __, _x } from '@wordpress/i18n'; import { redo as redoIcon, undo as undoIcon } from '@wordpress/icons'; +import { store as noticesStore } from '@wordpress/notices'; import { Link, useNavigate, useParams } from '@wordpress/route'; import { Button, Dialog, Stack, Text } from '@wordpress/ui'; import { useCallback, useEffect, useRef, useState } from 'react'; @@ -271,7 +272,8 @@ type ReadyProps = { */ function EditorReady( { video, onSelectTool }: ReadyProps ): ReactElement { const navigate = useNavigate(); - const { createSuccessNotice, createWarningNotice, createErrorNotice } = useGlobalNotices(); + const { createSuccessNotice, createWarningNotice, createErrorNotice } = + useDispatch( noticesStore ); // The two halves of Save: the description meta POST, then the // fire-and-notice VTT sync (same pair the Details tab saves through). const { mutateAsync: saveVideoMeta, isPending: metaSavePending } = useUpdateVideoMeta(); @@ -455,7 +457,9 @@ function EditorReady( { video, onSelectTool }: ReadyProps ): ReactElement { try { await saveVideoMeta( { id: item.id, patch: { description: nextDescription } } ); } catch { - createErrorNotice( __( 'Failed to save chapters.', 'jetpack-videopress-pkg' ) ); + createErrorNotice( __( 'Failed to save chapters.', 'jetpack-videopress-pkg' ), { + type: 'snackbar', + } ); return; } void syncChapters( item, nextDescription ); @@ -466,14 +470,17 @@ function EditorReady( { video, onSelectTool }: ReadyProps ): ReactElement { // catalog entry for this sentence — there the callee has to differ, // because both branches go through the same `notify`. if ( chaptersValid ) { - createSuccessNotice( __( 'Chapters saved.', 'jetpack-videopress-pkg' ) ); + createSuccessNotice( __( 'Chapters saved.', 'jetpack-videopress-pkg' ), { + type: 'snackbar', + } ); } else { createWarningNotice( _x( 'Chapters saved to the description, but they won’t appear in the player until they meet the requirements.', 'chapters save outcome', 'jetpack-videopress-pkg' - ) + ), + { type: 'snackbar' } ); } }, [ diff --git a/projects/packages/videopress/routes/video-editor/test/stage.test.tsx b/projects/packages/videopress/routes/video-editor/test/stage.test.tsx index bccc2c316ea9..c9c6aac1ff68 100644 --- a/projects/packages/videopress/routes/video-editor/test/stage.test.tsx +++ b/projects/packages/videopress/routes/video-editor/test/stage.test.tsx @@ -68,13 +68,29 @@ jest.mock( '@wordpress/admin-ui', () => ( { Breadcrumbs: () => VideoPress, } ) ); +jest.mock( '@automattic/jetpack-connection/use-connection-error-notice', () => ( { + __esModule: true, + default: () => ( { hasConnectionError: false } ), + ConnectionError: () => null, +} ) ); + // Variables referenced inside jest.mock() factories must be prefixed with // "mock" (case-insensitive) to satisfy Jest's babel-jest hoisting rules. const mockSuccessNotice = jest.fn(); const mockWarningNotice = jest.fn(); const mockErrorNotice = jest.fn(); -jest.mock( '@automattic/jetpack-components/global-notices', () => ( { - useGlobalNotices: () => ( { +jest.mock( '@wordpress/notices', () => ( { store: 'core/notices' } ) ); +jest.mock( '@wordpress/data', () => ( { + combineReducers: jest.fn( reducers => reducers ), + createReduxStore: jest.fn( () => ( { name: 'mock-store' } ) ), + createSelector: jest.fn( selector => selector ), + keyedReducer: jest.fn( ( _key, reducer ) => reducer ), + register: jest.fn(), + select: jest.fn( () => ( {} ) ), + dispatch: jest.fn( () => ( {} ) ), + useSelect: jest.fn( () => ( {} ) ), + useRegistry: jest.fn( () => ( { select: jest.fn(), dispatch: jest.fn() } ) ), + useDispatch: () => ( { createSuccessNotice: mockSuccessNotice, createWarningNotice: mockWarningNotice, createErrorNotice: mockErrorNotice, @@ -551,7 +567,9 @@ describe( 'video-editor stage', () => { await user.click( screen.getByRole( 'button', { name: 'Save' } ) ); - await waitFor( () => expect( mockSuccessNotice ).toHaveBeenCalledWith( 'Chapters saved.' ) ); + await waitFor( () => + expect( mockSuccessNotice ).toHaveBeenCalledWith( 'Chapters saved.', { type: 'snackbar' } ) + ); // A valid set announces success and nothing else. expect( mockWarningNotice ).not.toHaveBeenCalled(); // The POSTed description is exactly the serializer's rewrite of the @@ -597,7 +615,8 @@ describe( 'video-editor stage', () => { // …but the outcome notice must not read as an unqualified success. expect( mockWarningNotice ).toHaveBeenCalledWith( - 'Chapters saved to the description, but they won’t appear in the player until they meet the requirements.' + 'Chapters saved to the description, but they won’t appear in the player until they meet the requirements.', + { type: 'snackbar' } ); expect( mockSuccessNotice ).not.toHaveBeenCalled(); } ); @@ -616,7 +635,9 @@ describe( 'video-editor stage', () => { await user.click( screen.getByRole( 'button', { name: 'Save' } ) ); await waitFor( () => - expect( mockErrorNotice ).toHaveBeenCalledWith( 'Failed to save chapters.' ) + expect( mockErrorNotice ).toHaveBeenCalledWith( 'Failed to save chapters.', { + type: 'snackbar', + } ) ); // The sync must never run over a description that failed to save, // and the session stays dirty for another attempt. diff --git a/projects/packages/videopress/routes/video/package.json b/projects/packages/videopress/routes/video/package.json index d99569c7882f..628f330f3758 100644 --- a/projects/packages/videopress/routes/video/package.json +++ b/projects/packages/videopress/routes/video/package.json @@ -10,10 +10,12 @@ "@wordpress/api-fetch": "7.55.0", "@wordpress/components": "40.1.0", "@wordpress/compose": "8.8.0", + "@wordpress/data": "10.55.0", "@wordpress/date": "5.55.0", "@wordpress/element": "8.7.0", "@wordpress/i18n": "6.28.0", "@wordpress/icons": "16.0.0", + "@wordpress/notices": "5.55.0", "@wordpress/route": "0.21.0", "@wordpress/ui": "0.22.0", "@wordpress/url": "4.55.0" diff --git a/projects/packages/videopress/routes/video/stage.tsx b/projects/packages/videopress/routes/video/stage.tsx index 0b68051d624e..6b45c0493b24 100644 --- a/projects/packages/videopress/routes/video/stage.tsx +++ b/projects/packages/videopress/routes/video/stage.tsx @@ -1,12 +1,13 @@ import AdminPage from '@automattic/jetpack-components/admin-page'; -import { useGlobalNotices } from '@automattic/jetpack-components/global-notices'; import useConnectionErrorNotice, { ConnectionError, } from '@automattic/jetpack-connection/use-connection-error-notice'; import { useQueryClient } from '@tanstack/react-query'; import { Breadcrumbs } from '@wordpress/admin-ui'; +import { useDispatch } from '@wordpress/data'; import { useCallback, useEffect, useRef, useState } from '@wordpress/element'; import { __ } from '@wordpress/i18n'; +import { store as noticesStore } from '@wordpress/notices'; import { Link, useNavigate, useParams } from '@wordpress/route'; import { Stack, Text } from '@wordpress/ui'; import CaptionManagerModal from '../../src/client/components/caption-manager-modal/lazy'; @@ -281,7 +282,7 @@ const StageReady = ( { video }: StageReadyProps ) => { const { mutate: updateMeta, isPending: isSaving } = useUpdateVideoMeta(); const { syncChapters } = useUpdateChapters(); const { mutateAsync: deleteVideo, isPending: isDeleting } = useDeleteVideo(); - const { createSuccessNotice, createErrorNotice, createInfoNotice } = useGlobalNotices(); + const { createSuccessNotice, createErrorNotice, createInfoNotice } = useDispatch( noticesStore ); const [ chaptersOpen, setChaptersOpen ] = useState( false ); const [ captionsOpen, setCaptionsOpen ] = useState( false ); const queryClient = useQueryClient(); @@ -334,12 +335,15 @@ const StageReady = ( { video }: StageReadyProps ) => { if ( values.description !== video.description ) { void syncChapters( video, values.description ); } - createSuccessNotice( __( 'Video details saved.', 'jetpack-videopress-pkg' ) ); + createSuccessNotice( __( 'Video details saved.', 'jetpack-videopress-pkg' ), { + type: 'snackbar', + } ); reset( values ); }, onError: () => { createErrorNotice( - __( 'Failed to save video details.', 'jetpack-videopress-pkg' ) + __( 'Failed to save video details.', 'jetpack-videopress-pkg' ), + { type: 'snackbar' } ); }, } @@ -356,6 +360,7 @@ const StageReady = ( { video }: StageReadyProps ) => { createInfoNotice( __( 'Deleting video…', 'jetpack-videopress-pkg' ), { id: deletingNoticeId( video.id ), explicitDismiss: true, + type: 'snackbar', } ); // Promise chain rather than mutate-level callbacks: those are // dropped when the component unmounts mid-flight, which would @@ -364,6 +369,7 @@ const StageReady = ( { video }: StageReadyProps ) => { .then( () => { createSuccessNotice( __( 'Video deleted.', 'jetpack-videopress-pkg' ), { id: deletingNoticeId( video.id ), + type: 'snackbar', } ); if ( isMountedRef.current ) { navigate( { href: '/' } ); @@ -372,6 +378,7 @@ const StageReady = ( { video }: StageReadyProps ) => { .catch( () => { createErrorNotice( __( 'Failed to delete video.', 'jetpack-videopress-pkg' ), { id: deletingNoticeId( video.id ), + type: 'snackbar', } ); } ); } } diff --git a/projects/packages/videopress/routes/video/test/stage.test.tsx b/projects/packages/videopress/routes/video/test/stage.test.tsx index 721b5b7c24ca..31224e9a693f 100644 --- a/projects/packages/videopress/routes/video/test/stage.test.tsx +++ b/projects/packages/videopress/routes/video/test/stage.test.tsx @@ -74,13 +74,29 @@ jest.mock( '@wordpress/admin-ui', () => ( { }, } ) ); +jest.mock( '@automattic/jetpack-connection/use-connection-error-notice', () => ( { + __esModule: true, + default: () => ( { hasConnectionError: false } ), + ConnectionError: () => null, +} ) ); + // Variables referenced inside jest.mock() factories must be prefixed with // "mock" (case-insensitive) to satisfy Jest's babel-jest hoisting rules. const mockSuccessNotice = jest.fn(); const mockErrorNotice = jest.fn(); const mockInfoNotice = jest.fn(); -jest.mock( '@automattic/jetpack-components/global-notices', () => ( { - useGlobalNotices: () => ( { +jest.mock( '@wordpress/notices', () => ( { store: 'core/notices' } ) ); +jest.mock( '@wordpress/data', () => ( { + combineReducers: jest.fn( reducers => reducers ), + createReduxStore: jest.fn( () => ( { name: 'mock-store' } ) ), + createSelector: jest.fn( selector => selector ), + keyedReducer: jest.fn( ( _key, reducer ) => reducer ), + register: jest.fn(), + select: jest.fn( () => ( {} ) ), + dispatch: jest.fn( () => ( {} ) ), + useSelect: jest.fn( () => ( {} ) ), + useRegistry: jest.fn( () => ( { select: jest.fn(), dispatch: jest.fn() } ) ), + useDispatch: () => ( { createSuccessNotice: mockSuccessNotice, createErrorNotice: mockErrorNotice, createInfoNotice: mockInfoNotice, @@ -360,7 +376,9 @@ describe( 'video stage', () => { expect.objectContaining( { id: '42', guid: GUID } ), `${ DESCRIPTION }!` ); - expect( mockSuccessNotice ).toHaveBeenCalledWith( 'Video details saved.' ); + expect( mockSuccessNotice ).toHaveBeenCalledWith( 'Video details saved.', { + type: 'snackbar', + } ); } ); it( 'skips the chapters sync when only the title changed', async () => { @@ -379,7 +397,9 @@ describe( 'video stage', () => { // The description didn't change, so the VTT is already in sync. expect( mockSyncChapters ).not.toHaveBeenCalled(); - expect( mockSuccessNotice ).toHaveBeenCalledWith( 'Video details saved.' ); + expect( mockSuccessNotice ).toHaveBeenCalledWith( 'Video details saved.', { + type: 'snackbar', + } ); } ); // The crumb is the page's

. It reads the form's live value, so it has @@ -424,7 +444,9 @@ describe( 'video stage', () => { } ); expect( mockSyncChapters ).not.toHaveBeenCalled(); - expect( mockErrorNotice ).toHaveBeenCalledWith( 'Failed to save video details.' ); + expect( mockErrorNotice ).toHaveBeenCalledWith( 'Failed to save video details.', { + type: 'snackbar', + } ); expect( mockSuccessNotice ).not.toHaveBeenCalled(); } ); } ); diff --git a/projects/packages/videopress/src/dashboard/components/upload-dropzone/index.tsx b/projects/packages/videopress/src/dashboard/components/upload-dropzone/index.tsx index 15518add81ba..d4fb48b221ca 100644 --- a/projects/packages/videopress/src/dashboard/components/upload-dropzone/index.tsx +++ b/projects/packages/videopress/src/dashboard/components/upload-dropzone/index.tsx @@ -1,8 +1,9 @@ -import { useGlobalNotices } from '@automattic/jetpack-components/global-notices'; import { Button, Tooltip } from '@wordpress/components'; +import { useDispatch } from '@wordpress/data'; import { useCallback, useRef, useState } from '@wordpress/element'; import { __ } from '@wordpress/i18n'; import { upload } from '@wordpress/icons'; +import { store as noticesStore } from '@wordpress/notices'; import { EmptyState, Text } from '@wordpress/ui'; import { useVideoPressUpgrade } from '../../hooks/use-videopress-upgrade'; import { FREE_TIER_AT_LIMIT_MESSAGE, FREE_TIER_AT_LIMIT_NOTICE_ID } from '../free-tier-notice'; @@ -67,7 +68,7 @@ const UploadDropzone = ( { } ) => { const inputRef = useRef< HTMLInputElement >( null ); const [ dragging, setDragging ] = useState( false ); - const { createErrorNotice } = useGlobalNotices(); + const { createErrorNotice } = useDispatch( noticesStore ); const runUpgrade = useVideoPressUpgrade(); const plural = ( copyVariant ?? ( allowMultiple ? 'multiple' : 'single' ) ) === 'multiple'; const dropzoneClassName = `vp-upload-dropzone${ dragging ? ' is-dragging' : '' }${ @@ -82,6 +83,7 @@ const UploadDropzone = ( { createErrorNotice( FREE_TIER_AT_LIMIT_MESSAGE, { id: FREE_TIER_AT_LIMIT_NOTICE_ID, actions: [ { label: __( 'Upgrade', 'jetpack-videopress-pkg' ), onClick: runUpgrade } ], + type: 'snackbar', } ); }, [ createErrorNotice, runUpgrade ] ); @@ -111,6 +113,7 @@ const UploadDropzone = ( { // someone holding one is simply untrue. createErrorNotice( await describeRefusal( files ), { id: INVALID_FILE_NOTICE_ID, + type: 'snackbar', } ); return; } diff --git a/projects/packages/videopress/src/dashboard/components/upload-dropzone/test/index.test.tsx b/projects/packages/videopress/src/dashboard/components/upload-dropzone/test/index.test.tsx index f15a7ad82e62..1c5efa02ac52 100644 --- a/projects/packages/videopress/src/dashboard/components/upload-dropzone/test/index.test.tsx +++ b/projects/packages/videopress/src/dashboard/components/upload-dropzone/test/index.test.tsx @@ -5,8 +5,18 @@ import UploadDropzone from '../index'; import { selectFilesForPlan } from '../select-files'; const mockCreateErrorNotice = jest.fn(); -jest.mock( '@automattic/jetpack-components/global-notices', () => ( { - useGlobalNotices: () => ( { +jest.mock( '@wordpress/notices', () => ( { store: 'core/notices' } ) ); +jest.mock( '@wordpress/data', () => ( { + combineReducers: jest.fn( reducers => reducers ), + createReduxStore: jest.fn( () => ( { name: 'mock-store' } ) ), + createSelector: jest.fn( selector => selector ), + keyedReducer: jest.fn( ( _key, reducer ) => reducer ), + register: jest.fn(), + select: jest.fn( () => ( {} ) ), + dispatch: jest.fn( () => ( {} ) ), + useSelect: jest.fn( () => ( {} ) ), + useRegistry: jest.fn( () => ( { select: jest.fn(), dispatch: jest.fn() } ) ), + useDispatch: () => ( { createSuccessNotice: jest.fn(), createErrorNotice: ( ...args: unknown[] ) => mockCreateErrorNotice( ...args ), createInfoNotice: jest.fn(), @@ -199,6 +209,7 @@ describe( 'UploadDropzone', () => { await waitFor( () => expect( mockCreateErrorNotice ).toHaveBeenCalledWith( 'Only video files can be uploaded.', { id: 'vp-upload-invalid-file', + type: 'snackbar', } ) ); expect( onFiles ).not.toHaveBeenCalled(); @@ -225,7 +236,7 @@ describe( 'UploadDropzone', () => { await waitFor( () => expect( mockCreateErrorNotice ).toHaveBeenCalledWith( 'WEBM files can’t be uploaded. Convert your video to MP4 or MOV, then try again.', - { id: 'vp-upload-invalid-file' } + { id: 'vp-upload-invalid-file', type: 'snackbar' } ) ); expect( mockCreateErrorNotice ).not.toHaveBeenCalledWith( diff --git a/projects/packages/videopress/src/dashboard/components/video-details/test/thumbnail-card.test.tsx b/projects/packages/videopress/src/dashboard/components/video-details/test/thumbnail-card.test.tsx index 4ba273d58438..65ee6275fe4e 100644 --- a/projects/packages/videopress/src/dashboard/components/video-details/test/thumbnail-card.test.tsx +++ b/projects/packages/videopress/src/dashboard/components/video-details/test/thumbnail-card.test.tsx @@ -42,8 +42,18 @@ jest.mock( '../select-frame-dialog', () => ( { // (case-insensitive) to satisfy Jest's babel-jest hoisting restrictions. const mockSuccessNotice = jest.fn(); const mockErrorNotice = jest.fn(); -jest.mock( '@automattic/jetpack-components/global-notices', () => ( { - useGlobalNotices: () => ( { +jest.mock( '@wordpress/notices', () => ( { store: 'core/notices' } ) ); +jest.mock( '@wordpress/data', () => ( { + combineReducers: jest.fn( reducers => reducers ), + createReduxStore: jest.fn( () => ( { name: 'mock-store' } ) ), + createSelector: jest.fn( selector => selector ), + keyedReducer: jest.fn( ( _key, reducer ) => reducer ), + register: jest.fn(), + select: jest.fn( () => ( {} ) ), + dispatch: jest.fn( () => ( {} ) ), + useSelect: jest.fn( () => ( {} ) ), + useRegistry: jest.fn( () => ( { select: jest.fn(), dispatch: jest.fn() } ) ), + useDispatch: () => ( { createSuccessNotice: mockSuccessNotice, createErrorNotice: mockErrorNotice, } ), diff --git a/projects/packages/videopress/src/dashboard/components/video-details/test/video-info-card.test.tsx b/projects/packages/videopress/src/dashboard/components/video-details/test/video-info-card.test.tsx index 32b4bde0c978..17460ad9d575 100644 --- a/projects/packages/videopress/src/dashboard/components/video-details/test/video-info-card.test.tsx +++ b/projects/packages/videopress/src/dashboard/components/video-details/test/video-info-card.test.tsx @@ -6,8 +6,18 @@ import VideoInfoCard from '../video-info-card'; // (case-insensitive) to satisfy Jest's babel-jest hoisting restrictions. const mockSuccessNotice = jest.fn(); const mockErrorNotice = jest.fn(); -jest.mock( '@automattic/jetpack-components/global-notices', () => ( { - useGlobalNotices: () => ( { +jest.mock( '@wordpress/notices', () => ( { store: 'core/notices' } ) ); +jest.mock( '@wordpress/data', () => ( { + combineReducers: jest.fn( reducers => reducers ), + createReduxStore: jest.fn( () => ( { name: 'mock-store' } ) ), + createSelector: jest.fn( selector => selector ), + keyedReducer: jest.fn( ( _key, reducer ) => reducer ), + register: jest.fn(), + select: jest.fn( () => ( {} ) ), + dispatch: jest.fn( () => ( {} ) ), + useSelect: jest.fn( () => ( {} ) ), + useRegistry: jest.fn( () => ( { select: jest.fn(), dispatch: jest.fn() } ) ), + useDispatch: () => ( { createSuccessNotice: mockSuccessNotice, createErrorNotice: mockErrorNotice, } ), diff --git a/projects/packages/videopress/src/dashboard/components/video-details/video-info-card.tsx b/projects/packages/videopress/src/dashboard/components/video-details/video-info-card.tsx index 0cf6af175b62..a0bf2f3306f3 100644 --- a/projects/packages/videopress/src/dashboard/components/video-details/video-info-card.tsx +++ b/projects/packages/videopress/src/dashboard/components/video-details/video-info-card.tsx @@ -1,8 +1,9 @@ -import { useGlobalNotices } from '@automattic/jetpack-components/global-notices'; import { useCopyToClipboard } from '@wordpress/compose'; +import { useDispatch } from '@wordpress/data'; import { dateI18n, getSettings as getDateSettings } from '@wordpress/date'; import { __, sprintf } from '@wordpress/i18n'; import { copy } from '@wordpress/icons'; +import { store as noticesStore } from '@wordpress/notices'; import { Card, Field, IconButton, InputControl, Stack, Text } from '@wordpress/ui'; import type { LibraryItem } from '../../types/library'; import type { ReactElement } from 'react'; @@ -23,8 +24,8 @@ const linkForVideo = ( video: LibraryItem ): string => { * `@wordpress/compose`'s `useCopyToClipboard` (clipboard.js under the hood) * so it falls back to `document.execCommand('copy')` on non-secure origins — * the native `navigator.clipboard` API is undefined on plain HTTP, which - * the dev environments here run on. Posts a success snackbar via the - * dashboard's GlobalNotices store on every successful copy. + * the dev environments here run on. Posts a success snackbar via core + * notices on every successful copy. * * @param props - Component props. * @param props.text - The string to write to the clipboard on click. @@ -39,14 +40,15 @@ const CopyIconButton = ( { text: string; fieldLabel: string; } ): ReactElement => { - const { createSuccessNotice } = useGlobalNotices(); + const { createSuccessNotice } = useDispatch( noticesStore ); const ref = useCopyToClipboard( text, () => createSuccessNotice( sprintf( /* translators: %s: name of the copied field, e.g. "Link to video". */ __( '%s copied to clipboard.', 'jetpack-videopress-pkg' ), fieldLabel - ) + ), + { type: 'snackbar' } ) ); return ( diff --git a/projects/packages/videopress/src/dashboard/hooks/test/use-update-chapters.test.ts b/projects/packages/videopress/src/dashboard/hooks/test/use-update-chapters.test.ts index 1b41a1f2d77c..df7d2b6c3d44 100644 --- a/projects/packages/videopress/src/dashboard/hooks/test/use-update-chapters.test.ts +++ b/projects/packages/videopress/src/dashboard/hooks/test/use-update-chapters.test.ts @@ -15,8 +15,18 @@ const mockedSyncChaptersCore = syncChaptersCore as jest.Mock; // Variables referenced inside jest.mock() factories must be prefixed with // "mock" (case-insensitive) to satisfy Jest's babel-jest hoisting restrictions. const mockWarningNotice = jest.fn(); -jest.mock( '@automattic/jetpack-components/global-notices', () => ( { - useGlobalNotices: () => ( { +jest.mock( '@wordpress/notices', () => ( { store: 'core/notices' } ) ); +jest.mock( '@wordpress/data', () => ( { + combineReducers: jest.fn( reducers => reducers ), + createReduxStore: jest.fn( () => ( { name: 'mock-store' } ) ), + createSelector: jest.fn( selector => selector ), + keyedReducer: jest.fn( ( _key, reducer ) => reducer ), + register: jest.fn(), + select: jest.fn( () => ( {} ) ), + dispatch: jest.fn( () => ( {} ) ), + useSelect: jest.fn( () => ( {} ) ), + useRegistry: jest.fn( () => ( { select: jest.fn(), dispatch: jest.fn() } ) ), + useDispatch: () => ( { createWarningNotice: mockWarningNotice, } ), } ) ); @@ -51,7 +61,9 @@ describe( 'useUpdateChapters', () => { await expect( result.current.syncChapters( VIDEO, DESCRIPTION ) ).resolves.toBe( 'error' ); - expect( mockWarningNotice ).toHaveBeenCalledWith( 'Video chapters could not be updated.' ); + expect( mockWarningNotice ).toHaveBeenCalledWith( 'Video chapters could not be updated.', { + type: 'snackbar', + } ); } ); it( 'passes every non-error status through untouched', async () => { diff --git a/projects/packages/videopress/src/dashboard/hooks/test/use-upload-intake.test.ts b/projects/packages/videopress/src/dashboard/hooks/test/use-upload-intake.test.ts index 486536741529..77a2fdcab7de 100644 --- a/projects/packages/videopress/src/dashboard/hooks/test/use-upload-intake.test.ts +++ b/projects/packages/videopress/src/dashboard/hooks/test/use-upload-intake.test.ts @@ -23,8 +23,18 @@ jest.mock( '../use-videopress-upgrade', () => ( { } ) ); const mockCreateErrorNotice = jest.fn(); -jest.mock( '@automattic/jetpack-components/global-notices', () => ( { - useGlobalNotices: () => ( { createErrorNotice: mockCreateErrorNotice } ), +jest.mock( '@wordpress/notices', () => ( { store: 'core/notices' } ) ); +jest.mock( '@wordpress/data', () => ( { + combineReducers: jest.fn( reducers => reducers ), + createReduxStore: jest.fn( () => ( { name: 'mock-store' } ) ), + createSelector: jest.fn( selector => selector ), + keyedReducer: jest.fn( ( _key, reducer ) => reducer ), + register: jest.fn(), + select: jest.fn( () => ( {} ) ), + dispatch: jest.fn( () => ( {} ) ), + useSelect: jest.fn( () => ( {} ) ), + useRegistry: jest.fn( () => ( { select: jest.fn(), dispatch: jest.fn() } ) ), + useDispatch: () => ( { createErrorNotice: mockCreateErrorNotice } ), } ) ); const video = ( name: string ): File => new File( [ 'x' ], name, { type: 'video/mp4' } ); @@ -73,6 +83,7 @@ describe( 'useUploadIntake', () => { expect( mockStartUpload ).not.toHaveBeenCalled(); expect( mockCreateErrorNotice ).toHaveBeenCalledWith( NOT_A_VIDEO_MESSAGE, { id: INVALID_FILE_NOTICE_ID, + type: 'snackbar', } ); } ); @@ -84,6 +95,7 @@ describe( 'useUploadIntake', () => { expect( mockStartUpload ).not.toHaveBeenCalled(); expect( mockCreateErrorNotice ).toHaveBeenCalledWith( FREE_TIER_AT_LIMIT_MESSAGE, { actions: [ { label: 'Upgrade', onClick: mockRunUpgrade } ], + type: 'snackbar', } ); } ); @@ -96,7 +108,8 @@ describe( 'useUploadIntake', () => { expect( mockStartUpload ).toHaveBeenCalledTimes( 1 ); expect( mockStartUpload ).toHaveBeenCalledWith( files[ 0 ] ); expect( mockCreateErrorNotice ).toHaveBeenCalledWith( - '2 videos weren’t uploaded because they exceed your plan’s limit.' + '2 videos weren’t uploaded because they exceed your plan’s limit.', + { type: 'snackbar' } ); } ); } ); diff --git a/projects/packages/videopress/src/dashboard/hooks/use-update-chapters.ts b/projects/packages/videopress/src/dashboard/hooks/use-update-chapters.ts index 267bd96e6d82..d0a66373c797 100644 --- a/projects/packages/videopress/src/dashboard/hooks/use-update-chapters.ts +++ b/projects/packages/videopress/src/dashboard/hooks/use-update-chapters.ts @@ -5,10 +5,11 @@ * the player's chapter menu silently de-syncs. The pipeline itself lives in * `src/client/utils/video-chapters/sync-chapters` (shared with the block * editor's chapter manager modal); this hook only binds its warning seam to - * the dashboard's global notices. + * core snackbar notices. */ -import { useGlobalNotices } from '@automattic/jetpack-components/global-notices'; +import { useDispatch } from '@wordpress/data'; import { useCallback } from '@wordpress/element'; +import { store as noticesStore } from '@wordpress/notices'; import { syncChapters as syncChaptersCore } from '../../client/utils/video-chapters/sync-chapters'; import type { ChaptersSyncStatus } from '../../client/utils/video-chapters/sync-chapters'; import type { LibraryItem } from '../types/library'; @@ -28,11 +29,13 @@ type ChaptersVideo = Pick< LibraryItem, 'guid' | 'isPrivate' | 'durationSeconds' * @return An object with the stable `syncChapters` callback. */ export function useUpdateChapters() { - const { createWarningNotice } = useGlobalNotices(); + const { createWarningNotice } = useDispatch( noticesStore ); const syncChapters = useCallback( ( video: ChaptersVideo, description: string ): Promise< ChaptersSyncStatus > => - syncChaptersCore( video, description, { onWarning: createWarningNotice } ), + syncChaptersCore( video, description, { + onWarning: message => createWarningNotice( message, { type: 'snackbar' } ), + } ), [ createWarningNotice ] ); diff --git a/projects/packages/videopress/src/dashboard/hooks/use-update-video-poster.ts b/projects/packages/videopress/src/dashboard/hooks/use-update-video-poster.ts index 9766596ac6fa..0986676d71a8 100644 --- a/projects/packages/videopress/src/dashboard/hooks/use-update-video-poster.ts +++ b/projects/packages/videopress/src/dashboard/hooks/use-update-video-poster.ts @@ -1,7 +1,8 @@ -import { useGlobalNotices } from '@automattic/jetpack-components/global-notices'; import { useMutation, useQueryClient } from '@tanstack/react-query'; import apiFetch from '@wordpress/api-fetch'; +import { useDispatch } from '@wordpress/data'; import { __ } from '@wordpress/i18n'; +import { store as noticesStore } from '@wordpress/notices'; import { LIBRARY_ITEM_QUERY_SEGMENT, LIBRARY_QUERY_KEY } from './use-library'; import type { LibraryItem } from '../types/library'; @@ -97,7 +98,7 @@ async function mutationFn( vars: UpdatePosterVars ): Promise< { poster?: string */ export function useUpdateVideoPoster() { const client = useQueryClient(); - const { createSuccessNotice, createErrorNotice } = useGlobalNotices(); + const { createSuccessNotice, createErrorNotice } = useDispatch( noticesStore ); return useMutation< { poster?: string }, Error, UpdatePosterVars >( { mutationFn, @@ -109,10 +110,14 @@ export function useUpdateVideoPoster() { ); } client.invalidateQueries( { queryKey: [ LIBRARY_QUERY_KEY ] } ); - createSuccessNotice( __( 'Thumbnail updated.', 'jetpack-videopress-pkg' ) ); + createSuccessNotice( __( 'Thumbnail updated.', 'jetpack-videopress-pkg' ), { + type: 'snackbar', + } ); }, onError: () => { - createErrorNotice( __( 'Failed to update thumbnail.', 'jetpack-videopress-pkg' ) ); + createErrorNotice( __( 'Failed to update thumbnail.', 'jetpack-videopress-pkg' ), { + type: 'snackbar', + } ); }, } ); } diff --git a/projects/packages/videopress/src/dashboard/hooks/use-upload-intake.ts b/projects/packages/videopress/src/dashboard/hooks/use-upload-intake.ts index fbfaa25b1361..e098ee1c62d9 100644 --- a/projects/packages/videopress/src/dashboard/hooks/use-upload-intake.ts +++ b/projects/packages/videopress/src/dashboard/hooks/use-upload-intake.ts @@ -1,6 +1,7 @@ -import { useGlobalNotices } from '@automattic/jetpack-components/global-notices'; +import { useDispatch } from '@wordpress/data'; import { useCallback } from '@wordpress/element'; import { __, _n, sprintf } from '@wordpress/i18n'; +import { store as noticesStore } from '@wordpress/notices'; import { FREE_TIER_AT_LIMIT_MESSAGE } from '../components/free-tier-notice'; import { INVALID_FILE_NOTICE_ID, @@ -25,7 +26,7 @@ import { useVideoPressUpgrade } from './use-videopress-upgrade'; export function useUploadIntake(): ( files: File[] ) => number { const { isFree, isUnlimited, limit, videoCount } = useFreeTier(); const { startUpload } = useUpload(); - const { createErrorNotice } = useGlobalNotices(); + const { createErrorNotice } = useDispatch( noticesStore ); const runUpgrade = useVideoPressUpgrade(); return useCallback( @@ -38,13 +39,17 @@ export function useUploadIntake(): ( files: File[] ) => number { } ); if ( decision.kind === 'no-videos' ) { - createErrorNotice( NOT_A_VIDEO_MESSAGE, { id: INVALID_FILE_NOTICE_ID } ); + createErrorNotice( NOT_A_VIDEO_MESSAGE, { + id: INVALID_FILE_NOTICE_ID, + type: 'snackbar', + } ); return 0; } if ( decision.kind === 'at-limit' ) { createErrorNotice( FREE_TIER_AT_LIMIT_MESSAGE, { actions: [ { label: __( 'Upgrade', 'jetpack-videopress-pkg' ), onClick: runUpgrade } ], + type: 'snackbar', } ); return 0; } @@ -62,7 +67,8 @@ export function useUploadIntake(): ( files: File[] ) => number { 'jetpack-videopress-pkg' ), decision.skipped - ) + ), + { type: 'snackbar' } ); } diff --git a/projects/plugins/jetpack/_inc/client/ai/main.jsx b/projects/plugins/jetpack/_inc/client/ai/main.jsx index 3ffe45825a12..ae2b45cd6e91 100644 --- a/projects/plugins/jetpack/_inc/client/ai/main.jsx +++ b/projects/plugins/jetpack/_inc/client/ai/main.jsx @@ -13,11 +13,13 @@ * MCP hub as the landing view and no tab bar. */ -import { AdminPage, GlobalNotices, useGlobalNotices } from '@automattic/jetpack-components'; +import { AdminPage } from '@automattic/jetpack-components'; import { useConnectionErrorNotice } from '@automattic/jetpack-connection'; +import { useDispatch } from '@wordpress/data'; import { Suspense, lazy, useCallback, useEffect, useRef, useState } from '@wordpress/element'; import { __, isRTL, sprintf } from '@wordpress/i18n'; import { chevronLeft, chevronRight, Icon } from '@wordpress/icons'; +import { store as noticesStore, SnackbarNotices } from '@wordpress/notices'; import { Badge, Notice, Stack, Tabs } from '@wordpress/ui'; import ChunkErrorBoundary from './components/chunk-error-boundary/index'; import LoadingSpinner from './components/loading-spinner/index'; @@ -202,10 +204,8 @@ export default function App() { showA12sBadge = false, } = window?.jetpackAiSettings ?? {}; const [ view, setView ] = useState( getViewFromHash ); - // Save feedback goes through the shared GlobalNotices snackbars (the - // design-system SnackbarList behind @wordpress/notices): transient, - // auto-dismissing, no page-level styling needed. - const { createSuccessNotice, createErrorNotice } = useGlobalNotices(); + // Save feedback goes through core SnackbarNotices (@wordpress/notices). + const { createSuccessNotice, createErrorNotice } = useDispatch( noticesStore ); const { hasConnectionError } = useConnectionErrorNotice(); const mcpViewedRecorded = useRef( false ); // Strict false: older page data (undefined) must not read as unlinked. @@ -288,6 +288,7 @@ export default function App() { // makes the store replace the previous outcome for this surface, // so retries never show stale results alongside fresh ones. createErrorNotice( __( 'Failed to save MCP settings. Please try again.', 'jetpack' ), { + type: 'snackbar', id: 'jetpack-mcp-save-status', explicitDismiss: true, } ); @@ -305,6 +306,7 @@ export default function App() { // The shared id keeps this surface last-outcome-wins: a // success replaces a sticky error from an earlier attempt. createSuccessNotice( __( 'Your AI settings have been saved.', 'jetpack' ), { + type: 'snackbar', id: 'jetpack-ai-save-status', } ); return true; @@ -312,6 +314,7 @@ export default function App() { () => { // Errors must not auto-vanish before they're read. createErrorNotice( __( 'Failed to save AI settings. Please try again.', 'jetpack' ), { + type: 'snackbar', id: 'jetpack-ai-save-status', explicitDismiss: true, } ); @@ -439,7 +442,7 @@ export default function App() { { isSubView && ( ) } - + { try { await operation(); - createSuccessNotice( successMessage, { id: 'jetpack-ai-scheduled-task-status' } ); + createSuccessNotice( successMessage, { + type: 'snackbar', + id: 'jetpack-ai-scheduled-task-status', + } ); } catch ( mutationError ) { createErrorNotice( mutationError.message, { + type: 'snackbar', id: 'jetpack-ai-scheduled-task-status', explicitDismiss: true, } ); diff --git a/projects/plugins/jetpack/_inc/client/ai/style.scss b/projects/plugins/jetpack/_inc/client/ai/style.scss index 80c137ad7aa4..102c541590b1 100644 --- a/projects/plugins/jetpack/_inc/client/ai/style.scss +++ b/projects/plugins/jetpack/_inc/client/ai/style.scss @@ -1,5 +1,6 @@ @use "sass:meta"; @use "@automattic/jetpack-base-styles/admin-page-layout" as *; +@use "@automattic/jetpack-base-styles/gutenberg-base-styles" as gb; // DataViews ships its structural table, toolbar, and row styles separately. // It is bundled with the AI Hub rather than enqueued by WordPress. @@ -10,6 +11,12 @@ body.jetpack_page_jetpack-ai { @include jetpack-admin-page-layout; } +// Core snackbar placement (matches `@wordpress/boot`'s snackbar-container). +.jetpack-ai-admin__snackbar-notices { + + @include gb.snackbar-container(); +} + .jetpack-ai-admin { // Content wrapper inside AdminPage's fluid container. // Use border-box so the 24px padding is included in the 100% width, diff --git a/projects/plugins/jetpack/_inc/client/ai/test/main.jsx b/projects/plugins/jetpack/_inc/client/ai/test/main.jsx index 62d800d51681..d6b40bb59ec5 100644 --- a/projects/plugins/jetpack/_inc/client/ai/test/main.jsx +++ b/projects/plugins/jetpack/_inc/client/ai/test/main.jsx @@ -127,7 +127,7 @@ const mcpViewCount = () => ).length; beforeEach( () => { - // GlobalNotices renders SnackbarList, whose framer-motion animations + // SnackbarNotices renders SnackbarList, whose framer-motion animations // measure keyframes via window.scrollTo — not implemented in jsdom. jest.spyOn( window, 'scrollTo' ).mockImplementation(); apiFetch.mockReset(); @@ -781,7 +781,7 @@ describe( 'AI admin page (main.jsx)', () => { await userEvent.click( toggle ); // Save feedback is transient, so it renders through the shared - // GlobalNotices snackbars (the design-system SnackbarList), not a + // Core SnackbarNotices snackbars (SnackbarList), not a // persistent Notice banner. The snackbar's signature is its // click-to-dismiss button wrapper. const snackbar = await screen.findByRole( 'button', { name: 'Dismiss this notice' } ); diff --git a/projects/plugins/jetpack/_inc/client/settings/index.jsx b/projects/plugins/jetpack/_inc/client/settings/index.jsx index 5201145c29f5..c42e4da40c83 100644 --- a/projects/plugins/jetpack/_inc/client/settings/index.jsx +++ b/projects/plugins/jetpack/_inc/client/settings/index.jsx @@ -1,6 +1,7 @@ -import { GlobalNotices, ThemeProvider } from '@automattic/jetpack-components'; +import { ThemeProvider } from '@automattic/jetpack-components'; import { __, sprintf } from '@wordpress/i18n'; import { search } from '@wordpress/icons'; +import { SnackbarNotices } from '@wordpress/notices'; import { EmptyState, Stack } from '@wordpress/ui'; import { Component } from 'react'; import { connect } from 'react-redux'; @@ -113,7 +114,7 @@ class Settings extends Component {

- + ); } diff --git a/projects/plugins/jetpack/_inc/client/settings/style.scss b/projects/plugins/jetpack/_inc/client/settings/style.scss index 768d2e4a97bb..8b2ca9a9addf 100644 --- a/projects/plugins/jetpack/_inc/client/settings/style.scss +++ b/projects/plugins/jetpack/_inc/client/settings/style.scss @@ -1,10 +1,17 @@ @use "../scss/mixins/breakpoints"; @use "../scss/functions/rem"; +@use "@automattic/jetpack-base-styles/gutenberg-base-styles" as gb; .jp-settings-admin-page .jp-admin-page__page { background-color: #fcfcfc; } +// Core snackbar placement (matches `@wordpress/boot`'s snackbar-container). +.jp-settings-snackbar-notices { + + @include gb.snackbar-container(); +} + .jp-settings-admin-page .jp-lower { max-width: 660px; margin-inline-start: auto; diff --git a/projects/plugins/jetpack/changelog/update-move-jetpack-notices-to-bottom-left b/projects/plugins/jetpack/changelog/update-move-jetpack-notices-to-bottom-left new file mode 100644 index 000000000000..3eb9eecd127d --- /dev/null +++ b/projects/plugins/jetpack/changelog/update-move-jetpack-notices-to-bottom-left @@ -0,0 +1,4 @@ +Significance: patch +Type: other + +Use core snackbar notice placement across Jetpack admin screens. diff --git a/projects/plugins/social/changelog/update-move-jetpack-notices-to-bottom-left b/projects/plugins/social/changelog/update-move-jetpack-notices-to-bottom-left new file mode 100644 index 000000000000..26cfb3600a5b --- /dev/null +++ b/projects/plugins/social/changelog/update-move-jetpack-notices-to-bottom-left @@ -0,0 +1,4 @@ +Significance: patch +Type: changed + +Use core snackbar notice placement. diff --git a/projects/plugins/videopress/changelog/update-move-jetpack-notices-to-bottom-left b/projects/plugins/videopress/changelog/update-move-jetpack-notices-to-bottom-left new file mode 100644 index 000000000000..26cfb3600a5b --- /dev/null +++ b/projects/plugins/videopress/changelog/update-move-jetpack-notices-to-bottom-left @@ -0,0 +1,4 @@ +Significance: patch +Type: changed + +Use core snackbar notice placement. From b2e06d6dcb8dd8119253fedd7ef3b5452a6ceb39 Mon Sep 17 00:00:00 2001 From: Christian Gastrell Date: Mon, 21 Sep 2026 10:48:56 -0300 Subject: [PATCH 02/12] My Jetpack: convert the last useGlobalNotices call site use-install-plugins was left on the deleted export, so typecheck and the build failed. Convert it like use-activate-plugins and use-deactivate-plugins, and pass the snackbar type the wrapper used to default. Co-Authored-By: Claude Opus 5 (1M context) --- .../my-jetpack/_inc/data/products/use-install-plugins.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/projects/packages/my-jetpack/_inc/data/products/use-install-plugins.ts b/projects/packages/my-jetpack/_inc/data/products/use-install-plugins.ts index af8156dadaae..d259836b801e 100644 --- a/projects/packages/my-jetpack/_inc/data/products/use-install-plugins.ts +++ b/projects/packages/my-jetpack/_inc/data/products/use-install-plugins.ts @@ -1,5 +1,6 @@ -import { useGlobalNotices } from '@automattic/jetpack-components'; +import { useDispatch } from '@wordpress/data'; import { __, sprintf } from '@wordpress/i18n'; +import { store as noticesStore } from '@wordpress/notices'; import { REST_API_SITE_PRODUCTS_ENDPOINT, QUERY_INSTALL_PRODUCT_KEY } from '../constants'; import useSimpleMutation from '../use-simple-mutation'; import useProducts from './use-products'; @@ -8,7 +9,7 @@ const useInstallPlugins = ( productSlugs: string | string[] ) => { const productIds = Array.isArray( productSlugs ) ? productSlugs : [ productSlugs ]; const { products, refetch } = useProducts( productIds ); - const { createSuccessNotice } = useGlobalNotices(); + const { createSuccessNotice } = useDispatch( noticesStore ); const successMessageSingular = sprintf( /* translators: %s is the name of a Jetpack plugin, i.e.- "VaultPress Backup" or "Boost" or "Social" or "Search" or "VideoPress", etc. */ @@ -28,7 +29,7 @@ const useInstallPlugins = ( productSlugs: string | string[] ) => { options: { onSuccess: () => { refetch().then( () => { - createSuccessNotice( successMessage ); + createSuccessNotice( successMessage, { type: 'snackbar' } ); } ); }, }, From 2db796a8f486f49295709e470ed79c9df3ec8d88 Mon Sep 17 00:00:00 2001 From: Christian Gastrell Date: Mon, 21 Sep 2026 10:49:01 -0300 Subject: [PATCH 03/12] My Jetpack: mock @wordpress/notices in the two suites that load it Both suites mock @wordpress/data wholesale, so the real notices store resolved keyedReducer to undefined and the suites failed to run. Mock the store the way the VideoPress suites already do. Co-Authored-By: Claude Opus 5 (1M context) --- .../my-jetpack/_inc/components/module-toggle/test/index.test.tsx | 1 + .../my-jetpack-tab-panel/products/test/pending-notice.test.tsx | 1 + 2 files changed, 2 insertions(+) diff --git a/projects/packages/my-jetpack/_inc/components/module-toggle/test/index.test.tsx b/projects/packages/my-jetpack/_inc/components/module-toggle/test/index.test.tsx index 85eb6f578f04..6e228fa915fb 100644 --- a/projects/packages/my-jetpack/_inc/components/module-toggle/test/index.test.tsx +++ b/projects/packages/my-jetpack/_inc/components/module-toggle/test/index.test.tsx @@ -12,6 +12,7 @@ const mockCreateSuccessNotice = jest.fn(); const mockCreateErrorNotice = jest.fn(); jest.mock( '@automattic/jetpack-shared-stores', () => ( { store: {} } ) ); +jest.mock( '@wordpress/notices', () => ( { store: 'core/notices' } ) ); jest.mock( '@wordpress/data', () => ( { useDispatch: () => ( { diff --git a/projects/packages/my-jetpack/_inc/components/my-jetpack-tab-panel/products/test/pending-notice.test.tsx b/projects/packages/my-jetpack/_inc/components/my-jetpack-tab-panel/products/test/pending-notice.test.tsx index 12ec2abebb9d..e6fc2be30e71 100644 --- a/projects/packages/my-jetpack/_inc/components/my-jetpack-tab-panel/products/test/pending-notice.test.tsx +++ b/projects/packages/my-jetpack/_inc/components/my-jetpack-tab-panel/products/test/pending-notice.test.tsx @@ -6,6 +6,7 @@ import { } from '../pending-notice'; const mockCreateSuccessNotice = jest.fn(); +jest.mock( '@wordpress/notices', () => ( { store: 'core/notices' } ) ); jest.mock( '@wordpress/data', () => ( { useDispatch: () => ( { createSuccessNotice: mockCreateSuccessNotice } ), } ) ); From 3cdf0e5ae1d1c130804d76f3385f62ea1fdb2a64 Mon Sep 17 00:00:00 2001 From: Christian Gastrell Date: Mon, 21 Sep 2026 12:47:16 -0300 Subject: [PATCH 04/12] VideoPress: update a test mock that trunk added after this branch private-thumbnail-source landed on trunk mocking the global-notices subpath this branch removes, so the suite could not run. Mock the core store instead, like its siblings here. Co-Authored-By: Claude Opus 5 (1M context) --- .../test/private-thumbnail-source.test.tsx | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/projects/packages/videopress/src/dashboard/components/video-details/test/private-thumbnail-source.test.tsx b/projects/packages/videopress/src/dashboard/components/video-details/test/private-thumbnail-source.test.tsx index 4b22047a23e0..9a12a4582c29 100644 --- a/projects/packages/videopress/src/dashboard/components/video-details/test/private-thumbnail-source.test.tsx +++ b/projects/packages/videopress/src/dashboard/components/video-details/test/private-thumbnail-source.test.tsx @@ -11,8 +11,18 @@ jest.mock( '@wordpress/api-fetch', () => ( { default: jest.fn(), } ) ); -jest.mock( '@automattic/jetpack-components/global-notices', () => ( { - useGlobalNotices: () => ( { +jest.mock( '@wordpress/notices', () => ( { store: 'core/notices' } ) ); +jest.mock( '@wordpress/data', () => ( { + combineReducers: jest.fn( reducers => reducers ), + createReduxStore: jest.fn( () => ( { name: 'mock-store' } ) ), + createSelector: jest.fn( selector => selector ), + keyedReducer: jest.fn( ( _key, reducer ) => reducer ), + register: jest.fn(), + select: jest.fn( () => ( {} ) ), + dispatch: jest.fn( () => ( {} ) ), + useSelect: jest.fn( () => ( {} ) ), + useRegistry: jest.fn( () => ( { select: jest.fn(), dispatch: jest.fn() } ) ), + useDispatch: () => ( { createSuccessNotice: jest.fn(), createErrorNotice: jest.fn(), } ), From 7ce8e1b76aaaa65082baa69d038bb7afca0007f1 Mon Sep 17 00:00:00 2001 From: Christian Gastrell Date: Mon, 21 Sep 2026 12:53:31 -0300 Subject: [PATCH 05/12] AI Hub: let boot render the snackbars The AI Hub moved onto wp-build in #52411, so boot's Root already mounts a SnackbarNotices and a second list shows every toast twice. Drop the mount and its placement rule. The save-confirmation tests render the app beside a SnackbarNotices, which is what boot supplies in production, so they keep asserting on the text a user reads. Co-Authored-By: Claude Opus 5 (1M context) --- .../plugins/jetpack/_inc/client/ai/main.jsx | 5 ++--- .../plugins/jetpack/_inc/client/ai/style.scss | 7 ------- .../jetpack/_inc/client/ai/test/main.jsx | 18 ++++++++++++++---- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/projects/plugins/jetpack/_inc/client/ai/main.jsx b/projects/plugins/jetpack/_inc/client/ai/main.jsx index ae2b45cd6e91..7f4e690d4c6a 100644 --- a/projects/plugins/jetpack/_inc/client/ai/main.jsx +++ b/projects/plugins/jetpack/_inc/client/ai/main.jsx @@ -19,7 +19,7 @@ import { useDispatch } from '@wordpress/data'; import { Suspense, lazy, useCallback, useEffect, useRef, useState } from '@wordpress/element'; import { __, isRTL, sprintf } from '@wordpress/i18n'; import { chevronLeft, chevronRight, Icon } from '@wordpress/icons'; -import { store as noticesStore, SnackbarNotices } from '@wordpress/notices'; +import { store as noticesStore } from '@wordpress/notices'; import { Badge, Notice, Stack, Tabs } from '@wordpress/ui'; import ChunkErrorBoundary from './components/chunk-error-boundary/index'; import LoadingSpinner from './components/loading-spinner/index'; @@ -204,7 +204,7 @@ export default function App() { showA12sBadge = false, } = window?.jetpackAiSettings ?? {}; const [ view, setView ] = useState( getViewFromHash ); - // Save feedback goes through core SnackbarNotices (@wordpress/notices). + // Save feedback goes through the snackbars boot's layout renders. const { createSuccessNotice, createErrorNotice } = useDispatch( noticesStore ); const { hasConnectionError } = useConnectionErrorNotice(); const mcpViewedRecorded = useRef( false ); @@ -442,7 +442,6 @@ export default function App() { { isSubView && ( ) } - ( { tracks: { recordEvent: jest.fn() } } ), { virtual: true } ); + +// boot's layout renders the page's snackbars, so the app no longer mounts a +// list of its own. Pair them here to keep asserting on what a user reads. +const renderWithSnackbars = () => + render( + <> + + + + ); jest.mock( '@automattic/jetpack-ai-client/jwt', () => ( { __esModule: true, default: jest.fn(), @@ -775,7 +785,7 @@ describe( 'AI admin page (main.jsx)', () => { test( 'save-confirmation: a successful AI-settings save shows a success snackbar', async () => { mockApiFetch( { featurePost: () => Promise.resolve( enabledSettings() ) } ); - render( ); + renderWithSnackbars(); const toggle = await screen.findByRole( 'checkbox', { name: /Writing Assistant/ } ); await userEvent.click( toggle ); @@ -795,7 +805,7 @@ describe( 'AI admin page (main.jsx)', () => { test( 'save-confirmation: a failed AI-settings save shows an explicit-dismiss error snackbar', async () => { mockApiFetch( { featurePost: () => Promise.reject( new Error( 'nope' ) ) } ); - render( ); + renderWithSnackbars(); const toggle = await screen.findByRole( 'checkbox', { name: /Writing Assistant/ } ); await userEvent.click( toggle ); @@ -828,7 +838,7 @@ describe( 'AI admin page (main.jsx)', () => { }, } ); - render( ); + renderWithSnackbars(); const toggle = await screen.findByRole( 'checkbox', { name: /Writing Assistant/ } ); await userEvent.click( toggle ); From 8945375a3ea027c8b0813effcf18dc981b32ff1b Mon Sep 17 00:00:00 2001 From: Christian Gastrell Date: Mon, 21 Sep 2026 14:28:11 -0300 Subject: [PATCH 06/12] Componentry: deprecate GlobalNotices instead of removing it @automattic/jetpack-components is published to npm, so dropping the named exports under a patch would break downstream consumers on a semver-compatible upgrade. We cannot see who imports it outside this monorepo. Restore the component, the hook and the barrel export, mark both deprecated, add a README pointing at SnackbarNotices, and file the changelog as a minor deprecation. Nothing in this repo imports it any more, so it can go in the next major. Co-Authored-By: Claude Opus 5 (1M context) --- pnpm-lock.yaml | 3 + ...update-move-jetpack-notices-to-bottom-left | 6 +- .../components/global-notices/README.md | 25 +++++++++ .../global-notices/global-notices.tsx | 35 ++++++++++++ .../components/global-notices/index.ts | 3 + .../global-notices/stories/index.stories.tsx | 55 +++++++++++++++++++ .../global-notices/styles.module.scss | 24 ++++++++ .../global-notices/use-global-notices.ts | 40 ++++++++++++++ projects/js-packages/components/index.ts | 1 + projects/js-packages/components/package.json | 6 ++ 10 files changed, 195 insertions(+), 3 deletions(-) create mode 100644 projects/js-packages/components/components/global-notices/README.md create mode 100644 projects/js-packages/components/components/global-notices/global-notices.tsx create mode 100644 projects/js-packages/components/components/global-notices/index.ts create mode 100644 projects/js-packages/components/components/global-notices/stories/index.stories.tsx create mode 100644 projects/js-packages/components/components/global-notices/styles.module.scss create mode 100644 projects/js-packages/components/components/global-notices/use-global-notices.ts diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index fc13d9317e64..4ee8fae1f13f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -568,6 +568,9 @@ importers: '@wordpress/icons': specifier: 16.0.0 version: 16.0.0(@types/react-dom@18.3.7(@types/react@18.3.31))(@types/react@18.3.31)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) + '@wordpress/notices': + specifier: 5.55.0 + version: 5.55.0(@types/react-dom@18.3.7(@types/react@18.3.31))(@types/react@18.3.31)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) '@wordpress/theme': specifier: 2.1.0 version: 2.1.0(@types/react-dom@18.3.7(@types/react@18.3.31))(@types/react@18.3.31)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) diff --git a/projects/js-packages/components/changelog/update-move-jetpack-notices-to-bottom-left b/projects/js-packages/components/changelog/update-move-jetpack-notices-to-bottom-left index 9d90ac5b25e4..7d9e13d7a4b8 100644 --- a/projects/js-packages/components/changelog/update-move-jetpack-notices-to-bottom-left +++ b/projects/js-packages/components/changelog/update-move-jetpack-notices-to-bottom-left @@ -1,4 +1,4 @@ -Significance: patch -Type: removed +Significance: minor +Type: deprecated -Remove GlobalNotices and useGlobalNotices in favor of core SnackbarNotices. +Deprecate GlobalNotices and useGlobalNotices. Use SnackbarNotices from @wordpress/notices instead. diff --git a/projects/js-packages/components/components/global-notices/README.md b/projects/js-packages/components/components/global-notices/README.md new file mode 100644 index 000000000000..cd4e579ee8a2 --- /dev/null +++ b/projects/js-packages/components/components/global-notices/README.md @@ -0,0 +1,25 @@ +GlobalNotices +========= + +> **Deprecated.** Use `SnackbarNotices` from `@wordpress/notices` instead, and +> dispatch to that store directly with `{ type: 'snackbar' }`. Pages rendered by +> `@wordpress/boot` already mount a `SnackbarNotices`, so mounting this one too +> shows every notice twice. Retained as a compatibility shim for downstream +> consumers and will be removed in the next major version. + +Renders the snackbar notices held in the `@wordpress/notices` store. + +## General Usage: + +```js +import { GlobalNotices } from '@automattic/jetpack-components'; +render() { + return ( + + ); +} +``` + +## Props + +- `maxVisibleNotices`: how many notices to show at once. Defaults to 3. diff --git a/projects/js-packages/components/components/global-notices/global-notices.tsx b/projects/js-packages/components/components/global-notices/global-notices.tsx new file mode 100644 index 000000000000..f8e2d1e0f210 --- /dev/null +++ b/projects/js-packages/components/components/global-notices/global-notices.tsx @@ -0,0 +1,35 @@ +import { SnackbarList } from '@wordpress/components'; +import styles from './styles.module.scss'; +import { useGlobalNotices } from './use-global-notices.ts'; + +export type GlobalNoticesProps = { + maxVisibleNotices?: number; +}; + +/** + * Renders the global notices. + * + * @deprecated Use `SnackbarNotices` from `@wordpress/notices` instead. Pages + * rendered by `@wordpress/boot` already mount one, so mounting this as well + * shows every notice twice. + * + * @param {GlobalNoticesProps} props - Component props. + * + * @return {import('react').ReactNode} The rendered notices list. + */ +export function GlobalNotices( { maxVisibleNotices = 3 }: GlobalNoticesProps ) { + const { getNotices, removeNotice } = useGlobalNotices(); + + const snackbarNotices = getNotices() + .filter( ( { type } ) => type === 'snackbar' ) + // Slices from the tail end of the list. + .slice( -maxVisibleNotices ); + + return ( + + ); +} diff --git a/projects/js-packages/components/components/global-notices/index.ts b/projects/js-packages/components/components/global-notices/index.ts new file mode 100644 index 000000000000..889eca40706d --- /dev/null +++ b/projects/js-packages/components/components/global-notices/index.ts @@ -0,0 +1,3 @@ +export * from './global-notices.tsx'; +export * from './use-global-notices.ts'; +export { store as globalNoticesStore } from '@wordpress/notices'; diff --git a/projects/js-packages/components/components/global-notices/stories/index.stories.tsx b/projects/js-packages/components/components/global-notices/stories/index.stories.tsx new file mode 100644 index 000000000000..811fcf694f14 --- /dev/null +++ b/projects/js-packages/components/components/global-notices/stories/index.stories.tsx @@ -0,0 +1,55 @@ +import { useCallback } from 'react'; +import Button from '../../button/index.tsx'; +import { GlobalNotices, useGlobalNotices } from '../index.ts'; +import type { Meta } from '@storybook/react'; + +const meta: Meta< typeof GlobalNotices > = { + title: 'JS Packages/Components/GlobalNotices', + component: GlobalNotices, + decorators: [ story =>
{ story() }
], +}; + +export default meta; + +const Template = args => { + const { createErrorNotice, createSuccessNotice, createInfoNotice, createWarningNotice } = + useGlobalNotices(); + + return ( +
+ +
+ + + + +
+
+ ); +}; + +export const _Default = Template.bind( {} ); diff --git a/projects/js-packages/components/components/global-notices/styles.module.scss b/projects/js-packages/components/components/global-notices/styles.module.scss new file mode 100644 index 000000000000..d16357fe9b3f --- /dev/null +++ b/projects/js-packages/components/components/global-notices/styles.module.scss @@ -0,0 +1,24 @@ +@use "@automattic/jetpack-base-styles/gutenberg-base-styles" as gb; + +.global-notices { + + &:global(.components-snackbar-list) { + position: fixed; + inset-block-start: auto; // top + inset-block-end: 0; // bottom + inset-inline: 0; // left and right + // Modals have 100000, so this needs to be above them + z-index: 100001; + + @include gb.break-small { + width: auto; + inset-inline: unset; // left and right + inset-block-start: 4rem; + inset-inline-end: 1rem; + } + + @include gb.break-medium { + inset-block-start: 3rem; + } + } +} diff --git a/projects/js-packages/components/components/global-notices/use-global-notices.ts b/projects/js-packages/components/components/global-notices/use-global-notices.ts new file mode 100644 index 000000000000..24288b8825e6 --- /dev/null +++ b/projects/js-packages/components/components/global-notices/use-global-notices.ts @@ -0,0 +1,40 @@ +import { useDispatch, useSelect } from '@wordpress/data'; +import { store as noticesStore } from '@wordpress/notices'; + +type NoticesStore = ReturnType< ( typeof noticesStore )[ 'instantiate' ] >; + +export type TGlobalNotices = ReturnType< NoticesStore[ 'getActions' ] > & + ReturnType< NoticesStore[ 'getSelectors' ] >; + +/** + * The global notices hook. + * + * @deprecated Dispatch to `@wordpress/notices` directly, passing + * `{ type: 'snackbar' }` — this hook only defaulted that option. + * + * @return {TGlobalNotices} The global notices selectors and actions. + */ +export function useGlobalNotices(): TGlobalNotices { + const actionCreators = useDispatch( noticesStore ); + const notices = useSelect( select => select( noticesStore ).getNotices(), [] ); + + return { + ...actionCreators, + createNotice( status, content, options ) { + return actionCreators.createNotice( status, content, { type: 'snackbar', ...options } ); + }, + createErrorNotice( content, options ) { + return actionCreators.createErrorNotice( content, { type: 'snackbar', ...options } ); + }, + createInfoNotice( content, options ) { + return actionCreators.createInfoNotice( content, { type: 'snackbar', ...options } ); + }, + createSuccessNotice( content, options ) { + return actionCreators.createSuccessNotice( content, { type: 'snackbar', ...options } ); + }, + createWarningNotice( content, options ) { + return actionCreators.createWarningNotice( content, { type: 'snackbar', ...options } ); + }, + getNotices: () => notices, + }; +} diff --git a/projects/js-packages/components/index.ts b/projects/js-packages/components/index.ts index e9bd3ef06c2d..69633d5ded0f 100644 --- a/projects/js-packages/components/index.ts +++ b/projects/js-packages/components/index.ts @@ -69,4 +69,5 @@ export { default as StatCard } from './components/stat-card/index.tsx'; export { default as DiffViewer } from './components/diff-viewer/index.tsx'; export { default as MarkedLines } from './components/marked-lines/index.tsx'; export { default as DetailsViewer } from './components/details-viewer/index.tsx'; +export * from './components/global-notices/index.ts'; export * from './components/navigator-modal/index.tsx'; diff --git a/projects/js-packages/components/package.json b/projects/js-packages/components/package.json index dfb7eecc786d..bab1d637d94e 100644 --- a/projects/js-packages/components/package.json +++ b/projects/js-packages/components/package.json @@ -33,6 +33,11 @@ "types": "./build/components/button/index.d.ts", "default": "./build/components/button/index.js" }, + "./global-notices": { + "jetpack:src": "./components/global-notices/index.ts", + "types": "./build/components/global-notices/index.d.ts", + "default": "./build/components/global-notices/index.js" + }, "./gravatar": { "jetpack:src": "./components/gravatar/index.tsx", "types": "./build/components/gravatar/index.d.ts", @@ -99,6 +104,7 @@ "@wordpress/element": "8.7.0", "@wordpress/i18n": "6.28.0", "@wordpress/icons": "16.0.0", + "@wordpress/notices": "5.55.0", "@wordpress/theme": "2.1.0", "@wordpress/ui": "0.22.0", "clsx": "2.1.1", From 1babfa7900aec7201fa569f1efe832154c4d12b5 Mon Sep 17 00:00:00 2001 From: Christian Gastrell Date: Mon, 21 Sep 2026 15:01:52 -0300 Subject: [PATCH 07/12] My Jetpack: mock @wordpress/notices in the new features suite use-main-features landed on trunk mocking @wordpress/data wholesale, and it reaches pending-notice, which this branch points at the core notices store. The real store then resolves keyedReducer to undefined and the suite cannot run. Mock the store, like its siblings here. Co-Authored-By: Claude Opus 5 (1M context) --- .../features/test/use-main-features.test.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/projects/packages/my-jetpack/_inc/components/my-jetpack-tab-panel/features/test/use-main-features.test.tsx b/projects/packages/my-jetpack/_inc/components/my-jetpack-tab-panel/features/test/use-main-features.test.tsx index e2aca14e1d19..ff19bb4d6d53 100644 --- a/projects/packages/my-jetpack/_inc/components/my-jetpack-tab-panel/features/test/use-main-features.test.tsx +++ b/projects/packages/my-jetpack/_inc/components/my-jetpack-tab-panel/features/test/use-main-features.test.tsx @@ -22,6 +22,7 @@ jest.mock( '@automattic/jetpack-components', () => ( { } ) ); jest.mock( '@automattic/jetpack-shared-stores', () => ( { store: 'modules-store' } ) ); +jest.mock( '@wordpress/notices', () => ( { store: 'core/notices' } ) ); jest.mock( '@wordpress/data', () => ( { useDispatch: () => ( { invalidateResolution: jest.fn() } ), From 602e56ea462ae3e7fce4648144db5e67b06ca791 Mon Sep 17 00:00:00 2001 From: Christian Gastrell Date: Mon, 21 Sep 2026 16:11:52 -0300 Subject: [PATCH 08/12] Fix indentation left behind by a rebase conflict Two continuation lines kept spaces where prettier wants a tab. Rebase replays do not run the pre-commit hook, so the drift survived the earlier conflict resolution and failed the ESLint job. Co-Authored-By: Claude Opus 5 (1M context) --- .../packages/my-jetpack/_inc/components/module-toggle/index.tsx | 2 +- projects/packages/videopress/routes/library/promote-local.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/projects/packages/my-jetpack/_inc/components/module-toggle/index.tsx b/projects/packages/my-jetpack/_inc/components/module-toggle/index.tsx index edc7db0f633f..7a5933095179 100644 --- a/projects/packages/my-jetpack/_inc/components/module-toggle/index.tsx +++ b/projects/packages/my-jetpack/_inc/components/module-toggle/index.tsx @@ -80,7 +80,7 @@ export function useModuleActivation( /* translators: %s is the module name */ __( '%s has been deactivated.', 'jetpack-my-jetpack' ), $module.name - ); + ); createSuccessNotice( message, { type: 'snackbar' } ); } else { const message = diff --git a/projects/packages/videopress/routes/library/promote-local.ts b/projects/packages/videopress/routes/library/promote-local.ts index 644d95ad2fb5..2e5369e14142 100644 --- a/projects/packages/videopress/routes/library/promote-local.ts +++ b/projects/packages/videopress/routes/library/promote-local.ts @@ -77,7 +77,7 @@ export function createPromoteLocal( deps: PromoteLocalDeps ): ( id: string ) => /* translators: %s: reason returned by the upload endpoint, e.g. "403: Invalid Mime". */ __( 'Failed to upload video to VideoPress: %s', 'jetpack-videopress-pkg' ), reason - ) + ) : __( 'Failed to upload video to VideoPress.', 'jetpack-videopress-pkg' ), { type: 'snackbar' } ); From 5b3c1dedfc8324433c3e3eee3f999bf99906a322 Mon Sep 17 00:00:00 2001 From: Christian Gastrell Date: Tue, 22 Sep 2026 09:22:36 -0300 Subject: [PATCH 09/12] Import the snackbar mixin from @wordpress/base-styles directly Both files pulled in the jetpack-base-styles wrapper for one mixin. The wrapper only forwards @wordpress/base-styles, and both projects already depend on it directly, so the indirection buys nothing here. Emitted CSS is unchanged. Co-Authored-By: Claude Opus 5 (1M context) --- projects/packages/newsletter/src/settings/style.scss | 2 +- projects/plugins/jetpack/_inc/client/settings/style.scss | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/projects/packages/newsletter/src/settings/style.scss b/projects/packages/newsletter/src/settings/style.scss index f905e753e141..9dd2a93619de 100644 --- a/projects/packages/newsletter/src/settings/style.scss +++ b/projects/packages/newsletter/src/settings/style.scss @@ -1,5 +1,5 @@ @use "@automattic/jetpack-base-styles/admin-page-layout" as *; -@use "@automattic/jetpack-base-styles/gutenberg-base-styles" as gb; +@use "@wordpress/base-styles/mixins" as gb; @use "sass:meta"; // This stylesheet feeds two bundles: the wp-build dashboard diff --git a/projects/plugins/jetpack/_inc/client/settings/style.scss b/projects/plugins/jetpack/_inc/client/settings/style.scss index 8b2ca9a9addf..c1209384a95b 100644 --- a/projects/plugins/jetpack/_inc/client/settings/style.scss +++ b/projects/plugins/jetpack/_inc/client/settings/style.scss @@ -1,6 +1,6 @@ @use "../scss/mixins/breakpoints"; @use "../scss/functions/rem"; -@use "@automattic/jetpack-base-styles/gutenberg-base-styles" as gb; +@use "@wordpress/base-styles/mixins" as gb; .jp-settings-admin-page .jp-admin-page__page { background-color: #fcfcfc; From 909066397edcafe322b774d3fc0078ddff3a5970 Mon Sep 17 00:00:00 2001 From: Christian Gastrell Date: Tue, 22 Sep 2026 10:01:28 -0300 Subject: [PATCH 10/12] My Jetpack: mock @wordpress/notices in the bulk switch suite use-bulk-feature-switch landed on trunk mocking @wordpress/data wholesale and reaches a file this branch points at the core notices store, so keyedReducer resolves to undefined and the suite cannot run. Same one-liner as its siblings. Co-Authored-By: Claude Opus 5 (1M context) --- .../features/test/use-bulk-feature-switch.test.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/projects/packages/my-jetpack/_inc/components/my-jetpack-tab-panel/features/test/use-bulk-feature-switch.test.tsx b/projects/packages/my-jetpack/_inc/components/my-jetpack-tab-panel/features/test/use-bulk-feature-switch.test.tsx index 81b6ba467bb9..a1e37d43452f 100644 --- a/projects/packages/my-jetpack/_inc/components/my-jetpack-tab-panel/features/test/use-bulk-feature-switch.test.tsx +++ b/projects/packages/my-jetpack/_inc/components/my-jetpack-tab-panel/features/test/use-bulk-feature-switch.test.tsx @@ -18,6 +18,7 @@ jest.mock( '@automattic/jetpack-components', () => ( { } ) ); jest.mock( '@automattic/jetpack-shared-stores', () => ( { store: 'modules-store' } ) ); +jest.mock( '@wordpress/notices', () => ( { store: 'core/notices' } ) ); jest.mock( '@wordpress/data', () => ( { useDispatch: () => ( { fetchModules: mockFetchModules } ), From 5fec96e50786ce9624780f02c61f7c451629d419 Mon Sep 17 00:00:00 2001 From: Christian Gastrell Date: Mon, 28 Sep 2026 13:05:11 -0300 Subject: [PATCH 11/12] VideoPress: send the trim editor's notices to the core store Trunk added useEditSession after this branch; VideoPress no longer mounts GlobalNotices, so its notices would never render. Co-Authored-By: Claude Opus 5.5 --- .../editor/test/editor-screen.test.tsx | 18 ++++++++++++++---- .../editor/test/use-edit-session.test.tsx | 11 +++++------ .../components/editor/use-edit-session.ts | 5 +++-- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/projects/packages/videopress/src/dashboard/components/editor/test/editor-screen.test.tsx b/projects/packages/videopress/src/dashboard/components/editor/test/editor-screen.test.tsx index 620ed6cb5418..ac8f558e5e87 100644 --- a/projects/packages/videopress/src/dashboard/components/editor/test/editor-screen.test.tsx +++ b/projects/packages/videopress/src/dashboard/components/editor/test/editor-screen.test.tsx @@ -1,7 +1,7 @@ /* eslint-disable testing-library/prefer-user-event -- Media, browser navigation, and document shortcuts need native events. */ -import { useGlobalNotices } from '@automattic/jetpack-components/global-notices'; import { act, fireEvent, render, screen, within } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; +import { useDispatch } from '@wordpress/data'; import { useNavigate } from '@wordpress/route'; import { useRestoreOriginal } from '../../../hooks/use-restore-original'; import { useRetryVideoProcessing } from '../../../hooks/use-retry-video-processing'; @@ -13,8 +13,18 @@ import TrimCutEditor from '../editor-screen'; import type { EditsJob, VideoEdits } from '../../../types/edits'; import type { ReactNode } from 'react'; -jest.mock( '@automattic/jetpack-components/global-notices', () => ( { - useGlobalNotices: jest.fn(), +jest.mock( '@wordpress/notices', () => ( { store: 'core/notices' } ) ); +jest.mock( '@wordpress/data', () => ( { + combineReducers: jest.fn( reducers => reducers ), + createReduxStore: jest.fn( () => ( { name: 'mock-store' } ) ), + createSelector: jest.fn( selector => selector ), + keyedReducer: jest.fn( ( _key, reducer ) => reducer ), + register: jest.fn(), + select: jest.fn( () => ( {} ) ), + dispatch: jest.fn( () => ( {} ) ), + useSelect: jest.fn( () => ( {} ) ), + useRegistry: jest.fn( () => ( { select: jest.fn(), dispatch: jest.fn() } ) ), + useDispatch: jest.fn(), } ) ); jest.mock( '@automattic/jetpack-components/admin-page', () => ( { __esModule: true, @@ -159,7 +169,7 @@ beforeEach( () => { jest.clearAllMocks(); confirmNavigation = jest.spyOn( window, 'confirm' ).mockReturnValue( false ); jest.mocked( useNavigate ).mockReturnValue( navigate ); - jest.mocked( useGlobalNotices ).mockReturnValue( { + jest.mocked( useDispatch ).mockReturnValue( { createSuccessNotice: successNotice, createErrorNotice: errorNotice, } as never ); diff --git a/projects/packages/videopress/src/dashboard/components/editor/test/use-edit-session.test.tsx b/projects/packages/videopress/src/dashboard/components/editor/test/use-edit-session.test.tsx index 5190588c496e..d9eb7a16348e 100644 --- a/projects/packages/videopress/src/dashboard/components/editor/test/use-edit-session.test.tsx +++ b/projects/packages/videopress/src/dashboard/components/editor/test/use-edit-session.test.tsx @@ -1,5 +1,5 @@ -import { useGlobalNotices } from '@automattic/jetpack-components/global-notices'; import { act, renderHook } from '@testing-library/react'; +import { useDispatch } from '@wordpress/data'; import { useSyncExternalStore } from 'react'; import { useRestoreOriginal } from '../../../hooks/use-restore-original'; import { EditsConflictError, useSaveVideoEdits } from '../../../hooks/use-save-video-edits'; @@ -9,9 +9,8 @@ import { createTestWrapper } from '../../../test-utils/query-client-wrapper'; import { useEditSession } from '../use-edit-session'; import type { VideoEdits } from '../../../types/edits'; -jest.mock( '@automattic/jetpack-components/global-notices', () => ( { - useGlobalNotices: jest.fn(), -} ) ); +jest.mock( '@wordpress/notices', () => ( { store: 'core/notices' } ) ); +jest.mock( '@wordpress/data', () => ( { useDispatch: jest.fn() } ) ); jest.mock( '../../../hooks/use-video-edits', () => ( { useVideoEdits: jest.fn() } ) ); jest.mock( '../../../hooks/use-restore-original', () => ( { useRestoreOriginal: jest.fn() } ) ); jest.mock( '../../../hooks/use-save-video-edits', () => ( { @@ -55,7 +54,7 @@ beforeEach( () => { job: { id: null, status: 'idle', target_revision: null, progress: null, error: null }, updated: '2026-09-20T00:00:00Z', } ); - jest.mocked( useGlobalNotices ).mockReturnValue( { + jest.mocked( useDispatch ).mockReturnValue( { createSuccessNotice: successNotice, createErrorNotice: errorNotice, } as never ); @@ -125,7 +124,7 @@ describe( 'useEditSession', () => { listeners.delete( notify ); }; }; - jest.mocked( useGlobalNotices ).mockImplementation( () => { + jest.mocked( useDispatch ).mockImplementation( () => { useSyncExternalStore( subscribe, () => version ); return { createErrorNotice: errorNotice, diff --git a/projects/packages/videopress/src/dashboard/components/editor/use-edit-session.ts b/projects/packages/videopress/src/dashboard/components/editor/use-edit-session.ts index c16df3b4ab97..0750f5bd1dd4 100644 --- a/projects/packages/videopress/src/dashboard/components/editor/use-edit-session.ts +++ b/projects/packages/videopress/src/dashboard/components/editor/use-edit-session.ts @@ -1,5 +1,6 @@ -import { useGlobalNotices } from '@automattic/jetpack-components/global-notices'; +import { useDispatch } from '@wordpress/data'; import { __ } from '@wordpress/i18n'; +import { store as noticesStore } from '@wordpress/notices'; import { useCallback, useEffect, useReducer, useRef, useState } from 'react'; import { createHistory, @@ -32,7 +33,7 @@ export function useEditSession( video: LibraryItem ) { const saveMutation = useSaveVideoEdits(); const restoreMutation = useRestoreOriginal(); const retryMutation = useRetryVideoProcessing(); - const notices = useGlobalNotices(); + const notices = useDispatch( noticesStore ); const noticesRef = useRef( notices ); noticesRef.current = notices; const [ history, dispatch ] = useReducer( reducer, video.durationSeconds, duration => From 73f1dda07f5bcd4c06bb4ad0ad2cede308368acc Mon Sep 17 00:00:00 2001 From: Christian Gastrell Date: Mon, 28 Sep 2026 14:06:32 -0300 Subject: [PATCH 12/12] VideoPress: show the trim editor's notices as snackbars Boot renders only snackbar-type notices, so the three trim editor notices dispatched without `type: 'snackbar'` never appeared. Co-Authored-By: Claude Opus 5.5 --- .../components/editor/test/editor-screen.test.tsx | 2 +- .../components/editor/test/use-edit-session.test.tsx | 9 +++++++++ .../src/dashboard/components/editor/use-edit-session.ts | 9 ++++++--- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/projects/packages/videopress/src/dashboard/components/editor/test/editor-screen.test.tsx b/projects/packages/videopress/src/dashboard/components/editor/test/editor-screen.test.tsx index ac8f558e5e87..7daf39412abb 100644 --- a/projects/packages/videopress/src/dashboard/components/editor/test/editor-screen.test.tsx +++ b/projects/packages/videopress/src/dashboard/components/editor/test/editor-screen.test.tsx @@ -274,7 +274,7 @@ it( 'submits the current edits against their loaded revision and waits for the c job: { ...processingJob, status: 'complete' }, } ); refresh(); - expect( successNotice ).toHaveBeenCalledWith( 'Video edits applied.' ); + expect( successNotice ).toHaveBeenCalledWith( 'Video edits applied.', { type: 'snackbar' } ); expect( screen.getByRole( 'button', { name: 'Save' } ) ).toHaveAttribute( 'aria-disabled', 'true' diff --git a/projects/packages/videopress/src/dashboard/components/editor/test/use-edit-session.test.tsx b/projects/packages/videopress/src/dashboard/components/editor/test/use-edit-session.test.tsx index d9eb7a16348e..41761686781a 100644 --- a/projects/packages/videopress/src/dashboard/components/editor/test/use-edit-session.test.tsx +++ b/projects/packages/videopress/src/dashboard/components/editor/test/use-edit-session.test.tsx @@ -113,6 +113,7 @@ describe( 'useEditSession', () => { expect( result.current.locked ).toBe( false ); expect( result.current.history.past ).toHaveLength( 0 ); expect( successNotice ).toHaveBeenCalledTimes( 1 ); + expect( successNotice ).toHaveBeenCalledWith( expect.any( String ), { type: 'snackbar' } ); } ); it( 'handles completion once when publishing a notice synchronously updates an external store', async () => { @@ -225,6 +226,14 @@ describe( 'useEditSession', () => { expect( errorNotice ).not.toHaveBeenCalled(); } ); + it( 'reports a failed save as a snackbar', async () => { + save.mockRejectedValue( new Error( 'boom' ) ); + const { result } = renderSession(); + trim( result ); + await act( async () => result.current.submit() ); + expect( errorNotice ).toHaveBeenCalledWith( expect.any( String ), { type: 'snackbar' } ); + } ); + it( 'prevents duplicate submissions before React commits the pending state', async () => { const { result } = renderSession(); trim( result ); diff --git a/projects/packages/videopress/src/dashboard/components/editor/use-edit-session.ts b/projects/packages/videopress/src/dashboard/components/editor/use-edit-session.ts index 0750f5bd1dd4..1c7d264e2aed 100644 --- a/projects/packages/videopress/src/dashboard/components/editor/use-edit-session.ts +++ b/projects/packages/videopress/src/dashboard/components/editor/use-edit-session.ts @@ -101,7 +101,8 @@ export function useEditSession( video: LibraryItem ) { if ( edits.job.status === 'complete' ) { adopt( edits ); noticesRef.current.createSuccessNotice( - __( 'Video edits applied.', 'jetpack-videopress-pkg' ) + __( 'Video edits applied.', 'jetpack-videopress-pkg' ), + { type: 'snackbar' } ); } } else if ( ! currentBaseline ) { @@ -157,7 +158,8 @@ export function useEditSession( video: LibraryItem ) { setConflict( true ); } else { noticesRef.current.createErrorNotice( - __( 'Unable to apply video edits. Please try again.', 'jetpack-videopress-pkg' ) + __( 'Unable to apply video edits. Please try again.', 'jetpack-videopress-pkg' ), + { type: 'snackbar' } ); } } finally { @@ -183,7 +185,8 @@ export function useEditSession( video: LibraryItem ) { setPending( response ); } catch { noticesRef.current.createErrorNotice( - __( 'Unable to retry processing. Please try again.', 'jetpack-videopress-pkg' ) + __( 'Unable to retry processing. Please try again.', 'jetpack-videopress-pkg' ), + { type: 'snackbar' } ); void query.refetch(); } finally {