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

Commit 93a6a8d

Browse files
authored
Merge branch 'trunk' into remove-proptypes-reviews-by-product
2 parents 036b1bf + f1d5d48 commit 93a6a8d

File tree

33 files changed

+502
-127
lines changed

33 files changed

+502
-127
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/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 {
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* External dependencies
3+
*/
4+
import { useSelect } from '@wordpress/data';
5+
6+
export const useIsDescendentOfSingleProductTemplate = () => {
7+
const isDescendentOfSingleProductTemplate = useSelect( ( select ) => {
8+
const store = select( 'core/edit-site' );
9+
const postId = store?.getEditedPostId< string | undefined >();
10+
11+
return Boolean( postId?.includes( '//single-product' ) );
12+
}, [] );
13+
14+
return { isDescendentOfSingleProductTemplate };
15+
};

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

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ import type { BlockEditProps } from '@wordpress/blocks';
66
import EditProductLink from '@woocommerce/editor-components/edit-product-link';
77
import { ProductQueryContext as Context } from '@woocommerce/blocks/product-query/types';
88
import { useEffect } from '@wordpress/element';
9-
import { useSelect } from '@wordpress/data';
109

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

1818
const Edit = ( {
1919
attributes,
@@ -32,22 +32,12 @@ const Edit = ( {
3232
const { isDescendentOfSingleProductBlock } =
3333
useIsDescendentOfSingleProductBlock( { blockClientId: blockProps.id } );
3434

35-
const isDescendentOfSingleProductTemplate = useSelect(
36-
( select ) => {
37-
const store = select( 'core/edit-site' );
38-
const postId = store?.getEditedPostId< string | undefined >();
35+
let { isDescendentOfSingleProductTemplate } =
36+
useIsDescendentOfSingleProductTemplate();
3937

40-
if ( ! postId ) {
41-
return false;
42-
}
43-
44-
return (
45-
postId.includes( '//single-product' ) &&
46-
! isDescendentOfQueryLoop
47-
);
48-
},
49-
[ isDescendentOfQueryLoop ]
50-
);
38+
if ( isDescendentOfQueryLoop ) {
39+
isDescendentOfSingleProductTemplate = false;
40+
}
5141

5242
useEffect(
5343
() =>

0 commit comments

Comments
 (0)