Skip to content

Commit

Permalink
Refactor Simple Payments block registration
Browse files Browse the repository at this point in the history
  • Loading branch information
monsieur-z committed Oct 26, 2023
1 parent 3bb0b6b commit 0adf412
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 200 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,5 @@
"email": "jetpack@jetpack.com",
"featuredMediaUrl": "./simple-payments_example-1.jpg"
}
},
"editorScript": "file:../editor.js"
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,36 @@
import registerJetpackBlock from '../../shared/register-jetpack-block';
import { name, settings } from '.';
import { registerJetpackBlockFromMetadata } from '../../shared/register-jetpack-block';
import metadata from './block.json';
import deprecatedV1 from './deprecated/v1';
import deprecatedV2 from './deprecated/v2';
import edit from './edit';
import save from './save';
import './editor.scss';

registerJetpackBlock( name, settings );
registerJetpackBlockFromMetadata( metadata, {
edit,
save,
transforms: {
from: [
{
type: 'shortcode',
tag: 'simple-payment',
attributes: {
productId: {
type: 'number',
shortcode: ( { named: { id } } ) => {
if ( ! id ) {
return;
}

const result = parseInt( id, 10 );
if ( result ) {
return result;
}
},
},
},
},
],
},
deprecated: [ deprecatedV1, deprecatedV2 ],
} );
186 changes: 0 additions & 186 deletions projects/plugins/jetpack/extensions/blocks/simple-payments/index.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,14 @@
use Automattic\Jetpack\Blocks;
use Jetpack_Simple_Payments;

const FEATURE_NAME = 'simple-payments';
const BLOCK_NAME = 'jetpack/' . FEATURE_NAME;

/**
* 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_block() {
Blocks::jetpack_register_block(
BLOCK_NAME,
__DIR__,
array(
'render_callback' => __NAMESPACE__ . '\render_block',
'plan_check' => true,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { settings } from '../';
import runBlockFixtureTests from '../../../shared/test/block-fixtures';
import metadata from '../block.json';
import deprecatedV1 from '../deprecated/v1';
import deprecatedV2 from '../deprecated/v2';
import edit from '../edit';
import save from '../save';

const intlNumberFormatSpy = jest.spyOn( Intl, 'NumberFormat' );
beforeEach( () => {
Expand All @@ -8,8 +12,18 @@ beforeEach( () => {
.mockImplementation( () => ( { format: value => `A$${ value.toString() }.00` } ) );
} );

// Need to include all the blocks involved in rendering this block.
// The main block should be the first in the array.
const blocks = [ { name: 'jetpack/simple-payments', settings } ];
const { name } = metadata;
const blocks = [
{
name,
settings: {
...metadata,
edit,
save,

runBlockFixtureTests( 'jetpack/simple-payments', blocks, __dirname );
deprecated: [ deprecatedV1, deprecatedV2 ],
},
},
];

runBlockFixtureTests( name, blocks, __dirname );

0 comments on commit 0adf412

Please sign in to comment.