Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: changed

Show the dashboard in the new rounded admin page frame.
1 change: 0 additions & 1 deletion projects/packages/search/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
"automattic/jetpack-config": "@dev",
"automattic/jetpack-my-jetpack": "@dev",
"automattic/jetpack-sync": "@dev",
"automattic/jetpack-feature-flags": "@dev",
"automattic/jetpack-wp-build-polyfills": "@dev"
},
"require-dev": {
Expand Down
5 changes: 2 additions & 3 deletions projects/packages/search/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@
"test": "tests"
},
"scripts": {
"build": "pnpm run clean && concurrently 'pnpm:build-instant' 'pnpm:build-customberg' 'pnpm:build-dashboard' 'pnpm:build-inline' 'pnpm:build-blocks' 'pnpm:build-blocks-editor' 'pnpm:build:wp-build' && pnpm run build:stamp-textdomains && pnpm run build:boot-asset",
"build": "pnpm run clean && concurrently 'pnpm:build-instant' 'pnpm:build-customberg' 'pnpm:build-inline' 'pnpm:build-blocks' 'pnpm:build-blocks-editor' 'pnpm:build:wp-build' && pnpm run build:stamp-textdomains && pnpm run build:boot-asset",
"build:boot-asset": "provide-boot-asset-file",
"build:stamp-textdomains": "stamp-textdomains",
"build:strip-unminified-prod": "strip-unminified-prod",
"build:wp-build": "wp-build",
"build-blocks": "webpack --config ./tools/webpack.blocks.config.js",
"build-blocks-editor": "webpack --config ./tools/webpack.blocks-editor.config.js",
"build-customberg": "webpack --config ./tools/webpack.customberg.config.js",
"build-dashboard": "webpack --config ./tools/webpack.dashboard.config.js",
"build-development": "NODE_ENV=development BABEL_ENV=development pnpm run build",
"build-inline": "webpack --config ./tools/webpack.inline.config.js",
"build-instant": "webpack --config ./tools/webpack.instant.config.js",
Expand All @@ -39,7 +38,7 @@
"test-url-tests": "jest --config=jest.url-tests.config.js --passWithNoTests",
"typecheck": "tsgo --noEmit",
"validate": "pnpm exec validate-es --no-error-on-unmatched-pattern build/",
"watch": "concurrently 'pnpm:build-instant --watch' 'pnpm:build-customberg --watch' 'pnpm:build-dashboard --watch' 'pnpm:watch:wp-build' 'pnpm:build-inline --watch' 'pnpm:build-blocks --watch' 'pnpm:build-blocks-editor --watch'",
"watch": "concurrently 'pnpm:build-instant --watch' 'pnpm:build-customberg --watch' 'pnpm:watch:wp-build' 'pnpm:build-inline --watch' 'pnpm:build-blocks --watch' 'pnpm:build-blocks-editor --watch'",
"watch:wp-build": "wp-build --watch"
},
"browserslist": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Provide the `jetpackConfig` that webpack.dashboard.config.js declares as an external, which esbuild cannot.
* Provide the `jetpackConfig` global `@automattic/jetpack-config` reads, which esbuild cannot declare as an external.
*/
export function provideJetpackConfig(): void {
( globalThis as typeof globalThis & { jetpackConfig?: object } ).jetpackConfig = {
Expand Down
9 changes: 4 additions & 5 deletions projects/packages/search/routes/dashboard/stage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ import SearchDashboard from '../../src/dashboard/components/dashboard/wrapped-da
import { STORE_ID, storeConfig } from '../../src/dashboard/store';
import './route.scss';

// Mirrors the module-scope registration in `src/dashboard/index.jsx`: `<SearchDashboard>`
// reads this store via `useSelect()`, so it must exist before boot mounts `stage`.
// `<SearchDashboard>` reads this store via `useSelect()`, so it must exist before boot mounts `stage`.
const store = createReduxStore( STORE_ID, storeConfig );
register( store );

/**
* Keeps the `#jp-search-dashboard` wrapper the legacy entry mounted into. `dashboard-page.scss`
* scopes its rules to it, including the `font-size: 16px` every em in the dashboard resolves
* against — without it the tree renders against wp-admin's 13px.
* Renders the `#jp-search-dashboard` wrapper `dashboard-page.scss` scopes its rules to, including
* the `font-size: 16px` every em in the dashboard resolves against — without it the tree renders
* against wp-admin's 13px.
*
* @return The dashboard, wrapped as the stylesheet expects.
*/
Expand Down
117 changes: 23 additions & 94 deletions projects/packages/search/src/dashboard/class-dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@
namespace Automattic\Jetpack\Search;

use Automattic\Jetpack\Admin_UI\Admin_Menu;
use Automattic\Jetpack\Assets;
use Automattic\Jetpack\Connection\Initial_State as Connection_Initial_State;
use Automattic\Jetpack\Connection\Manager as Connection_Manager;
use Automattic\Jetpack\Feature_Flags\Feature_Flags;
use Automattic\Jetpack\Status;
use Automattic\Jetpack\Tracking;
use Automattic\Jetpack\WP_Build_Polyfills\WP_Build_Polyfills;
Expand All @@ -21,11 +19,6 @@
* @package Automattic\Jetpack\Search
*/
class Dashboard {
/**
* Feature flag enabling the modernized, wp-build-served dashboard.
*/
const WP_BUILD_FEATURE_FLAG = 'search-wp-build';

/**
* Slug emitted by `@wordpress/build` (`wpPlugin.pages[0].id`). Must differ from the
* `jetpack-search` menu slug: the generated page.php takes over, and exits, any request
Expand All @@ -41,7 +34,7 @@ class Dashboard {
const WP_BUILD_RENDER_FN = 'jetpack_search_jetpack_search_dashboard_wp_admin_render_page';

/**
* Classic script handle with no source, registered only so the wp-build path has
* Classic script handle with no source, registered only so the dashboard has
* something to hang {@see Initial_State} and the connection initial state on.
*/
const DATA_SCRIPT_HANDLE = 'jetpack-search-dashboard-data';
Expand Down Expand Up @@ -117,8 +110,8 @@ public function __construct( $plan = null, $connection_manager = null, $module_c
public function init_hooks() {
if ( ! self::$initialized ) {
self::$initialized = true;
// Any priority works: the predicate's readers, render() and load_admin_scripts(),
// both run after admin_menu — and the wpcom subclass overrides this to 100000.
// Any priority works: render() reads the loaded build after admin_menu, and the
// wpcom subclass overrides this to 100000.
add_action( 'admin_menu', array( $this, 'maybe_load_wp_build' ), $this->search_menu_priority );
add_action( 'admin_menu', array( $this, 'add_wp_admin_submenu' ), $this->search_menu_priority );
// Check if the site plan changed and deactivate module accordingly.
Expand All @@ -127,13 +120,12 @@ public function init_hooks() {
}

/**
* Load the wp-build dashboard bundle for this request, when the site opted in.
* Load the wp-build dashboard bundle for this request.
*
* A no-op unless the flag is on, this is the Search page, and `build/build.php`
* exists; {@see self::is_wp_build_dashboard_active()} falls back otherwise.
* A no-op unless this is the Search page and `build/build.php` exists.
*/
public function maybe_load_wp_build() {
if ( ! $this->is_modernized() || ! $this->is_search_admin_request() ) {
if ( ! $this->is_search_admin_request() ) {
return;
}

Expand Down Expand Up @@ -161,48 +153,8 @@ public function maybe_load_wp_build() {
}

/**
* Register the package's feature flags.
*
* Called from {@see Initializer::init()} rather than this class, so the flag stays
* listable by `wp companion feature-flag` on requests that never build the dashboard.
*
* @return void
*/
public static function register_feature_flags() {
Feature_Flags::register(
self::WP_BUILD_FEATURE_FLAG,
array(
'default' => false,
'description' => 'Serve the Jetpack Search dashboard through the wp-build pipeline.',
'owner' => 'jetpack-search',
)
);
}

/**
* Whether the site opted into the modernized dashboard.
*
* @return bool
*/
protected function is_modernized() {
return Feature_Flags::is_enabled( self::WP_BUILD_FEATURE_FLAG );
}

/**
* Returns true when the modernization filter is on AND the wp-build dashboard loaded.
*
* Both render() and load_admin_scripts() read this one predicate, so they can never
* disagree about which dashboard is live — see #51436, which broke Backup this way.
*
* @return bool
*/
protected function is_wp_build_dashboard_active() {
return $this->is_modernized() && function_exists( $this->wp_build_render_function() );
}

/**
* Name of the generated render function. A seam: tests override it to reach the
* wp-build branch without depending on whether the package happens to be built.
* Name of the generated render function. A seam: tests override it to render
* the dashboard without depending on whether the package happens to be built.
*
* @return string
*/
Expand Down Expand Up @@ -292,21 +244,15 @@ public function add_wp_admin_submenu() {
}

/**
* Override render funtion
* Render the dashboard page.
*
* Both add_wp_admin_submenu() branches register this same callback, so gating
* the wp-build swap here keeps them from being able to disagree about it.
* The generated render function is missing where the package was never built.
*/
public function render() {
if ( $this->is_wp_build_dashboard_active() ) {
call_user_func( $this->wp_build_render_function() );
return;
$render_function = $this->wp_build_render_function();
if ( function_exists( $render_function ) ) {
call_user_func( $render_function );
}
?>
<div id="jp-search-dashboard" class="jp-search-dashboard">
<div class="hide-if-js"><?php esc_html_e( 'Your Jetpack Search dashboard requires JavaScript to function properly.', 'jetpack-search-pkg' ); ?></div>
</div>
<?php
}

/**
Expand Down Expand Up @@ -348,44 +294,27 @@ public function load_admin_scripts() {
Tracking::register_tracks_functions_scripts( true );
}

if ( $this->is_wp_build_dashboard_active() ) {
// wp-build enqueues the app itself; this empty handle exists only to
// print the initial state before boot runs on DOMContentLoaded.
wp_register_script( self::DATA_SCRIPT_HANDLE, false, array(), Package::VERSION, true );
wp_enqueue_script( self::DATA_SCRIPT_HANDLE );

// The i18n loader is registered on every admin page but only enqueued
// when depended on; the esbuild bundle doesn't pull it in.
if ( wp_script_is( 'wp-jp-i18n-loader', 'registered' ) ) {
wp_enqueue_script( 'wp-jp-i18n-loader' );
}

$data_handle = self::DATA_SCRIPT_HANDLE;
} else {
Assets::register_script(
'jp-search-dashboard',
'../../build/dashboard/jp-search-dashboard.js',
__FILE__,
array(
'in_footer' => true,
'textdomain' => 'jetpack-search-pkg',
)
);
Assets::enqueue_script( 'jp-search-dashboard' );
// wp-build enqueues the app itself; this empty handle exists only to
// print the initial state before boot runs on DOMContentLoaded.
wp_register_script( self::DATA_SCRIPT_HANDLE, false, array(), Package::VERSION, true );
wp_enqueue_script( self::DATA_SCRIPT_HANDLE );

$data_handle = 'jp-search-dashboard';
// The i18n loader is registered on every admin page but only enqueued
// when depended on; the esbuild bundle doesn't pull it in.
if ( wp_script_is( 'wp-jp-i18n-loader', 'registered' ) ) {
wp_enqueue_script( 'wp-jp-i18n-loader' );
}

// Add objects to be passed to the initial state of the app.
// Use wp_add_inline_script instead of wp_localize_script, see https://core.trac.wordpress.org/ticket/25280.
wp_add_inline_script(
$data_handle,
self::DATA_SCRIPT_HANDLE,
( new Initial_State() )->render(),
'before'
);

// Connection initial state.
Connection_Initial_State::render_script( $data_handle );
Connection_Initial_State::render_script( self::DATA_SCRIPT_HANDLE );
}

/**
Expand Down
28 changes: 0 additions & 28 deletions projects/packages/search/src/dashboard/index.jsx

This file was deleted.

6 changes: 0 additions & 6 deletions projects/packages/search/src/dashboard/scss/admin-layout.scss

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ class Initializer {
* The method is called from the `Config` class.
*/
public static function init() {
// Ahead of the abort filter below, so the flag stays listable by
// `wp companion feature-flag` even where Search initialization bails.
Dashboard::register_feature_flags();

// Load compatibility files - at this point all plugins are already loaded.
static::include_compatibility_files();

Expand Down
Loading
Loading