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

Commit

Permalink
Merge branch 'trunk' of github.com:woocommerce/woocommerce-gutenberg-…
Browse files Browse the repository at this point in the history
…products-block into add/4965-product-title
  • Loading branch information
gigitux committed Jan 6, 2022
2 parents 6d79824 + f2a2a3e commit 4bcdc58
Show file tree
Hide file tree
Showing 43 changed files with 1,158 additions and 872 deletions.
2 changes: 2 additions & 0 deletions assets/js/base/components/formatted-monetary-amount/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ interface FormattedMonetaryAmountProps
extends Omit< NumberFormatProps, 'onValueChange' > {
className?: string;
displayType?: NumberFormatProps[ 'displayType' ];
allowNegative?: boolean;
isAllowed?: ( formattedValue: NumberFormatValues ) => boolean;
value: number | string; // Value of money amount.
currency: Currency | Record< string, never >; // Currency configuration object.
onValueChange?: ( unit: number ) => void; // Function to call when value changes.
Expand Down
29 changes: 29 additions & 0 deletions assets/js/base/components/price-slider/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { Currency, isObject } from '@woocommerce/types';
import './style.scss';
import { constrainRangeSliderValues } from './constrain-range-slider-values';
import FilterSubmitButton from '../filter-submit-button';
import { isValidMaxValue, isValidMinValue } from './utils';

export interface PriceSliderProps {
/**
Expand Down Expand Up @@ -240,9 +241,27 @@ const PriceSlider = ( {
) {
return;
}

const isMin = event.target.classList.contains(
'wc-block-price-filter__amount--min'
);

// When the user inserts in the max price input a value less or equal than the current minimum price,
// we set to 0 the minimum price.
if ( minPriceInput >= maxPriceInput ) {
const values = constrainRangeSliderValues(
[ 0, maxPriceInput ],
null,
null,
stepValue,
isMin
);
return onChange( [
parseInt( values[ 0 ], 10 ),
parseInt( values[ 1 ], 10 ),
] );
}

const values = constrainRangeSliderValues(
[ minPriceInput, maxPriceInput ],
null,
Expand Down Expand Up @@ -351,6 +370,12 @@ const PriceSlider = ( {
'Filter products by minimum price',
'woo-gutenberg-products-block'
) }
allowNegative={ false }
isAllowed={ isValidMinValue( {
minConstraint,
minorUnit: currency.minorUnit,
currentMaxValue: maxPriceInput,
} ) }
onValueChange={ ( value ) => {
if ( value === minPriceInput ) {
return;
Expand All @@ -369,6 +394,10 @@ const PriceSlider = ( {
'Filter products by maximum price',
'woo-gutenberg-products-block'
) }
isAllowed={ isValidMaxValue( {
maxConstraint,
minorUnit: currency.minorUnit,
} ) }
onValueChange={ ( value ) => {
if ( value === maxPriceInput ) {
return;
Expand Down
41 changes: 41 additions & 0 deletions assets/js/base/components/price-slider/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* External dependencies
*/
import { NumberFormatValues } from 'react-number-format';

/**
Check if that the value is minor than the max price and greater than 0.
*/
export const isValidMaxValue = ( {
maxConstraint,
minorUnit,
}: {
maxConstraint: number;
minorUnit: number;
} ) => ( { floatValue }: NumberFormatValues ): boolean => {
const maxPrice = maxConstraint / 10 ** minorUnit;

return floatValue !== undefined && floatValue <= maxPrice && floatValue > 0;
};

/**
Check if that the value is minor than the max price and greater than 0.
*/
export const isValidMinValue = ( {
minConstraint,
currentMaxValue,
minorUnit,
}: {
minConstraint: number;
currentMaxValue: number;
minorUnit: number;
} ) => ( { floatValue }: NumberFormatValues ): boolean => {
const minPrice = minConstraint / 10 ** minorUnit;
const currentMaxPrice = currentMaxValue / 10 ** minorUnit;

return (
floatValue !== undefined &&
floatValue >= minPrice &&
floatValue < currentMaxPrice
);
};
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
/**
* External dependencies
*/
import { StoreNoticesProvider } from '@woocommerce/base-context';
import { useEmitResponse } from '@woocommerce/base-context/hooks';

/**
* Internal dependencies
*/
import { PaymentMethods } from '../../../payment-methods';

const Block = (): JSX.Element | null => {
const { noticeContexts } = useEmitResponse();

return (
<StoreNoticesProvider context={ noticeContexts.PAYMENTS }>
<PaymentMethods />
</StoreNoticesProvider>
);
return <PaymentMethods />;
};

export default Block;
1 change: 1 addition & 0 deletions assets/js/blocks/cart-checkout/mini-cart/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const settings = {
* to add color classes and style to the wrapper.
*/
__experimentalSkipSerialization: true,
background: false,
},
/**
* We need this experimental flag because we don't want to style the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
border: 0.15em solid;
border-radius: 1em;
box-sizing: border-box;
color: #000;
color: inherit;
display: flex;
font-size: 0.875em;
font-weight: 600;
Expand Down
8 changes: 4 additions & 4 deletions assets/js/blocks/legacy-template/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,28 @@ import { __ } from '@wordpress/i18n';
export const TEMPLATES: Record< string, Record< string, string > > = {
'single-product': {
title: __(
'WooCommerce Single Product Template',
'WooCommerce Single Product Block',
'woo-gutenberg-products-block'
),
placeholder: 'single-product',
},
'archive-product': {
title: __(
'WooCommerce Product Archive Template',
'WooCommerce Product Grid Block',
'woo-gutenberg-products-block'
),
placeholder: 'archive-product',
},
'taxonomy-product_cat': {
title: __(
'WooCommerce Product Taxonomy Template',
'WooCommerce Product Taxonomy Block',
'woo-gutenberg-products-block'
),
placeholder: 'archive-product',
},
'taxonomy-product_tag': {
title: __(
'WooCommerce Product Tag Template',
'WooCommerce Product Tag Block',
'woo-gutenberg-products-block'
),
placeholder: 'archive-product',
Expand Down
5 changes: 5 additions & 0 deletions assets/js/blocks/legacy-template/editor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
margin-bottom: 30px;
}

.wp-block-woocommerce-legacy-template__placeholder-warning {
border-left: 5px solid #2181d2;
padding-left: em(40px);
}

.wp-block-woocommerce-legacy-template__placeholder-wireframe {
width: 100%;
height: 250px;
Expand Down
28 changes: 21 additions & 7 deletions assets/js/blocks/legacy-template/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,28 @@ const Edit = ( { attributes }: Props ) => {
className="wp-block-woocommerce-legacy-template__placeholder"
>
<div className="wp-block-woocommerce-legacy-template__placeholder-copy">
{ sprintf(
/* translators: %s is the template title */
__(
'This is an editor placeholder for the %s. On your store this will be replaced by the template and display with your product image(s), title, price, etc. You can move this placeholder around and add further blocks around it to extend the template.',
<p className="wp-block-woocommerce-legacy-template__placeholder-warning">
<strong>
{ __(
'Attention: Do not remove this block!',
'woo-gutenberg-products-block'
) }
</strong>{ ' ' }
{ __(
'Removal will cause unintended effects on your store.',
'woo-gutenberg-products-block'
),
templateTitle
) }
) }
</p>
<p>
{ sprintf(
/* translators: %s is the template title */
__(
'This is an editor placeholder for the %s. On your store this will be replaced by the template and display with your product image(s), title, price, etc. You can move this placeholder around and add further blocks around it to extend the template.',
'woo-gutenberg-products-block'
),
templateTitle
) }
</p>
</div>
<div className="wp-block-woocommerce-legacy-template__placeholder-wireframe">
<img
Expand Down
10 changes: 10 additions & 0 deletions assets/js/editor-components/feedback-prompt/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,13 @@ export const CartCheckoutFeedbackPrompt = () => (
url="https://github.com/woocommerce/woocommerce-gutenberg-products-block/issues/new?template=--cart-checkout-feedback.md"
/>
);

export const LegacyFeedbackPrompt = () => (
<FeedbackPrompt
text={ __(
'We are working on a better editing experience that will replace legacy blocks. Keep an eye out for updates!',
'woo-gutenberg-products-block'
) }
url="https://github.com/woocommerce/woocommerce-gutenberg-products-block/issues/new?template=--legacy-block-feedback.md"
/>
);
6 changes: 3 additions & 3 deletions bin/hook-docs/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const {
returns,
example,
related,
files,
} = require( '../format-hook-doc' );
const {
createDocs,
Expand Down Expand Up @@ -52,9 +53,8 @@ const generate = ( hooks ) => {
...sectionWithHeading( exceptions( hookDocs ), 'Exceptions' ),
...sectionWithHeading( returns( hookDocs ), 'Returns' ),
...sectionWithHeading( example( hookDocs ), 'Example' ),
...sectionWithHeading( related( hookDocs ), 'Related' ),
{ h3: `Source` },
{ p: `File: [${ hook.file }](../src/${ hook.file })` },
...sectionWithHeading( related( hookDocs ), 'See' ),
...sectionWithHeading( files( hook.file ), 'Source' ),
{ hr: '' },
].filter( Boolean );
} ),
Expand Down
Loading

0 comments on commit 4bcdc58

Please sign in to comment.