Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
Remove data attributes from being saved in html of All products block (
Browse files Browse the repository at this point in the history
…#10032)

* Remove data attributes from being saved in html of All products block

* added old save in deprecated

* Addressed review comments

---------

Co-authored-by: Tung Du <dinhtungdu@gmail.com>
Co-authored-by: Roy Ho <roykho77@gmail.com>
  • Loading branch information
3 people authored Sep 25, 2023
1 parent 9cace64 commit 829fdec
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 11 deletions.
30 changes: 29 additions & 1 deletion assets/js/blocks/products/all-products/deprecated.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,32 @@ const v1 = {
},
};

export default [ v1 ];
const v2 = {
attributes: Object.assign( {}, attributeDefinitions, {
rows: { type: 'number', default: 1 },
} ),
save( { attributes } ) {
const dataAttributes = {};
Object.keys( attributes )
.sort()
.forEach( ( key ) => {
dataAttributes[ key ] = attributes[ key ];
} );
const data = {
'data-attributes': JSON.stringify( dataAttributes ),
};
return (
<div
className={ getBlockClassName(
'wc-block-all-products',
attributes
) }
{ ...data }
>
<InnerBlocks.Content />
</div>
);
},
};

export default [ v2, v1 ];
10 changes: 0 additions & 10 deletions assets/js/blocks/products/all-products/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,12 @@ import { InnerBlocks } from '@wordpress/block-editor';
import { getBlockClassName } from '../utils.js';

export default function save( { attributes } ) {
const dataAttributes = {};
Object.keys( attributes )
.sort()
.forEach( ( key ) => {
dataAttributes[ key ] = attributes[ key ];
} );
const data = {
'data-attributes': JSON.stringify( dataAttributes ),
};
return (
<div
className={ getBlockClassName(
'wc-block-all-products',
attributes
) }
{ ...data }
>
<InnerBlocks.Content />
</div>
Expand Down

0 comments on commit 829fdec

Please sign in to comment.