Skip to content

Commit

Permalink
Merge pull request #2937 from Parsely/add/plugin-dashboard-page
Browse files Browse the repository at this point in the history
  • Loading branch information
acicovic authored Nov 13, 2024
2 parents 8760356 + a6f1b07 commit 22a3772
Show file tree
Hide file tree
Showing 9 changed files with 129 additions and 2 deletions.
1 change: 1 addition & 0 deletions build/content-helper/dashboard-page-rtl.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions build/content-helper/dashboard-page.asset.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php return array('dependencies' => array('react', 'wp-dom-ready', 'wp-element'), 'version' => '12fe4372400030ba8741');
1 change: 1 addition & 0 deletions build/content-helper/dashboard-page.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions build/content-helper/dashboard-page.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

95 changes: 95 additions & 0 deletions src/UI/class-dashboard-page.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?php
/**
* UI: Dashboard page class
*
* @package Parsely
* @since 3.18.0
*/

declare(strict_types=1);

namespace Parsely\UI;

use Parsely\Parsely;
use Parsely\Utils\Utils;

use const Parsely\PARSELY_FILE;

/**
* Renders the plugin's dashboard page.
*
* @since 3.18.0
*/
final class Dashboard_Page {
/**
* Registers the dashboard page.
*
* @since 3.18.0
*/
public function run(): void {
add_action( 'admin_menu', array( $this, 'add_dashboard_page_to_menu' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_dashboard_page_scripts' ) );
}

/**
* Adds the dashboard page to the admin menu.
*
* @since 3.18.0
*/
public function add_dashboard_page_to_menu(): void {
// Base64-encoded version of leaf-icon.tsx with size of 20 and fill of #1d2327.
// <svg width="20" height="20" viewBox="0 0 60 65" xmlns="http://www.w3.org/2000/svg"><path fill="#1d2327" d="M23.72,51.53c0-.18,0-.34-.06-.52a13.11,13.11,0,0,0-2.1-5.53A14.74,14.74,0,0,0,19.12,43c-.27-.21-.5-.11-.51.22l-.24,3.42c0,.33-.38.35-.49,0l-1.5-4.8a1.4,1.4,0,0,0-.77-.78,23.91,23.91,0,0,0-3.1-.84c-1.38-.24-3.39-.39-3.39-.39-.34,0-.45.21-.25.49l2.06,3.76c.2.27,0,.54-.29.33l-4.51-3.6a3.68,3.68,0,0,0-2.86-.48c-1,.16-2.44.46-2.44.46a.68.68,0,0,0-.39.25.73.73,0,0,0-.14.45S.41,43,.54,44a3.63,3.63,0,0,0,1.25,2.62L6.48,50c.28.2.09.49-.23.37l-4.18-.94c-.32-.12-.5,0-.4.37,0,0,.69,1.89,1.31,3.16a24,24,0,0,0,1.66,2.74,1.34,1.34,0,0,0,1,.52l5,.13c.33,0,.41.38.1.48L7.51,58c-.31.1-.34.35-.07.55a14.29,14.29,0,0,0,3.05,1.66,13.09,13.09,0,0,0,5.9.5,25.13,25.13,0,0,0,4.34-1,9.55,9.55,0,0,1-.08-1.2,9.32,9.32,0,0,1,3.07-6.91"></path><path fill="#1d2327" d="M59.7,41.53a.73.73,0,0,0-.14-.45.68.68,0,0,0-.39-.25s-1.43-.3-2.44-.46a3.64,3.64,0,0,0-2.86.48l-4.51,3.6c-.26.21-.49-.06-.29-.33l2.06-3.76c.2-.28.09-.49-.25-.49,0,0-2,.15-3.39.39a23.91,23.91,0,0,0-3.1.84,1.4,1.4,0,0,0-.77.78l-1.5,4.8c-.11.32-.48.3-.49,0l-.24-3.42c0-.33-.24-.43-.51-.22a14.74,14.74,0,0,0-2.44,2.47A13.11,13.11,0,0,0,36.34,51c0,.18,0,.34-.06.52a9.26,9.26,0,0,1,3,8.1,24.1,24.1,0,0,0,4.34,1,13.09,13.09,0,0,0,5.9-.5,14.29,14.29,0,0,0,3.05-1.66c.27-.2.24-.45-.07-.55l-3.22-1.17c-.31-.1-.23-.47.1-.48l5-.13a1.38,1.38,0,0,0,1-.52A24.6,24.6,0,0,0,57,52.92c.61-1.27,1.31-3.16,1.31-3.16.1-.33-.08-.49-.4-.37l-4.18.94c-.32.12-.51-.17-.23-.37l4.69-3.34A3.63,3.63,0,0,0,59.46,44c.13-1,.24-2.47.24-2.47"></path><path fill="#1d2327" d="M46.5,25.61c0-.53-.35-.72-.8-.43l-4.86,2.66c-.45.28-.56-.27-.23-.69l4.66-6.23a2,2,0,0,0,.28-1.68,36.51,36.51,0,0,0-2.19-4.89,34,34,0,0,0-2.81-3.94c-.33-.41-.74-.35-.91.16l-2.28,5.68c-.16.5-.6.48-.59-.05l.28-8.93a2.54,2.54,0,0,0-.66-1.64S35,4.27,33.88,3.27,30.78.69,30.78.69a1.29,1.29,0,0,0-1.54,0s-1.88,1.49-3.12,2.59-2.48,2.35-2.48,2.35A2.5,2.5,0,0,0,23,7.27l.27,8.93c0,.53-.41.55-.58.05l-2.29-5.69c-.17-.5-.57-.56-.91-.14a35.77,35.77,0,0,0-3,4.2,35.55,35.55,0,0,0-2,4.62,2,2,0,0,0,.27,1.67l4.67,6.24c.33.42.23,1-.22.69l-4.87-2.66c-.45-.29-.82-.1-.82.43a18.6,18.6,0,0,0,.83,5.07,20.16,20.16,0,0,0,5.37,7.77c3.19,3,5.93,7.8,7.45,11.08A9.6,9.6,0,0,1,30,49.09a9.31,9.31,0,0,1,2.86.45c1.52-3.28,4.26-8.11,7.44-11.09a20.46,20.46,0,0,0,5.09-7,19,19,0,0,0,1.11-5.82"></path><path fill="#1d2327" d="M36.12,58.44A6.12,6.12,0,1,1,30,52.32a6.11,6.11,0,0,1,6.12,6.12"></path></svg>.
$icon = 'data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjAiIGhlaWdodD0iMjAiIHZpZXdCb3g9IjAgMCA2MCA2NSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48cGF0aCBmaWxsPSIjMWQyMzI3IiBkPSJNMjMuNzIsNTEuNTNjMC0uMTgsMC0uMzQtLjA2LS41MmExMy4xMSwxMy4xMSwwLDAsMC0yLjEtNS41M0ExNC43NCwxNC43NCwwLD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LS45MS4xNmwtMi4yOCw1LjY4Yy0uMTYuNS0uNi40OC0uNTktLjA1bC4yOC04LjkzYTIuNTQsMi41NCwwLDAsMC0uNjYtMS42NFMzNSw0LjI3LDMzLjg4LDMuMjcsMzAuNzguNjksMzAuNzguNjlhMS4yOSwxLjI5LDAsMCwwLTEuNTQsMHMtMS44OCwxLjQ5LTMuMTIsMi41OS0yLjQ4LDIuMzUtMi40OCwyLjM1QTIuNSwyLjUsMCwwLDAsMjMsNy4yN2wuMjcsOC45M2MwLC41My0uNDEuNTUtLjU4LjA1bC0yLjI5LTUuNjljLS4xNy0uNS0uNTctLjU2LS45MS0uMTRhMzUuNzcsMzUuNzcsMCwwLDAtMyw0LjIsMzUuNTUsMzUuNTUsMCwwLDAtMiw0LjYyLDIsMiwwLDAsMCwuMjcsMS42N2w0LjY3LDYuMjRjLjMzLjQyLjIzLDEtLjIyLjY5bC00Ljg3LTIuNjZjLS40NS0uMjktLjgyLS4xLS44Mi40M2ExOC42LDE4LjYsMCwwLDAsLjgzLDUuMDcsMjAuMTYsMjAuMTYsMCwwLDAsNS4zNyw3Ljc3YzMuMTksMyw1LjkzLDcuOCw3LjQ1LDExLjA4QTkuNiw5LjYsMCwwLDEsMzAsNDkuMDlhOS4zMSw5LjMxLDAsMCwxLDIuODYuNDVjMS41Mi0zLjI4LDQuMjYtOC4xMSw3LjQ0LTExLjA5YTIwLjQ2LDIwLjQ2LDAsMCwwLDUuMDktNywxOSwxOSwwLDAsMCwxLjExLTUuODIiPjwvcGF0aD48cGF0aCBmaWxsPSIjMWQyMzI3IiBkPSJNMzYuMTIsNTguNDRBNi4xMiw2LjEyLDAsMSwxLDMwLDUyLjMyYTYuMTEsNi4xMSwwLDAsMSw2LjEyLDYuMTIiPjwvcGF0aD48L3N2Zz4=';

add_menu_page(
'Parse.ly Dashboard Page',
'Parse.ly',
Parsely::CAPABILITY, // phpcs:ignore WordPress.WP.Capabilities.Undetermined
'parsely-dashboard-page',
array( $this, 'add_dashboard_page_placeholder' ),
$icon,
30
);
}

/**
* Adds a placeholder for the dashboard page to render into.
*
* @since 3.18.0
*/
public function add_dashboard_page_placeholder(): void {
echo '<div id="parsely-dashboard-page"></div>';
}

/**
* Enqueues all needed scripts and styles for the dashboard page.
*
* @since 3.18.0
*
* @param ?string $hook_suffix The current page being loaded.
*/
public function enqueue_dashboard_page_scripts( ?string $hook_suffix ): void {
// Only load the scripts on the dashboard page.
if ( 'toplevel_page_parsely-dashboard-page' !== $hook_suffix ) {
return;
}

$asset_info = Utils::get_asset_info( 'build/content-helper/dashboard-page.asset.php' );
$built_assets_url = plugin_dir_url( PARSELY_FILE ) . '/build/content-helper/';

wp_enqueue_script(
'parsely-dashboard-page',
$built_assets_url . 'dashboard-page.js',
$asset_info['dependencies'],
$asset_info['version'],
true
);

wp_enqueue_style(
'parsely-dashboard-page',
$built_assets_url . 'dashboard-page.css',
$asset_info['dependencies'],
$asset_info['version']
);
}
}
2 changes: 2 additions & 0 deletions src/content-helper/dashboard-page/dashboard-page.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@import "../common/css/variables";
@import "../common/css/functions";
18 changes: 18 additions & 0 deletions src/content-helper/dashboard-page/dashboard-page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* WordPress dependencies
*/
import domReady from '@wordpress/dom-ready';
import { createRoot } from '@wordpress/element';

domReady( () => {
const root = createRoot(
document.getElementById( 'parsely-dashboard-page' ) as Element
);

root.render(
<>
<h1>Parse.ly</h1>
<p>Welcome to the Parse.ly Dashboard page!</p>
</>
);
} );
4 changes: 4 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ module.exports = {
path.resolve( __dirname, 'src', 'js', 'admin-settings' ),
path.resolve( __dirname, 'src', 'css', 'admin-settings.scss' ),
],
'content-helper/dashboard-page': [
path.resolve( __dirname, 'src', 'content-helper', 'dashboard-page', 'dashboard-page' ),
path.resolve( __dirname, 'src', 'content-helper', 'dashboard-page', 'dashboard-page.scss' ),
],
'content-helper/dashboard-widget': [
path.resolve( __dirname, 'src', 'content-helper', 'dashboard-widget', 'dashboard-widget' ),
path.resolve( __dirname, 'src', 'content-helper', 'dashboard-widget', 'dashboard-widget.scss' ),
Expand Down
8 changes: 6 additions & 2 deletions wp-parsely.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,15 @@

use Parsely\Content_Helper\Dashboard_Widget;
use Parsely\Content_Helper\Editor_Sidebar;
use Parsely\Content_Helper\Excerpt_Suggestions;
use Parsely\Content_Helper\Post_List_Stats;
use Parsely\Endpoints\GraphQL_Metadata;
use Parsely\Endpoints\Rest_Metadata;
use Parsely\Integrations\Amp;
use Parsely\Integrations\Google_Web_Stories;
use Parsely\Integrations\Integrations;
use Parsely\REST_API\REST_API_Controller;
use Parsely\UI\Admin_Bar;
use Parsely\UI\Admin_Warning;
use Parsely\UI\Dashboard_Page;
use Parsely\UI\Metadata_Renderer;
use Parsely\UI\Network_Admin_Sites_List;
use Parsely\UI\Plugins_Actions;
Expand Down Expand Up @@ -105,9 +104,14 @@ function parsely_admin_init_register(): void {
* Network Admin Sites List table.
*/
function parsely_wp_admin_early_register(): void {
// Plugin settings page.
$GLOBALS['parsely_settings_page'] = new Settings_Page( $GLOBALS['parsely'] );
$GLOBALS['parsely_settings_page']->run();

// Plugin dashboard page.
$GLOBALS['parsely_dashboard_page'] = new Dashboard_Page();
$GLOBALS['parsely_dashboard_page']->run();

$network_admin_sites_list = new Network_Admin_Sites_List( $GLOBALS['parsely'] );
$network_admin_sites_list->run();

Expand Down

0 comments on commit 22a3772

Please sign in to comment.