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

WIP Donations block: Update donations block to use inner blocks #22470

Closed
wants to merge 169 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
169 commits
Select commit Hold shift + click to select a range
2caf0a0
TIP/POC, Donations block is now built using InnerBlocks instead of fi…
rcrdortiz Jan 24, 2022
14252e7
Added a changelog entry
rcrdortiz Jan 24, 2022
eee7003
js-test-runner: Add WorDBless dir to jest collectCoverageFrom (#22472)
anomiex Jan 24, 2022
4838949
Docker Image: Update Ubuntu version to 21.04 (#22449)
pablinos Jan 24, 2022
dace448
Add backup to previous vendor copy logic (#22451)
jwebbdev Jan 24, 2022
56c07f2
widget-conditions: fix regression introduced in #22414 (#22457)
yoavf Jan 24, 2022
8a829ce
cli: Add missing `nyc` dep when creating JS packages (#22471)
anomiex Jan 24, 2022
f0c1647
Analyzer: Add API for a service (#22035)
brbrr Jan 25, 2022
d281792
Search Package: Add watch command (#22455)
jsnmoon Jan 25, 2022
3dd572e
My Jetpack: check user connectivity before hitting wpcom side (#22478)
retrofox Jan 25, 2022
4cac634
Connection: Fix misspelling of propTypes in ConnectedPlugins componen…
oskosk Jan 25, 2022
264a0d4
Jetpack: add testing list for 10.6 (#22485)
jeherve Jan 25, 2022
63db714
i18n-loader-webpack-plugin: Move the actual downloading out of the ru…
anomiex Jan 25, 2022
6f28f0b
TWe now show the donations icon for each donation view in the block i…
rcrdortiz Jan 25, 2022
d59d9a1
Bump PHP test timeout to 20 min (#22488)
kraftbj Jan 25, 2022
f55264a
Jetpack 10.6: changelogs for Beta release (#22487)
jeherve Jan 25, 2022
22eea22
Added basic saving functionality. The block is now partially rendered…
rcrdortiz Jan 25, 2022
453cb69
Release: start 10.7-a.0 cycle (#22492)
jeherve Jan 25, 2022
768c6f9
Connection: Fix access to display_name property in connection status …
oskosk Jan 25, 2022
fb959d1
My Jetpack: Update data handling - Implement request status in Produc…
retrofox Jan 25, 2022
7cb65b2
Reduced Sync Search test data sample. (#22493)
zinigor Jan 25, 2022
f36173e
Use twentytwentyone theme for e2e tests (#22501)
adimoldovan Jan 26, 2022
cbaf0d6
Search: allow the Search team to approve changes to the package (#22461)
jeherve Jan 26, 2022
65966f6
My Jetpack: Implement first approach for global notice (#22484)
retrofox Jan 26, 2022
9beef49
My Jetpack: Update plugin absent status consistently (#22503)
retrofox Jan 26, 2022
2cf4154
My Jetpack: Fire Tracks events for product activation and deactivatio…
oskosk Jan 26, 2022
a12a061
Extract/jetpack plugin installer (#22477)
leogermani Jan 26, 2022
e164982
fix the set_error_message logic (#22509)
leogermani Jan 26, 2022
bb1b6a9
[Plugin] Backup: Post-release changelog / readme update (#22510)
jwebbdev Jan 26, 2022
549a2d7
cli: Add dependency analysis helper and command (#22433)
anomiex Jan 26, 2022
6c89e07
Uses Plugins Installer package in My Jetpack (#22512)
leogermani Jan 26, 2022
33634ac
JT: Add disclaimer (#22513)
kraftbj Jan 26, 2022
c744b54
Markdown: Fix filter_var usage (#22515)
sdixon194 Jan 27, 2022
b5f3436
Search: fix search product supporting determination (#22519)
kangzj Jan 27, 2022
f5832e5
Dashboard: Replace renderPairs logic for a more declarative approach …
oskosk Jan 27, 2022
f7e25bb
Added new filter to update the output HTML of Related Posts module (#…
mkm119 Jan 27, 2022
989ca75
Search: release a new version of the package. (#22523)
jeherve Jan 27, 2022
62acd85
Build: add missing mirror repo details, so package can be deployed (#…
jeherve Jan 27, 2022
3a3e024
IDC: "Safe Mode" admin bar button redesign (#22494)
sergeymitr Jan 27, 2022
8b83a86
Plans: add more variations on the Security plans' slugs. (#22533)
jeherve Jan 27, 2022
512c54a
Docs: Update command to run server-rendered fixture tests. (#22525)
yansern Jan 27, 2022
19937d1
Release packages/identity-crisis v0.7 (#22535)
sergeymitr Jan 27, 2022
2571da7
Add/installation to my jetpack (#22529)
leogermani Jan 27, 2022
f6252a8
Docker: Set SCRIPT_DEBUG constant when setting up the environment (#2…
oskosk Jan 27, 2022
de79d42
Admin: update upgrade links to use new instertials when possible (#22…
jeherve Jan 27, 2022
447774f
cli: Refactor build and install commands (#22538)
anomiex Jan 27, 2022
99b0acc
Build: remove unneeded files from packages' production builds. (#22498)
jeherve Jan 27, 2022
0f53d59
My Jetpack: Use apiNonce and apiRoot from a new global var, and not f…
oskosk Jan 27, 2022
4f00976
Dashboard: Fix all React warnings shown on the console (#22518)
oskosk Jan 28, 2022
3980b6e
Shared Extension Utilities: Initial setup of the package (#22505)
pablinos Jan 28, 2022
773e44a
Search package: Add constant version number and some global functions…
kangzj Jan 28, 2022
1af5545
cli: Add timing to build output (#22539)
anomiex Jan 28, 2022
f798ee2
Payments block: Add transform from buttons (#22375)
dsas Jan 28, 2022
046b0d1
Business Hours: Add color, typography, spacing & alignment design to…
yansern Jan 28, 2022
7c4856a
My Community widget: widget deprecation (#22532)
ivan-ottinger Jan 28, 2022
26a8bb5
Search: Initialize debug bar using correct class (#22541)
jsnmoon Jan 28, 2022
86c47c5
Dashboard: Update Apps Card to not require utm_source prop (#22545)
oskosk Jan 28, 2022
5d06380
Instant Search: add image alt text from API (#22295)
bluefuton Jan 28, 2022
8fccc73
Premium content block: Add a warning message for invalid plans (#22446)
BogdanUngureanu Jan 28, 2022
3a7c4b2
Fix E2E tests (#22459)
thingalon Jan 28, 2022
d683d41
Fix breaking unit tests (#22551)
jim-coffey Jan 28, 2022
694f111
My Jetpack: Handle when site is not connected (#22530)
retrofox Jan 28, 2022
cd75f36
My Jetpack: handle redirect when no connection (#22549)
retrofox Jan 28, 2022
cc220d5
Do not initialize My Jetpack if site not connected (#22552)
leogermani Jan 28, 2022
a875b06
Fix My jetpack tests (#22555)
leogermani Jan 28, 2022
98aabd0
Fix list-changed-projects.sh (#22554)
anomiex Jan 28, 2022
1bcdaca
RNA: New layout structure for Container and Col (#22496)
renatoagds Jan 29, 2022
1af92d6
Boost: refactor Critical CSS: Part 1 (#22163)
pyronaur Jan 31, 2022
556b650
Search: Allow unconnected admins to manage setting (#22557)
jsnmoon Jan 31, 2022
86b4357
actions: Remove hack now that WP 5.9 is "latest" (#22556)
anomiex Jan 31, 2022
8108a20
Extension utils: prepare for an initial release (#22544)
jeherve Jan 31, 2022
832da50
Search: update package (#22560)
jeherve Jan 31, 2022
d7ad078
Components: re organize stories by project and package name (#22565)
retrofox Jan 31, 2022
958ea49
My Jetpack: tweak dims of the Product card status (#22561)
retrofox Jan 31, 2022
84b01a3
My Jetpack: Fix stories for ProductCard component (#22574)
retrofox Jan 31, 2022
47b59ec
My Jetpack: fix tracking event when activating product (#22575)
retrofox Jan 31, 2022
aa5719b
my-jetpack: reorganize stories by project/type/ (#22576)
retrofox Jan 31, 2022
476b02f
Track user clicks on Links/Buttons in disconnect modal footer (#22467)
jim-coffey Jan 31, 2022
0ece064
My Jetpack: Fix gap between product cards (#22577)
renatoagds Jan 31, 2022
9e4eb07
My Jetpack: Add products abstraction (#22550)
leogermani Jan 31, 2022
752b614
Dashboard: Update jQuery usage to comply with jQMIGRATE recommendatio…
oskosk Jan 31, 2022
e23c6e2
Search: set default value when saving widget instance (#22567)
jeherve Feb 1, 2022
825a238
Sharing: Add an AMP-compatible version of the email share button (#22…
laurelfulford Feb 1, 2022
7d15e1e
Recurring Payments: Remove BlockIcon Wrappers (#13324)
ockham Feb 1, 2022
e8c9c80
My Jetpack: Add react-router for route handling (#22585)
renatoagds Feb 1, 2022
cc1d2f9
VaultPress: update WordPress version requirements (#22592)
jeherve Feb 1, 2022
33dca90
My Jetpack: My Jetpack: connect Backup product class with Product cla…
retrofox Feb 1, 2022
4e69791
My Jetpack: connect all product cards with data provider (#22578)
retrofox Feb 1, 2022
fb2c7da
cli: Build in dependency order, optionally with dependencies (#22580)
anomiex Feb 1, 2022
7d966b1
Janitorial: update orphan projects (#22591)
jeherve Feb 1, 2022
ab2c107
My Jetpack: Add filter for avoiding initalization (#22553)
oskosk Feb 1, 2022
fe8cf5d
VaultPress: start new release cycle (#22599)
jeherve Feb 1, 2022
523447f
Widget Visibility: ensure we find the correct site type (#22527)
jeherve Feb 1, 2022
e053d2b
Add/module products (#22596)
leogermani Feb 1, 2022
0752934
Storybook: Add 'Jetpack Dashboard' background color (#22597)
retrofox Feb 1, 2022
b82e303
My Jetpack: avoid performing a request for each product (#22605)
retrofox Feb 1, 2022
d1d52c8
add user connection requirement to product info (#22606)
leogermani Feb 1, 2022
2922c67
Update Eslint packages (major) (#21604)
renovate[bot] Feb 1, 2022
7e80d11
VaultPress: do not ship PHPCS config file in production (#22604)
jeherve Feb 1, 2022
bc6886e
Codesniffer: Disallow relative includes (#22603)
kraftbj Feb 1, 2022
510ae6a
search pkg: Add `@use "sass:math"` in base styles scss (#22601)
anomiex Feb 2, 2022
ce7bb10
Stale Action: updates for better stale flagging (#22571)
jeherve Feb 2, 2022
2dd537b
cli: Fix friendly error for missing modules (#22620)
anomiex Feb 2, 2022
b02774b
Jetpack 10.7-a.1 Atomic Release (#22621)
sdixon194 Feb 2, 2022
b9ed0d7
Jetpack 10.7-a.2 Cycle Start (#22624)
sdixon194 Feb 2, 2022
b984aa7
Docs: Adding minor edits to the Quick Start Guide (#22500)
coder-karen Feb 2, 2022
4b320c1
Docs: Adding working link to show Good For Community issues (#22616)
coder-karen Feb 2, 2022
2b70118
Block Upgrade banner: Updated the upgrade banner description to inclu…
BogdanUngureanu Feb 2, 2022
ba1dfa7
VideoPress: fix potential use of unexisting allow_download property (…
thedebian Feb 2, 2022
b22e4e8
My Jetpack: Adding Connection Screen (#22609)
renatoagds Feb 2, 2022
864d6a3
Update wordpress monorepo (#22586)
renovate[bot] Feb 2, 2022
fdf40bb
Introduce Waf package (#22402)
miguelxpn Feb 2, 2022
12622b9
Update: license activation dialog text (#22570)
andrii-lysenko Feb 2, 2022
0e4fe4f
WordAds: deprecate legacy widget (#22208)
jeherve Feb 2, 2022
ac3daa7
My Jetpack: Update/my jetpack restore get product resolver (#22618)
retrofox Feb 2, 2022
c591f2d
Workaround add_submenu_page bug to fix jetpack menu order (#22623)
leogermani Feb 2, 2022
d1916fd
My Jetpack: Add ProductDetailCard component (#22593)
retrofox Feb 2, 2022
9ea6026
My Jetpack: Fire Tracks events for click on product add link (#22629)
oskosk Feb 2, 2022
4a9a5c1
codesniffer: Update `wp-coding-standards/wpcs` to `dev-develop` (#22600)
anomiex Feb 2, 2022
eea0c5b
Add anti spam into my jetpack (#22628)
leogermani Feb 2, 2022
bab7139
E2E tests: merge github workflows (#22318)
adimoldovan Feb 2, 2022
fdecb31
User Queries: update parameters to take into account changes in WP 5.…
jeherve Feb 3, 2022
ff3ce45
Fix: Lazy Loading images (#22566)
pyronaur Feb 3, 2022
8e0dff0
Contact Form: Defensive coding against bad hash (#20923)
kraftbj Feb 3, 2022
f1ebb6d
E2E tests: fix unsupported GITHUB_EVENT_NAME for schedule runs (#22637)
adimoldovan Feb 3, 2022
04d1389
WIP, merged the donations editable blocks block with the actual donat…
rcrdortiz Feb 3, 2022
4ef58af
Search: migrate search widget to package (#22364)
kangzj Feb 3, 2022
f5d01d0
cli: Build in parallel! (#22631)
anomiex Feb 3, 2022
5cecab9
WAF: do not ship .phpcs.dir.xml in production build (#22635)
jeherve Feb 3, 2022
006bb98
My Jetpack: Fix reducer for SET_PRODUCT_STATUS (#22644)
oskosk Feb 3, 2022
4752c6c
My Jetpack: expose pricing product data (#22630)
retrofox Feb 3, 2022
2422574
My Jetpack: Add product/Boost interstitial component (#22643)
retrofox Feb 3, 2022
ff4490a
My Jetpack: Add notice styles improvement and redirect for connection…
renatoagds Feb 3, 2022
1557a93
Search dashboard: add scaffolding for Record Meter (#22497)
bluefuton Feb 3, 2022
8493041
My Jetpack: Add title and features to products data (#22651)
retrofox Feb 3, 2022
301c0f5
Create new Plans package (#22650)
leogermani Feb 3, 2022
9f23aae
Search package: Add search auto_config CLI (#22614)
kangzj Feb 4, 2022
46cde78
E2E tests: optimize scheduled runs
adimoldovan Feb 4, 2022
daf8b9c
Do not send Slack notifications for cancelled test jobs (#22638)
adimoldovan Feb 4, 2022
630d64e
Publicize: Add empty Composer package (#22607)
danielpost Feb 4, 2022
be9c645
My Jetpack: Connect Boost card with the interstitial (#22656)
retrofox Feb 4, 2022
ffa189b
My Jetpack: useCallback for track functions that are bound to onEvent…
retrofox Feb 4, 2022
8d82969
My Jetpack: Fire Tracks event when showing product Interstitial page …
oskosk Feb 4, 2022
630677a
Premium content: Improve editing consistency (#22626)
dsas Feb 4, 2022
d2bc493
My Jetpack: Fire Tracks event when clicking CTA button on product Int…
oskosk Feb 4, 2022
b5a7ebb
Internet Defense League widget: Widget deprecation (#22676)
ivan-ottinger Feb 4, 2022
eac7a0c
Plans: update to support mirror repo. (#22658)
jeherve Feb 4, 2022
08f88f5
My Jetpack: Introduce basic Layout component. Add GoBackLink componen…
retrofox Feb 4, 2022
d84c8b3
WIP, mThe amount block controls now properly style the block. Text is…
rcrdortiz Feb 4, 2022
a40f746
Twitter Gather: make endpoint restricted to contributors (#22657)
jeherve Feb 4, 2022
53d899b
Add has_required_plan to product info and implement it in Search (#22…
leogermani Feb 4, 2022
8501283
My Jetpack: add search product data (#22685)
retrofox Feb 4, 2022
c6c09d3
PHPCS: Ignore rule by file for WP.com (#22689)
kraftbj Feb 4, 2022
f150c5f
Jetpack At-a-glance: Replace Backup upgrade banner with a coupon rede…
atanas-dev Feb 7, 2022
57f52d0
Add plan verification for backup and scan (#22688)
leogermani Feb 7, 2022
68ce07f
My Jetpack: Implement Free price for Boost product (#22680)
retrofox Feb 7, 2022
9a0ab28
My Jetpack: add Search interstitial view (#22687)
retrofox Feb 7, 2022
88ed8df
VideoPress: Change the default for the "usesAverageColor" setting to …
jgcaruso Feb 7, 2022
975d71f
Jetpack plugin: add Jetpack partner coupon banner on My Page (#22633)
kallehauge Feb 7, 2022
01cddea
Jetpack: Add coupon event properties to My Plan Partner Banner compon…
kallehauge Feb 7, 2022
2bc858a
Fix front-end performance of Tiled Gallery block (#22547)
guarani Feb 7, 2022
0e7e3fe
[not verified] TIP/POC, Donations block is now built using InnerBlock…
rcrdortiz Jan 24, 2022
d0a04ab
[not verified] Added a changelog entry
rcrdortiz Jan 24, 2022
3c1cd2f
[not verified] TWe now show the donations icon for each donation view…
rcrdortiz Jan 25, 2022
5ec6e99
[not verified] Added basic saving functionality. The block is now par…
rcrdortiz Jan 25, 2022
b81a965
[not verified] WIP, merged the donations editable blocks block with t…
rcrdortiz Feb 3, 2022
385604a
[not verified] WIP, mThe amount block controls now properly style the…
rcrdortiz Feb 4, 2022
97904a4
Implemented migration of the deprecated block. The old block is now d…
rcrdortiz Feb 7, 2022
c41d35e
Merge branch 'update/donations-block-to-inner-blocks' of github.com:A…
rcrdortiz Feb 7, 2022
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: enhancement

Ported Donations block from RichText to InnerBlocks.
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php
/**
* Donations Amount Child Block.
*
* @package automattic/jetpack
*/

namespace Automattic\Jetpack\Extensions\Donations_Editable;

use Automattic\Jetpack\Blocks;
use Jetpack_Currencies;
use Jetpack_Gutenberg;
use Jetpack_Memberships;

const DONATIONS_AMOUNT_BLOCK_NAME = 'donations-amount';

/**
* Registers the block for use in Gutenberg
* This is done via an action so that we can disable
* registration if we need to.
*/
function register_donations_amount_block() {
Blocks::jetpack_register_block(
DONATIONS_AMOUNT_BLOCK_NAME,
array(
'render_callback' => __NAMESPACE__ . '\render_amount_block',
)
);
}

add_action( 'init', __NAMESPACE__ . '\register_donations_amount_block' );

/**
* Render callback.
*
* @param array $attr Array containing the block attributes.
*
* @return string
*/
function render_amount_block( $attr ) {
jetpack_require_lib( 'class-jetpack-currencies' );

Jetpack_Gutenberg::load_styles_as_required( DONATIONS_AMOUNT_BLOCK_NAME );

if ( $attr['disabled'] ) {
$default_custom_amount = Jetpack_Memberships::SUPPORTED_CURRENCIES[ $attr['currency'] ] * 100;
return sprintf(
'<div class="donations__amount donations__custom-amount">
%1$s
<div class="donations__amount-value" data-currency="%2$s" data-empty-text="%3$s"></div>
</div>',
esc_html( Jetpack_Currencies::CURRENCIES[ $attr['currency'] ]['symbol'] ),
esc_attr( $attr['currency'] ),
esc_attr( Jetpack_Currencies::format_price( $default_custom_amount, $attr['currency'], false ) )
);
}

return sprintf(
'<div class="donations__amount" data-amount="%1$s">%2$s</div>',
esc_attr( $attr['amount'] ),
esc_html( Jetpack_Currencies::format_price( $attr['amount'], $attr['currency'] ) )
);
}
Original file line number Diff line number Diff line change
@@ -1,53 +1,48 @@
/**
* External dependencies
*/
import formatCurrency, { CURRENCIES } from '@automattic/format-currency';
import classnames from 'classnames';
import { minimumTransactionAmountForCurrency, parseAmount } from '../../../shared/currencies';

/**
* WordPress dependencies
* Internal dependencies
*/
import { RichText } from '@wordpress/block-editor';
import { useCallback, useEffect, useRef, useState } from '@wordpress/element';
import DonationsContext from '../common/context';

/**
* Internal dependencies
* WordPress dependencies
*/
import { minimumTransactionAmountForCurrency, parseAmount } from '../../shared/currencies';
import { RichText } from '@wordpress/block-editor';
import formatCurrency, { CURRENCIES } from '@automattic/format-currency';
import { useCallback, useContext, useEffect, useMemo, useRef, useState } from '@wordpress/element';

const Amount = ( {
className = null,
currency = null,
defaultValue = null,
disabled = false,
label = '',
onChange = null,
value = '',
} ) => {
const Edit = props => {
const { attributes, setAttributes } = props;
const { baseAmountMultiplier, className, label, amount, disabled = false } = attributes;
const { currency } = useContext( DonationsContext );
const defaultValue = useMemo(
() => minimumTransactionAmountForCurrency( currency ) * baseAmountMultiplier,
[ currency, baseAmountMultiplier ]
);
const [ editedValue, setEditedValue ] = useState(
formatCurrency( value, currency, { symbol: '' } )
formatCurrency( amount, currency, { symbol: '' } )
);
const [ isFocused, setIsFocused ] = useState( false );
const [ isInvalid, setIsInvalid ] = useState( false );
const richTextRef = useRef( null );

const setAmount = useCallback(
amount => {
setEditedValue( amount );

if ( ! onChange ) {
return;
}

const parsedAmount = parseAmount( amount, currency );
newAmount => {
setEditedValue( newAmount );
setAttributes( { amount: newAmount, currency } );
const parsedAmount = parseAmount( newAmount, currency );
if ( parsedAmount && parsedAmount >= minimumTransactionAmountForCurrency( currency ) ) {
onChange( parsedAmount );
setIsInvalid( false );
} else if ( amount ) {
} else if ( newAmount ) {
setIsInvalid( true );
}
},
[ currency, onChange ]
[ currency, setAttributes ]
);

const setFocus = () => {
Expand All @@ -73,17 +68,8 @@ const Amount = ( {
if ( isFocused || editedValue ) {
return;
}

setAmount( formatCurrency( defaultValue, currency, { symbol: '' } ) );
}, [ currency, defaultValue, editedValue, isFocused, setAmount ] );

// Syncs the edited value with the actual value whenever the latter changes (e.g. new default amount after a currency change).
useEffect( () => {
if ( isFocused || isInvalid ) {
return;
}
setEditedValue( formatCurrency( value, currency, { symbol: '' } ) );
}, [ currency, isFocused, isInvalid, setAmount, value ] );
}, [ currency, editedValue, isFocused, setAmount, defaultValue ] );

return (
<div
Expand All @@ -99,23 +85,21 @@ const Amount = ( {
{ CURRENCIES[ currency ].symbol }
{ disabled ? (
<div className="donations__amount-value">
{ formatCurrency( value ? value : defaultValue, currency, { symbol: '' } ) }
{ formatCurrency( amount ? amount : defaultValue, currency, { symbol: '' } ) }
</div>
) : (
<RichText
allowedFormats={ [] }
aria-label={ label }
keepPlaceholderOnFocus={ true }
multiline={ false }
onChange={ amount => setAmount( amount ) }
placeholder={ formatCurrency( defaultValue, currency, { symbol: '' } ) }
onChange={ newAmount => setAmount( newAmount ) }
ref={ richTextRef }
value={ editedValue }
withoutInteractiveFormatting
/>
) }
</div>
);
};

export default Amount;
export default Edit;
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { button as icon } from '@wordpress/icons';

/**
* Internal dependencies
*/
import edit from './edit';
import save from './save';

const name = 'donations-amount';
const BUTTON_BEHAVIOUR_TITLE = __( 'Amount selector', 'jetpack' );
const INPUT_BEHAVIOUR_TITLE = __( 'Custom amount field', 'jetpack' );

const settings = {
title: __( 'Donations amount button', 'jetpack' ),
description: __( 'Button that determines a fixed donation amount', 'jetpack' ),
category: 'earn',
attributes: {
baseAmountMultiplier: {
type: 'string',
},
label: {
type: 'string',
},
currency: {
type: 'string',
},
amount: {
type: 'string',
},
disabled: {
type: 'boolean',
},
},
__experimentalLabel: ( { disabled } ) =>
disabled ? INPUT_BEHAVIOUR_TITLE : BUTTON_BEHAVIOUR_TITLE,
icon,
supports: {
Copy link
Contributor Author

@rcrdortiz rcrdortiz Feb 3, 2022

Choose a reason for hiding this comment

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

All the supports are in place but they have no effect on the actual block. The controls are being shown though.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the problem is with __experimentalSkipSerialization in the block definition.
With that flag, style attributes won't be applied to the actual HTML element.

If you remove all the skips in the block definition and add useBlockProps to the block's Edit, the styles magically work. 🙂

import { RichText, useBlockProps } from '@wordpress/block-editor';

<RichText
  { /* all the existing props */ }
  { ...useBlockProps() }
/>

Copy link
Contributor

Choose a reason for hiding this comment

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

This said, I've always been very unclear about the purpose of __experimentalSkipSerialization.
I'll randomly tag @ockham who has worked with them and might have some insights. 🙂

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It magically worked! I had to update the save.js to save the blockProps and remove some logic from the amount.php file. Thanks for the insight!

align: true,
alignWide: true,
html: false,
lightBlockWrapper: true,
color: {
__experimentalSkipSerialization: true,
gradients: true,
},
typography: {
fontSize: true,
__experimentalFontFamily: true,
__experimentalDefaultControls: {
fontSize: true,
},
},
reusable: false,
spacing: {
__experimentalSkipSerialization: true,
padding: [ 'horizontal', 'vertical' ],
__experimentalDefaultControls: {
padding: true,
},
},
__experimentalBorder: {
radius: true,
__experimentalSkipSerialization: true,
__experimentalDefaultControls: {
radius: true,
},
},
},
styles: [
{ name: 'fill', label: __( 'Fill', 'jetpack' ), isDefault: true },
{ name: 'outline', label: __( 'Outline', 'jetpack' ) },
],
edit,
save,
};

export { name, settings };
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* WordPress dependencies
*/
import { InnerBlocks } from '@wordpress/block-editor';

const Save = () => <InnerBlocks.Content />;
Copy link
Contributor

Choose a reason for hiding this comment

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

The Amount block doesn't have InnerBlocks, so this Save wouldn't save any HTML in the post content.
We might as well remove it, and replace it with a simple save: () => null in the block definition.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated to your suggestion.


export default Save;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const ONE_TIME_DONATION = 'oneTimeDonation';
export const MONTHLY_DONATION = 'monthlyDonation';
export const ANNUAL_DONATION = 'annualDonation';
export const DEFAULT_TAB = ONE_TIME_DONATION;
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* WordPress dependencies
*/
import { createContext } from '@wordpress/element';

/**
* Internal dependencies
*/
import { DEFAULT_TAB } from './constants';

const defaultContext = {
activeTab: DEFAULT_TAB,
fallbackLinkUrl: '',
products: [],
currency: '',
showCustomAmount: true,
};

const Context = createContext( defaultContext );

export default Context;
44 changes: 17 additions & 27 deletions projects/plugins/jetpack/extensions/blocks/donations/controls.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
/**
* External dependencies
*/
import { CURRENCIES } from '@automattic/format-currency';

/**
* WordPress dependencies
*/
import { BlockControls, InspectorControls } from '@wordpress/block-editor';
import {
Button,
Dashicon,
Expand All @@ -20,32 +14,28 @@ import {
ToolbarItem,
} from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { BlockControls, InspectorControls } from '@wordpress/block-editor';
import { DOWN } from '@wordpress/keycodes';

/**
* External dependencies
*/
import getSiteFragment from '../../shared/get-site-fragment';

/**
* Internal dependencies
*/
import { ANNUAL_DONATION, MONTHLY_DONATION } from './common/constants';
import { CURRENCIES } from '@automattic/format-currency';
import { SUPPORTED_CURRENCIES } from '../../shared/currencies';
import getSiteFragment from '../../shared/get-site-fragment';

const Controls = props => {
const { attributes, setAttributes } = props;
const { currency, monthlyDonation, annualDonation, showCustomAmount } = attributes;

const toggleDonation = ( interval, show ) => {
const donationAttributes = {
'1 month': 'monthlyDonation',
'1 year': 'annualDonation',
};
const donationAttribute = donationAttributes[ interval ];
const donation = attributes[ donationAttribute ];
const { attributes, setAttributes, onChangeTab } = props;
const { showCustomAmount, currency } = attributes;

setAttributes( {
[ donationAttribute ]: {
...donation,
show,
},
} );
const toggleDonation = ( donationType, show ) => {
setAttributes( { [ donationType ]: show } );
onChangeTab( donationType, show );
};

return (
Expand Down Expand Up @@ -104,13 +94,13 @@ const Controls = props => {
<InspectorControls>
<PanelBody title={ __( 'Settings', 'jetpack' ) }>
<ToggleControl
checked={ monthlyDonation.show }
onChange={ value => toggleDonation( '1 month', value ) }
checked={ attributes[ MONTHLY_DONATION ] }
onChange={ value => toggleDonation( MONTHLY_DONATION, value ) }
label={ __( 'Show monthly donations', 'jetpack' ) }
/>
<ToggleControl
checked={ annualDonation.show }
onChange={ value => toggleDonation( '1 year', value ) }
checked={ attributes[ ANNUAL_DONATION ] }
onChange={ value => toggleDonation( ANNUAL_DONATION, value ) }
label={ __( 'Show annual donations', 'jetpack' ) }
/>
<ToggleControl
Expand Down
Loading