Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 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
9 changes: 6 additions & 3 deletions projects/packages/forms/.phan/baseline.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@
// # Issue statistics:
// PhanTypeMismatchArgument : 45+ occurrences
// PhanPluginDuplicateConditionalNullCoalescing : 30+ occurrences
// PhanTypeMismatchReturnProbablyReal : 7 occurrences
// PhanDeprecatedFunction : 8 occurrences
// PhanTypeMismatchReturnProbablyReal : 8 occurrences
// PhanTypeMismatchArgumentProbablyReal : 6 occurrences
// PhanPluginDuplicateAdjacentStatement : 2 occurrences
// PhanPluginDuplicateAdjacentStatement : 3 occurrences
// PhanTypeConversionFromArray : 2 occurrences
// PhanTypeMismatchReturn : 2 occurrences
// PhanDeprecatedClass : 1 occurrence
// PhanPluginMixedKeyNoKey : 1 occurrence
// PhanPluginRedundantAssignment : 1 occurrence
// PhanPossiblyNullTypeMismatchProperty : 1 occurrence
Expand All @@ -30,9 +32,10 @@
'src/contact-form/class-contact-form-plugin.php' => ['PhanPluginDuplicateAdjacentStatement', 'PhanPluginDuplicateConditionalNullCoalescing', 'PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentProbablyReal', 'PhanTypeMismatchReturnProbablyReal'],
'src/contact-form/class-contact-form-shortcode.php' => ['PhanPluginDuplicateConditionalNullCoalescing', 'PhanTypeMismatchReturnProbablyReal'],
'src/contact-form/class-contact-form.php' => ['PhanPluginDuplicateConditionalNullCoalescing', 'PhanPluginRedundantAssignment', 'PhanTypeMismatchArgument', 'PhanTypeMismatchReturnNullable', 'PhanTypeMismatchReturnProbablyReal'],
'src/dashboard/class-dashboard-view-switch.php' => ['PhanUnreferencedUseNormal'],
'src/dashboard/class-dashboard-view-switch.php' => ['PhanDeprecatedFunction', 'PhanUnreferencedUseNormal'],
'src/service/class-google-drive.php' => ['PhanTypeMismatchReturnProbablyReal'],
'tests/php/contact-form/Contact_Form_Plugin_Test.php' => ['PhanPluginMixedKeyNoKey'],
'tests/php/dashboard/Dashboard_View_Switch_Test.php' => ['PhanDeprecatedClass', 'PhanDeprecatedFunction'],
],
// 'directory_suppressions' => ['src/directory_name' => ['PhanIssueName1', 'PhanIssueName2']] can be manually added if needed.
// (directory_suppressions will currently be ignored by subsequent calls to --save-baseline, but may be preserved in future Phan releases)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: removed

Forms: remove unused code Dashboard_View_Switch and move useful methods into Dashboard static methods
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use Automattic\Jetpack\Current_Plan;
use Automattic\Jetpack\Forms\ContactForm\Contact_Form;
use Automattic\Jetpack\Forms\ContactForm\Contact_Form_Plugin;
use Automattic\Jetpack\Forms\Dashboard\Dashboard_View_Switch;
use Automattic\Jetpack\Forms\Dashboard\Dashboard as Forms_Dashboard;
use Automattic\Jetpack\Forms\Jetpack_Forms;
use Automattic\Jetpack\Modules;
use Automattic\Jetpack\Status\Request;
Expand Down Expand Up @@ -779,11 +779,9 @@ public static function load_editor_scripts() {
);

// Create a Contact_Form instance to get the default values
$dashboard_view_switch = new Dashboard_View_Switch();
$form_responses_url = $dashboard_view_switch->get_forms_admin_url();
$form_responses_url = Forms_Dashboard::get_forms_admin_url();
$akismet_active_with_key = Jetpack::is_akismet_active();
$akismet_key_url = admin_url( 'admin.php?page=akismet-key-config' );
$preferred_view = $dashboard_view_switch->get_preferred_view();

$data = array(
'defaults' => array(
Expand All @@ -793,7 +791,6 @@ public static function load_editor_scripts() {
'akismetActiveWithKey' => $akismet_active_with_key,
'akismetUrl' => $akismet_key_url,
'assetsUrl' => Jetpack_Forms::assets_url(),
'preferredView' => $preferred_view,
'isMailPoetEnabled' => Jetpack_Forms::is_mailpoet_enabled(),
),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use Automattic\Jetpack\Connection\Manager as Connection_Manager;
use Automattic\Jetpack\External_Connections;
use Automattic\Jetpack\Forms\Dashboard\Dashboard as Forms_Dashboard;
use Automattic\Jetpack\Forms\Dashboard\Dashboard_View_Switch;
use Automattic\Jetpack\Forms\Jetpack_Forms;
use Automattic\Jetpack\Forms\Service\Google_Drive;
use Automattic\Jetpack\Forms\Service\MailPoet_Integration;
Expand Down Expand Up @@ -985,9 +984,8 @@ private function get_plugin_status( $plugin_slug, array $status ) {
// Override base shape for specific plugins.
switch ( $plugin_slug ) {
case 'akismet':
$dashboard_view_switch = new Dashboard_View_Switch();
$status['isConnected'] = class_exists( 'Jetpack' ) && \Jetpack::is_akismet_active();
$status['details']['formSubmissionsSpamUrl'] = $dashboard_view_switch->get_forms_admin_url( 'spam' );
$status['details']['formSubmissionsSpamUrl'] = Forms_Dashboard::get_forms_admin_url( 'spam' );
$status['needsConnection'] = true;
break;
case 'zero-bs-crm':
Expand Down Expand Up @@ -1042,7 +1040,6 @@ public function disable_integration( $request ) {
* @return WP_REST_Response
*/
public function get_forms_config( WP_REST_Request $request ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
$switch = new Dashboard_View_Switch();
$has_ai = false;
if ( class_exists( 'Jetpack_AI_Helper' ) ) {
$feature = Jetpack_AI_Helper::get_ai_assistance_feature();
Expand All @@ -1051,8 +1048,7 @@ public function get_forms_config( WP_REST_Request $request ) { // phpcs:ignore V

$config = array(
// From jpFormsBlocks in class-contact-form-block.php.
'formsResponsesUrl' => $switch->get_forms_admin_url(),
'preferredView' => $switch->get_preferred_view(),
'formsResponsesUrl' => Forms_Dashboard::get_forms_admin_url(),
'isMailPoetEnabled' => Jetpack_Forms::is_mailpoet_enabled(),
// From config in class-dashboard.php.
'blogId' => get_current_blog_id(),
Expand All @@ -1062,8 +1058,7 @@ public function get_forms_config( WP_REST_Request $request ) { // phpcs:ignore V
'hasFeedback' => ( new Forms_Dashboard() )->has_feedback(),
'hasAI' => $has_ai,
'isIntegrationsEnabled' => Jetpack_Forms::is_integrations_enabled(),
'renderMigrationPage' => $switch->is_jetpack_forms_announcing_new_menu(),
'dashboardURL' => add_query_arg( 'jetpack_forms_migration_announcement_seen', 'yes', $switch->get_forms_admin_url() ),
'dashboardURL' => Forms_Dashboard::get_forms_admin_url(),
// New data.
'canInstallPlugins' => current_user_can( 'install_plugins' ),
'canActivatePlugins' => current_user_can( 'activate_plugins' ),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ protected function __construct() {
),
'menu_icon' => 'dashicons-feedback',
// when the legacy menu item is retired, we don't want to show the default post type listing
'show_ui' => ! Jetpack_Forms::is_legacy_menu_item_retired(),
'show_ui' => false,
'show_in_menu' => false,
'show_in_admin_bar' => false,
'public' => false,
Expand Down Expand Up @@ -1358,7 +1358,7 @@ public static function gutenblock_render_field_image_select( $atts, $content, $b
public function admin_menu() {
$slug = 'feedback';

if ( is_plugin_active( 'polldaddy/polldaddy.php' ) || ! Jetpack_Forms::is_legacy_menu_item_retired() ) {
if ( is_plugin_active( 'polldaddy/polldaddy.php' ) ) {
add_menu_page(
__( 'Feedback', 'jetpack-forms' ),
__( 'Feedback', 'jetpack-forms' ),
Expand All @@ -1385,12 +1385,11 @@ public function admin_menu() {
$slug
);

if ( Jetpack_Forms::is_legacy_menu_item_retired() ) {
remove_submenu_page(
$slug,
'edit.php?post_type=feedback'
);
}
// remove the first default submenu item
remove_submenu_page(
$slug,
'edit.php?post_type=feedback'
);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
namespace Automattic\Jetpack\Forms\ContactForm;

use Automattic\Jetpack\Connection\Tokens;
use Automattic\Jetpack\Forms\Dashboard\Dashboard_View_Switch;
use Automattic\Jetpack\Forms\Dashboard\Dashboard as Forms_Dashboard;
use Automattic\Jetpack\JWT;
use Automattic\Jetpack\Sync\Settings;
use Jetpack_Tracks_Event;
Expand Down Expand Up @@ -504,7 +504,7 @@ public static function add_quick_link_to_admin_bar( \WP_Admin_Bar $admin_bar ) {
return;
}

$url = ( new Dashboard_View_Switch() )->get_forms_admin_url();
$url = Forms_Dashboard::get_forms_admin_url();

$admin_bar->add_menu(
array(
Expand Down Expand Up @@ -1978,7 +1978,7 @@ public function process_submission() {
$dashboard_url = '';
$footer_mark_as_spam_url = '';
if ( $feedback_status !== 'jp-temp-feedback' ) {
$dashboard_url = ( new Dashboard_View_Switch() )->get_forms_admin_url( $status, true ) . '&r=' . $post_id;
$dashboard_url = Forms_Dashboard::get_forms_admin_url( $status ) . '&r=' . $post_id;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: $status is a confusing name, $tab would work better.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll agree with you semantically, but as the tab also represents the post status, I think it can stay. Besides, it's unrelated to the main goal of this PR.

$mark_as_spam_url = $dashboard_url . '&mark_as_spam';
$footer_mark_as_spam_url = sprintf(
'<a href="%1$s">%2$s</a>',
Expand Down
2 changes: 1 addition & 1 deletion projects/packages/forms/src/dashboard/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ This is the React-app implementation for the new Jetpack Forms dashboard.
├── state/ - App state.
├── index.js - App entrypoint.
├── class-dashboard.php - Jetpack Forms WP Admin setup.
└── class-dashboard-view-switch.php - Feedback view toggle implementation.
└── class-dashboard-view-switch.php - Feedback view toggle implementation (deprecated, unused).
```

*\**: All views get their own dedicated directory while reusable components go into `components/`.
Expand Down
137 changes: 0 additions & 137 deletions projects/packages/forms/src/dashboard/admin-migrate-page/index.tsx

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

/**
* Understands switching between classic and redesigned versions of the feedback admin area.
*
* @deprecated $$next-version$$ This class is no longer needed and has been removed from active use.
*/
class Dashboard_View_Switch {

Expand All @@ -35,8 +37,11 @@ class Dashboard_View_Switch {

/**
* Initialize the switch.
*
* @deprecated $$next-version$$ This class is no longer needed and has been removed from active use.
*/
public function init() {
_deprecated_function( __METHOD__, 'jetpack-$$next-version$$' );
add_action( 'admin_print_styles', array( $this, 'print_styles' ) );
add_filter( 'in_admin_header', array( $this, 'render_switch' ) );
add_action( 'admin_footer', array( $this, 'add_scripts' ) );
Expand Down Expand Up @@ -339,9 +344,12 @@ public function is_modern_view() {
/**
* Returns true if the current screen is the Jetpack Forms admin page.
*
* @deprecated $$next-version$$ Use Dashboard::is_jetpack_forms_admin_page() instead.
*
* @return boolean
*/
public function is_jetpack_forms_admin_page() {
_deprecated_function( __METHOD__, 'jetpack-$$next-version$$', 'Dashboard::is_jetpack_forms_admin_page' );
if ( ! function_exists( 'get_current_screen' ) ) {
return false;
}
Expand All @@ -353,12 +361,15 @@ public function is_jetpack_forms_admin_page() {
/**
* Returns url of forms admin page.
*
* @deprecated $$next-version$$ Use Dashboard::get_forms_admin_url() instead.
*
* @param string|null $tab Tab to open in the forms admin page.
* @param boolean $force_inbox Whether to force the inbox view URL.
*
* @return string
*/
public function get_forms_admin_url( $tab = null, $force_inbox = false ) {
_deprecated_function( __METHOD__, 'jetpack-$$next-version$$', 'Dashboard::get_forms_admin_url' );
$is_classic = $this->get_preferred_view() === self::CLASSIC_VIEW;
$switch_is_available = $this->is_jetpack_forms_view_switch_available();

Expand Down Expand Up @@ -401,9 +412,12 @@ private function append_tab_to_url( $url, $tab, $is_classic_view ) {
/**
* Returns true if the new Jetpack Forms admin page is available.
*
* @deprecated $$next-version$$ Use Dashboard::is_jetpack_forms_admin_page_available() instead.
*
* @return boolean
*/
public static function is_jetpack_forms_admin_page_available() {
_deprecated_function( __METHOD__, 'jetpack-$$next-version$$', 'Dashboard::is_jetpack_forms_admin_page_available' );
return apply_filters( 'jetpack_forms_use_new_menu_parent', true );
}

Expand Down
Loading
Loading