Skip to content
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

Widgets: Hide Simple Payments create and edit buttons in widgets.php #9811

Conversation

Copons
Copy link
Contributor

@Copons Copons commented Jun 22, 2018

Context: Automattic/wp-calypso#25576

The upcoming Simple Payments widget does not work in the Appearance/Widget page.
At a first look, it may require a heavy rework of its JS logic, that could probably make us miss the next JP release.

This is not exactly a fix, but a quick (and dirty) way to hide a feature from a section where it's broken, while keeping it in the section where it works, and all by remaining on time for the next JP release.

Changes proposed in this Pull Request:

  • In the Customizer: show the Simple Payments widget's Create and Edit buttons.
  • In the Appearance/Widget page: replace them with a message linking to the Customizer's widget panel.
Customizer Appearance/Widgets
screen shot 2018-06-22 at 11 58 13 screen shot 2018-06-25 at 15 00 19

Testing instructions:

  • Apply this PR on a Premium/Pro site.
  • Navigate to wp-admin/customize.php, open the Widgets panel, and add a Simple Payments widget.
  • Make sure it shows the "Add New" and "Edit Selected" buttons.
  • Navigate to wp-admin/widgets.php, and add a Simple Payments widget.
  • Make sure it doesn't show those buttons, but instead a message linking to the Customizer.
  • Also, make sure that the link to the Customizer actually opens its Widgets panel.

@Copons Copons added [Feature] Extra Sidebar Widgets [Status] Needs Review To request a review from Crew. Label will be renamed soon. Simple Payments labels Jun 22, 2018
@Copons Copons self-assigned this Jun 22, 2018
@Copons Copons requested review from a team June 22, 2018 10:59
@Copons Copons changed the title Add workaround message Widgets: Hide Simple Payments create and edit buttons in widgets.php Jun 22, 2018
@rodrigoi rodrigoi force-pushed the add/simple-payments-widget branch 2 times, most recently from 20f0b95 to f9a214c Compare June 22, 2018 18:41
@gwwar
Copy link
Contributor

gwwar commented Jun 22, 2018

For reference without any simple payment buttons it looks like:
screen shot 2018-06-22 at 2 17 47 pm

🤔 We can ask editorial for help but what would folks think of for "Create or edit payment buttons in the customizer." With the "Create or edit payment buttons" linked.

} );

function initWidget( widgetContainer ) {
var widgetForm = widgetContainer.find( '> .widget-inside > .form, > .widget-inside > form' );
Copy link
Contributor

Choose a reason for hiding this comment

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

No need for such a large refactor, but this may be a better fit for a delegated event handler, for example if we have a consistent parent such as:

$('.wpbody-content').on( 'click', '.jetpack-simple-payments-add-product', showAddNewForm );

This would allow us to only need to bind events once, but we'd need to rewrite handlers to be able to find the relevant widget to react to the correct form. Usually it's enough to do actions relative the to the closest parent SP widget.

http://api.jquery.com/on/

}

var productEmail = widgetForm.find( '.jetpack-simple-payments-form-product-email' ).val();
var isProductEmailValid = /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i.test( productEmail );
Copy link
Contributor

Choose a reason for hiding this comment

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

This is likely a copy pasta from elsewhere, but where did we get this one from? As a warning getting email validation right in a regex is rather difficult (the official spec is quite complex) so oftentimes folks can only be certain if we email something and it works. So expect a few false positive and negatives with valid/invalid emails, even if this looks quite long.

@gwwar
Copy link
Contributor

gwwar commented Jun 22, 2018

@apeatling how do you feel about the compromise here on the https://helpingcat.wpsandbox.me/wp-admin/widgets.php page? Due to the approaching deadline, I think I'd be okay with this provided that we followed up on improving this flow in Jetpack release after.

@Copons
Copy link
Contributor Author

Copons commented Jun 23, 2018

@gwwar Sorry, I think unrelated work going on in the feature branch messed up the diff of this PR.
Only change proposed here is:
https://github.com/Automattic/jetpack/blob/199c320b05991f2fdfa8bfd4364249dccb54bb79/modules/widgets/simple-payments/form.php#L139-L151
I'll rebase when I get a chance.

@gwwar
Copy link
Contributor

gwwar commented Jun 25, 2018

I'd be okay with going forward with this if we're running out of time for this release. Let's get another 👀 on copy before 🚢 , and write another issue to follow up or continue the convo on what we should do in this section.

@Copons Copons force-pushed the fix/disable-simple-payments-edit-on-widgets-page branch from 199c320 to b710e5a Compare June 25, 2018 12:02
@michelleweber
Copy link

There's nothing wrong with the language you're proposing. Personally tho, I'm inclined to be more positive and direct: "This widget adds a payment button of your choice to your sidebar. To create or edit the payment buttons themselves, use the Customizer," where "use the Customizer" is a link.

Tell them what to do and lose the "can only" -- close to what @gwwar's suggesting -- and offer a little explanation as to why this item is available in appearance > widgets at all if you can't create buttons there.

@rodrigoi
Copy link
Contributor

@Copons with the latest changes on the feature branch, there's a duplication of messages when the user has no products:

screen shot 2018-06-25 at 14 27 25

@Copons
Copy link
Contributor Author

Copons commented Jun 26, 2018

@rodrigoi Good catch!
I've moved the "no products" message inside the is_customizer check, so that in widgets.php we will only show the "can't create or edit" message.

@rodrigoi rodrigoi merged this pull request into add/simple-payments-widget Jun 26, 2018
@rodrigoi rodrigoi deleted the fix/disable-simple-payments-edit-on-widgets-page branch June 26, 2018 14:12
oskosk pushed a commit that referenced this pull request Jun 26, 2018
* Widgets: Adds support for Simple Payment Buttons as Widgets

* Simple Payments Widget: Add style overrides (#9580)

Override the media query and ensure that Simple Payments widgets are always displayed as a single column.

* Widgets: Only render the Simple Payments widget if its button exists (#9673)

In the frontend, only show the widget if the Simple Payments shortcode is parsed successfully.

In the customizer, show the widget regardless, so that it can be modified via the pencil icon.

* Simple Payment Widget: Manage Products from the Customizer (#9699)

* Customizer: Simple Payments Widget breaks when starting without products (#9809)

* Widgets: Hide Simple Payments create and edit buttons in widgets.php (#9811)

* Widgets: Record events for the Simple Payments widget (#9803)

* Widgets: Add Plan Check to the Simple Payments Widget (#9824)

* Customizer: keep Simple Payments Widget Customizer in sync between instances (#9814)

* Customizer: improves price validation on the Simple Payments Widget Customizer

* Customizer: improves the behaviour of the action buttons on the Simple Payments Widget Customizer
@oskosk oskosk added this to the 6.3 milestone Jun 28, 2018
@kraftbj kraftbj removed the [Status] Needs Review To request a review from Crew. Label will be renamed soon. label Sep 29, 2021
@jeherve jeherve added the [Feature] Pay with PayPal aka Simple Payments label Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants