diff --git a/projects/js-packages/base-styles/admin-page-layout.scss b/projects/js-packages/base-styles/admin-page-layout.scss index a95a66439f1b..1eb253685bb2 100644 --- a/projects/js-packages/base-styles/admin-page-layout.scss +++ b/projects/js-packages/base-styles/admin-page-layout.scss @@ -31,6 +31,7 @@ // `Tabs.List`; see the // "Tabs strip" section // below) +// Tabs marker: .jp-admin-page-has-tabs (see "Tabs strip" below) // Implementation note — `postcss-custom-properties` with `preserve: false`: // several consumer packages in this monorepo (publicize, videopress, search, @@ -222,14 +223,12 @@ $jp-breakpoint-mobile: 782px; flex-shrink: 0; // pinned at top of the flex column. } - // When the page hosts a tabs strip, drop the header's bottom border AND - // its bottom padding so the strip sits flush against the header. The - // strip's own hairline becomes the only divider between header and tab - // content. Same `:has()` pattern used elsewhere in this mixin to react - // to the page's content shape. - .jp-admin-page__page:has(.jp-admin-page-tabs) > :first-child { + // When the page hosts a tabs strip, drop the header's bottom border so the + // strip's own hairline is the only divider. Leave its padding: removing that + // spaced these pages differently from the rest. `.jp-admin-page-has-tabs` is + // the style-free marker for a strip that is not `.jp-admin-page-tabs`. + .jp-admin-page__page:has(.jp-admin-page-tabs, .jp-admin-page-has-tabs) > :first-child { border-bottom: none; - padding-bottom: 0; } // The scrollable middle. does not pass `hasPadding` to @@ -255,7 +254,9 @@ $jp-breakpoint-mobile: 782px; // fill their bounded slot. Form-style pages keep working: their // children stay content-sized (default `flex: 0 1 auto`) and any // overflow still falls back to Container's `overflow: auto`. - .jp-admin-page__page > :not(:first-child):not(.jetpack-footer) { + // The JITM slot is chrome, not the middle: excluded so it is not made the + // scrollable area, which would force its card into a column. + .jp-admin-page__page > :not(:first-child):not(.jetpack-footer):not(.jp-jitm-slot) { flex: 1 1 auto; min-height: 0; min-width: 0; diff --git a/projects/js-packages/base-styles/changelog/add-header-padding-tabbed-pages b/projects/js-packages/base-styles/changelog/add-header-padding-tabbed-pages new file mode 100644 index 000000000000..86493a7fa95c --- /dev/null +++ b/projects/js-packages/base-styles/changelog/add-header-padding-tabbed-pages @@ -0,0 +1,4 @@ +Significance: patch +Type: fixed + +Keep the page header's bottom padding on dashboards that have a tabs strip. diff --git a/projects/js-packages/base-styles/changelog/add-jitm-slot-all-layouts b/projects/js-packages/base-styles/changelog/add-jitm-slot-all-layouts new file mode 100644 index 000000000000..40d4dcc3b9a2 --- /dev/null +++ b/projects/js-packages/base-styles/changelog/add-jitm-slot-all-layouts @@ -0,0 +1,4 @@ +Significance: patch +Type: fixed + +Keep the Jetpack in-dashboard message slot out of the scrollable page middle. diff --git a/projects/js-packages/base-styles/changelog/add-tabs-marker-header-border b/projects/js-packages/base-styles/changelog/add-tabs-marker-header-border new file mode 100644 index 000000000000..d33be935bac6 --- /dev/null +++ b/projects/js-packages/base-styles/changelog/add-tabs-marker-header-border @@ -0,0 +1,4 @@ +Significance: patch +Type: fixed + +Drop the page header's bottom border on dashboards whose tabs strip is not the shared one. diff --git a/projects/js-packages/components/changelog/add-jitm-slot-all-layouts b/projects/js-packages/components/changelog/add-jitm-slot-all-layouts new file mode 100644 index 000000000000..9425cbcfba85 --- /dev/null +++ b/projects/js-packages/components/changelog/add-jitm-slot-all-layouts @@ -0,0 +1,4 @@ +Significance: minor +Type: added + +Add a JitmSlot component so every dashboard renders the Jetpack in-dashboard message slot the same way, and keeps the message across route changes. diff --git a/projects/js-packages/components/components/jitm-slot/index.tsx b/projects/js-packages/components/components/jitm-slot/index.tsx new file mode 100644 index 000000000000..f226f2014a78 --- /dev/null +++ b/projects/js-packages/components/components/jitm-slot/index.tsx @@ -0,0 +1,67 @@ +import clsx from 'clsx'; +import { useLayoutEffect, useRef } from 'react'; +import './style.scss'; +import type { JitmSlotProps } from './types.ts'; +import type { FC } from 'react'; + +const NOTICES_ID = 'jp-admin-notices'; + +/** + * Returns the page's one `#jp-admin-notices`, creating it on first use. + * + * Found through the DOM, not a module variable: each wp-build route bundles its own copy + * of this module. + * + * @return {HTMLElement} The element. + */ +const getNotices = (): HTMLElement => { + let element = document.getElementById( NOTICES_ID ); + if ( ! element ) { + element = document.createElement( 'div' ); + element.id = NOTICES_ID; + } + return element; +}; + +/** + * Hosts the element the JITM script re-parents its card into. + * + * The JITM script places its card once per page load, so the element outlives any + * one slot: an unmounted slot parks it, hidden, and the next slot takes it back. + * `className` is for width and alignment; `style.scss` owns spacing. + * + * @param {JitmSlotProps} props - Component props. + * @return {JSX.Element} The slot. + */ +const JitmSlot: FC< JitmSlotProps > = ( { className, inset } ) => { + const ref = useRef< HTMLDivElement >( null ); + + useLayoutEffect( () => { + const host = ref.current; + if ( ! host ) { + return; + } + + const element = getNotices(); + element.hidden = false; + host.appendChild( element ); + + return () => { + // A slot that mounted before this one unmounted may already hold it. + if ( element.parentNode === host ) { + element.hidden = true; + document.body.appendChild( element ); + } + }; + }, [] ); + + return ( +
+ ); +}; + +export default JitmSlot; diff --git a/projects/js-packages/components/components/jitm-slot/style.scss b/projects/js-packages/components/components/jitm-slot/style.scss new file mode 100644 index 000000000000..881ce13319c9 --- /dev/null +++ b/projects/js-packages/components/components/jitm-slot/style.scss @@ -0,0 +1,16 @@ +// The slot is always rendered and usually empty, so it takes no space +// of its own; spacing sits on the card so a dismissed one leaves no gap. +.jp-jitm-slot { + margin: 0; + padding: 0; + + // `jitm-card` comes from packages/jitm/src/js/jetpack-jitm.js. + .jitm-card { + margin: var(--wpds-dimension-gap-xl) 0; + } +} + +// Same specificity as the rule above, so it has to come after it. +.jp-jitm-slot--inset .jitm-card { + margin-inline: var(--wpds-dimension-padding-2xl); +} diff --git a/projects/js-packages/components/components/jitm-slot/test/index.test.tsx b/projects/js-packages/components/components/jitm-slot/test/index.test.tsx new file mode 100644 index 000000000000..bfd720bcc842 --- /dev/null +++ b/projects/js-packages/components/components/jitm-slot/test/index.test.tsx @@ -0,0 +1,73 @@ +/* eslint-disable testing-library/no-node-access -- The slot adopts an element it did not render. */ +import { render, screen } from '@testing-library/react'; +import JitmSlot from '../index.tsx'; + +describe( 'JitmSlot', () => { + it( 'holds the element the JITM script looks for', () => { + render( ); + + // `#jp-admin-notices` is the contract with packages/jitm's script, not a style hook. + expect( screen.getByTestId( 'jp-jitm-slot' ) ).toContainElement( + document.getElementById( 'jp-admin-notices' ) + ); + } ); + + it( 'keeps its own class when given another', () => { + render( ); + const slot = screen.getByTestId( 'jp-jitm-slot' ); + + expect( slot ).toHaveClass( 'jp-jitm-slot' ); + expect( slot ).toHaveClass( 'jetpack-backup-jitm-card' ); + } ); + + it( 'takes the page gutter when inset', () => { + render( ); + + expect( screen.getByTestId( 'jp-jitm-slot' ) ).toHaveClass( 'jp-jitm-slot--inset' ); + } ); + + it( 'renders empty, so a page with no message shows nothing', () => { + render( ); + + expect( document.getElementById( 'jp-admin-notices' ) ).toBeEmptyDOMElement(); + } ); + + it( 'hands a placed card to the next slot after a remount', () => { + const { unmount } = render( ); + const card = document.createElement( 'div' ); + document.getElementById( 'jp-admin-notices' ).append( card ); + + unmount(); + expect( card ).not.toBeVisible(); + + render( ); + + expect( screen.getByTestId( 'jp-jitm-slot' ) ).toContainElement( card ); + expect( card ).toBeVisible(); + card.remove(); + } ); + + it( 'adopts the element a slot from another bundle parked', () => { + document.getElementById( 'jp-admin-notices' )?.remove(); + const parked = document.createElement( 'div' ); + parked.id = 'jp-admin-notices'; + parked.hidden = true; + document.body.append( parked ); + + render( ); + + expect( screen.getByTestId( 'jp-jitm-slot' ) ).toContainElement( parked ); + expect( parked ).toBeVisible(); + } ); + + it( 'leaves the element with a slot that mounted before this one unmounted', () => { + const { unmount } = render( ); + render( ); + + unmount(); + + expect( document.querySelector( '.incoming' ) ).toContainElement( + document.getElementById( 'jp-admin-notices' ) + ); + } ); +} ); diff --git a/projects/js-packages/components/components/jitm-slot/types.ts b/projects/js-packages/components/components/jitm-slot/types.ts new file mode 100644 index 000000000000..db603aedbe30 --- /dev/null +++ b/projects/js-packages/components/components/jitm-slot/types.ts @@ -0,0 +1,10 @@ +export type JitmSlotProps = { + /** + * Layout the dashboard owns: width, column span, centering. Not spacing. + */ + className?: string; + /** + * The slot sits outside the page's padded container, so the card takes the page gutter. + */ + inset?: boolean; +}; diff --git a/projects/js-packages/components/index.ts b/projects/js-packages/components/index.ts index baa996d92b90..69633d5ded0f 100644 --- a/projects/js-packages/components/index.ts +++ b/projects/js-packages/components/index.ts @@ -35,6 +35,7 @@ export { default as Col } from './components/layout/col/index.tsx'; export { default as Testimonials } from './components/testimonials/index.tsx'; export { default as Container } from './components/layout/container/index.tsx'; export { default as CopyToClipboard } from './components/copy-to-clipboard/index.tsx'; +export { default as JitmSlot } from './components/jitm-slot/index.tsx'; export * from './components/icons/index.tsx'; export { default as ThemeProvider } from './components/theme-provider/index.tsx'; export { default as Text, H2, H3, Title } from './components/text/index.tsx'; diff --git a/projects/js-packages/components/package.json b/projects/js-packages/components/package.json index 96772f5f93b2..47f3927cb590 100644 --- a/projects/js-packages/components/package.json +++ b/projects/js-packages/components/package.json @@ -53,6 +53,11 @@ "types": "./build/components/jetpack-logo/index.d.ts", "default": "./build/components/jetpack-logo/index.js" }, + "./jitm-slot": { + "jetpack:src": "./components/jitm-slot/index.tsx", + "types": "./build/components/jitm-slot/index.d.ts", + "default": "./build/components/jitm-slot/index.js" + }, "./pricing-table": { "jetpack:src": "./components/pricing-table/index.tsx", "types": "./build/components/pricing-table/index.d.ts", diff --git a/projects/packages/backup/changelog/add-jitm-slot-all-layouts b/projects/packages/backup/changelog/add-jitm-slot-all-layouts new file mode 100644 index 000000000000..87f14bb43277 --- /dev/null +++ b/projects/packages/backup/changelog/add-jitm-slot-all-layouts @@ -0,0 +1,4 @@ +Significance: patch +Type: fixed + +Show Jetpack in-dashboard messages on the modernized dashboard. diff --git a/projects/packages/backup/composer.json b/projects/packages/backup/composer.json index f3d7d4cfd245..52a58f96efb4 100644 --- a/projects/packages/backup/composer.json +++ b/projects/packages/backup/composer.json @@ -13,6 +13,7 @@ "automattic/jetpack-config": "@dev", "automattic/jetpack-connection": "@dev", "automattic/jetpack-constants": "@dev", + "automattic/jetpack-jitm": "@dev", "automattic/jetpack-my-jetpack": "@dev", "automattic/jetpack-sync": "@dev", "automattic/jetpack-status": "@dev", diff --git a/projects/packages/backup/src/class-jetpack-backup.php b/projects/packages/backup/src/class-jetpack-backup.php index c6376e15c372..dc89c77178e6 100644 --- a/projects/packages/backup/src/class-jetpack-backup.php +++ b/projects/packages/backup/src/class-jetpack-backup.php @@ -24,6 +24,7 @@ use Automattic\Jetpack\Connection\Manager as Connection_Manager; use Automattic\Jetpack\Connection\Rest_Authentication as Connection_Rest_Authentication; use Automattic\Jetpack\Constants; +use Automattic\Jetpack\JITMS\JITM; use Automattic\Jetpack\My_Jetpack\Wpcom_Products; use Automattic\Jetpack\Status; use Automattic\Jetpack\Terms_Of_Service; @@ -250,13 +251,14 @@ public static function admin_init() { add_action( 'admin_enqueue_scripts', array( __CLASS__, 'enqueue_admin_scripts' ) ); if ( self::is_wp_build_dashboard_active() ) { - // The modernized Backup overview is a focused, full-screen product - // surface. Suppress JITMs and other core/plugin admin notices so they - // don't reflow on top of the dual-pane layout. Mirrors how Jetpack - // Forms handles its dashboard page - // (`plugins/forms/src/dashboard/class-dashboard.php`). - remove_all_actions( 'admin_notices' ); - remove_all_actions( 'all_admin_notices' ); + // Notices reflow the dual-pane layout, so clear them but keep our own. + // An older jetpack-jitm may predate the helper; the fallback costs the JITM. + if ( method_exists( JITM::class, 'suppress_foreign_admin_notices' ) ) { + JITM::suppress_foreign_admin_notices(); + } else { + remove_all_actions( 'admin_notices' ); + remove_all_actions( 'all_admin_notices' ); + } } } diff --git a/projects/packages/backup/src/dashboard/components/dashboard-layout/index.tsx b/projects/packages/backup/src/dashboard/components/dashboard-layout/index.tsx index fff9515985e2..3f4ceacbbd65 100644 --- a/projects/packages/backup/src/dashboard/components/dashboard-layout/index.tsx +++ b/projects/packages/backup/src/dashboard/components/dashboard-layout/index.tsx @@ -1,5 +1,6 @@ import JetpackFooter from '@automattic/jetpack-components/jetpack-footer'; import JetpackLogo from '@automattic/jetpack-components/jetpack-logo'; +import JitmSlot from '@automattic/jetpack-components/jitm-slot'; import { Page } from '@wordpress/admin-ui'; import { __ } from '@wordpress/i18n'; import Gates from '../gates'; @@ -52,6 +53,7 @@ export default function DashboardLayout( { children, actions }: Props ) { >
+ { children }
diff --git a/projects/packages/backup/src/dashboard/components/dashboard-layout/style.scss b/projects/packages/backup/src/dashboard/components/dashboard-layout/style.scss index e4857c099270..cc743b342977 100644 --- a/projects/packages/backup/src/dashboard/components/dashboard-layout/style.scss +++ b/projects/packages/backup/src/dashboard/components/dashboard-layout/style.scss @@ -15,3 +15,9 @@ padding: 24px; } } + +// The body already pads the top, so drop the slot's own leading margin +// and keep the gap above the card the same as on every other dashboard. +.jpb-dashboard-body__inner > .jp-jitm-slot .jitm-card { + margin-block-start: 0; +} diff --git a/projects/packages/backup/tests/php/Admin_Notices_Suppression_Test.php b/projects/packages/backup/tests/php/Admin_Notices_Suppression_Test.php new file mode 100644 index 000000000000..5fdbb679c583 --- /dev/null +++ b/projects/packages/backup/tests/php/Admin_Notices_Suppression_Test.php @@ -0,0 +1,165 @@ +foreign_notice = static function () { + echo 'third-party upsell'; + }; + + set_current_screen( self::SCREEN_ID ); + $_GET['page'] = Jetpack_Backup::JETPACK_BACKUP_SLUG; + + add_filter( Jetpack_Backup::MODERNIZATION_FILTER, '__return_true' ); + } + + public function tearDown(): void { + remove_all_filters( Jetpack_Backup::MODERNIZATION_FILTER ); + remove_all_actions( 'admin_notices' ); + remove_all_actions( 'all_admin_notices' ); + remove_all_actions( 'admin_enqueue_scripts' ); + + unset( $_GET['page'] ); + set_current_screen( 'front' ); + + parent::tearDown(); + } + + /** + * Registers one foreign callback and one belonging to a JITM instance. + * + * @return array{0: callable, 1: array} The foreign callback and the JITM one. + */ + private function register_both_notices() { + // WordPress registers its own `admin_notices` callbacks; the cases below are + // about which of OUR two survive, so start from an empty hook. + remove_all_actions( 'admin_notices' ); + + $jitm = JITM::get_instance(); + $jitm_callback = array( $jitm, 'ajax_message' ); + + add_action( 'admin_notices', $this->foreign_notice ); + add_action( 'admin_notices', $jitm_callback ); + + return array( $this->foreign_notice, $jitm_callback ); + } + + /** + * @dataProvider provide_notice_hooks + * + * @param string $hook Hook the foreign notice is registered on. + */ + #[DataProvider( 'provide_notice_hooks' )] + public function test_modern_dashboard_drops_a_third_party_notice( $hook ) { + $this->register_both_notices(); + add_action( $hook, $this->foreign_notice ); + + Jetpack_Backup::admin_init(); + + $this->assertFalse( + has_action( $hook, $this->foreign_notice ), + "Another plugin's notice must not survive onto the modernized dashboard." + ); + } + + /** + * @return array + */ + public static function provide_notice_hooks() { + return array( + 'admin_notices' => array( 'admin_notices' ), + 'all_admin_notices' => array( 'all_admin_notices' ), + ); + } + + public function test_modern_dashboard_keeps_the_jitm_notice() { + list( , $jitm_callback ) = $this->register_both_notices(); + + Jetpack_Backup::admin_init(); + + $this->assertNotFalse( + has_action( 'admin_notices', $jitm_callback ), + 'JITMs are a first-party channel and must survive the suppression.' + ); + } + + public function test_legacy_dashboard_suppresses_nothing() { + remove_all_filters( Jetpack_Backup::MODERNIZATION_FILTER ); + add_filter( Jetpack_Backup::MODERNIZATION_FILTER, '__return_false' ); + + list( $foreign, $jitm_callback ) = $this->register_both_notices(); + + Jetpack_Backup::admin_init(); + + $this->assertNotFalse( has_action( 'admin_notices', $foreign ) ); + $this->assertNotFalse( has_action( 'admin_notices', $jitm_callback ) ); + } + + public function test_a_screen_that_opted_out_of_jitms_gets_none_back() { + remove_all_actions( 'admin_notices' ); + add_action( 'admin_notices', $this->foreign_notice ); + + Jetpack_Backup::admin_init(); + + $this->assertSame( + array(), + $this->registered_admin_notice_callbacks(), + 'With no JITM hooked, suppression must leave the hook empty rather than inventing one.' + ); + } + + /** + * @return array Callbacks currently on `admin_notices`. + */ + private function registered_admin_notice_callbacks() { + global $wp_filter; + + if ( ! isset( $wp_filter['admin_notices'] ) ) { + return array(); + } + + $found = array(); + foreach ( $wp_filter['admin_notices']->callbacks as $callbacks ) { + foreach ( $callbacks as $callback ) { + $found[] = $callback['function']; + } + } + + return $found; + } +} diff --git a/projects/packages/forms/changelog/add-jitm-slot-all-layouts b/projects/packages/forms/changelog/add-jitm-slot-all-layouts new file mode 100644 index 000000000000..65723a1daf66 --- /dev/null +++ b/projects/packages/forms/changelog/add-jitm-slot-all-layouts @@ -0,0 +1,4 @@ +Significance: patch +Type: fixed + +Show Jetpack in-dashboard messages on the Forms dashboard. diff --git a/projects/packages/forms/changelog/add-tabs-marker-header-border b/projects/packages/forms/changelog/add-tabs-marker-header-border new file mode 100644 index 000000000000..de1a5db1c504 --- /dev/null +++ b/projects/packages/forms/changelog/add-tabs-marker-header-border @@ -0,0 +1,4 @@ +Significance: patch +Type: fixed + +Remove the duplicate divider between the dashboard header and the tabs. diff --git a/projects/packages/forms/src/dashboard/wp-build/components/dataviews-header-row/index.tsx b/projects/packages/forms/src/dashboard/wp-build/components/dataviews-header-row/index.tsx index cc9d7416b813..7246ff15cbec 100644 --- a/projects/packages/forms/src/dashboard/wp-build/components/dataviews-header-row/index.tsx +++ b/projects/packages/forms/src/dashboard/wp-build/components/dataviews-header-row/index.tsx @@ -1,6 +1,7 @@ /** * External dependencies */ +import JitmSlot from '@automattic/jetpack-components/jitm-slot'; import { formatNumberCompact } from '@automattic/number-formatters'; /** * WordPress dependencies @@ -85,7 +86,10 @@ export default function DataViewsHeaderRow( { return ( <> - + { isSingleFormView ? ( + ); diff --git a/projects/packages/forms/src/dashboard/wp-build/style.scss b/projects/packages/forms/src/dashboard/wp-build/style.scss index cdbf576419bd..ad6e179ad00a 100644 --- a/projects/packages/forms/src/dashboard/wp-build/style.scss +++ b/projects/packages/forms/src/dashboard/wp-build/style.scss @@ -67,8 +67,10 @@ body.jetpack-forms-responses { flex: 1 1 auto; min-block-size: 0; + // The JITM slot is chrome like the toolbar and footer: natural height. .jp-forms-dataviews__view-actions, .jp-forms-dataviews-filters__container, + .jp-jitm-slot, .dataviews-footer { flex: 0 0 auto; min-block-size: 0; diff --git a/projects/packages/jitm/changelog/add-jitm-slot-all-layouts b/projects/packages/jitm/changelog/add-jitm-slot-all-layouts new file mode 100644 index 000000000000..c459cd6d6d44 --- /dev/null +++ b/projects/packages/jitm/changelog/add-jitm-slot-all-layouts @@ -0,0 +1,4 @@ +Significance: minor +Type: added + +Add a helper that clears admin notices from a screen while keeping Jetpack in-dashboard messages. diff --git a/projects/packages/jitm/src/class-jitm.php b/projects/packages/jitm/src/class-jitm.php index 8c1689d34728..cae4234e5f04 100644 --- a/projects/packages/jitm/src/class-jitm.php +++ b/projects/packages/jitm/src/class-jitm.php @@ -117,6 +117,65 @@ private static function get_configured_instance() { return self::$configured_instance; } + /** + * Clears admin notices from the current screen, keeping JITMs. + * + * A screen that opted out through `jetpack_display_jitms_on_screen` has nothing + * to keep, so it stays silent. + * + * @since $$next-version$$ + * + * @return void + */ + public static function suppress_foreign_admin_notices() { + foreach ( array( 'admin_notices', 'all_admin_notices' ) as $hook ) { + $ours = self::collect_own_callbacks( $hook ); + + remove_all_actions( $hook ); + + foreach ( $ours as $priority => $callbacks ) { + foreach ( $callbacks as $callback ) { + add_action( $hook, $callback['function'], $priority, $callback['accepted_args'] ); + } + } + } + } + + /** + * Returns our callbacks on $hook, keyed by priority. + * + * Matched by class: `prepare_jitms()` hooks the cached instance and + * `get_instance()` builds a fresh one, so comparing objects would miss. + * + * @since $$next-version$$ + * + * @param string $hook Hook name. + * @return array> + */ + private static function collect_own_callbacks( $hook ) { + global $wp_filter; + + $kept = array(); + + if ( ! isset( $wp_filter[ $hook ] ) || ! is_object( $wp_filter[ $hook ] ) ) { + return $kept; + } + + foreach ( $wp_filter[ $hook ]->callbacks as $priority => $callbacks ) { + foreach ( $callbacks as $callback ) { + if ( + is_array( $callback['function'] ) + && isset( $callback['function'][0] ) + && $callback['function'][0] instanceof self + ) { + $kept[ $priority ][] = $callback; + } + } + } + + return $kept; + } + /** * Sets up JITM action callbacks if needed. */ diff --git a/projects/packages/my-jetpack/_inc/components/my-jetpack-screen/index.jsx b/projects/packages/my-jetpack/_inc/components/my-jetpack-screen/index.jsx index c0d190d13ec0..f6c9fa004c62 100644 --- a/projects/packages/my-jetpack/_inc/components/my-jetpack-screen/index.jsx +++ b/projects/packages/my-jetpack/_inc/components/my-jetpack-screen/index.jsx @@ -2,6 +2,7 @@ * External dependencies */ import { ActionButton, AdminPage, Col, Container } from '@automattic/jetpack-components'; +import JitmSlot from '@automattic/jetpack-components/jitm-slot'; import { isSimpleSite } from '@automattic/jetpack-script-data'; import { __ } from '@wordpress/i18n'; import { Notice } from '@wordpress/ui'; @@ -196,12 +197,10 @@ export default function MyJetpackScreen() { - { /* No snackbar list here: the wp-build page shell already renders the - notices store, and a second list showed every notice twice. */ } { ! isNewUser && ( -
+ ) } diff --git a/projects/packages/my-jetpack/changelog/add-jitm-slot-all-layouts b/projects/packages/my-jetpack/changelog/add-jitm-slot-all-layouts new file mode 100644 index 000000000000..81b8d3e8ffcb --- /dev/null +++ b/projects/packages/my-jetpack/changelog/add-jitm-slot-all-layouts @@ -0,0 +1,4 @@ +Significance: patch +Type: changed + +Render the Jetpack in-dashboard message slot from the shared component. diff --git a/projects/packages/newsletter/_inc/components/newsletter-page.tsx b/projects/packages/newsletter/_inc/components/newsletter-page.tsx index 549f982b6bcf..7c2b3b668d8a 100644 --- a/projects/packages/newsletter/_inc/components/newsletter-page.tsx +++ b/projects/packages/newsletter/_inc/components/newsletter-page.tsx @@ -1,4 +1,5 @@ import AdminPage from '@automattic/jetpack-components/admin-page'; +import JitmSlot from '@automattic/jetpack-components/jitm-slot'; import { getSiteData } from '@automattic/jetpack-script-data'; import { useCallback } from '@wordpress/element'; import { __ } from '@wordpress/i18n'; @@ -109,6 +110,13 @@ export default function NewsletterPage( { ? 'jetpack-newsletter-page__content jetpack-newsletter-page__content--padded' : 'jetpack-newsletter-page__content'; + const content = ( + <> + +
{ children }
+ + ); + return ( { __( 'Settings', 'jetpack-newsletter' ) }
-
{ children }
+ { content } ) : ( -
{ children }
+ content ) } ); diff --git a/projects/packages/newsletter/changelog/add-jitm-slot-all-layouts b/projects/packages/newsletter/changelog/add-jitm-slot-all-layouts new file mode 100644 index 000000000000..1d258e99c845 --- /dev/null +++ b/projects/packages/newsletter/changelog/add-jitm-slot-all-layouts @@ -0,0 +1,4 @@ +Significance: patch +Type: fixed + +Show Jetpack in-dashboard messages on the dashboard again. diff --git a/projects/packages/newsletter/src/class-settings.php b/projects/packages/newsletter/src/class-settings.php index b5f344991e6f..5524de695199 100644 --- a/projects/packages/newsletter/src/class-settings.php +++ b/projects/packages/newsletter/src/class-settings.php @@ -58,13 +58,6 @@ class Settings { */ private static $wp_build_original_screen_id = null; - /** - * The dashboard screen hide_jitms_on_wp_build_dashboard() opts out of JITMs. - * - * @var string|null - */ - private static $jitm_opt_out_screen_id = null; - /** * Register Newsletter feature flags. * @@ -292,7 +285,6 @@ public function add_wp_admin_menu() { if ( $page_suffix ) { add_action( 'load-' . $page_suffix, array( $this, 'admin_init' ) ); - self::maybe_opt_out_of_jitms( $page_suffix ); } } @@ -326,7 +318,6 @@ public function add_wp_admin_submenu() { if ( $page_suffix ) { add_action( 'load-' . $page_suffix, array( $this, 'admin_init' ) ); - self::maybe_opt_out_of_jitms( $page_suffix ); } } @@ -649,41 +640,6 @@ public static function restore_screen_id_after_wp_build() { self::$wp_build_original_screen_id = null; } - /** - * Opt the dashboard's screen out of JITMs while the wp-build dashboard serves it. - * - * @param string $screen_id The hook suffix the page was registered under, which is its screen ID. - * @return void - */ - private static function maybe_opt_out_of_jitms( $screen_id ) { - // The legacy dashboard renders `#jp-admin-notices`, so it keeps its JITMs. - if ( ! self::is_modernized() ) { - return; - } - - self::$jitm_opt_out_screen_id = $screen_id; - add_filter( 'jetpack_display_jitms_on_screen', array( __CLASS__, 'hide_jitms_on_wp_build_dashboard' ), 10, 2 ); - } - - /** - * Keep JITMs off the wp-build dashboard, which has no `#jp-admin-notices` to show them in. - * - * Fetching a JITM records a view, so one the page hides would still be counted. - * - * @since 0.16.0 - * - * @param bool $show Whether to show JITMs on the screen. - * @param string $screen_id The screen ID. - * @return bool - */ - public static function hide_jitms_on_wp_build_dashboard( $show, $screen_id ) { - if ( null !== self::$jitm_opt_out_screen_id && self::$jitm_opt_out_screen_id === $screen_id ) { - return false; - } - - return $show; - } - /** * Returns true when the wp-build modernization filter is enabled. * diff --git a/projects/packages/newsletter/tests/php/Settings_Test.php b/projects/packages/newsletter/tests/php/Settings_Test.php index 00111ec9c26f..ae7b2d2105e0 100644 --- a/projects/packages/newsletter/tests/php/Settings_Test.php +++ b/projects/packages/newsletter/tests/php/Settings_Test.php @@ -61,7 +61,6 @@ public function set_up() { // Clear the load action registered by add_wp_admin_menu on success. remove_all_actions( 'load-jetpack_page_jetpack-newsletter' ); remove_all_actions( 'load-admin_page_jetpack-newsletter' ); - remove_filter( 'jetpack_display_jitms_on_screen', array( Settings::class, 'hide_jitms_on_wp_build_dashboard' ) ); } /** @@ -83,7 +82,6 @@ public function tear_down() { remove_all_filters( Settings::MODERNIZATION_FILTER ); remove_all_filters( 'jetpack_show_newsletter_menu_item' ); - remove_filter( 'jetpack_display_jitms_on_screen', array( Settings::class, 'hide_jitms_on_wp_build_dashboard' ) ); remove_all_filters( 'site_url' ); remove_all_filters( 'home_url' ); remove_all_filters( 'jetpack_feature_flag_enabled' ); @@ -567,22 +565,9 @@ public function test_alias_screen_id_round_trip() { } /** - * The wp-build dashboard opts its own screen out of JITMs, and no other. + * A hidden menu item registers under another screen ID. */ - public function test_modernized_dashboard_opts_its_screen_out_of_jitms() { - $this->connect_site_with_subscriptions(); - - ( new Settings() )->add_wp_admin_menu(); - - $this->assertFalse( apply_filters( 'jetpack_display_jitms_on_screen', true, 'jetpack_page_jetpack-newsletter' ) ); - $this->assertTrue( apply_filters( 'jetpack_display_jitms_on_screen', true, 'jetpack_page_jetpack-social' ) ); - $this->assertFalse( apply_filters( 'jetpack_display_jitms_on_screen', false, 'jetpack_page_jetpack-social' ) ); - } - - /** - * A hidden menu item registers under another screen ID, and that is the one opted out. - */ - public function test_hidden_menu_item_opts_its_own_screen_out_of_jitms() { + public function test_hidden_menu_item_registers_under_its_own_screen() { $this->connect_site_with_subscriptions(); wp_set_current_user( wp_insert_user( @@ -599,12 +584,18 @@ public function test_hidden_menu_item_opts_its_own_screen_out_of_jitms() { $settings->add_wp_admin_menu(); $this->assertNotFalse( has_action( 'load-admin_page_jetpack-newsletter', array( $settings, 'admin_init' ) ) ); - $this->assertFalse( apply_filters( 'jetpack_display_jitms_on_screen', true, 'admin_page_jetpack-newsletter' ) ); - $this->assertTrue( apply_filters( 'jetpack_display_jitms_on_screen', true, 'jetpack_page_jetpack-newsletter' ) ); } - public function test_legacy_dashboard_keeps_jitms() { + /** + * Both dashboards render the JITM slot, so neither opts its screen out. + */ + public function test_dashboard_keeps_jitms() { $this->connect_site_with_subscriptions(); + + ( new Settings() )->add_wp_admin_menu(); + + $this->assertTrue( apply_filters( 'jetpack_display_jitms_on_screen', true, 'jetpack_page_jetpack-newsletter' ) ); + add_filter( Settings::MODERNIZATION_FILTER, '__return_false' ); ( new Settings() )->add_wp_admin_menu(); diff --git a/projects/packages/publicize/_inc/components/social-page.scss b/projects/packages/publicize/_inc/components/social-page.scss index cd96d17e2d92..e5e503efc7f4 100644 --- a/projects/packages/publicize/_inc/components/social-page.scss +++ b/projects/packages/publicize/_inc/components/social-page.scss @@ -33,20 +33,4 @@ body.toplevel_page_jetpack-social { .jetpack-social-page__content--padded { padding: $jetpack-social-inset; } - - // Line the JITM card up with the Overview and Settings columns. - .jetpack-social-jitm-card { - margin-inline: auto; - max-inline-size: 720px; - inline-size: 100%; - - &--settings { - max-inline-size: 660px; - } - - // On the card, so a dismissed (hidden) card leaves no gap. - .jitm-card { - margin: 0 0 var(--wpds-dimension-gap-lg); - } - } } diff --git a/projects/packages/publicize/_inc/components/social-page.tsx b/projects/packages/publicize/_inc/components/social-page.tsx index b3d8aef5cf28..9b0158ee700a 100644 --- a/projects/packages/publicize/_inc/components/social-page.tsx +++ b/projects/packages/publicize/_inc/components/social-page.tsx @@ -1,4 +1,5 @@ import AdminPage from '@automattic/jetpack-components/admin-page'; +import JitmSlot from '@automattic/jetpack-components/jitm-slot'; import { currentUserCan, getSiteData } from '@automattic/jetpack-script-data'; import { useCallback } from '@wordpress/element'; import { __ } from '@wordpress/i18n'; @@ -88,15 +89,12 @@ export default function SocialPage( { ); const content = ( -
- { /* The JITM script moves its card here, since the page template hides the default spot. */ } -
- { children } -
+ <> + +
+ { children } +
+ ); return ( diff --git a/projects/packages/publicize/_inc/components/test/social-page.test.tsx b/projects/packages/publicize/_inc/components/test/social-page.test.tsx index ccab7a7e230a..d755a538c50e 100644 --- a/projects/packages/publicize/_inc/components/test/social-page.test.tsx +++ b/projects/packages/publicize/_inc/components/test/social-page.test.tsx @@ -84,7 +84,7 @@ describe( 'SocialPage', () => {
); - const notices = screen.getByTestId( 'jetpack-social-jitm-card' ); + const notices = screen.getByTestId( 'jp-jitm-slot' ); rerender( @@ -92,8 +92,7 @@ describe( 'SocialPage', () => { ); - expect( notices ).toHaveAttribute( 'id', 'jp-admin-notices' ); - expect( screen.getByTestId( 'jetpack-social-jitm-card' ) ).toBe( notices ); + expect( screen.getByTestId( 'jp-jitm-slot' ) ).toBe( notices ); } ); it( 'renders the JITM container without the tab chrome', () => { @@ -105,9 +104,7 @@ describe( 'SocialPage', () => { ); - expect( screen.getByTestId( 'jetpack-social-jitm-card' ) ).toHaveAttribute( - 'id', - 'jp-admin-notices' - ); + expect( screen.queryAllByRole( 'tab' ) ).toHaveLength( 0 ); + expect( screen.getByTestId( 'jp-jitm-slot' ) ).toBeInTheDocument(); } ); } ); diff --git a/projects/packages/publicize/changelog/add-jitm-slot-all-layouts b/projects/packages/publicize/changelog/add-jitm-slot-all-layouts new file mode 100644 index 000000000000..4709aa459191 --- /dev/null +++ b/projects/packages/publicize/changelog/add-jitm-slot-all-layouts @@ -0,0 +1,4 @@ +Significance: patch +Type: changed + +Show the Jetpack in-dashboard message above the tabs, from the shared slot. diff --git a/projects/packages/search/changelog/add-jitm-slot-all-layouts b/projects/packages/search/changelog/add-jitm-slot-all-layouts new file mode 100644 index 000000000000..5a7a60259488 --- /dev/null +++ b/projects/packages/search/changelog/add-jitm-slot-all-layouts @@ -0,0 +1,4 @@ +Significance: patch +Type: fixed + +Show Jetpack in-dashboard messages on every Search tab, not just Overview. diff --git a/projects/packages/search/src/dashboard/components/pages/dashboard-page.jsx b/projects/packages/search/src/dashboard/components/pages/dashboard-page.jsx index 4d942514a528..1fb77be561b4 100644 --- a/projects/packages/search/src/dashboard/components/pages/dashboard-page.jsx +++ b/projects/packages/search/src/dashboard/components/pages/dashboard-page.jsx @@ -1,4 +1,5 @@ import { AdminPage, Button, getProductCheckoutUrl } from '@automattic/jetpack-components'; +import JitmSlot from '@automattic/jetpack-components/jitm-slot'; import { useConnectionErrorNotice, ConnectionError } from '@automattic/jetpack-connection'; import { useSelect, useDispatch } from '@wordpress/data'; import { __ } from '@wordpress/i18n'; @@ -330,15 +331,9 @@ export default function DashboardPage( { isLoading = false } ) { { __( 'AI Answers', 'jetpack-search-pkg' ) }
+
- { /* Always in the DOM so JITM JS finds it immediately (Path A). */ } -
-
-
{ isPageLoading && } { ! isPageLoading && ( + { TAB_VALUES.map( tab => ( { activeTab === tab ? children : null } diff --git a/projects/packages/videopress/tests/php/Admin_UI_Test.php b/projects/packages/videopress/tests/php/Admin_UI_Test.php index f5b7d5958631..1c9163901375 100644 --- a/projects/packages/videopress/tests/php/Admin_UI_Test.php +++ b/projects/packages/videopress/tests/php/Admin_UI_Test.php @@ -28,7 +28,6 @@ public function tearDown(): void { remove_action( 'admin_menu', array( Admin_UI::class, 'enable_menu' ), 1 ); remove_action( 'admin_enqueue_scripts', array( Admin_UI::class, 'alias_screen_id_for_wp_build' ) ); remove_action( 'admin_enqueue_scripts', array( Admin_UI::class, 'restore_screen_id_after_wp_build' ) ); - remove_filter( 'jetpack_display_jitms_on_screen', array( Admin_UI::class, 'hide_jitms_on_wp_build_dashboard' ) ); remove_all_actions( 'load-jetpack_page_' . Admin_UI::ADMIN_PAGE_SLUG ); unset( $_GET['page'], $GLOBALS['current_screen'] ); $this->set_admin_menu_items( array() ); @@ -293,9 +292,9 @@ public function test_alias_screen_id_round_trip() { } /** - * The Simple registration opts the screen add_submenu_page() returns out of JITMs, and no other. + * The Simple registration hooks admin_init on the screen add_submenu_page() returns. */ - public function test_add_wp_admin_submenu_opts_its_screen_out_of_jitms() { + public function test_add_wp_admin_submenu_registers_its_load_action() { $this->mock_connected_user(); // Stands in for the Jetpack parent menu wpcom-admin-menu.php creates. add_menu_page( 'Jetpack', 'Jetpack', 'manage_options', 'jetpack', '__return_null' ); @@ -303,27 +302,22 @@ public function test_add_wp_admin_submenu_opts_its_screen_out_of_jitms() { Admin_UI::add_wp_admin_submenu(); $this->assertNotFalse( has_action( 'load-jetpack_page_jetpack-videopress', array( Admin_UI::class, 'admin_init' ) ) ); - $this->assertFalse( apply_filters( 'jetpack_display_jitms_on_screen', true, 'jetpack_page_jetpack-videopress' ) ); - $this->assertTrue( apply_filters( 'jetpack_display_jitms_on_screen', true, 'jetpack_page_jetpack-social' ) ); - $this->assertFalse( apply_filters( 'jetpack_display_jitms_on_screen', false, 'jetpack_page_jetpack-social' ) ); } /** - * Self-hosted, only the wp-build dashboard opts out of JITMs. + * Both dashboards render the JITM slot, so neither opts its screen out. * * @runInSeparateProcess * @preserveGlobalState disabled */ #[RunInSeparateProcess] #[PreserveGlobalState( false )] - public function test_enable_menu_opts_out_of_jitms_only_for_the_wp_build_dashboard() { + public function test_enable_menu_keeps_jitms_on_both_dashboards() { require_once __DIR__ . '/mocks/class-jetpack-videopress-plugin.php'; Admin_UI::enable_menu(); - $this->assertFalse( apply_filters( 'jetpack_display_jitms_on_screen', true, 'jetpack_page_jetpack-videopress' ) ); - $this->assertTrue( apply_filters( 'jetpack_display_jitms_on_screen', true, 'jetpack_page_jetpack-social' ) ); + $this->assertTrue( apply_filters( 'jetpack_display_jitms_on_screen', true, 'jetpack_page_jetpack-videopress' ) ); - remove_filter( 'jetpack_display_jitms_on_screen', array( Admin_UI::class, 'hide_jitms_on_wp_build_dashboard' ) ); add_filter( Admin_UI::MODERNIZATION_FILTER, '__return_false' ); Admin_UI::enable_menu(); diff --git a/projects/plugins/backup/changelog/add-jitm-slot-all-layouts b/projects/plugins/backup/changelog/add-jitm-slot-all-layouts new file mode 100644 index 000000000000..47f5577b9214 --- /dev/null +++ b/projects/plugins/backup/changelog/add-jitm-slot-all-layouts @@ -0,0 +1,5 @@ +Significance: patch +Type: changed +Comment: Update composer.lock. + + diff --git a/projects/plugins/backup/composer.lock b/projects/plugins/backup/composer.lock index 75e962d0961c..433ad28f6eb9 100644 --- a/projects/plugins/backup/composer.lock +++ b/projects/plugins/backup/composer.lock @@ -359,7 +359,7 @@ "dist": { "type": "path", "url": "../../packages/backup", - "reference": "72d8a235906ad12b0e5ef4bde2d2bc6fd25dbda1" + "reference": "2c3381cfda3ec5f65dc0a7b37aa62203ffb38823" }, "require": { "automattic/jetpack-admin-ui": "@dev", @@ -370,6 +370,7 @@ "automattic/jetpack-config": "@dev", "automattic/jetpack-connection": "@dev", "automattic/jetpack-constants": "@dev", + "automattic/jetpack-jitm": "@dev", "automattic/jetpack-my-jetpack": "@dev", "automattic/jetpack-status": "@dev", "automattic/jetpack-sync": "@dev", diff --git a/projects/plugins/jetpack/changelog/add-jitm-slot-all-layouts b/projects/plugins/jetpack/changelog/add-jitm-slot-all-layouts new file mode 100644 index 000000000000..497ea05a775d --- /dev/null +++ b/projects/plugins/jetpack/changelog/add-jitm-slot-all-layouts @@ -0,0 +1,4 @@ +Significance: patch +Type: bugfix + +Show Jetpack in-dashboard messages on the modernized product dashboards again. diff --git a/projects/plugins/jetpack/composer.lock b/projects/plugins/jetpack/composer.lock index 10fe60e710b7..c3b349431f02 100644 --- a/projects/plugins/jetpack/composer.lock +++ b/projects/plugins/jetpack/composer.lock @@ -565,7 +565,7 @@ "dist": { "type": "path", "url": "../../packages/backup", - "reference": "72d8a235906ad12b0e5ef4bde2d2bc6fd25dbda1" + "reference": "2c3381cfda3ec5f65dc0a7b37aa62203ffb38823" }, "require": { "automattic/jetpack-admin-ui": "@dev", @@ -576,6 +576,7 @@ "automattic/jetpack-config": "@dev", "automattic/jetpack-connection": "@dev", "automattic/jetpack-constants": "@dev", + "automattic/jetpack-jitm": "@dev", "automattic/jetpack-my-jetpack": "@dev", "automattic/jetpack-status": "@dev", "automattic/jetpack-sync": "@dev", diff --git a/projects/plugins/protect/changelog/add-jitm-slot-all-layouts b/projects/plugins/protect/changelog/add-jitm-slot-all-layouts new file mode 100644 index 000000000000..19819c484b81 --- /dev/null +++ b/projects/plugins/protect/changelog/add-jitm-slot-all-layouts @@ -0,0 +1,4 @@ +Significance: patch +Type: fixed + +Show Jetpack in-dashboard messages under the tabs, on every tab. diff --git a/projects/plugins/protect/src/js/components/admin-section-hero/admin-section-hero-notices.tsx b/projects/plugins/protect/src/js/components/admin-section-hero/admin-section-hero-notices.tsx index 28ba4f8e4025..96813703ff79 100644 --- a/projects/plugins/protect/src/js/components/admin-section-hero/admin-section-hero-notices.tsx +++ b/projects/plugins/protect/src/js/components/admin-section-hero/admin-section-hero-notices.tsx @@ -6,15 +6,14 @@ import type { FC } from 'react'; const AdminSectionHeroNotices: FC = () => { const { hasConnectionError } = useConnectionErrorNotice(); + if ( ! hasConnectionError ) { + return null; + } + return ( - { hasConnectionError && ( - - - - ) } - -
+ + ); diff --git a/projects/plugins/protect/src/js/components/protect-app/index.jsx b/projects/plugins/protect/src/js/components/protect-app/index.jsx index 155ab346636f..d287868c6396 100644 --- a/projects/plugins/protect/src/js/components/protect-app/index.jsx +++ b/projects/plugins/protect/src/js/components/protect-app/index.jsx @@ -1,4 +1,5 @@ import { AdminPage as JetpackAdminPage } from '@automattic/jetpack-components'; +import JitmSlot from '@automattic/jetpack-components/jitm-slot'; import { useConnection } from '@automattic/jetpack-connection'; import { __, sprintf } from '@wordpress/i18n'; import { Tabs } from '@wordpress/ui'; @@ -101,6 +102,7 @@ const ProtectApp = () => { { __( 'Settings', 'jetpack-protect' ) }
+ { /* Every tab panel shares the same react-router , which always renders the active route. Tabs.Panel (via @base-ui/react) keeps the outgoing panel mounted until its close transition completes, so diff --git a/projects/plugins/search/changelog/add-jitm-slot-all-layouts b/projects/plugins/search/changelog/add-jitm-slot-all-layouts new file mode 100644 index 000000000000..97cdb9ed9a5f --- /dev/null +++ b/projects/plugins/search/changelog/add-jitm-slot-all-layouts @@ -0,0 +1,4 @@ +Significance: patch +Type: fixed + +Show Jetpack in-dashboard messages on every tab, not just Overview. diff --git a/projects/plugins/social/changelog/add-jitm-slot-all-layouts b/projects/plugins/social/changelog/add-jitm-slot-all-layouts new file mode 100644 index 000000000000..eb3a74ec7c2d --- /dev/null +++ b/projects/plugins/social/changelog/add-jitm-slot-all-layouts @@ -0,0 +1,4 @@ +Significance: patch +Type: fixed + +Line up the Jetpack in-dashboard message with the rest of the page. diff --git a/projects/plugins/videopress/changelog/add-jitm-slot-all-layouts b/projects/plugins/videopress/changelog/add-jitm-slot-all-layouts new file mode 100644 index 000000000000..1d258e99c845 --- /dev/null +++ b/projects/plugins/videopress/changelog/add-jitm-slot-all-layouts @@ -0,0 +1,4 @@ +Significance: patch +Type: fixed + +Show Jetpack in-dashboard messages on the dashboard again.