Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
2d626e6
JITM: one slot component and one suppression helper for every dashboard
CGastrell Sep 22, 2026
52ed4df
Keep the slot stylesheet inside the 80-column limit
CGastrell Sep 22, 2026
e86c76a
Shorten the new comments, and add the slot to Forms
CGastrell Sep 22, 2026
754a0f0
Drop the stray capture scripts and sort the exports map
CGastrell Sep 22, 2026
4e2e729
Keep the JITM slot out of the scrollable page middle
CGastrell Sep 22, 2026
50141f1
My Jetpack: use the shared JITM slot
CGastrell Sep 22, 2026
7c427c7
Put the slot in the same place on every dashboard
CGastrell Sep 22, 2026
99d3d90
Social: use the shared JITM slot, above the tabs
CGastrell Sep 23, 2026
f9d64f3
Place the slot below the tabs, at the top of the content
CGastrell Sep 23, 2026
f8e4f03
Forms: make the slot a row directly under the tabs
CGastrell Sep 23, 2026
295c039
Search: use the shared slot, and show it on every tab
CGastrell Sep 23, 2026
753d871
Keep the header's bottom padding on tabbed dashboards
CGastrell Sep 23, 2026
7088d08
Add the changelog entry for the header padding fix
CGastrell Sep 23, 2026
b551b5e
Settle the tabbed-header border in the shared layout mixin
CGastrell Sep 23, 2026
7396284
Protect: use the shared slot, and align the card on every dashboard
CGastrell Sep 23, 2026
f6d2fc2
Newsletter, VideoPress: restore JITMs with the shared slot
CGastrell Sep 23, 2026
d4b34a9
Say the slot's spacing contract once
CGastrell Sep 23, 2026
d0e43d4
Drop three comments the JSX already says
CGastrell Sep 23, 2026
b34131e
Social: fix the test's formatting
CGastrell Sep 23, 2026
ed24417
JITM: say the helper keeps JITMs, not every Jetpack notice
CGastrell Sep 23, 2026
9a57c4e
Backup: cover a foreign notice on all_admin_notices
CGastrell Sep 23, 2026
2942566
JitmSlot: keep the card when a route remounts the slot
CGastrell Sep 23, 2026
6df5470
Review follow-ups on the slot remount fix
CGastrell Sep 23, 2026
b2a0cac
JitmSlot: take the page gutter through a prop
CGastrell Sep 23, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions projects/js-packages/base-styles/admin-page-layout.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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. <AdminPage> does not pass `hasPadding` to
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

Keep the page header's bottom padding on dashboards that have a tabs strip.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

Keep the Jetpack in-dashboard message slot out of the scrollable page middle.
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
@@ -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.
67 changes: 67 additions & 0 deletions projects/js-packages/components/components/jitm-slot/index.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<div
ref={ ref }
className={ clsx( 'jp-jitm-slot', { 'jp-jitm-slot--inset': inset }, className ) }
data-testid="jp-jitm-slot"
/>
);
};

export default JitmSlot;
16 changes: 16 additions & 0 deletions projects/js-packages/components/components/jitm-slot/style.scss
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
@@ -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( <JitmSlot /> );

// `#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( <JitmSlot className="jetpack-backup-jitm-card" /> );
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( <JitmSlot inset /> );

expect( screen.getByTestId( 'jp-jitm-slot' ) ).toHaveClass( 'jp-jitm-slot--inset' );
} );

it( 'renders empty, so a page with no message shows nothing', () => {
render( <JitmSlot /> );

expect( document.getElementById( 'jp-admin-notices' ) ).toBeEmptyDOMElement();
} );

it( 'hands a placed card to the next slot after a remount', () => {
const { unmount } = render( <JitmSlot /> );
const card = document.createElement( 'div' );
document.getElementById( 'jp-admin-notices' ).append( card );

unmount();
expect( card ).not.toBeVisible();

render( <JitmSlot /> );

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( <JitmSlot /> );

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( <JitmSlot className="outgoing" /> );
render( <JitmSlot className="incoming" /> );

unmount();

expect( document.querySelector( '.incoming' ) ).toContainElement(
document.getElementById( 'jp-admin-notices' )
);
} );
} );
10 changes: 10 additions & 0 deletions projects/js-packages/components/components/jitm-slot/types.ts
Original file line number Diff line number Diff line change
@@ -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;
};
1 change: 1 addition & 0 deletions projects/js-packages/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
5 changes: 5 additions & 0 deletions projects/js-packages/components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 4 additions & 0 deletions projects/packages/backup/changelog/add-jitm-slot-all-layouts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

Show Jetpack in-dashboard messages on the modernized dashboard.
1 change: 1 addition & 0 deletions projects/packages/backup/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
16 changes: 9 additions & 7 deletions projects/packages/backup/src/class-jetpack-backup.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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' );
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -52,6 +53,7 @@ export default function DashboardLayout( { children, actions }: Props ) {
>
<div className="jpb-dashboard-body">
<div className="jpb-dashboard-body__inner">
<JitmSlot />
<Gates>{ children }</Gates>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Loading
Loading