-
Notifications
You must be signed in to change notification settings - Fork 813
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
Donations block: Make currency and amounts editable #16593
Conversation
@Automattic/serenity folks, you're welcome to hop onto this PR and push commits addressing any feedback you might have. |
Thank you for the great PR description! When this PR is ready for review, please apply the E2E results is available here (for debugging purposes): https://jetpack-e2e-dashboard.herokuapp.com/pr-16593 Scheduled Jetpack release: August 4, 2020. |
const { currency, amounts, monthlyPlanId, annuallyPlanId, showCustomAmount } = attributes; | ||
const [ editedAmounts, setEditedAmounts ] = useState( amounts ); | ||
|
||
const minAmount = minimumTransactionAmountForCurrency( currency ); |
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.
We can wait on this for follow up, but we can maybe build a new currency validation package, since format-currency has the inverse job of making sure currency displays correctly given some known amount from the server.
As a reminder, we'll need to also mirror logic on the server API checks.
if ( ! amount ) { | ||
isValidAmount = false; | ||
} | ||
amount = parseFloat( amount ); |
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.
Leaving some general reminders for us when working with money:
JavaScript is unfortunately all floating point (so we end up needing to do string->float), but for later work on the server, as a general reminder:
- use ints to the desired precision level (eg a number in the smallest unit eg cents or fractions of a cent)
- Avoid type conversions until the end of computations to avoid compounding rounding errors. As a simple example, with floats (0.1+0.2) > 0.3 evaluates to
true
.
Good start here @mmtr ✨! I think we need to revisit the design here for editing tiers. For primary actions we'll want to be able to do this in the edit view, the block options in the sidebar are for advanced, optional settings, or providing another way to do something they can already do in the block. (For example, notice how we don't put every text field that's editable as an option in the sidebar settings. It's more intuitive for folks to double click on text). One way of doing this, when clicking on a tier button, we transform this into a plain text field or number field. Validation can run when we click outside of the area. cc @danhauk @sixhours @davemart-in in case y'all had thoughts |
I'll leave this for @danhauk to weigh in. |
As @gwwar noted, we should make the buttons directly editable. This was the intention with the earlier mockups but things may have gotten confused and/or lost in the shuffle of reshaping and scoping. Here's an older mockup of what that would look like (note: I still have a link to manage donations in Calypso so please ignore that): I modeled the behavior after the core button block where simply clicking into the button text would make it editable. A plain text field with number validation would be better IMO. The number field is sometimes cumbersome to use. The currency symbol would be uneditable, similar to the custom amount field at the bottom of the form. |
Thanks @danhauk! In regards to the amount validation, how we should highlight errors to users? Say a user enters a word (since it's a text field) or an invalid number (such an amount below the minimum threshold). Should we keep the invalid value user and indicate somehow in the UI there is an error (e.g. change the border color to red)? Or should we replace the invalid value with the previous valid value once the user focus another area of the editor? |
Caution: This PR has changes that must be merged to WordPress.com |
Just pushed an update that makes the amounts directly editable within the editor as suggested above. The currency selector has been moved away as well from the sidebar to the block toolbar. Also added some styles so the border color of the inputs changes when hovering them to make more clear they are editable, although I have the feeling there is room for improvement there. @danhauk feel free to propose any other idea! Didn't include anything for highlighting invalid amounts since I guess we can work on that on a follow-up PR once we have more feedback about the desired behavior. So far, the amounts are validated and only stored as attributes if they are valid. |
This is looking great @mmtr! As for the validation, what are your thoughts on using an HTML input pattern to take advantage of browser validation rather than a custom solution? I'm honestly not sure how the interaction would feel here. Are there any existing block examples you can think of that we could model the same behavior? I'll think a little bit on what a custom solution would look like. |
Hi @mmtr , Nice work! Tested this (Chrome, Safari and Firefox) and can verify it works as expected. When testing this with the Gutenberg plugin activated, the following notices appeared: Finally, some UX related comments:
|
Thanks for the review @fgiannar!
Do you see the same notices when testing this with Jetpack master? They seem to be unrelated to changes here.
Yup, this is expected at this moment. It'll be definitely nice to have the ability to customize the button styles, but it's not required for the initial launch of the Donations block. In a follow-up, we'll try to reuse either the core button block or the JP button block so we can get the styling controls out of the box.
I'll defer on @danhauk for this. I guess we have to approaches here:
I opted for the latter in this implementation, but I don't have any strong preference here.
I don't think we can automatically change the button label for other tabs, because it can cause semantic issues. Let's say the label in the monthly donations is built dynamically as |
Those notices were only reproduced in a post with a Donation block. I had tested it in an empty blog post and couldn't see them, so I assumed there was a relation to the Donation block. Since you checked it and can confirm it is unrelated, please ignore my comment.
Yes, you are right in terms of dynamically generated content. I was only expecting the static text to replace the dynamically generated one in all tabs. Eg all buttons share the same static text: "Want to donate? Click here". If you decide to defer any further UX related opts for a next release, please feel free to mark this as "Ready to merge", otherwise we could add the "Needs Design Review" label. Thanks for your prompt response! |
As per discussion with @danhauk in p1596458577169300-slack-C0Q664T29, we want to keep common items in sync while more specific items should not be synced. Items to sync
Items to not sync
Items marked with ✅ are currently covered in this PR, while items with ❌ need additional implementation. Would folks be open to keep things as they are now and do a follow-up for improvements? Don't want this PR to become much more complex, and since the block is still in beta we have flexibility for shipping small and iterative changes. |
Yes, followups please! Let's keep iterating forward while it's beta. @mmtr Fantastic, this feels even more bullet-proof. I removed references to the red border in the description, since we no longer see them (invalid characters are removed on focus change). Really great work 🎉 |
@fgiannar I added the "Ready to merge" label as advised, but I think the "Required review" still needs an explicit approval from your end (or anyone in @Automattic/jetpack-crew) to unblock merging. |
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.
LGTM
…ic/jetpack into add/jetpack-lazy-images-package * 'add/jetpack-lazy-images-package' of github.com:Automattic/jetpack: (40 commits) Lodash: Revert to previous version (#16735) New class to handle async XML-RPC requests (#16674) Social Previews: Sidebar design updates (#16725) Update E2E locator for classic connection flow (#16708) Woo Services: update to use existing Jetpack plugin install tools (#16672) Admin Page: avoid blank dashboard when notice is not a string (#16721) Admin Page: update string still using old i18n format (#16722) Social Previews: Add sidebar UI (#16633) Fix recurring payments block disconnecting (sometimes) when existing article is reopened in block editor. (#16640) Connection Register: Add current user email to connection register request (#16712) Update versions to start 8.9 Release cycle (#16706) Donations block: Make currency and amounts editable (#16593) Update dependency @automattic/calypso-color-schemes to v2 Error Notice: removing HTML code, adjusting maximum width. (#16690) Update dependency swiper to v6 (#16587) Site Scan: Short-circuit update_threats_link() if Admin Bar is not present (#16677) Update vulnerable NPM packages (#16659) E2E Tests: Add Jetpack updater test (#16437) check for subdir site before rendering Ads.txt section (#16671) VideoPress Block: Retain alignment support (#16651) ...
* Adds support for saving the content of a donations block into the post content, so the published view contains the block output. * It also follows up #16593 (comment) and implements the content sync logic as suggested there.
…16593) Adds the ability to edit the currency and amounts in a donations block.
* Adds support for saving the content of a donations block into the post content, so the published view contains the block output. * It also follows up #16593 (comment) and implements the content sync logic as suggested there.
Part of Automattic/wp-calypso#42856
Changes proposed in this Pull Request:
Adds the ability to edit the currency and amounts in a donations block.
Jetpack product discussion
pbMlHh-dW-p2
Does this pull request change what data or activity we track or use?
No.
Testing instructions:
JETPACK_BETA_BLOCKS
.JETPACK__SANDBOX_DOMAIN
value.Proposed changelog entry for your changes:
N/A