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

Commit 9f73f37

Browse files
authored
Merge branch 'trunk' into test/9692
2 parents 4b43aa5 + f1d5d48 commit 9f73f37

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1153
-222
lines changed

.github/workflows/auto-merge-dependabot.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
steps:
1414
- name: Dependabot metadata
1515
id: metadata
16-
uses: dependabot/fetch-metadata@v1.4.0
16+
uses: dependabot/fetch-metadata@v1.5.1
1717
with:
1818
github-token: "${{ secrets.GITHUB_TOKEN }}"
1919

.github/workflows/typescript-monitoring.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ jobs:
4646
4747
- name: Get branch name
4848
id: branch-name
49-
uses: tj-actions/branch-names@v6
49+
uses: tj-actions/branch-names@v7
5050

5151
- name: Monitor TypeScript errors
5252
uses: ./.github/monitor-typescript-errors

assets/js/atomic/blocks/product-elements/add-to-cart-form/block.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
"version": "1.0.0",
44
"title": "Add to Cart with Options",
55
"description": "Display a button so the customer can add a product to their cart. Options will also be displayed depending on product type. e.g. quantity, variation.",
6+
"attributes": {
7+
"isDescendentOfSingleProductBlock": {
8+
"type": "boolean",
9+
"default": false
10+
}
11+
},
612
"category": "woocommerce",
713
"keywords": [ "WooCommerce" ],
814
"usesContext": ["postId"],

assets/js/atomic/blocks/product-elements/add-to-cart-form/edit.tsx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,38 @@
11
/**
22
* External dependencies
33
*/
4+
import { useEffect } from '@wordpress/element';
45
import { useBlockProps } from '@wordpress/block-editor';
56
import { __ } from '@wordpress/i18n';
67
import { Button, Disabled, Tooltip } from '@wordpress/components';
78
import { Skeleton } from '@woocommerce/base-components/skeleton';
9+
import { BlockEditProps } from '@wordpress/blocks';
810

911
/**
1012
* Internal dependencies
1113
*/
1214
import './editor.scss';
15+
import { useIsDescendentOfSingleProductBlock } from '../shared/use-is-descendent-of-single-product-block';
1316
export interface Attributes {
1417
className?: string;
18+
isDescendentOfSingleProductBlock: boolean;
1519
}
1620

17-
const Edit = () => {
21+
const Edit = ( props: BlockEditProps< Attributes > ) => {
22+
const { setAttributes } = props;
1823
const blockProps = useBlockProps( {
1924
className: 'wc-block-add-to-cart-form',
2025
} );
26+
const { isDescendentOfSingleProductBlock } =
27+
useIsDescendentOfSingleProductBlock( {
28+
blockClientId: blockProps?.id,
29+
} );
30+
31+
useEffect( () => {
32+
setAttributes( {
33+
isDescendentOfSingleProductBlock,
34+
} );
35+
}, [ setAttributes, isDescendentOfSingleProductBlock ] );
2136

2237
return (
2338
<div { ...blockProps }>

assets/js/atomic/blocks/product-elements/price/edit.tsx

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ import {
88
} from '@wordpress/block-editor';
99
import { useEffect } from '@wordpress/element';
1010
import type { BlockAlignment } from '@wordpress/blocks';
11-
import { useSelect } from '@wordpress/data';
1211

1312
/**
1413
* Internal dependencies
1514
*/
1615
import Block from './block';
16+
import { useIsDescendentOfSingleProductTemplate } from '../shared/use-is-descendent-of-single-product-template';
1717

1818
type UnsupportedAligments = 'wide' | 'full';
1919
type AllowedAlignments = Exclude< BlockAlignment, UnsupportedAligments >;
@@ -53,18 +53,12 @@ const PriceEdit = ( {
5353
};
5454
const isDescendentOfQueryLoop = Number.isFinite( context.queryId );
5555

56-
const isDescendentOfSingleProductTemplate = useSelect(
57-
( select ) => {
58-
const store = select( 'core/edit-site' );
59-
const postId = store?.getEditedPostId< string | undefined >();
56+
let { isDescendentOfSingleProductTemplate } =
57+
useIsDescendentOfSingleProductTemplate( { isDescendentOfQueryLoop } );
6058

61-
return (
62-
postId?.includes( '//single-product' ) &&
63-
! isDescendentOfQueryLoop
64-
);
65-
},
66-
[ isDescendentOfQueryLoop ]
67-
);
59+
if ( isDescendentOfQueryLoop ) {
60+
isDescendentOfSingleProductTemplate = false;
61+
}
6862

6963
useEffect(
7064
() =>

assets/js/atomic/blocks/product-elements/price/style.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,8 @@
44
.wc-block-all-products & {
55
margin-bottom: $gap-small;
66
}
7+
8+
ins {
9+
text-decoration: none;
10+
}
711
}

assets/js/atomic/blocks/product-elements/product-meta/edit.tsx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,16 @@
33
*/
44
import { InnerBlocks, useBlockProps } from '@wordpress/block-editor';
55
import { InnerBlockTemplate } from '@wordpress/blocks';
6-
import { useSelect } from '@wordpress/data';
76

87
/**
98
* Internal dependencies
109
*/
1110
import './editor.scss';
11+
import { useIsDescendentOfSingleProductTemplate } from '../shared/use-is-descendent-of-single-product-template';
1212

1313
const Edit = () => {
14-
const isDescendentOfSingleProductTemplate = useSelect( ( select ) => {
15-
const store = select( 'core/edit-site' );
16-
const postId = store?.getEditedPostId< string | undefined >();
17-
18-
return postId?.includes( '//single-product' );
19-
}, [] );
14+
const isDescendentOfSingleProductTemplate =
15+
useIsDescendentOfSingleProductTemplate();
2016

2117
const TEMPLATE: InnerBlockTemplate[] = [
2218
[

assets/js/atomic/blocks/product-elements/rating/block.tsx

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,35 @@ const getRatingCount = ( product: ProductResponseItem ) => {
4040
return Number.isFinite( count ) && count > 0 ? count : 0;
4141
};
4242

43+
const getStarStyle = ( rating: number ) => ( {
44+
width: ( rating / 5 ) * 100 + '%',
45+
} );
46+
47+
const NoRating = ( { parentClassName }: { parentClassName: string } ) => {
48+
const starStyle = getStarStyle( 0 );
49+
50+
return (
51+
<div
52+
className={ classnames(
53+
'wc-block-components-product-rating__norating-container',
54+
`${ parentClassName }-product-rating__norating-container`
55+
) }
56+
>
57+
<div
58+
className={ 'wc-block-components-product-rating__norating' }
59+
role="img"
60+
>
61+
<span style={ starStyle } />
62+
</div>
63+
<span>{ __( 'No Reviews', 'woo-gutenberg-products-block' ) }</span>
64+
</div>
65+
);
66+
};
67+
4368
const Rating = ( props: RatingProps ): JSX.Element => {
4469
const { rating, reviews, parentClassName } = props;
4570

46-
const starStyle = {
47-
width: ( rating / 5 ) * 100 + '%',
48-
};
71+
const starStyle = getStarStyle( rating );
4972

5073
const ratingText = sprintf(
5174
/* translators: %f is referring to the average rating value */
@@ -132,11 +155,7 @@ export const Block = ( props: ProductRatingProps ): JSX.Element | null => {
132155
}
133156
);
134157
const mockedRatings = shouldDisplayMockedReviewsWhenProductHasNoReviews ? (
135-
<Rating
136-
rating={ 0 }
137-
reviews={ 0 }
138-
parentClassName={ parentClassName }
139-
/>
158+
<NoRating parentClassName={ parentClassName } />
140159
) : null;
141160

142161
const content = reviews ? (

assets/js/atomic/blocks/product-elements/rating/edit.tsx

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
import type { BlockEditProps } from '@wordpress/blocks';
1010
import { useEffect } from '@wordpress/element';
1111
import { ProductQueryContext as Context } from '@woocommerce/blocks/product-query/types';
12-
import { useSelect } from '@wordpress/data';
1312

1413
/**
1514
* Internal dependencies
@@ -18,6 +17,7 @@ import Block from './block';
1817
import { BlockAttributes } from './types';
1918
import './editor.scss';
2019
import { useIsDescendentOfSingleProductBlock } from '../shared/use-is-descendent-of-single-product-block';
20+
import { useIsDescendentOfSingleProductTemplate } from '../shared/use-is-descendent-of-single-product-template';
2121

2222
const Edit = (
2323
props: BlockEditProps< BlockAttributes > & { context: Context }
@@ -36,21 +36,12 @@ const Edit = (
3636
useIsDescendentOfSingleProductBlock( {
3737
blockClientId: blockProps?.id,
3838
} );
39-
const { isDescendentOfSingleProductTemplate } = useSelect(
40-
( select ) => {
41-
const store = select( 'core/edit-site' );
42-
const postId = store?.getEditedPostId< string | undefined >();
39+
let { isDescendentOfSingleProductTemplate } =
40+
useIsDescendentOfSingleProductTemplate();
4341

44-
return {
45-
isDescendentOfSingleProductTemplate: Boolean(
46-
postId?.includes( '//single-product' ) &&
47-
! isDescendentOfQueryLoop &&
48-
! isDescendentOfSingleProductBlock
49-
),
50-
};
51-
},
52-
[ isDescendentOfQueryLoop, isDescendentOfSingleProductBlock ]
53-
);
42+
if ( isDescendentOfQueryLoop || isDescendentOfSingleProductBlock ) {
43+
isDescendentOfSingleProductTemplate = false;
44+
}
5445

5546
useEffect( () => {
5647
setAttributes( {

assets/js/atomic/blocks/product-elements/rating/style.scss

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,37 @@
5656
margin-top: 0;
5757
margin-bottom: $gap-small;
5858
}
59+
60+
&__norating-container {
61+
display: inline-flex;
62+
flex-direction: row;
63+
align-items: center;
64+
gap: $gap-smaller;
65+
}
66+
67+
&__norating {
68+
display: inline-block;
69+
overflow: hidden;
70+
position: relative;
71+
width: 1.5em;
72+
height: 1.618em;
73+
line-height: 1.618;
74+
font-size: 1em;
75+
/* stylelint-disable-next-line font-family-no-missing-generic-family-keyword */
76+
font-family: star;
77+
font-weight: 400;
78+
-webkit-text-stroke: 2px var(--wp--preset--color--black, #000);
79+
&::before {
80+
content: "\53";
81+
top: 0;
82+
left: 0;
83+
right: 0;
84+
position: absolute;
85+
color: transparent;
86+
white-space: nowrap;
87+
text-align: center;
88+
}
89+
}
5990
}
6091

6192
.wp-block-woocommerce-single-product {

0 commit comments

Comments
 (0)