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

Commit 34ee199

Browse files
authored
Improve transform classic product template UX (#9386)
* improve transform classic product template UX * improve layout * not update deps * improve logic * add bold * fix height and width preview on hover * fix label * improve logic for revert button * fix regression
1 parent d9c1471 commit 34ee199

11 files changed

Lines changed: 485 additions & 49 deletions

File tree

assets/js/blocks/classic-template/archive-product.ts

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
} from '../product-query/constants';
2020
import { VARIATION_NAME as productsVariationName } from '../product-query/variations/product-query';
2121
import { createArchiveTitleBlock, createRowBlock } from './utils';
22-
import { type InheritedAttributes } from './types';
22+
import { OnClickCallbackParameter, type InheritedAttributes } from './types';
2323

2424
const createProductsBlock = ( inheritedAttributes: InheritedAttributes ) =>
2525
createBlock(
@@ -71,7 +71,7 @@ const getDescriptionAllowingConversion = ( templateTitle: string ) =>
7171
sprintf(
7272
/* translators: %s is the template title */
7373
__(
74-
"This block serves as a placeholder for your %s. We recommend upgrading to the Products block for more features to edit your products visually. Don't worry, you can always revert back.",
74+
'Transform this template into multiple blocks so you can add, remove, reorder, and customize your %s template.',
7575
'woo-gutenberg-products-block'
7676
),
7777
templateTitle
@@ -96,17 +96,69 @@ const getDescription = ( templateTitle: string, canConvert: boolean ) => {
9696
};
9797

9898
const getButtonLabel = () =>
99-
__( 'Upgrade to Products block', 'woo-gutenberg-products-block' );
99+
__( 'Transform into blocks', 'woo-gutenberg-products-block' );
100+
101+
const onClickCallback = ( {
102+
clientId,
103+
attributes,
104+
getBlocks,
105+
replaceBlock,
106+
selectBlock,
107+
}: OnClickCallbackParameter ) => {
108+
replaceBlock( clientId, getBlockifiedTemplate( attributes ) );
109+
110+
const blocks = getBlocks();
111+
112+
const groupBlock = blocks.find(
113+
( block ) =>
114+
block.name === 'core/group' &&
115+
block.innerBlocks.some(
116+
( innerBlock ) =>
117+
innerBlock.name === 'woocommerce/store-notices'
118+
)
119+
);
120+
121+
if ( groupBlock ) {
122+
selectBlock( groupBlock.clientId );
123+
}
124+
};
125+
126+
const onClickCallbackWithTermDescription = ( {
127+
clientId,
128+
attributes,
129+
getBlocks,
130+
replaceBlock,
131+
selectBlock,
132+
}: OnClickCallbackParameter ) => {
133+
replaceBlock( clientId, getBlockifiedTemplate( attributes, true ) );
134+
135+
const blocks = getBlocks();
136+
137+
const groupBlock = blocks.find(
138+
( block ) =>
139+
block.name === 'core/group' &&
140+
block.innerBlocks.some(
141+
( innerBlock ) =>
142+
innerBlock.name === 'woocommerce/store-notices'
143+
)
144+
);
145+
146+
if ( groupBlock ) {
147+
selectBlock( groupBlock.clientId );
148+
}
149+
};
100150

101151
export const blockifiedProductCatalogConfig = {
102152
getBlockifiedTemplate,
103153
isConversionPossible,
104154
getDescription,
105155
getButtonLabel,
156+
onClickCallback,
106157
};
107158

108159
export const blockifiedProductTaxonomyConfig = {
109160
getBlockifiedTemplate: getBlockifiedTemplateWithTermDescription,
161+
onClickCallback: onClickCallbackWithTermDescription,
110162
isConversionPossible,
111163
getDescription,
112164
getButtonLabel,
Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
:where(.wp-block-woocommerce-legacy-template) {
22
margin-left: auto;
33
margin-right: auto;
4-
max-width: 1000px;
54
}
65

76
.wp-block-woocommerce-classic-template__placeholder-copy {
7+
display: flex;
8+
flex-direction: column;
89
max-width: 900px;
9-
margin-bottom: 30px;
10+
width: 400px;
11+
margin: auto;
1012
}
1113

1214
.wp-block-woocommerce-classic-template__placeholder-warning {
@@ -15,9 +17,12 @@
1517
}
1618

1719
.wp-block-woocommerce-classic-template__placeholder-wireframe {
18-
width: 100%;
1920
height: 250px;
2021
background: #e5e5e5;
22+
display: flex;
23+
flex-wrap: wrap;
24+
gap: $gap-large;
25+
margin: auto;
2126

2227
@media only screen and (min-width: 768px) {
2328
height: auto;
@@ -27,22 +32,26 @@
2732

2833
.wp-block-woocommerce-classic-template__placeholder .wp-block-woocommerce-classic-template__placeholder-image {
2934
display: none;
30-
width: 100%;
35+
width: 400px;
3136
height: auto;
3237

3338
@media only screen and (min-width: 768px) {
3439
display: block;
3540
}
3641
}
3742

38-
39-
.wp-block-woocommerce-classic-template__placeholder-wireframe {
40-
display: flex;
41-
flex-direction: column;
42-
}
43-
4443
.wp-block-woocommerce-classic-template__placeholder-migration-button-container {
4544
justify-content: center;
4645
align-items: center;
4746
margin: 0 auto;
4847
}
48+
49+
.wp-block-woocommerce-classic-template__placeholder-copy__icon-container {
50+
display: flex;
51+
align-items: center;
52+
gap: $gap-small;
53+
54+
span {
55+
@include font-size(larger);
56+
}
57+
}

0 commit comments

Comments
 (0)