-
Notifications
You must be signed in to change notification settings - Fork 835
Blaze: add new dashboard menu #30103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
50 commits
Select commit
Hold shift + click to select a range
2d27bbc
Blaze: add new dashboard menu
jeherve bf75d2c
Add some basic tests
jeherve 896ef8f
[not verified] Merge remote-tracking branch 'origin/trunk' into add/b…
jeherve 5e37310
Add local setup for testing
sbarbosa 22e9ae6
Rename dashboard classes and remove unneeded config parameters
sbarbosa 148fd7b
Adds JS dependencies when loading the Blaze dashboard from the CDN
sbarbosa 3b39aea
Merge branch 'trunk' into add/blaze-dashboard-menu
sbarbosa d5cf234
Merge remote-tracking branch 'origin/trunk' into add/blaze-dashboard-…
jeherve 1cf5231
Move menu to Tools core menu
jeherve 19d4660
Update tests following menu location change
jeherve 538b16b
Changes Blaze entry points
sbarbosa f75f845
Merge remote-tracking branch 'origin/trunk' into add/blaze-dashboard-…
jeherve 5fe6693
Fix linting error
jeherve 08cda61
Add Status package dependency
jeherve 6888c0e
Update dashboard page path
jeherve 7a865b9
Switch to Plans package to avoid dependency to the Jetpack plugin
jeherve e3e1fd7
Add safeguards around endpoints
jeherve 86f260c
Switch to extracted method to check for wpcom simple
jeherve dbc779d
Only load admin scripts when necessary
jeherve a1857c4
Change dashboard link interceptor to new path
sbarbosa 6db420e
Update tests following dbc779d2c38c11b19381746dd112be149601f04a
jeherve 4f2d68e
Gate access to the new dashboard.
jeherve f91e4c4
Simplify the script enqueue test
jeherve b62ed16
Simplify how scripts and styles are enqueued
jeherve c2214e1
Extract filter into its own method and add test for it
jeherve 16e6bab
Pass filter status and site values from PHP to JS
jeherve 86c94c0
Introduce new method to display links to the Blaze dashboard
jeherve 014f8d7
Start using new method to display links in the Posts list
jeherve b547bfd
Introduce conditional Blaze links to the block editor panel
jeherve 9795e0a
Remove extra changelog entries
jeherve bf58c8d
Merge remote-tracking branch 'origin/trunk' into add/blaze-dashboard-…
jeherve 276c33c
Simplify fetching post title
jeherve 3fa2099
Remove unnecessary argument
jeherve de17d88
[not verified] Merge remote-tracking branch 'origin/trunk' into add/b…
jeherve a20893c
Added query strings to the DSP redirect calls
sbarbosa 3ba3264
Add validation to the query params
sbarbosa 77aea5f
Merge remote-tracking branch 'origin/trunk' into add/blaze-dashboard-…
jeherve 769f72e
Merge remote-tracking branch 'origin/trunk' into add/blaze-dashboard-…
jeherve 626f3cf
[not verified] Merge remote-tracking branch 'origin/trunk' into add/b…
jeherve 80c7c8e
Merge remote-tracking branch 'origin/trunk' into add/blaze-dashboard-…
jeherve a4638d5
Fixes error HTTP 414 on POST/PUT endpoints
sbarbosa ed25519
[not verified] Merge remote-tracking branch 'origin/trunk' into add/b…
jeherve 29dedd3
Separate generic rest into root controllers
sbarbosa 75f85bd
Improves get_data logic by reusing a variable
sbarbosa 724c172
[not verified] Merge remote-tracking branch 'origin/trunk' into add/b…
jeherve d428a3f
Bump versions
jeherve 7b3631e
Filter parameters to the WP endpoint call
sbarbosa 5ff108d
Fixes the register_rest_route to support queryparams if plain permali…
sbarbosa 7b1b445
[not verified] Merge remote-tracking branch 'origin/trunk' into add/b…
jeherve f51d02a
Fix copy/paste miss
jeherve File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
vendor/ | ||
wordpress/ | ||
node_modules/ | ||
dist/ | ||
build/ | ||
.cache/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Significance: minor | ||
Type: added | ||
|
||
Add new Blaze Dashboard menu item. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
145 changes: 145 additions & 0 deletions
145
projects/packages/blaze/src/class-dashboard-config-data.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
<?php | ||
/** | ||
* Blaze dashboard Initial State | ||
* | ||
* @package automattic/jetpack-blaze | ||
*/ | ||
|
||
namespace Automattic\Jetpack\Blaze; | ||
|
||
use Automattic\Jetpack\Current_Plan; | ||
use Jetpack_Options; | ||
|
||
/** | ||
* Class Dashboard_Config_Data | ||
*/ | ||
class Dashboard_Config_Data { | ||
/** | ||
* Set configData to window.configData. | ||
* | ||
* @param array $config_data The config data. | ||
*/ | ||
public function get_js_config_data( $config_data = null ) { | ||
return 'window.configData = ' . wp_json_encode( | ||
$config_data === null ? $this->get_data() : $config_data | ||
) . ';'; | ||
} | ||
|
||
/** | ||
* Return the config for the app. | ||
*/ | ||
public function get_data() { | ||
$blog_id = Jetpack_Options::get_option( 'id' ); | ||
$empty_object = json_decode( '{}' ); | ||
return array( | ||
'admin_page_base' => $this->get_admin_path(), | ||
'api_root' => esc_url_raw( rest_url() ), | ||
'blog_id' => $blog_id, | ||
'enable_all_sections' => false, | ||
'env_id' => 'production', | ||
'google_analytics_key' => 'UA-10673494-15', | ||
'hostname' => wp_parse_url( get_site_url(), PHP_URL_HOST ), | ||
'i18n_default_locale_slug' => 'en', | ||
'mc_analytics_enabled' => false, | ||
'meta' => array(), | ||
'nonce' => wp_create_nonce( 'wp_rest' ), | ||
'site_name' => \get_bloginfo( 'name' ), | ||
'sections' => array(), | ||
// Features are inlined in Calypso Blaze app (wp-calypso/apps/blaze-dashboard) | ||
'features' => array(), | ||
'intial_state' => array( | ||
'currentUser' => array( | ||
'id' => 1000, | ||
'user' => array( | ||
'ID' => 1000, | ||
'username' => 'no-user', | ||
'localeSlug' => $this->get_site_locale(), | ||
), | ||
'capabilities' => array( | ||
"$blog_id" => $this->get_current_user_capabilities(), | ||
), | ||
), | ||
'sites' => array( | ||
'items' => array( | ||
"$blog_id" => array( | ||
'ID' => $blog_id, | ||
'URL' => site_url(), | ||
'jetpack' => true, | ||
'visible' => true, | ||
'capabilities' => $empty_object, | ||
'products' => array(), | ||
'plan' => $empty_object, // we need this empty object, otherwise the front end would crash on insight page. | ||
'options' => array( | ||
'admin_url' => admin_url(), | ||
'gmt_offset' => $this->get_gmt_offset(), | ||
), | ||
), | ||
), | ||
'features' => array( "$blog_id" => array( 'data' => $this->get_plan_features() ) ), | ||
), | ||
), | ||
); | ||
} | ||
|
||
/** | ||
* Get the current site GMT Offset. | ||
* | ||
* @return float The current site GMT Offset by hours. | ||
*/ | ||
protected function get_gmt_offset() { | ||
return (float) get_option( 'gmt_offset' ); | ||
} | ||
|
||
/** | ||
* Page base for the Calypso admin page. | ||
*/ | ||
protected function get_admin_path() { | ||
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | ||
if ( ! isset( $_SERVER['PHP_SELF'] ) || ! isset( $_SERVER['QUERY_STRING'] ) ) { | ||
$parsed = wp_parse_url( admin_url( 'tools.php?page=advertising' ) ); | ||
return $parsed['path'] . '?' . $parsed['query']; | ||
} | ||
// We do this because page.js requires the exactly page base to be set otherwise it will not work properly. | ||
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | ||
return wp_unslash( $_SERVER['PHP_SELF'] ) . '?' . wp_unslash( $_SERVER['QUERY_STRING'] ); | ||
} | ||
|
||
/** | ||
* Get locale acceptable by Calypso. | ||
*/ | ||
protected function get_site_locale() { | ||
/** | ||
* In WP, locales are formatted as LANGUAGE_REGION, for example `en`, `en_US`, `es_AR`, | ||
* but Calypso expects language-region, e.g. `en-us`, `en`, `es-ar`. So we need to convert | ||
* them to lower case and replace the underscore with a dash. | ||
*/ | ||
$locale = strtolower( get_locale() ); | ||
$locale = str_replace( '_', '-', $locale ); | ||
|
||
return $locale; | ||
} | ||
|
||
/** | ||
* Get the features of the current plan. | ||
*/ | ||
protected function get_plan_features() { | ||
$plan = Current_Plan::get(); | ||
if ( empty( $plan['features'] ) ) { | ||
return array(); | ||
} | ||
return $plan['features']; | ||
} | ||
Comment on lines
+107
to
+131
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Down the road (not in this PR), I think it may be nice to extract those instead of copying them from the Stats Admin class. |
||
|
||
/** | ||
* Get the capabilities of the current user. | ||
* | ||
* @return array An array of capabilities. | ||
*/ | ||
protected function get_current_user_capabilities() { | ||
$user = wp_get_current_user(); | ||
if ( ! $user || is_wp_error( $user ) ) { | ||
return array(); | ||
} | ||
return $user->allcaps; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not a huge fan of returning an array here just to get the info on whether we should link outside of wp-admin or not, I would rather return just the URL. That said, this seemed cleaner than having to check the string returned by this method later on just to find out if it was an external link or not.